Annotation of loncom/interface/londocs.pm, revision 1.484.2.89
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.89! raeburn 4: # $Id: londocs.pm,v 1.484.2.88 2020/03/12 07:40:51 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.19 raeburn 43: use Apache::lonextresedit();
1.484.2.43 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.484.2.7 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
1.484.2.51 raeburn 49: use File::MMagic;
1.329 droeschl 50: use Apache::lonlocal;
51: use Cwd;
52: use LONCAPA qw(:DEFAULT :match);
53:
54: my $iconpath;
55:
56: my %hash;
57:
58: my $hashtied;
59: my %alreadyseen=();
60:
61: my $hadchanges;
1.484.2.37 raeburn 62: my $suppchanges;
1.329 droeschl 63:
64:
65: my %help=();
66:
67:
68: sub mapread {
69: my ($coursenum,$coursedom,$map)=@_;
70: return
71: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
72: $map);
73: }
74:
75: sub storemap {
1.484.2.7 raeburn 76: my ($coursenum,$coursedom,$map,$contentchg)=@_;
77: my $report;
78: if (($contentchg) && ($map =~ /^default/)) {
79: $report = 1;
80: }
1.329 droeschl 81: my ($outtext,$errtext)=
82: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 83: $map,1,$report);
1.329 droeschl 84: if ($errtext) { return ($errtext,2); }
1.364 bisitz 85:
1.484.2.37 raeburn 86: if ($map =~ /^default/) {
87: $hadchanges=1;
88: } else {
89: $suppchanges=1;
90: }
1.329 droeschl 91: return ($errtext,0);
92: }
93:
94:
95:
96: sub authorhosts {
97: my %outhash=();
98: my $home=0;
99: my $other=0;
100: foreach my $key (keys(%env)) {
101: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
102: my $role=$1;
103: my $realm=$2;
104: my ($start,$end)=split(/\./,$env{$key});
105: if (($start) && ($start>time)) { next; }
106: if (($end) && (time>$end)) { next; }
107: my ($ca,$cd);
108: if ($1 eq 'au') {
109: $ca=$env{'user.name'};
110: $cd=$env{'user.domain'};
111: } else {
112: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
113: }
114: my $allowed=0;
115: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
116: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 117: foreach my $id (@ids) {
118: if ($id eq $myhome) {
119: $allowed=1;
120: last;
121: }
122: }
1.329 droeschl 123: if ($allowed) {
124: $home++;
1.484 raeburn 125: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 126: } else {
1.484 raeburn 127: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 128: $other++;
129: }
130: }
131: }
132: return ($home,$other,%outhash);
133: }
134:
135:
136: sub clean {
137: my ($title)=@_;
138: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 139: return $title;
1.329 droeschl 140: }
141:
1.484.2.67 raeburn 142: sub default_folderpath {
143: my ($coursenum,$coursedom,$navmapref) = @_;
144: return unless ($coursenum && $coursedom && ref($navmapref));
145: # Check if entire course is hidden and/or encrypted
146: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
147: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
148: unless (ref($$navmapref)) {
149: $$navmapref = Apache::lonnavmaps::navmap->new();
150: }
151: if (ref($$navmapref)) {
152: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
153: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
154: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
155: unless (@resources) {
156: $hiddenmap = 1;
157: unless ($env{'request.role.adv'}) {
158: $hiddentop = 1;
159: if ($env{'form.folder'}) {
160: undef($env{'form.folder'});
161: }
162: }
163: }
164: }
165: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
166: $encryptmap = 1;
167: }
168: }
169: unless ($hiddentop) {
170: $folderpath='default&'.&escape(&mt('Main Content')).
171: '::'.$hiddenmap.':'.$encryptmap.'::';
172: }
173: if (wantarray) {
174: return ($folderpath,$hiddentop);
175: } else {
176: return $folderpath;
177: }
178: }
1.329 droeschl 179:
180: sub dumpcourse {
181: my ($r) = @_;
1.408 raeburn 182: my $crstype = &Apache::loncommon::course_type();
1.484.2.43 raeburn 183: my ($starthash,$js);
184: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
185: $js = <<"ENDJS";
186: <script type="text/javascript">
187: // <![CDATA[
188:
189: function hide_searching() {
190: if (document.getElementById('searching')) {
191: document.getElementById('searching').style.display = 'none';
192: }
193: return;
194: }
195:
196: // ]]>
197: </script>
198: ENDJS
199: $starthash = {
200: add_entries => {'onload' => "hide_searching();"},
201: };
202: }
203: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
204: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 205: $r->print(&startContentScreen('tools'));
1.329 droeschl 206: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 207: unless ($home) {
208: $r->print(&endContentScreen());
209: return '';
210: }
1.329 droeschl 211: my $origcrsid=$env{'request.course.id'};
212: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
213: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
214: # Do the dumping
1.484 raeburn 215: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
216: $r->print(&endContentScreen());
217: return '';
218: }
1.484.2.24 raeburn 219: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 220: $r->print('<h3>'.&mt('Copying Files').'</h3>');
221: my $title=$env{'form.authorfolder'};
222: $title=&clean($title);
1.484.2.43 raeburn 223: my ($navmap,$errormsg) =
224: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
225: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
226: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
227: my (%maps,%resources,%titles);
228: if (!ref($navmap)) {
229: $r->print($errormsg.
230: &endContentScreen());
231: return '';
232: } else {
233: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
234: 'dumpdocs',$cdom,$cnum);
235: }
236: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
237: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
238: %newcontent,%has_simpleprobs);
239: foreach my $item (sort {$a <=> $b} (@todump)) {
240: my $name = $env{'form.namefor_'.$item};
241: if ($resources{$item}) {
242: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
243: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
244: $tocopy{$1} = $name;
245: $display{$item} = $1;
246: $lookup{$1} = $item;
247: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
248: $simpleproblems{$item} = {
249: symb => $resources{$item},
250: name => $name,
251: };
252: $display{$item} = 'simpleproblem_'.$name;
253: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
254: $has_simpleprobs{$1}{$id} = $item;
255: }
256: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
257: my $marker = $1;
258: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
259: $simplepages{$item} = {
260: res => $res,
261: title => $titles{$item},
262: db => $db_name,
263: marker => $marker,
264: symb => $resources{$item},
265: name => $name,
266: };
267: $display{$item} = '/'.$res;
268: }
269: } elsif ($maps{$item}) {
270: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
271: $tocopy{$1} = $name;
272: $display{$item} = $1;
273: $lookup{$1} = $item;
274: }
275: } else {
276: next;
277: }
278: }
1.329 droeschl 279: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
280: $crs=~s/\_/\//g;
1.484.2.43 raeburn 281: my $mm = new File::MMagic;
282: my $prefix = "/uploaded/$cdom/$cnum/";
283: %replacehash = %tocopy;
284: foreach my $item (sort(keys(%simpleproblems))) {
285: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
286: $newcontent{$display{$item}} = $content;
287: }
288: my $gateway = Apache::lonhtmlgateway->new('web');
289: foreach my $item (sort(keys(%simplepages))) {
290: if (ref($simplepages{$item}) eq 'HASH') {
291: my $pagetitle = $simplepages{$item}{'title'};
292: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
293: my %contents;
294: foreach my $field (keys(%fields)) {
295: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
296: my $name = $1;
297: my $msg = $fields{$field};
298: if ($name eq 'webreferences') {
299: if ($msg =~ m{^https?://}) {
300: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
301: }
302: } else {
303: $msg = &Encode::decode('utf8',$msg);
304: $msg = $gateway->process_outgoing_html($msg,1);
305: $contents{$name} = $msg;
306: }
307: } elsif ($field eq 'uploaded.photourl') {
308: my $marker = $simplepages{$item}{marker};
309: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
310: my $filepath = $1;
311: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
312: if ($fname ne '') {
313: $fname=~s/\.(\w+)$//;
314: my $ext=$1;
315: $fname = &clean($fname);
316: $fname.='.'.$ext;
317: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
318: $replacehash{$filepath} = $relpath.$fname;
319: $deps{$item}{$filepath} = 1;
320: }
321: }
322: }
323: }
324: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
325: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
326: my $content = '
327: <html>
328: <head>
329: <title>'.$pagetitle.'</title>
330: </head>
331: <body bgcolor="#ffffff">';
332: if ($contents{title}) {
333: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
334: }
335: if ($contents{image}) {
336: $content .= "\n".$contents{image};
337: }
338: if ($contents{content}) {
339: $content .= '
340: <div class="LC_Box">
1.484.2.50 raeburn 341: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.484.2.43 raeburn 342: $contents{content}.'
343: </div>';
344: }
345: if ($contents{webreferences}) {
346: $content .= '
347: <div class="LC_Box">
1.484.2.50 raeburn 348: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.484.2.43 raeburn 349: $contents{webreferences}.'
350: </div>';
351: }
352: $content .= '
353: </body>
354: </html>
355: ';
356: $newcontent{'/'.$simplepages{$item}{res}} = $content;
357: }
358: }
359: foreach my $item (keys(%tocopy)) {
360: unless ($item=~/\.(sequence|page)$/) {
361: my $currurlpath = $prefix.$item;
362: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
363: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
364: }
365: }
366: foreach my $num (sort {$a <=> $b} (@todump)) {
367: my $src = $display{$num};
368: next if ($src eq '');
369: my @needcopy = ();
370: if ($replacehash{$src}) {
371: push(@needcopy,$src);
372: if (ref($deps{$num}) eq 'HASH') {
373: foreach my $dep (sort(keys(%{$deps{$num}}))) {
374: if ($replacehash{$dep}) {
375: push(@needcopy,$dep);
376: }
377: }
378: }
379: } elsif ($src =~ /^simpleproblem_/) {
380: push(@needcopy,$src);
381: }
382: next if (@needcopy == 0);
383: my ($result,$depresult);
384: for (my $i=0; $i<@needcopy; $i++) {
385: my $item = $needcopy[$i];
386: my $newfilename;
387: if ($simpleproblems{$num}) {
388: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
389: } else {
390: $newfilename=$title.'/'.$replacehash{$item};
391: }
392: $newfilename=~s/\.(\w+)$//;
393: my $ext=$1;
394: $newfilename=&clean($newfilename);
395: $newfilename.='.'.$ext;
396: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
397: if ($newrelpath ne $replacehash{$item}) {
398: $replacehash{$item} = $newrelpath;
399: }
400: my @dirs=split(/\//,$newfilename);
401: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
402: my $makepath=$path;
403: my $fail;
404: my $origin;
405: for (my $i=0;$i<$#dirs;$i++) {
406: $makepath.='/'.$dirs[$i];
407: unless (-e $makepath) {
408: unless(mkdir($makepath,0755)) {
409: $fail = &mt('Directory creation failed.');
410: }
411: }
412: }
413: if ($i == 0) {
414: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
415: } else {
416: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
417: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
418: &mt('(dependency)').'</span>: ';
419: }
420: if (-e $path.'/'.$newfilename) {
421: $fail = &mt('Destination already exists -- not overwriting.');
422: } else {
423: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
424: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
425: ($item =~ /^simpleproblem_/)) {
426: print $fh $newcontent{$item};
427: } else {
428: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
429: if (-e $fileloc) {
430: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
431: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
432: (ref($has_simpleprobs{$item}) eq 'HASH')) {
433: my %changes = %{$has_simpleprobs{$item}};
434: my $content = &Apache::lonclonecourse::rewritefile(
435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
436: (%replacehash,$crs => '')
437: );
438: my $updatedcontent = '';
439: my $parser = HTML::TokeParser->new(\$content);
440: $parser->attr_encoded(1);
441: while (my $token = $parser->get_token) {
442: if ($token->[0] eq 'S') {
443: if (($token->[1] eq 'resource') &&
444: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
445: ($changes{$token->[2]->{'id'}})) {
446: my $id = $token->[2]->{'id'};
447: $updatedcontent .= '<'.$token->[1];
448: foreach my $attrib (@{$token->[3]}) {
449: next unless ($attrib =~ /^(src|type|title|id)$/);
450: if ($attrib eq 'src') {
451: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
452: if ($file) {
453: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
454: } else {
455: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
456: }
457: } else {
458: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
459: }
460: }
461: $updatedcontent .= ' />'."\n";
462: } else {
463: $updatedcontent .= $token->[4]."\n";
464: }
465: } else {
466: $updatedcontent .= $token->[2];
467: }
468: }
469: print $fh $updatedcontent;
470: } else {
471: print $fh &Apache::lonclonecourse::rewritefile(
472: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
473: (%replacehash,$crs => '')
474: );
475: }
476: } else {
477: print $fh
478: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
479: }
480: } else {
481: $fail = &mt('Source does not exist.');
482: }
483: }
484: $fh->close();
485: } else {
486: $fail = &mt('Could not write to destination.');
487: }
488: }
489: my $text;
490: if ($fail) {
491: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
492: } else {
493: $text = '<span class="LC_success">'.&mt('ok').'</span>';
494: }
495: if ($i == 0) {
496: $result .= $text;
497: } else {
498: $depresult .= $text.'</li>';
499: }
500: }
501: $r->print($result);
502: if ($depresult) {
503: $r->print('<ul>'.$depresult.'</ul>');
504: }
505: }
1.329 droeschl 506: } else {
1.484.2.43 raeburn 507: my ($navmap,$errormsg) =
508: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
509: if (!ref($navmap)) {
510: $r->print($errormsg);
511: } else {
512: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
513: $r->rflush();
514: my ($preamble,$formname);
515: $formname = 'dumpdoc';
516: unless ($home==1) {
517: $preamble = '<div class="LC_left_float">'.
518: '<fieldset><legend>'.
519: &mt('Select the Authoring Space').
520: '</legend><select name="authorspace">';
521: }
522: my @orderspaces = ();
523: foreach my $key (sort(keys(%outhash))) {
524: if ($key=~/^home_(.+)$/) {
525: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
526: unshift(@orderspaces,$1);
527: } else {
528: push(@orderspaces,$1);
529: }
530: }
531: }
532: if ($home>1) {
533: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
534: }
535: foreach my $user (@orderspaces) {
536: if ($home==1) {
537: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
538: } else {
539: $preamble .= '<option value="'.$user.'">'.$user.' - '.
540: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
541: }
542: }
543: unless ($home==1) {
544: $preamble .= '</select></fieldset></div>'."\n";
545: }
546: my $title=$origcrsdata{'description'};
547: $title=~s/[\/\s]+/\_/gs;
548: $title=&clean($title);
549: $preamble .= '<div class="LC_left_float">'.
550: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
551: '<input type="text" size="50" name="authorfolder" value="'.
552: $title.'" />'.
553: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
554: my %uploadedfiles;
555: &tiehash();
556: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
557: my ($ext)=($file=~/\.(\w+)$/);
558: # FIXME Check supplemental here
559: my $title=$hash{'title_'.$hash{
560: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
561: if (!$title) {
562: $title=$file;
563: } else {
564: $title=~s|/|_|g;
565: }
566: $title=~s/\.(\w+)$//;
567: $title=&clean($title);
568: $title.='.'.$ext;
569: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
570: $uploadedfiles{$file} = $title;
571: }
572: &untiehash();
573: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
574: undef,undef,$preamble,$home,\%uploadedfiles));
575: }
1.329 droeschl 576: }
1.484 raeburn 577: $r->print(&endContentScreen());
1.329 droeschl 578: }
579:
1.484.2.43 raeburn 580: sub recurse_html {
581: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
582: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
583: my (%allfiles,%codebase);
584: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
585: if (keys(%allfiles)) {
586: foreach my $dependency (keys(%allfiles)) {
587: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
588: my ($depurl,$relfile,$newcontainer);
589: if ($dependency =~ m{^/}) {
590: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
591: $relfile = $1;
592: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
593: $newcontainer = $1;
594: next if ($replacehash->{$newcontainer});
595: }
596: $depurl = $dependency;
597: } else {
598: next;
599: }
600: } else {
601: $relfile = $dependency;
602: $depurl = $currurlpath;
603: $depurl =~ s{[^/]+$}{};
604: $depurl .= $dependency;
605: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
606: }
607: next if ($relfile eq '');
608: my $newname = $replacehash->{$container};
609: $newname =~ s{[^/]+$}{};
610: $replacehash->{$newcontainer} = $newname.$relfile;
611: $deps->{$item}{$newcontainer} = 1;
612: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
613: my $depfile = &Apache::lonnet::filelocation('',$depurl);
614: my $type = $mm->checktype_filename($depfile);
615: if ($type eq 'text/html') {
616: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
617: }
618: }
619: }
620: }
621: return;
622: }
623:
1.329 droeschl 624: sub group_import {
625: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.484.2.23 raeburn 626: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
627: %removeparam,$importuploaded,$fixuperrors);
628: $allmaps = {};
1.329 droeschl 629: while (@files) {
630: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 631: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 632: && ($caller eq 'londocs')
633: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 634:
1.329 droeschl 635: my $errtext = '';
636: my $fatal = 0;
637: my $newmapstr = '<map>'."\n".
638: '<resource id="1" src="" type="start"></resource>'."\n".
639: '<link from="1" to="2" index="1"></link>'."\n".
640: '<resource id="2" src="" type="finish"></resource>'."\n".
641: '</map>';
642: $env{'form.output'}=$newmapstr;
643: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
644: 'output',$1.$2);
1.484.2.27 raeburn 645: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 646: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
647: $fatal = 2;
648: }
649: if ($fatal) {
650: return ($errtext,$fatal);
651: }
652: }
653: if ($url) {
1.484.2.23 raeburn 654: if (($caller eq 'londocs') &&
655: ($folder =~ /^default/)) {
1.484.2.27 raeburn 656: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.484.2.23 raeburn 657: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
658: my $cid = $coursedom.'_'.$coursenum;
659: $allmaps =
660: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
661: $chome,$cid);
662: $donechk = 1;
663: }
664: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
665: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
666: \%addedmaps,\%hierarchy,\%titles,$allmaps);
667: $importuploaded = 1;
668: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
669: next if ($allmaps->{$url});
670: }
671: }
1.344 bisitz 672: if (!$residx
1.329 droeschl 673: || defined($LONCAPA::map::zombies[$residx])) {
674: $residx = &LONCAPA::map::getresidx($url,$residx);
675: push(@LONCAPA::map::order, $residx);
676: }
677: my $ext = 'false';
678: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
679: $name = &LONCAPA::map::qtunescape($name);
1.484.2.27 raeburn 680: if ($name eq '') {
1.484.2.30 raeburn 681: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.484.2.27 raeburn 682: }
683: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
684: my $filepath = $1;
685: my $fname = $name;
686: if ($fname =~ /^\W+$/) {
687: $fname = 'web';
688: } else {
689: $fname =~ s/\W/_/g;
690: }
1.484.2.62 raeburn 691: if (length($fname) > 15) {
1.484.2.27 raeburn 692: $fname = substr($fname,0,14);
693: }
694: my $initialtext = &mt('Replace with your own content.');
695: my $newhtml = <<END;
1.484.2.31 raeburn 696: <html>
1.484.2.27 raeburn 697: <head>
698: <title>$name</title>
699: </head>
700: <body bgcolor="#ffffff">
701: $initialtext
702: </body>
703: </html>
704: END
705: $env{'form.output'}=$newhtml;
706: my $result =
707: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
708: 'output',
709: "$filepath/$residx/$fname.html");
710: if ($result =~ m{^/uploaded/}) {
711: $url = $result;
712: if ($filepath =~ /^supplemental/) {
713: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
714: $env{'user.domain'}.'___&&&___'.$name;
715: }
716: } else {
717: return (&mt('Failed to save new web page.'),1);
718: }
719: }
1.484.2.30 raeburn 720: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 721: $LONCAPA::map::resources[$residx] =
1.329 droeschl 722: join(':', ($name, $url, $ext, 'normal', 'res'));
723: }
724: }
1.484.2.23 raeburn 725: if ($importuploaded) {
726: my %import_errors;
727: my %updated = (
728: removefrommap => \%removefrommap,
729: removeparam => \%removeparam,
730: );
1.484.2.26 raeburn 731: my ($result,$msgsarray,$lockerror) =
732: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.484.2.23 raeburn 733: if (keys(%import_errors) > 0) {
734: $fixuperrors =
735: '<p span class="LC_warning">'."\n".
736: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
737: '<ul>'."\n";
738: foreach my $key (sort(keys(%import_errors))) {
739: $fixuperrors .= '<li>'.$key.'</li>'."\n";
740: }
741: $fixuperrors .= '</ul></p>'."\n";
742: }
1.484.2.26 raeburn 743: if (ref($msgsarray) eq 'ARRAY') {
744: if (@{$msgsarray} > 0) {
745: $fixuperrors .= '<p class="LC_info">'.
746: join('<br />',@{$msgsarray}).
747: '</p>';
748: }
749: }
750: if ($lockerror) {
751: $fixuperrors .= '<p class="LC_error">'.
752: $lockerror.
753: '</p>';
754: }
1.484.2.23 raeburn 755: }
756: my ($errtext,$fatal) =
757: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.484.2.37 raeburn 758: unless ($fatal) {
759: if ($folder =~ /^supplemental/) {
760: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.484.2.39 raeburn 761: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
762: $folder.'.'.$container);
1.484.2.37 raeburn 763: }
764: }
1.484.2.23 raeburn 765: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 766: }
767:
768: sub log_docs {
1.484.2.8 raeburn 769: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 770: }
771:
772: {
773: my @oldresources=();
774: my @oldorder=();
775: my $parmidx;
776: my %parmaction=();
777: my %parmvalue=();
778: my $changedflag;
779:
780: sub snapshotbefore {
781: @oldresources=@LONCAPA::map::resources;
782: @oldorder=@LONCAPA::map::order;
783: $parmidx=undef;
784: %parmaction=();
785: %parmvalue=();
786: $changedflag=0;
787: }
788:
789: sub remember_parms {
790: my ($idx,$parameter,$action,$value)=@_;
791: $parmidx=$idx;
792: $parmaction{$parameter}=$action;
793: $parmvalue{$parameter}=$value;
794: $changedflag=1;
795: }
796:
797: sub log_differences {
798: my ($plain)=@_;
799: my %storehash=('folder' => $plain,
800: 'currentfolder' => $env{'form.folder'});
801: if ($parmidx) {
802: $storehash{'parameter_res'}=$oldresources[$parmidx];
803: foreach my $parm (keys(%parmaction)) {
804: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
805: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
806: }
807: }
808: my $maxidx=$#oldresources;
809: if ($#LONCAPA::map::resources>$#oldresources) {
810: $maxidx=$#LONCAPA::map::resources;
811: }
812: for (my $idx=0; $idx<=$maxidx; $idx++) {
813: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
814: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
815: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
816: $changedflag=1;
817: }
818: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
819: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
820: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
821: $changedflag=1;
822: }
823: }
824: $storehash{'maxidx'}=$maxidx;
825: if ($changedflag) { &log_docs(\%storehash); }
826: }
827: }
828:
829: sub docs_change_log {
1.484.2.67 raeburn 830: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.484.2.6 raeburn 831: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.67 raeburn 832: my $navmap;
1.483 raeburn 833: my $js = '<script type="text/javascript">'."\n".
834: '// <![CDATA['."\n".
835: &Apache::loncommon::display_filter_js('docslog')."\n".
1.484.2.67 raeburn 836: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.484.2.80 raeburn 837: $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
1.483 raeburn 838: &history_tab_js()."\n".
1.484 raeburn 839: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 840: '// ]]>'."\n".
841: '</script>'."\n";
1.484 raeburn 842: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
843: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.484.2.7 raeburn 844: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 845: my %orderhash;
846: my $container='sequence';
847: my $pathitem;
1.484.2.19 raeburn 848: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 849: $container='page';
850: }
1.484.2.19 raeburn 851: my $folderpath=$env{'form.folderpath'};
852: if ($folderpath eq '') {
1.484.2.67 raeburn 853: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.19 raeburn 854: }
1.484.2.67 raeburn 855: undef($navmap);
1.484.2.19 raeburn 856: $pathitem = '<input type="hidden" name="folderpath" value="'.
857: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 858: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
859: my $jumpto = $readfile;
860: $jumpto =~ s{^/}{};
861: my $tid = 1;
1.484.2.7 raeburn 862: if ($supplementalflag) {
863: $tid = 2;
864: }
1.484.2.19 raeburn 865: my ($breadcrumbtrail) =
1.484.2.18 raeburn 866: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 867: $r->print($breadcrumbtrail.
868: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
869: $readfile));
1.329 droeschl 870: my %docslog=&Apache::lonnet::dump('nohist_docslog',
871: $env{'course.'.$env{'request.course.id'}.'.domain'},
872: $env{'course.'.$env{'request.course.id'}.'.num'});
873:
874: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
875:
876: my %saveable_parameters = ('show' => 'scalar',);
877: &Apache::loncommon::store_course_settings('docs_log',
878: \%saveable_parameters);
879: &Apache::loncommon::restore_course_settings('docs_log',
880: \%saveable_parameters);
881: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 882: # FIXME: internationalization seems wrong here
1.329 droeschl 883: my %lt=('hiddenresource' => 'Resources hidden',
884: 'encrypturl' => 'URL hidden',
885: 'randompick' => 'Randomly pick',
886: 'randomorder' => 'Randomly ordered',
887: 'set' => 'set to',
888: 'del' => 'deleted');
1.484 raeburn 889: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
890: $pathitem."\n".
891: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
892: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
893: $r->print('<div class="LC_left_float">'.
894: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
895: &makedocslogform($filter,1).
896: '</fieldset></div><br clear="all" />');
1.329 droeschl 897: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
898: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
899: &mt('After').'</th>'.
900: &Apache::loncommon::end_data_table_header_row());
901: my $shown=0;
902: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
903: if ($env{'form.displayfilter'} eq 'currentfolder') {
904: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
905: }
906: my @changes=keys(%{$docslog{$id}{'logentry'}});
907: if ($env{'form.displayfilter'} eq 'containing') {
908: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
909: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
910: foreach my $key (@changes) {
911: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
912: }
1.344 bisitz 913: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 914: }
915: my $count = 0;
916: my $time =
917: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
918: my $plainname =
919: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
920: $docslog{$id}{'exe_udom'});
921: my $about_me_link =
922: &Apache::loncommon::aboutmewrapper($plainname,
923: $docslog{$id}{'exe_uname'},
924: $docslog{$id}{'exe_udom'});
925: my $send_msg_link='';
926: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
927: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
928: $send_msg_link ='<br />'.
929: &Apache::loncommon::messagewrapper(&mt('Send message'),
930: $docslog{$id}{'exe_uname'},
931: $docslog{$id}{'exe_udom'});
932: }
933: $r->print(&Apache::loncommon::start_data_table_row());
934: $r->print('<td>'.$time.'</td>
935: <td>'.$about_me_link.
936: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
937: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
938: $send_msg_link.'</td><td>'.
939: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.484.2.19 raeburn 940: my $is_supp = 0;
1.484.2.7 raeburn 941: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
942: $is_supp = 1;
943: }
1.329 droeschl 944: # Before
945: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
946: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
947: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
948: if ($oldname ne $newname) {
1.484.2.7 raeburn 949: my $shown = &LONCAPA::map::qtescape($oldname);
950: if ($is_supp) {
951: $shown = &Apache::loncommon::parse_supplemental_title($shown);
952: }
953: $r->print($shown);
1.329 droeschl 954: }
955: }
956: $r->print('<ul>');
957: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
958: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.484.2.7 raeburn 959: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
960: if ($is_supp) {
961: $shown = &Apache::loncommon::parse_supplemental_title($shown);
962: }
1.484.2.19 raeburn 963: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 964: }
965: }
966: $r->print('</ul>');
967: # After
968: $r->print('</td><td>');
969:
970: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
971: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
972: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
973: if ($oldname ne '' && $oldname ne $newname) {
1.484.2.7 raeburn 974: my $shown = &LONCAPA::map::qtescape($newname);
975: if ($is_supp) {
976: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
977: }
978: $r->print($shown);
1.329 droeschl 979: }
1.364 bisitz 980: }
1.329 droeschl 981: $r->print('<ul>');
982: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
983: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.484.2.7 raeburn 984: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
985: if ($is_supp) {
986: $shown = &Apache::loncommon::parse_supplemental_title($shown);
987: }
988: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 989: }
990: }
991: $r->print('</ul>');
992: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
993: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
994: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
995: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 996: # FIXME: internationalization seems wrong here
1.329 droeschl 997: $r->print('<li>'.
998: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
999: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1000: .'</li>');
1001: }
1002: }
1003: $r->print('</ul>');
1004: }
1005: # End
1006: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1007: $shown++;
1008: if (!($env{'form.show'} eq &mt('all')
1009: || $shown<=$env{'form.show'})) { last; }
1010: }
1.484 raeburn 1011: $r->print(&Apache::loncommon::end_data_table()."\n".
1012: &makesimpleeditform($pathitem)."\n".
1013: '</div></div>');
1014: $r->print(&endContentScreen());
1.329 droeschl 1015: }
1016:
1017: sub update_paste_buffer {
1.484.2.7 raeburn 1018: my ($coursenum,$coursedom,$folder) = @_;
1.484.2.57 raeburn 1019: my (@possibles,%removals,%cuts,$output);
1.484.2.30 raeburn 1020: if ($env{'form.multiremove'}) {
1021: $env{'form.multiremove'} =~ s/,$//;
1022: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1023: }
1024: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1025: if ($env{'form.multicut'}) {
1026: $env{'form.multicut'} =~ s/,$//;
1027: foreach my $item (split(/,/,$env{'form.multicut'})) {
1028: unless ($removals{$item}) {
1029: $cuts{$item} = 1;
1030: push(@possibles,$item.':cut');
1031: }
1032: }
1033: }
1034: if ($env{'form.multicopy'}) {
1035: $env{'form.multicopy'} =~ s/,$//;
1036: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1037: unless ($removals{$item} || $cuts{$item}) {
1038: push(@possibles,$item.':copy');
1039: }
1040: }
1041: }
1042: } elsif ($env{'form.markcopy'}) {
1043: @possibles = split(/,/,$env{'form.markcopy'});
1044: }
1.329 droeschl 1045:
1.484.2.30 raeburn 1046: return if (@possibles == 0);
1.329 droeschl 1047: return if (!defined($env{'form.copyfolder'}));
1048:
1049: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1050: $env{'form.copyfolder'});
1051: return if ($fatal);
1052:
1.484.2.30 raeburn 1053: my %curr_groups = &Apache::longroup::coursegroups();
1054:
1055: # Retrieve current paste buffer suffixes.
1056: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1057: my (%pasteurls,@newpaste);
1058:
1059: # Construct identifiers for current contents of user's paste buffer
1060: if (@currpaste) {
1061: foreach my $suffix (@currpaste) {
1.484.2.87 raeburn 1062: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1063: my $url = $env{'docs.markedcopy_url_'.$suffix};
1064: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1065: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1066: ($url ne '')) {
1067: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1068: $pasteurls{$cid.'_'.$mapidx} = 1;
1069: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1070: $pasteurls{$url} = 1;
1071: } else {
1072: $pasteurls{$cid.'_'.$url} = 1;
1073: }
1074: }
1.484.2.30 raeburn 1075: }
1076: }
1077:
1078: # Mark items for copying (skip any items already in user's paste buffer)
1079: my %addtoenv;
1.484.2.82 raeburn 1080:
1081: my @pathitems = split(/\&/,$env{'form.folderpath'});
1082: my @folderconf = split(/\:/,$pathitems[-1]);
1.484.2.87 raeburn 1083: my $ispage = $folderconf[5];
1.484.2.82 raeburn 1084:
1.484.2.30 raeburn 1085: foreach my $item (@possibles) {
1086: my ($orderidx,$cmd) = split(/:/,$item);
1087: next if ($orderidx =~ /\D/);
1088: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.484.2.82 raeburn 1089: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.484.2.30 raeburn 1090: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1091: my %denied = &action_restrictions($coursenum,$coursedom,
1092: &LONCAPA::map::qtescape($url),
1093: $env{'form.folderpath'},\%curr_groups);
1094: next if ($denied{'copy'});
1095: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 1096: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1097: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1098: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1099: next if (exists($pasteurls{$url}));
1100: } else {
1101: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1102: }
1.484.2.30 raeburn 1103: my ($suffix,$errortxt,$locknotfreed) =
1104: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.484.2.57 raeburn 1105: if ($suffix ne '') {
1106: push(@newpaste,$suffix);
1107: } else {
1108: if ($locknotfreed) {
1109: return $locknotfreed;
1110: }
1.484.2.30 raeburn 1111: }
1112: if (&is_supplemental_title($title)) {
1113: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1114: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1115: }
1116:
1117: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1118: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1119: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1120: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.484.2.82 raeburn 1121: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.484.2.30 raeburn 1122: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1123: my $prefix = $1;
1124: my $subdir =$2;
1125: if ($subdir eq '') {
1126: $subdir = $prefix;
1.484.2.7 raeburn 1127: }
1.484.2.30 raeburn 1128: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1129: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1130: \%hierarchy,\%titles,\%allmaps);
1131: if (ref($hierarchy{$url}) eq 'HASH') {
1132: my ($nested,$nestednames);
1133: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1134: $nested =~ s/\&$//;
1135: $nestednames =~ s/\Q___&&&___\E$//;
1136: if ($nested ne '') {
1137: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1138: }
1139: if ($nestednames ne '') {
1140: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1141: }
1.484.2.7 raeburn 1142: }
1143: }
1.484.2.57 raeburn 1144: if ($locknotfreed) {
1145: $output = $locknotfreed;
1146: last;
1147: }
1.484.2.7 raeburn 1148: }
1.484.2.30 raeburn 1149: if (@newpaste) {
1150: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1151: }
1.484.2.7 raeburn 1152: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1153: delete($env{'form.markcopy'});
1.484.2.57 raeburn 1154: return $output;
1.329 droeschl 1155: }
1156:
1.484.2.7 raeburn 1157: sub recurse_uploaded_maps {
1158: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1159: if (ref($hierarchy->{$url}) eq 'HASH') {
1160: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1161: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1162: my (@uploaded,@names,%shorter);
1163: for (my $i=0; $i<@maps; $i++) {
1164: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1165: if ($inner ne '') {
1166: push(@uploaded,$inner);
1167: push(@names,&escape($titles[$i]));
1168: $shorter{$maps[$i]} = $inner;
1169: }
1170: }
1171: $$nestref .= "$dir:".join(',',@uploaded).'&';
1172: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1173: foreach my $map (@maps) {
1174: if ($shorter{$map} ne '') {
1175: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1176: }
1177: }
1178: }
1179: return;
1180: }
1181:
1.329 droeschl 1182: sub print_paste_buffer {
1.484.2.7 raeburn 1183: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.484.2.30 raeburn 1184: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1185:
1.484.2.30 raeburn 1186: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1187: return if ($env{'docs.markedcopies'} eq '');
1.484.2.7 raeburn 1188: }
1189:
1.484.2.30 raeburn 1190: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1191: my ($pasteitems,@pasteable);
1.484.2.47 raeburn 1192: my $clipboardcount = 0;
1.484.2.7 raeburn 1193:
1.484.2.30 raeburn 1194: # Construct identifiers for current contents of user's paste buffer
1195: foreach my $suffix (@currpaste) {
1196: next if ($suffix =~ /\D/);
1197: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1198: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.484.2.82 raeburn 1199: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.484.2.30 raeburn 1200: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1201: ($url ne '')) {
1.484.2.47 raeburn 1202: $clipboardcount ++;
1.484.2.30 raeburn 1203: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1204: $canpaste,$nopaste,$othercrs,$areachange);
1205: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1206: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1207: $is_external = 1;
1.484.2.7 raeburn 1208: }
1.484.2.30 raeburn 1209: if ($folder =~ /^supplemental/) {
1210: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1211: unless ($canpaste) {
1212: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1.484.2.7 raeburn 1213: }
1.484.2.30 raeburn 1214: } else {
1215: $canpaste = 1;
1.484.2.7 raeburn 1216: }
1.484.2.30 raeburn 1217: if ($canpaste) {
1218: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1219: my $srcdom = $1;
1220: my $srcnum = $2;
1221: my $rem = $3;
1222: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1223: $othercourse = 1;
1224: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.484.2.76 raeburn 1225: $othercrs = '<br />'.&mt('(from another course)');
1.484.2.30 raeburn 1226: } else {
1227: $canpaste = 0;
1228: $nopaste = &mt('Paste from another course unavailable.');
1.484.2.7 raeburn 1229: }
1230: }
1.484.2.30 raeburn 1231: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1232: my $prefix = $1;
1233: $parent = $2;
1234: if ($folder !~ /^\Q$prefix\E/) {
1235: $areachange = 1;
1236: }
1237: $is_uploaded_map = 1;
1238: }
1.484.2.82 raeburn 1239: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1240: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1241: if ($cid ne $env{'request.course.id'}) {
1242: my ($srcdom,$srcnum) = split(/_/,$cid);
1243: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1244: $othercrs = '<br />'.&mt('(from another course)');
1245: } else {
1246: $canpaste = 0;
1247: $nopaste = &mt('Paste from another course unavailable.');
1248: }
1249: }
1250: }
1251: if ($canpaste) {
1252: push(@pasteable,$suffix);
1.484.2.30 raeburn 1253: }
1254: }
1255: my $buffer;
1256: if ($is_external) {
1257: $buffer = &mt('External Resource').': '.
1258: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1259: &LONCAPA::map::qtescape($url).')';
1260: } else {
1261: my $icon = &Apache::loncommon::icon($extension);
1262: if ($extension eq 'sequence' &&
1263: $url =~ m{/default_\d+\.sequence$}x) {
1264: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1265: $icon .= '/navmap.folder.closed.gif';
1266: }
1.484.2.57 raeburn 1267: my $title = $env{'docs.markedcopy_title_'.$suffix};
1268: if ($title eq '') {
1269: ($title) = ($url =~ m{/([^/]+)$});
1270: }
1.484.2.30 raeburn 1271: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1272: ': '.
1273: &Apache::loncommon::parse_supplemental_title(
1.484.2.57 raeburn 1274: &LONCAPA::map::qtescape($title));
1.484.2.30 raeburn 1275: }
1276: $pasteitems .= '<div class="LC_left_float">';
1277: my ($options,$onclick);
1278: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1279: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1280: if (($is_uploaded_map) ||
1281: ($url =~ /(bulletinboard|smppg)$/) ||
1282: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1283: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1284: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1285: }
1286: }
1287: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1288: if ($nopaste) {
1289: $pasteitems .= $nopaste;
1290: } else {
1291: if ($othercrs) {
1292: $pasteitems .= $othercrs;
1293: }
1294: if ($options) {
1295: $pasteitems .= $options;
1.484.2.7 raeburn 1296: }
1297: }
1.484.2.30 raeburn 1298: $pasteitems .= '</div>';
1299: }
1300: }
1301: if ($pasteitems eq '') {
1302: &Apache::lonnet::delenv('docs.markedcopies');
1303: }
1304: my ($pasteform,$form_start,$buttons,$form_end);
1305: if ($pasteitems) {
1306: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1307: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1308: if (@pasteable) {
1.484.2.47 raeburn 1309: my $value = &mt('Paste to current folder');
1310: if ($container eq 'page') {
1311: $value = &mt('Paste to current page');
1312: }
1313: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1314: }
1315: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.(' 'x2);
1316: if ($clipboardcount > 1) {
1317: $buttons .=
1318: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1319: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1320: (' 'x2).
1321: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1322: (' 'x2);
1.484.2.7 raeburn 1323: }
1.484.2.48 raeburn 1324: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1325: '</form>';
1.484.2.30 raeburn 1326: } else {
1327: $pasteitems = &mt('Clipboard is empty');
1328: }
1329: $r->print($form_start
1330: .'<fieldset>'
1331: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1332: .$pasteitems
1333: .'</fieldset>'
1334: .$form_end);
1335: }
1336:
1337: sub paste_options {
1338: my ($suffix,$is_uploaded_map,$parent) = @_;
1339: my ($copytext,$movetext);
1340: if ($is_uploaded_map) {
1341: $copytext = &mt('Copy to new folder');
1342: $movetext = &mt('Move old');
1343: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1344: $copytext = &mt('Copy to new board');
1345: $movetext = &mt('Move (not posts)');
1346: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1347: $copytext = &mt('Copy to new page');
1348: $movetext = &mt('Move');
1.484.2.7 raeburn 1349: } else {
1.484.2.30 raeburn 1350: $copytext = &mt('Copy to new file');
1351: $movetext = &mt('Move');
1352: }
1353: my $output = '<br />'.
1354: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1355: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1356: '<label>'.
1357: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1358: $copytext.'</label></span>'.(' 'x2).' '.
1359: '<span class="LC_nobreak"><label>'.
1360: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1361: $movetext.'</label></span>';
1362: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1363: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1364: '</legend><table border="0">';
1365: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1366: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1367: my $lastdir = $parent;
1368: my %depths = (
1369: $lastdir => 0,
1370: );
1371: my (%display,%deps);
1372: for (my $i=0; $i<@pastemaps; $i++) {
1373: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1374: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1375: my @subfolders = split(/,/,$subfolderstr);
1376: $deps{$lastdir} = \@subfolders;
1377: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1378: my $depth = $depths{$lastdir} + 1;
1379: my $offset = int($depth * 4);
1380: my $indent = (' ' x $offset);
1381: for (my $j=0; $j<@subfolders; $j++) {
1382: $depths{$subfolders[$j]} = $depth;
1383: $display{$subfolders[$j]} =
1384: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1385: '<td><label>'.
1386: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1387: '<label>'.
1388: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1389: &mt('Move old').'</label>'.
1390: '</td></tr>';
1391: }
1392: }
1393: &recurse_print(\$output,$parent,\%deps,\%display);
1394: $output .= '</table></fieldset>';
1.329 droeschl 1395: }
1.484.2.30 raeburn 1396: $output .= '</div>';
1397: return $output;
1.329 droeschl 1398: }
1399:
1.484.2.7 raeburn 1400: sub recurse_print {
1.484.2.30 raeburn 1401: my ($outputref,$dir,$deps,$display) = @_;
1402: $$outputref .= $display->{$dir}."\n";
1.484.2.7 raeburn 1403: if (ref($deps->{$dir}) eq 'ARRAY') {
1404: foreach my $subdir (@{$deps->{$dir}}) {
1.484.2.30 raeburn 1405: &recurse_print($outputref,$subdir,$deps,$display);
1.484.2.7 raeburn 1406: }
1407: }
1408: }
1409:
1410: sub supp_pasteable {
1411: my ($url) = @_;
1412: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1413: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1414: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1415: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1416: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1417: return 1;
1418: }
1419: return;
1420: }
1421:
1422: sub paste_popup_js {
1.484.2.61 raeburn 1423: my %html_js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1424: show => 'Show Options',
1425: hide => 'Hide Options',
1.484.2.61 raeburn 1426: );
1427: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.30 raeburn 1428: none => 'No items selected from clipboard.',
1.484.2.7 raeburn 1429: );
1.484.2.61 raeburn 1430: &html_escape(\%html_js_lt);
1431: &js_escape(\%html_js_lt);
1432: &js_escape(\%js_lt);
1.484.2.7 raeburn 1433: return <<"END";
1434:
1.484.2.30 raeburn 1435: function showPasteOptions(suffix) {
1436: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.484.2.61 raeburn 1437: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.484.2.7 raeburn 1438: return;
1439: }
1440:
1.484.2.30 raeburn 1441: function hidePasteOptions(suffix) {
1442: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.484.2.61 raeburn 1443: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.7 raeburn 1444: return;
1445: }
1446:
1.484.2.30 raeburn 1447: function showOptions(caller,suffix) {
1448: if (document.getElementById('pasteoptionstext_'+suffix)) {
1449: if (caller.checked) {
1.484.2.61 raeburn 1450: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.484.2.30 raeburn 1451: } else {
1452: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1453: }
1454: if (document.getElementById('pasteoptions_'+suffix)) {
1455: document.getElementById('pasteoptions_'+suffix).style.display='none';
1456: }
1457: }
1458: return;
1459: }
1.484.2.7 raeburn 1460:
1.484.2.30 raeburn 1461: function validateClipboard() {
1462: var numchk = 0;
1463: if (document.pasteform.pasting.length > 1) {
1464: for (var i=0; i<document.pasteform.pasting.length; i++) {
1465: if (document.pasteform.pasting[i].checked) {
1466: numchk ++;
1467: }
1468: }
1469: } else {
1470: if (document.pasteform.pasting.type == 'checkbox') {
1471: if (document.pasteform.pasting.checked) {
1472: numchk ++;
1473: }
1474: }
1475: }
1476: if (numchk > 0) {
1477: return true;
1478: } else {
1.484.2.61 raeburn 1479: alert("$js_lt{'none'}");
1.484.2.30 raeburn 1480: return false;
1481: }
1.484.2.7 raeburn 1482: }
1483:
1.484.2.47 raeburn 1484: function checkClipboard() {
1485: if (document.pasteform.pasting.length > 1) {
1486: for (var i=0; i<document.pasteform.pasting.length; i++) {
1487: document.pasteform.pasting[i].checked = true;
1488: }
1489: }
1490: return;
1491: }
1492:
1493: function uncheckClipboard() {
1494: if (document.pasteform.pasting.length >1) {
1495: for (var i=0; i<document.pasteform.pasting.length; i++) {
1496: document.pasteform.pasting[i].checked = false;
1497: }
1498: }
1499: return;
1500: }
1501:
1.484.2.30 raeburn 1502: END
1503:
1504: }
1.484.2.7 raeburn 1505:
1.329 droeschl 1506: sub do_paste_from_buffer {
1.484.2.7 raeburn 1507: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1508:
1.484.2.30 raeburn 1509: # Array of items in paste buffer
1510: my (@currpaste,%pastebuffer,%allerrors);
1511: @currpaste = split(/,/,$env{'docs.markedcopies'});
1512:
1.484.2.7 raeburn 1513: # Early out if paste buffer is empty
1.484.2.30 raeburn 1514: if (@currpaste == 0) {
1.484.2.7 raeburn 1515: return ();
1.484.2.30 raeburn 1516: }
1517: map { $pastebuffer{$_} = 1; } @currpaste;
1518:
1519: # Array of items selected items to paste
1520: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1521:
1522: # Early out if nothing selected to paste
1523: if (@reqpaste == 0) {
1524: return();
1525: }
1526: my @topaste;
1527: foreach my $suffix (@reqpaste) {
1528: next if ($suffix =~ /\D/);
1529: next unless (exists($pastebuffer{$suffix}));
1530: push(@topaste,$suffix);
1.484.2.7 raeburn 1531: }
1532:
1.484.2.30 raeburn 1533: # Early out if nothing available to paste
1534: if (@topaste == 0) {
1535: return();
1.329 droeschl 1536: }
1537:
1.484.2.30 raeburn 1538: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.484.2.82 raeburn 1539: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.484.2.7 raeburn 1540:
1.484.2.30 raeburn 1541: foreach my $suffix (@topaste) {
1542: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.484.2.76 raeburn 1543: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.82 raeburn 1544: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.484.2.30 raeburn 1545: # Supplemental content may only include certain types of content
1546: # Early out if pasted content is not supported in Supplemental area
1547: if ($folder =~ /^supplemental/) {
1548: unless (&supp_pasteable($url)) {
1549: $notinsupp{$suffix} = 1;
1550: next;
1551: }
1552: }
1553: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1554: my $srcd = $1;
1555: my $srcn = $2;
1.484.2.7 raeburn 1556: # When paste buffer was populated using an active role in a different course
1.484.2.30 raeburn 1557: # check for mdc privilege in the course from which the resource was pasted
1558: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1559: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1560: $notincrs{$suffix} = 1;
1561: next;
1562: }
1.329 droeschl 1563: }
1.484.2.30 raeburn 1564: $srcdom{$suffix} = $srcd;
1565: $srcnum{$suffix} = $srcn;
1.484.2.82 raeburn 1566: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1567: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
1.484.2.76 raeburn 1568: my ($srcd,$srcn) = split(/_/,$cid);
1569: # When paste buffer was populated using an active role in a different course
1570: # check for mdc privilege in the course from which the resource was pasted
1571: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1572: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1573: $notincrs{$suffix} = 1;
1574: next;
1575: }
1576: }
1577: $srcdom{$suffix} = $srcd;
1578: $srcnum{$suffix} = $srcn;
1.484.2.30 raeburn 1579: }
1.484.2.82 raeburn 1580: $srcmapidx{$suffix} = $mapidx;
1.484.2.30 raeburn 1581: push(@dopaste,$suffix);
1582: if ($url=~/\.(page|sequence)$/) {
1583: $is_map{$suffix} = 1;
1.329 droeschl 1584: }
1.484.2.30 raeburn 1585:
1586: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1587: my $oldprefix = $1;
1.484.2.19 raeburn 1588: # When pasting content from Main Content to Supplemental Content and vice versa
1.484.2.7 raeburn 1589: # URLs will contain different paths (which depend on whether pasted item is
1.484.2.82 raeburn 1590: # a folder/page or a document).
1.484.2.30 raeburn 1591: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1592: $prefixchg{$suffix} = 'docstosupp';
1593: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1594: $prefixchg{$suffix} = 'supptodocs';
1595: }
1.484.2.7 raeburn 1596:
1597: # If pasting an uploaded map, get list of contained uploaded maps.
1.484.2.30 raeburn 1598: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1599: my @nested;
1600: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1601: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1602: my @deps = map { /\d+:([\d,]+$)/ } @items;
1603: foreach my $dep (@deps) {
1604: if ($dep =~ /,/) {
1605: push(@nested,split(/,/,$dep));
1606: } else {
1607: push(@nested,$dep);
1608: }
1.484.2.7 raeburn 1609: }
1.484.2.30 raeburn 1610: foreach my $item (@nested) {
1611: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1612: push(@{$marktomove{$suffix}},$type.'_'.$item);
1613: }
1.484.2.7 raeburn 1614: }
1615: }
1.329 droeschl 1616: }
1.484.2.7 raeburn 1617: }
1618:
1.484.2.30 raeburn 1619: # Early out if nothing available to paste
1620: if (@dopaste == 0) {
1621: return ();
1622: }
1623:
1624: # Populate message hash and hashes used for main content <=> supplemental content
1625: # changes
1626:
1627: %msgs = &Apache::lonlocal::texthash (
1628: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1629: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1630: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1631: );
1632:
1633: %before = (
1634: docstosupp => {
1635: map => 'default',
1636: doc => 'docs',
1637: },
1638: supptodocs => {
1639: map => 'supplemental',
1640: doc => 'supplemental',
1641: },
1642: );
1643:
1644: %after = (
1645: docstosupp => {
1646: map => 'supplemental',
1647: doc => 'supplemental'
1648: },
1649: supptodocs => {
1650: map => 'default',
1651: doc => 'docs',
1652: },
1653: );
1654:
1655: # Retrieve information about all course maps in main content area
1656:
1657: my $allmaps = {};
1.484.2.79 raeburn 1658: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1.484.2.30 raeburn 1659:
1660: # Loop over the items to paste
1661: foreach my $suffix (@dopaste) {
1.484.2.7 raeburn 1662: # Maps need to be copied first
1.484.2.30 raeburn 1663: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1664: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.484.2.82 raeburn 1665: %newurls,%tomove,%resdatacopy);
1.484.2.30 raeburn 1666: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1667: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1668: }
1669: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1670: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.484.2.76 raeburn 1671: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.484.2.30 raeburn 1672: my $oldurl = $url;
1673: if ($is_map{$suffix}) {
1.484.2.7 raeburn 1674: # If pasting a map, check if map contains other maps
1.484.2.30 raeburn 1675: my (%hierarchy,%titles);
1.484.2.79 raeburn 1676: if (($folder =~ /^default/) && (!$donechk)) {
1677: $allmaps =
1678: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1679: $env{"course.$env{'request.course.id'}.home"},
1680: $env{'request.course.id'});
1681: $donechk = 1;
1682: }
1.484.2.30 raeburn 1683: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1684: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1685: if ($url=~ m{^/uploaded/}) {
1686: my $newurl;
1687: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1688: ($newurl,my $error) =
1689: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1690: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1691: \$title,$allmaps,\%newurls);
1692: if ($error) {
1693: $allerrors{$suffix} = $error;
1694: next;
1695: }
1696: if ($newurl ne '') {
1697: if ($newurl ne $url) {
1698: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1699: $newsubdir{$url} = $1;
1700: }
1701: $mapchanges{$url} = 1;
1.484.2.7 raeburn 1702: }
1703: }
1704: }
1.484.2.30 raeburn 1705: if (($srcdom{$suffix} ne $coursedom) ||
1706: ($srcnum{$suffix} ne $coursenum) ||
1707: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1708: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1709: $coursedom,$coursenum,$srcdom{$suffix},
1710: $srcnum{$suffix},$allmaps,\%rewrites,
1711: \%retitles,\%copies,\%dbcopies,
1712: \%zombies,\%params,\%mapmoves,
1713: \%mapchanges,\%tomove,\%newsubdir,
1.484.2.82 raeburn 1714: \%newurls,\%resdatacopy)) {
1.484.2.30 raeburn 1715: $mapmoves{$url} = 1;
1716: }
1717: $url = $newurl;
1718: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1719: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1720: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1721: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1722: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.484.2.82 raeburn 1723: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.484.2.30 raeburn 1724: }
1725: } elsif ($url=~m {^/res/}) {
1.484.2.82 raeburn 1726: # published map can only exist once, so remove from paste buffer when done
1.484.2.30 raeburn 1727: push(@toclear,$suffix);
1728: # if pasting published map (main content area only) check map not already in course
1729: if ($folder =~ /^default/) {
1730: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1731: $duplicate{$suffix} = 1;
1732: next;
1733: }
1.484.2.7 raeburn 1734: }
1735: }
1736: }
1.484.2.30 raeburn 1737: if ($url=~ m{/(bulletinboard|smppg)$}) {
1738: my $prefix = $1;
1.484.2.76 raeburn 1739: my $fromothercrs;
1.484.2.30 raeburn 1740: #need to copy the db contents to a new one, unless this is a move.
1741: my %info = (
1742: src => $url,
1743: cdom => $coursedom,
1744: cnum => $coursenum,
1.484.2.76 raeburn 1745: );
1746: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1747: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1748: $fromothercrs = 1;
1749: $info{'cdom'} = $srcdom{$suffix};
1750: $info{'cnum'} = $srcnum{$suffix};
1751: }
1752: }
1753: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.484.2.30 raeburn 1754: my (%lockerr,$msg);
1755: my ($newurl,$result,$errtext) =
1756: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1757: if ($result eq 'ok') {
1758: $url = $newurl;
1759: $title=&mt('Copy of').' '.$title;
1760: } else {
1761: if ($prefix eq 'smppg') {
1762: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1763: } elsif ($prefix eq 'bulletinboard') {
1.484.2.42 raeburn 1764: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.484.2.30 raeburn 1765: }
1766: $results{$suffix} = $result;
1767: $msgerrs{$suffix} = $msg;
1768: $lockerrs{$suffix} = $lockerr{$prefix};
1769: next;
1770: }
1771: if ($lockerr{$prefix}) {
1772: $lockerrs{$suffix} = $lockerr{$prefix};
1.484.2.26 raeburn 1773: }
1.484.2.7 raeburn 1774: }
1.484.2.30 raeburn 1775: }
1776: $title = &LONCAPA::map::qtunescape($title);
1777: my $ext='false';
1778: if ($url=~m{^http(|s)://}) { $ext='true'; }
1779: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1780: if ($folder !~ /^supplemental/) {
1781: (undef,undef,$title) =
1782: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1783: }
1784: } else {
1785: if ($folder=~/^supplemental/) {
1786: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1787: $env{'user.domain'}.'___&&&___'.$title;
1.484.2.26 raeburn 1788: }
1789: }
1.484.2.7 raeburn 1790:
1791: # For uploaded files (excluding pages/sequences) path in copied file is changed
1792: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1793: # courses.
1794:
1.484.2.30 raeburn 1795: unless ($is_map{$suffix}) {
1796: my $newidx;
1.329 droeschl 1797: # Now insert the URL at the bottom
1.484.2.30 raeburn 1798: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1799: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1800: my $relpath = $1;
1801: if ($relpath ne '') {
1802: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1803: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1804: my $newprefix = $newloc;
1805: if ($newloc eq 'default') {
1806: $newprefix = 'docs';
1807: }
1808: if ($newdocsdir eq '') {
1809: $newdocsdir = 'default';
1810: }
1811: if (($prefixchg{$suffix}) ||
1812: ($srcdom{$suffix} ne $coursedom) ||
1813: ($srcnum{$suffix} ne $coursenum) ||
1814: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1815: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1816: $url =
1817: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1818: &Apache::lonnet::getfile($oldurl));
1819: if ($url eq '/adm/notfound.html') {
1820: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1821: next;
1822: } else {
1823: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1824: $newsubpath =~ s{/+$}{/};
1825: $docmoves{$oldurl} = $newsubpath;
1826: }
1.484.2.7 raeburn 1827: }
1828: }
1.484.2.82 raeburn 1829: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1830: my $template = $1;
1831: if ($newidx) {
1832: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1833: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1834: }
1.484.2.7 raeburn 1835: }
1.484.2.30 raeburn 1836: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1837: ':'.$ext.':normal:res';
1838: push(@LONCAPA::map::order,$newidx);
1839: # Store the result
1840: my ($errtext,$fatal) =
1841: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1842: if ($fatal) {
1843: $save_err .= $errtext;
1844: $allresult = 'fail';
1.484.2.7 raeburn 1845: }
1.329 droeschl 1846: }
1.484.2.30 raeburn 1847:
1.484.2.82 raeburn 1848: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1849: # resourcedata for simpleproblems copied from another course
1.484.2.30 raeburn 1850: unless ($allresult eq 'fail') {
1851: my %updated = (
1852: rewrites => \%rewrites,
1853: zombies => \%zombies,
1854: removefrommap => \%removefrommap,
1855: removeparam => \%removeparam,
1856: dbcopies => \%dbcopies,
1.484.2.82 raeburn 1857: resdatacopy => \%resdatacopy,
1.484.2.30 raeburn 1858: retitles => \%retitles,
1859: );
1860: my %info = (
1861: newsubdir => \%newsubdir,
1862: params => \%params,
1863: );
1864: if ($prefixchg{$suffix}) {
1865: $info{'before'} = $before{$prefixchg{$suffix}};
1866: $info{'after'} = $after{$prefixchg{$suffix}};
1867: }
1868: my %moves = (
1869: copies => \%copies,
1870: docmoves => \%docmoves,
1871: mapmoves => \%mapmoves,
1872: );
1873: (my $result,$msgs{$suffix},my $lockerror) =
1874: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1875: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1876: $url,'paste');
1877: $lockerrors .= $lockerror;
1878: if ($result eq 'ok') {
1879: if ($is_map{$suffix}) {
1880: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1881: $folder.'.'.$container);
1882: if ($fatal) {
1883: $allresult = 'failread';
1884: } else {
1885: if ($#LONCAPA::map::order<1) {
1886: my $idx=&LONCAPA::map::getresidx();
1887: if ($idx<=0) { $idx=1; }
1888: $LONCAPA::map::order[0]=$idx;
1889: $LONCAPA::map::resources[$idx]='';
1890: }
1891: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1892: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1893: ':'.$ext.':normal:res';
1894: push(@LONCAPA::map::order,$newidx);
1.484.2.7 raeburn 1895:
1896: # Store the result
1.484.2.30 raeburn 1897: my ($errtext,$fatal) =
1898: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1899: if ($fatal) {
1900: $save_err .= $errtext;
1901: $allresult = 'failstore';
1902: }
1903: }
1904: }
1905: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1906: push(@toclear,$suffix);
1907: }
1908: }
1.329 droeschl 1909: }
1910: }
1.484.2.30 raeburn 1911: &clear_from_buffer(\@toclear,\@currpaste);
1912: my $msgsarray;
1913: foreach my $suffix (keys(%msgs)) {
1914: if (ref($msgs{$suffix}) eq 'ARRAY') {
1915: $msgsarray .= join(',',@{$msgs{$suffix}});
1916: }
1917: }
1918: return ($allresult,$save_err,$msgsarray,$lockerrors);
1919: }
1920:
1921: sub do_buffer_empty {
1922: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1923: if (@currpaste == 0) {
1924: return &mt('Clipboard is already empty');
1925: }
1926: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1927: if (@toclear == 0) {
1928: return &mt('Nothing selected to clear from clipboard');
1929: }
1930: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1931: if ($numdel) {
1932: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1933: } else {
1934: return &mt('Clipboard unchanged');
1.484.2.7 raeburn 1935: }
1.484.2.30 raeburn 1936: return;
1937: }
1938:
1939: sub clear_from_buffer {
1940: my ($toclear,$currpaste) = @_;
1941: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1942: my %pastebuffer;
1943: map { $pastebuffer{$_} = 1; } @{$currpaste};
1944: my $numdel = 0;
1945: foreach my $suffix (@{$toclear}) {
1946: next if ($suffix =~ /\D/);
1947: next unless (exists($pastebuffer{$suffix}));
1948: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1949: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1950: delete($pastebuffer{$suffix});
1951: $numdel ++;
1952: }
1953: }
1954: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1955: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1956: return $numdel;
1.484.2.7 raeburn 1957: }
1958:
1959: sub get_newmap_url {
1960: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1961: $titleref,$allmaps,$newurls) = @_;
1962: my $newurl;
1963: if ($url=~ m{^/uploaded/}) {
1964: $$titleref=&mt('Copy of').' '.$$titleref;
1965: }
1966: my $now = time;
1967: my $suffix=$$.int(rand(100)).$now;
1968: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1969: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1970: my $path = $1;
1971: my $prefix = $2;
1972: my $ancestor = $3;
1973: if (length($ancestor) > 10) {
1974: $ancestor = substr($ancestor,-10,10);
1975: }
1976: my $newid;
1977: if ($prefixchg) {
1978: if ($folder =~ /^supplemental/) {
1979: $prefix =~ s/^default/supplemental/;
1980: } else {
1981: $prefix =~ s/^supplemental/default/;
1982: }
1983: }
1984: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1985: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1986: } else {
1987: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1988: }
1989: my $counter = 0;
1990: my $is_unique = &uniqueness_check($newurl);
1991: if ($folder =~ /^default/) {
1992: if ($allmaps->{$newurl}) {
1993: $is_unique = 0;
1994: }
1995: }
1996: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1997: $counter ++;
1998: $suffix ++;
1999: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2000: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2001: } else {
2002: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2003: }
2004: $is_unique = &uniqueness_check($newurl);
2005: }
2006: if ($is_unique) {
2007: $newurls->{$newurl} = 1;
2008: } else {
2009: if ($url=~/\.page$/) {
2010: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2011: } else {
2012: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2013: }
2014: }
2015: }
2016: return ($newurl);
2017: }
2018:
2019: sub dbcopy {
1.484.2.26 raeburn 2020: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2021: my ($url,$result,$errtext);
2022: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 2023: $url = $dbref->{'src'};
1.484.2.26 raeburn 2024: if ($url =~ m{/(smppg|bulletinboard)$}) {
2025: my $prefix = $1;
2026: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2027: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2028: my $db_name;
2029: my $marker = (split(m{/},$url))[4];
2030: $marker=~s/\D//g;
2031: if ($dbref->{'src'} =~ m{/smppg$}) {
2032: $db_name =
2033: &Apache::lonsimplepage::get_db_name($url,$marker,
2034: $dbref->{'cdom'},
2035: $dbref->{'cnum'});
2036: } else {
2037: $db_name = 'bulletinpage_'.$marker;
2038: }
2039: my ($suffix,$freedlock,$error) =
2040: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2041: $coursedom,$coursenum,
2042: 'concat');
2043: if (!$suffix) {
2044: if ($prefix eq 'smppg') {
2045: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2046: } else {
1.484.2.42 raeburn 2047: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.484.2.26 raeburn 2048: }
2049: if ($error) {
2050: $errtext .= '<br />'.$error;
2051: }
2052: } else {
2053: #need to copy the db contents to a new one.
2054: my %contents=&Apache::lonnet::dump($db_name,
2055: $dbref->{'cdom'},
2056: $dbref->{'cnum'});
2057: if (exists($contents{'uploaded.photourl'})) {
2058: my $photo = $contents{'uploaded.photourl'};
2059: my ($subdir,$fname) =
2060: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2061: my $newphoto;
2062: if ($fname ne '') {
2063: my $content = &Apache::lonnet::getfile($photo);
2064: unless ($content eq '-1') {
2065: $env{'form.'.$suffix.'.photourl'} = $content;
2066: $newphoto =
2067: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2068: delete($env{'form.'.$suffix.'.photourl'});
2069: }
2070: }
2071: if ($newphoto =~ m{^/uploaded/}) {
2072: $contents{'uploaded.photourl'} = $newphoto;
2073: }
2074: }
2075: $db_name =~ s{_\d*$ }{_$suffix}x;
2076: $result=&Apache::lonnet::put($db_name,\%contents,
2077: $coursedom,$coursenum);
2078: if ($result eq 'ok') {
2079: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
2080: }
2081: }
2082: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2083: $lockerrorsref->{$prefix} =
2084: '<div class="LC_error">'.
2085: &mt('There was a problem removing a lockfile.');
2086: if ($prefix eq 'smppg') {
2087: $lockerrorsref->{$prefix} .=
1.484.2.38 raeburn 2088: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.484.2.26 raeburn 2089: } else {
1.484.2.42 raeburn 2090: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 2091: }
1.484.2.38 raeburn 2092: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2093: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2094: '</div>';
1.484.2.26 raeburn 2095: }
2096: }
2097: } elsif ($url =~ m{/syllabus$}) {
2098: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2099: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2100: if (($dbref->{'cdom'} ne $coursedom) ||
2101: ($dbref->{'cnum'} ne $coursenum)) {
2102: my %contents=&Apache::lonnet::dump('syllabus',
2103: $dbref->{'cdom'},
2104: $dbref->{'cnum'});
2105: $result=&Apache::lonnet::put('syllabus',\%contents,
2106: $coursedom,$coursenum);
2107: }
2108: }
1.484.2.7 raeburn 2109: }
2110: }
1.484.2.26 raeburn 2111: return ($url,$result,$errtext);
1.329 droeschl 2112: }
2113:
1.484.2.82 raeburn 2114: sub copy_templated_files {
2115: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2116: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2117: my $srccontainer = 'sequence';
2118: if ($srcwaspage) {
2119: $srccontainer = 'page';
2120: }
2121: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2122: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2123: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2124: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2125: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2126: $template.'.problem';
2127: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2128: if ($template eq 'simpleproblem') {
2129: $srcprefix .= '.0.';
2130: my $weightprefix = $newprefix;
2131: $newprefix .= '.0.';
2132: my @simpleprobqtypes = qw(radio option string essay numerical);
2133: my $qtype=$srcparms{$srcprefix.'questiontype'};
2134: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2135: my %newdata = (
2136: $newprefix.'questiontype' => $qtype,
1.484.2.84 raeburn 2137: );
1.484.2.82 raeburn 2138: foreach my $type (@simpleprobqtypes) {
2139: if ($type eq $qtype) {
2140: $newdata{"$weightprefix.$type.weight"}=1;
2141: } else {
2142: $newdata{"$weightprefix.$type.weight"}=0;
2143: }
2144: }
2145: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2146: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2147: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2148: if ($qtype eq 'numerical') {
2149: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2150: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2151: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2152: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2153: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2154: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2155: unless (defined($maxfoils)) { $maxfoils=10; }
2156: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2157: if ($maxfoils<=0) { $maxfoils=10; }
2158: my $randomize=$srcparms{$srcprefix.'randomize'};
2159: unless (defined($randomize)) { $randomize='yes'; }
2160: unless ($randomize eq 'no') { $randomize='yes'; }
2161: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2162: $newdata{$newprefix.'randomize'} = $randomize;
2163: if ($qtype eq 'option') {
2164: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2165: }
2166: for (my $i=1; $i<=10; $i++) {
2167: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2168: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2169: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2170: }
2171:
2172: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2173: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2174: unless (defined($maxfoils)) { $maxfoils=10; }
2175: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2176: if ($maxfoils<=0) { $maxfoils=10; }
2177: my $randomize=$srcparms{$srcprefix.'randomize'};
2178: unless (defined($randomize)) { $randomize='yes'; }
2179: unless ($randomize eq 'no') { $randomize='yes'; }
2180: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2181: $newdata{$newprefix.'randomize'} = $randomize;
2182: if ($qtype eq 'option') {
2183: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2184: }
2185: for (my $i=1; $i<=10; $i++) {
2186: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2187: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2188: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2189: }
2190: } elsif ($qtype eq 'string') {
2191: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2192: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2193: }
2194: if (keys(%newdata)) {
2195: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2196: $coursenum);
2197: if ($putres eq 'ok') {
2198: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2199: }
2200: }
2201: }
2202: }
2203: }
2204:
1.329 droeschl 2205: sub uniqueness_check {
2206: my ($newurl) = @_;
2207: my $unique = 1;
2208: foreach my $res (@LONCAPA::map::order) {
2209: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2210: $url=&LONCAPA::map::qtescape($url);
2211: if ($newurl eq $url) {
2212: $unique = 0;
1.344 bisitz 2213: last;
1.329 droeschl 2214: }
2215: }
2216: return $unique;
2217: }
2218:
1.484.2.7 raeburn 2219: sub contained_map_check {
2220: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
2221: $allmaps) = @_;
2222: my $content = &Apache::lonnet::getfile($url);
2223: unless ($content eq '-1') {
2224: my $parser = HTML::TokeParser->new(\$content);
2225: $parser->attr_encoded(1);
2226: while (my $token = $parser->get_token) {
2227: next if ($token->[0] ne 'S');
2228: if ($token->[1] eq 'resource') {
2229: next if ($token->[2]->{'type'} eq 'zombie');
2230: my $ressrc = $token->[2]->{'src'};
2231: if ($folder =~ /^supplemental/) {
2232: unless (&supp_pasteable($ressrc)) {
2233: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2234: next;
2235: }
2236: }
2237: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2238: if ($1 eq 'uploaded') {
2239: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2240: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2241: } else {
2242: if ($allmaps->{$ressrc}) {
1.484.2.23 raeburn 2243: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.484.2.7 raeburn 2244: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2245: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2246: } else {
2247: $addedmaps->{$ressrc} = [$url];
2248: }
2249: }
2250: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2251: $addedmaps,$hierarchy,$titles,$allmaps);
2252: }
2253: } elsif ($token->[1] eq 'param') {
2254: if ($folder =~ /^supplemental/) {
2255: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2256: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2257: } else {
1.484.2.19 raeburn 2258: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1.484.2.7 raeburn 2259: }
2260: }
2261: }
2262: }
2263: }
2264: return;
2265: }
2266:
2267: sub url_paste_fixups {
1.484.2.26 raeburn 2268: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2269: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.484.2.82 raeburn 2270: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.484.2.7 raeburn 2271: my $checktitle;
2272: if (($prefixchg) &&
2273: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2274: $checktitle = 1;
2275: }
2276: my $skip;
2277: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2278: my $mapid = $1.$2;
2279: if ($tomove->{$mapid}) {
2280: $skip = 1;
2281: }
2282: }
2283: my $file = &Apache::lonnet::getfile($oldurl);
2284: return if ($file eq '-1');
2285: my $parser = HTML::TokeParser->new(\$file);
2286: $parser->attr_encoded(1);
2287: my $changed = 0;
2288: while (my $token = $parser->get_token) {
2289: next if ($token->[0] ne 'S');
2290: if ($token->[1] eq 'resource') {
2291: my $ressrc = $token->[2]->{'src'};
2292: next if ($ressrc eq '');
2293: my $id = $token->[2]->{'id'};
2294: my $title = $token->[2]->{'title'};
2295: if ($checktitle) {
2296: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.484.2.25 raeburn 2297: $retitles->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2298: }
2299: }
2300: next if ($token->[2]->{'type'} eq 'external');
2301: if ($token->[2]->{'type'} eq 'zombie') {
1.484.2.30 raeburn 2302: next if ($skip);
1.484.2.25 raeburn 2303: $zombies->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2304: $changed = 1;
2305: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2306: my $srcdom = $1;
2307: my $srcnum = $2;
2308: my $rem = $3;
2309: my $newurl;
2310: my $mapname;
2311: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2312: my $prefix = $1;
2313: $mapname = $prefix.$2;
2314: if ($tomove->{$mapname}) {
1.484.2.26 raeburn 2315: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2316: $srcdom,$srcnum,$allmaps,$rewrites,
2317: $retitles,$copies,$dbcopies,$zombies,
2318: $params,$mapmoves,$mapchanges,$tomove,
1.484.2.82 raeburn 2319: $newsubdir,$newurls,$resdatacopy);
1.484.2.7 raeburn 2320: next;
2321: } else {
2322: ($newurl,my $error) =
2323: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2324: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2325: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2326: $newsubdir->{$ressrc} = $1;
2327: }
2328: if ($error) {
2329: next;
2330: }
2331: }
2332: }
2333: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2334: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1.484.2.19 raeburn 2335:
1.484.2.7 raeburn 2336: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.484.2.25 raeburn 2337: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2338: $mapchanges->{$ressrc} = 1;
1.484.2.26 raeburn 2339: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2340: $cnum,$srcdom,$srcnum,$allmaps,
2341: $rewrites,$retitles,$copies,$dbcopies,
2342: $zombies,$params,$mapmoves,$mapchanges,
1.484.2.82 raeburn 2343: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.484.2.7 raeburn 2344: $mapmoves->{$ressrc} = 1;
2345: }
2346: $changed = 1;
2347: } else {
1.484.2.25 raeburn 2348: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.7 raeburn 2349: $copies->{$oldurl}{$ressrc} = $id;
2350: $changed = 1;
2351: }
2352: }
1.484.2.26 raeburn 2353: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1.484.2.30 raeburn 2354: next if ($skip);
1.484.2.7 raeburn 2355: my $srcdom = $1;
2356: my $srcnum = $2;
2357: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.25 raeburn 2358: $rewrites->{$oldurl}{$id} = $ressrc;
1.484.2.26 raeburn 2359: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2360: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2361: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2362: $changed = 1;
2363: }
2364: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2365: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2366: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2367: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2368: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2369: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.484.2.7 raeburn 2370: $changed = 1;
2371: }
1.484.2.82 raeburn 2372: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2373: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2374: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2375: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2376: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2377: }
1.484.2.7 raeburn 2378: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2379: next if ($skip);
2380: my $srcdom = $1;
2381: my $srcnum = $2;
2382: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.484.2.26 raeburn 2383: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2384: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2385: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.484.2.7 raeburn 2386: $changed = 1;
2387: }
2388: }
2389: } elsif ($token->[1] eq 'param') {
2390: next if ($skip);
1.484.2.19 raeburn 2391: my $to = $token->[2]->{'to'};
1.484.2.7 raeburn 2392: if ($to ne '') {
2393: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2394: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2395: } else {
2396: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2397: }
2398: }
2399: }
2400: }
2401: return $changed;
2402: }
2403:
2404: sub apply_fixups {
1.484.2.23 raeburn 2405: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2406: $oldurl,$url,$caller) = @_;
2407: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.484.2.26 raeburn 2408: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.484.2.82 raeburn 2409: %resdatacopy,%lockerrors,$lockmsg);
1.484.2.23 raeburn 2410: if (ref($updated) eq 'HASH') {
2411: if (ref($updated->{'rewrites'}) eq 'HASH') {
2412: %rewrites = %{$updated->{'rewrites'}};
2413: }
2414: if (ref($updated->{'zombies'}) eq 'HASH') {
2415: %zombies = %{$updated->{'zombies'}};
2416: }
2417: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2418: %removefrommap = %{$updated->{'removefrommap'}};
2419: }
2420: if (ref($updated->{'removeparam'}) eq 'HASH') {
2421: %removeparam = %{$updated->{'removeparam'}};
2422: }
2423: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2424: %dbcopies = %{$updated->{'dbcopies'}};
2425: }
2426: if (ref($updated->{'retitles'}) eq 'HASH') {
2427: %retitles = %{$updated->{'retitles'}};
2428: }
1.484.2.82 raeburn 2429: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2430: %resdatacopy = %{$updated->{'resdatacopy'}};
2431: }
1.484.2.23 raeburn 2432: }
2433: if (ref($info) eq 'HASH') {
2434: if (ref($info->{'newsubdir'}) eq 'HASH') {
2435: %newsubdir = %{$info->{'newsubdir'}};
2436: }
2437: if (ref($info->{'params'}) eq 'HASH') {
2438: %params = %{$info->{'params'}};
2439: }
2440: if (ref($info->{'before'}) eq 'HASH') {
2441: %before = %{$info->{'before'}};
2442: }
2443: if (ref($info->{'after'}) eq 'HASH') {
2444: %after = %{$info->{'after'}};
2445: }
2446: }
2447: if (ref($moves) eq 'HASH') {
2448: if (ref($moves->{'copies'}) eq 'HASH') {
2449: %copies = %{$moves->{'copies'}};
2450: }
2451: if (ref($moves->{'docmoves'}) eq 'HASH') {
2452: %docmoves = %{$moves->{'docmoves'}};
2453: }
2454: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2455: %mapmoves = %{$moves->{'mapmoves'}};
2456: }
2457: }
2458: foreach my $key (keys(%copies),keys(%docmoves)) {
1.484.2.7 raeburn 2459: my @allcopies;
1.484.2.23 raeburn 2460: if (exists($copies{$key})) {
2461: if (ref($copies{$key}) eq 'HASH') {
2462: my %added;
2463: foreach my $innerkey (keys(%{$copies{$key}})) {
2464: if (($innerkey ne '') && (!$added{$innerkey})) {
2465: push(@allcopies,$innerkey);
2466: $added{$innerkey} = 1;
2467: }
1.484.2.7 raeburn 2468: }
1.484.2.23 raeburn 2469: undef(%added);
1.484.2.7 raeburn 2470: }
2471: }
2472: if ($key eq $oldurl) {
1.484.2.23 raeburn 2473: if ((exists($docmoves{$key}))) {
1.484.2.25 raeburn 2474: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.484.2.7 raeburn 2475: push(@allcopies,$oldurl);
2476: }
2477: }
2478: }
2479: if (@allcopies > 0) {
2480: foreach my $item (@allcopies) {
1.484.2.19 raeburn 2481: my ($relpath,$oldsubdir,$fname) =
1.484.2.7 raeburn 2482: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2483: if ($fname ne '') {
2484: my $content = &Apache::lonnet::getfile($item);
2485: unless ($content eq '-1') {
2486: my $storefn;
1.484.2.23 raeburn 2487: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2488: $storefn = $docmoves{$key};
1.484.2.7 raeburn 2489: } else {
2490: $storefn = $relpath;
2491: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2492: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2493: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.484.2.7 raeburn 2494: }
1.484.2.23 raeburn 2495: if ($newsubdir{$key}) {
1.484.2.25 raeburn 2496: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.484.2.7 raeburn 2497: }
2498: }
2499: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1.484.2.19 raeburn 2500: my $copyurl =
1.484.2.7 raeburn 2501: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2502: $storefn.$fname,$content);
2503: if ($copyurl eq '/adm/notfound.html') {
1.484.2.23 raeburn 2504: if (exists($docmoves{$oldurl})) {
1.484.2.7 raeburn 2505: return &mt('Paste failed: an error occurred copying the file.');
2506: } elsif (ref($errors) eq 'HASH') {
2507: $errors->{$item} = 1;
2508: }
2509: }
2510: }
2511: }
2512: }
2513: }
2514: }
1.484.2.23 raeburn 2515: foreach my $key (keys(%mapmoves)) {
1.484.2.7 raeburn 2516: my $storefn=$key;
2517: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2518: if ($prefixchg && $before{'map'} && $after{'map'}) {
2519: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2520: }
1.484.2.23 raeburn 2521: if ($newsubdir{$key}) {
2522: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2523: }
2524: my $mapcontent = &Apache::lonnet::getfile($key);
2525: if ($mapcontent eq '-1') {
2526: if (ref($errors) eq 'HASH') {
2527: $errors->{$key} = 1;
2528: }
2529: } else {
2530: my $newmap =
2531: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2532: $mapcontent);
2533: if ($newmap eq '/adm/notfound.html') {
2534: if (ref($errors) eq 'HASH') {
2535: $errors->{$key} = 1;
2536: }
2537: }
2538: }
2539: }
2540: my %updates;
2541: if ($is_map) {
1.484.2.23 raeburn 2542: if (ref($updated) eq 'HASH') {
2543: foreach my $type (keys(%{$updated})) {
2544: if (ref($updated->{$type}) eq 'HASH') {
2545: foreach my $key (keys(%{$updated->{$type}})) {
2546: $updates{$key} = 1;
2547: }
2548: }
2549: }
1.484.2.7 raeburn 2550: }
2551: foreach my $key (keys(%updates)) {
2552: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.484.2.23 raeburn 2553: if (ref($rewrites{$key}) eq 'HASH') {
2554: %torewrite = %{$rewrites{$key}};
1.484.2.7 raeburn 2555: }
1.484.2.23 raeburn 2556: if (ref($retitles{$key}) eq 'HASH') {
2557: %toretitle = %{$retitles{$key}};
1.484.2.7 raeburn 2558: }
1.484.2.23 raeburn 2559: if (ref($removefrommap{$key}) eq 'HASH') {
2560: %toremove = %{$removefrommap{$key}};
1.484.2.7 raeburn 2561: }
1.484.2.23 raeburn 2562: if (ref($removeparam{$key}) eq 'HASH') {
2563: %remparam = %{$removeparam{$key}};
1.484.2.7 raeburn 2564: }
1.484.2.23 raeburn 2565: if (ref($zombies{$key}) eq 'HASH') {
2566: %zombie = %{$zombies{$key}};
1.484.2.7 raeburn 2567: }
1.484.2.23 raeburn 2568: if (ref($dbcopies{$key}) eq 'HASH') {
1.484.2.26 raeburn 2569: foreach my $idx (keys(%{$dbcopies{$key}})) {
2570: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2571: my ($newurl,$result,$errtext) =
2572: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2573: if ($result eq 'ok') {
2574: $newdb{$idx} = $newurl;
2575: } elsif (ref($errors) eq 'HASH') {
2576: $errors->{$key} = 1;
2577: }
2578: push(@msgs,$errtext);
2579: }
1.484.2.7 raeburn 2580: }
2581: }
1.484.2.82 raeburn 2582: if (ref($resdatacopy{$key}) eq 'HASH') {
2583: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2584: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2585: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2586: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2587: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2588: my $template = $1;
2589: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2590: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2591: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2592: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2593: unless ($gotnewmapname) {
2594: ($newmapname) = ($key =~ m{/([^/]+)$});
2595: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2596: if ($newsubdir{$key}) {
2597: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2598: }
2599: $gotnewmapname = 1;
2600: }
2601: my $srcmapinfo = $srcfolder.':'.$idx;
2602: if ($srccontainer eq 'page') {
2603: $srcmapinfo .= ':1';
2604: }
2605: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2606: $cnum,$template,$idx,$newmapname);
2607: }
2608: }
2609: }
2610: }
2611: }
1.484.2.23 raeburn 2612: if (ref($params{$key}) eq 'HASH') {
2613: %currparam = %{$params{$key}};
1.484.2.7 raeburn 2614: }
2615: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2616: if ($fatal) {
1.484.2.26 raeburn 2617: return ($errtext);
1.484.2.7 raeburn 2618: }
2619: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2620: if (defined($LONCAPA::map::zombies[$i])) {
2621: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.484.2.25 raeburn 2622: if ($zombie{$i} eq $src) {
1.484.2.7 raeburn 2623: undef($LONCAPA::map::zombies[$i]);
2624: }
2625: }
2626: }
1.484.2.77 raeburn 2627: my $total = scalar(@LONCAPA::map::order) - 1;
2628: for (my $i=$total; $i>=0; $i--) {
1.484.2.23 raeburn 2629: my $idx = $LONCAPA::map::order[$i];
2630: if (defined($LONCAPA::map::resources[$idx])) {
1.484.2.7 raeburn 2631: my $changed;
1.484.2.23 raeburn 2632: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.484.2.30 raeburn 2633: if ((exists($toremove{$idx})) &&
2634: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.484.2.7 raeburn 2635: splice(@LONCAPA::map::order,$i,1);
1.484.2.23 raeburn 2636: if (ref($currparam{$idx}) eq 'ARRAY') {
2637: foreach my $name (@{$currparam{$idx}}) {
1.484.2.77 raeburn 2638: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2639: }
2640: }
2641: next;
2642: }
2643: my $origsrc = $src;
1.484.2.25 raeburn 2644: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.484.2.7 raeburn 2645: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2646: $changed = 1;
2647: }
2648: }
1.484.2.25 raeburn 2649: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.484.2.7 raeburn 2650: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2651: if ($origsrc =~ m{^/uploaded/}) {
1.484.2.23 raeburn 2652: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.484.2.7 raeburn 2653: if ($src =~ /\.(page|sequence)$/) {
1.484.2.23 raeburn 2654: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.484.2.7 raeburn 2655: } else {
1.484.2.23 raeburn 2656: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.484.2.7 raeburn 2657: }
2658: }
1.484.2.25 raeburn 2659: if ($origsrc =~ /\.(page|sequence)$/) {
2660: if ($newsubdir{$origsrc}) {
1.484.2.23 raeburn 2661: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.484.2.7 raeburn 2662: }
1.484.2.25 raeburn 2663: } elsif ($newsubdir{$key}) {
2664: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.484.2.7 raeburn 2665: }
2666: }
2667: $changed = 1;
1.484.2.26 raeburn 2668: } elsif ($newdb{$idx} ne '') {
2669: $src = $newdb{$idx};
1.484.2.7 raeburn 2670: $changed = 1;
2671: }
2672: if ($changed) {
1.484.2.30 raeburn 2673: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.484.2.7 raeburn 2674: }
2675: }
2676: }
2677: foreach my $idx (keys(%remparam)) {
2678: if (ref($remparam{$idx}) eq 'ARRAY') {
1.484.2.19 raeburn 2679: foreach my $name (@{$remparam{$idx}}) {
1.484.2.77 raeburn 2680: &LONCAPA::map::delparameter($idx,$name);
1.484.2.7 raeburn 2681: }
2682: }
2683: }
1.484.2.26 raeburn 2684: if (values(%lockerrors) > 0) {
2685: $lockmsg = join('<br />',values(%lockerrors));
2686: }
1.484.2.7 raeburn 2687: my $storefn;
2688: if ($key eq $oldurl) {
2689: $storefn = $url;
2690: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2691: } else {
2692: $storefn = $key;
2693: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.484.2.23 raeburn 2694: if ($prefixchg && $before{'map'} && $after{'map'}) {
2695: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.484.2.7 raeburn 2696: }
1.484.2.23 raeburn 2697: if ($newsubdir{$key}) {
2698: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.484.2.7 raeburn 2699: }
2700: }
2701: my $report;
2702: if ($folder !~ /^supplemental/) {
2703: $report = 1;
2704: }
1.484.2.20 raeburn 2705: (my $outtext,$errtext) =
1.484.2.7 raeburn 2706: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2707: if ($errtext) {
1.484.2.23 raeburn 2708: if ($caller eq 'paste') {
1.484.2.26 raeburn 2709: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.484.2.23 raeburn 2710: }
1.484.2.7 raeburn 2711: }
2712: }
2713: }
1.484.2.26 raeburn 2714: return ('ok',\@msgs,$lockmsg);
1.484.2.7 raeburn 2715: }
2716:
2717: sub copy_dependencies {
2718: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2719: my $content;
2720: if (ref($contentref)) {
2721: $content = $$contentref;
2722: } else {
2723: $content = &Apache::lonnet::getfile($item);
2724: }
2725: unless ($content eq '-1') {
2726: my $mm = new File::MMagic;
2727: my $mimetype = $mm->checktype_contents($content);
2728: if ($mimetype eq 'text/html') {
2729: my (%allfiles,%codebase,$state);
2730: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2731: if ($res eq 'ok') {
2732: my ($numexisting,$numpathchanges,$existing);
2733: (undef,$numexisting,$numpathchanges,$existing) =
2734: &Apache::loncommon::ask_for_embedded_content(
2735: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2736: {'error_on_invalid_names' => 1,
2737: 'ignore_remote_references' => 1,
2738: 'docs_url' => $item,
2739: 'context' => 'paste'});
2740: if ($numexisting > 0) {
2741: if (ref($existing) eq 'HASH') {
2742: foreach my $dep (keys(%{$existing})) {
2743: my $depfile = $dep;
2744: unless ($depfile =~ m{^\Q$relpath\E}) {
2745: $depfile = $relpath.$dep;
2746: }
2747: my $depcontent = &Apache::lonnet::getfile($depfile);
2748: unless ($depcontent eq '-1') {
2749: my $storedep = $dep;
2750: $storedep =~ s{^\Q$relpath\E}{};
2751: my $dep_url =
2752: &Apache::lonclonecourse::writefile(
2753: $env{'request.course.id'},
2754: $storefn.$storedep,$depcontent);
2755: if ($dep_url eq '/adm/notfound.html') {
2756: if (ref($errors) eq 'HASH') {
2757: $errors->{$depfile} = 1;
2758: }
2759: } else {
2760: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2761: }
2762: }
2763: }
2764: }
2765: }
2766: }
2767: }
2768: }
2769: return;
2770: }
2771:
1.329 droeschl 2772: my %parameter_type = ( 'randompick' => 'int_pos',
2773: 'hiddenresource' => 'string_yesno',
2774: 'encrypturl' => 'string_yesno',
2775: 'randomorder' => 'string_yesno',);
2776: my $valid_parameters_re = join('|',keys(%parameter_type));
2777: # set parameters
2778: sub update_parameter {
1.484.2.29 raeburn 2779: if ($env{'form.changeparms'} eq 'all') {
2780: my (@allidx,@allmapidx,%allchecked,%currchecked);
2781: %allchecked = (
2782: 'hiddenresource' => {},
2783: 'encrypturl' => {},
2784: 'randompick' => {},
2785: 'randomorder' => {},
2786: );
2787: foreach my $which (keys(%allchecked)) {
2788: $env{'form.all'.$which} =~ s/,$//;
2789: if ($which eq 'randompick') {
2790: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2791: my ($res,$value) = split(/:/,$item);
2792: if ($value =~ /^\d+$/) {
2793: $allchecked{$which}{$res} = $value;
2794: }
2795: }
2796: } else {
1.484.2.30 raeburn 2797: if ($env{'form.all'.$which}) {
2798: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2799: }
1.484.2.29 raeburn 2800: }
2801: }
2802: my $haschanges = 0;
2803: foreach my $res (@LONCAPA::map::order) {
2804: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2805: $name=&LONCAPA::map::qtescape($name);
2806: $url=&LONCAPA::map::qtescape($url);
2807: next unless ($name && $url);
2808: my $is_map;
2809: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2810: $is_map = 1;
2811: }
2812: foreach my $which (keys(%allchecked)) {
2813: if (($which eq 'randompick' || $which eq 'randomorder')) {
2814: next if (!$is_map);
2815: }
2816: my $oldvalue = 0;
2817: my $newvalue = 0;
2818: if ($allchecked{$which}{$res}) {
2819: $newvalue = $allchecked{$which}{$res};
2820: }
2821: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2822: if ($which eq 'randompick') {
2823: if ($current =~ /^(\d+)$/) {
2824: $oldvalue = $1;
2825: }
2826: } else {
2827: if ($current =~ /^yes$/i) {
2828: $oldvalue = 1;
2829: }
2830: }
2831: if ($oldvalue ne $newvalue) {
2832: $haschanges = 1;
2833: if ($newvalue) {
2834: my $storeval = 'yes';
2835: if ($which eq 'randompick') {
2836: $storeval = $newvalue;
2837: }
2838: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2839: $storeval,
2840: $parameter_type{$which});
2841: &remember_parms($res,$which,'set',$storeval);
2842: } elsif ($oldvalue) {
2843: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2844: &remember_parms($res,$which,'del');
2845: }
2846: }
2847: }
2848: }
2849: return $haschanges;
1.329 droeschl 2850: } else {
1.484.2.59 raeburn 2851: my $haschanges = 0;
2852: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.364 bisitz 2853:
1.484.2.29 raeburn 2854: my $which = $env{'form.changeparms'};
2855: my $idx = $env{'form.setparms'};
1.484.2.59 raeburn 2856: my $oldvalue = 0;
2857: my $newvalue = 0;
2858: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
2859: if ($which eq 'randompick') {
2860: if ($current =~ /^(\d+)$/) {
2861: $oldvalue = $1;
2862: }
2863: } elsif ($current =~ /^yes$/i) {
2864: $oldvalue = 1;
2865: }
1.484.2.29 raeburn 2866: if ($env{'form.'.$which.'_'.$idx}) {
1.484.2.59 raeburn 2867: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2868: : 1;
1.484.2.29 raeburn 2869: }
1.484.2.59 raeburn 2870: if ($oldvalue ne $newvalue) {
2871: $haschanges = 1;
2872: if ($newvalue) {
2873: my $storeval = 'yes';
2874: if ($which eq 'randompick') {
2875: $storeval = $newvalue;
2876: }
2877: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
2878: $parameter_type{$which});
2879: &remember_parms($idx,$which,'set',$storeval);
2880: } else {
2881: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
2882: &remember_parms($idx,$which,'del');
2883: }
2884: }
2885: return $haschanges;
1.329 droeschl 2886: }
1.484.2.59 raeburn 2887: return;
1.329 droeschl 2888: }
2889:
2890: sub handle_edit_cmd {
2891: my ($coursenum,$coursedom) =@_;
1.484.2.30 raeburn 2892: if ($env{'form.cmd'} eq '') {
2893: return 0;
2894: }
1.329 droeschl 2895: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2896:
2897: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2898: my ($title, $url, @rrest) = split(':', $ratstr);
2899:
1.484.2.30 raeburn 2900: if ($cmd eq 'remove') {
1.329 droeschl 2901: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2902: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2903: &Apache::lonnet::removeuploadedurl($url);
2904: } else {
2905: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2906: }
2907: splice(@LONCAPA::map::order, $idx, 1);
2908:
2909: } elsif ($cmd eq 'cut') {
2910: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2911: splice(@LONCAPA::map::order, $idx, 1);
2912:
1.344 bisitz 2913: } elsif ($cmd eq 'up'
1.329 droeschl 2914: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2915: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2916:
2917: } elsif ($cmd eq 'down'
2918: && defined($LONCAPA::map::order[$idx+1])) {
2919: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2920:
2921: } elsif ($cmd eq 'rename') {
2922: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2923: if ($comment=~/\S/) {
2924: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2925: $comment.':'.join(':', $url, @rrest);
2926: }
2927: # Devalidate title cache
2928: my $renamed_url=&LONCAPA::map::qtescape($url);
2929: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.484.2.30 raeburn 2930:
1.329 droeschl 2931: } else {
2932: return 0;
2933: }
2934: return 1;
2935: }
2936:
2937: sub editor {
1.458 raeburn 2938: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.484.2.80 raeburn 2939: $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
2940: $hostname,$navmapref,$hiddentop)=@_;
1.484.2.19 raeburn 2941: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
2942: if ($allowed) {
2943: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2944: $is_random_order,$container) =
2945: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2946: $r->print($breadcrumbtrail);
2947: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2948: $container = 'page';
2949: } else {
2950: $container = 'sequence';
2951: }
1.484 raeburn 2952:
1.484.2.21 raeburn 2953: my $jumpto;
2954:
2955: unless ($supplementalflag) {
1.484.2.32 raeburn 2956: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.21 raeburn 2957: }
1.484 raeburn 2958:
2959: unless ($allowed) {
2960: $randompick = -1;
2961: }
2962:
1.484.2.67 raeburn 2963: my ($errtext,$fatal);
2964: if (($folder eq '') && (!$supplementalflag)) {
2965: if (@LONCAPA::map::order) {
2966: undef(@LONCAPA::map::order);
2967: undef(@LONCAPA::map::resources);
2968: undef(@LONCAPA::map::resparms);
2969: undef(@LONCAPA::map::zombies);
2970: }
2971: $folder = 'default';
2972: $container = 'sequence';
2973: } else {
2974: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2975: $folder.'.'.$container);
2976: return $errtext if ($fatal);
2977: }
1.329 droeschl 2978:
2979: if ($#LONCAPA::map::order<1) {
2980: my $idx=&LONCAPA::map::getresidx();
2981: if ($idx<=0) { $idx=1; }
2982: $LONCAPA::map::order[0]=$idx;
2983: $LONCAPA::map::resources[$idx]='';
2984: }
1.364 bisitz 2985:
1.329 droeschl 2986: # ------------------------------------------------------------ Process commands
2987:
2988: # ---------------- if they are for this folder and user allowed to make changes
1.484.2.67 raeburn 2989: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 2990: # set parameters and change order
2991: &snapshotbefore();
2992:
2993: if (&update_parameter()) {
1.484.2.59 raeburn 2994: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 2995: return $errtext if ($fatal);
2996: }
2997:
2998: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2999: # change order
3000: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3001: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3002:
3003: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3004: return $errtext if ($fatal);
3005: }
1.364 bisitz 3006:
1.329 droeschl 3007: if ($env{'form.pastemarked'}) {
1.484.2.7 raeburn 3008: my %paste_errors;
1.484.2.26 raeburn 3009: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.484.2.7 raeburn 3010: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3011: \%paste_errors);
1.484.2.30 raeburn 3012: if (ref($pastemsgarray) eq 'ARRAY') {
3013: if (@{$pastemsgarray} > 0) {
3014: $r->print('<p class="LC_info">'.
3015: join('<br />',@{$pastemsgarray}).
1.484.2.26 raeburn 3016: '</p>');
3017: }
1.484.2.30 raeburn 3018: }
3019: if ($lockerror) {
3020: $r->print('<p class="LC_error">'.
3021: $lockerror.
3022: '</p>');
3023: }
3024: if ($save_error ne '') {
3025: return $save_error;
3026: }
3027: if ($paste_res) {
3028: my %errortext = &Apache::lonlocal::texthash (
3029: fail => 'Storage of folder contents failed',
3030: failread => 'Reading folder contents failed',
3031: failstore => 'Storage of folder contents failed',
3032: );
3033: if ($errortext{$paste_res}) {
3034: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.484.2.7 raeburn 3035: }
1.329 droeschl 3036: }
1.484.2.7 raeburn 3037: if (keys(%paste_errors) > 0) {
1.484.2.30 raeburn 3038: $r->print('<p class="LC_warning">'."\n".
1.484.2.7 raeburn 3039: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
3040: '<ul>'."\n");
3041: foreach my $key (sort(keys(%paste_errors))) {
3042: $r->print('<li>'.$key.'</li>'."\n");
3043: }
3044: $r->print('</ul></p>'."\n");
3045: }
1.484.2.30 raeburn 3046: } elsif ($env{'form.clearmarked'}) {
3047: my $output = &do_buffer_empty();
3048: if ($output) {
3049: $r->print('<p class="LC_info">'.$output.'</p>');
3050: }
3051: }
1.329 droeschl 3052:
3053: $r->print($upload_output);
3054:
1.484.2.30 raeburn 3055: # Rename, cut, copy or remove a single resource
1.484.2.63 raeburn 3056: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.484.2.7 raeburn 3057: my $contentchg;
1.484.2.58 raeburn 3058: if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {
1.484.2.7 raeburn 3059: $contentchg = 1;
3060: }
3061: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3062: return $errtext if ($fatal);
3063: }
1.484.2.30 raeburn 3064:
3065: # Cut, copy and/or remove multiple resources
3066: if ($env{'form.multichange'}) {
3067: my %allchecked = (
3068: cut => {},
3069: remove => {},
3070: );
3071: my $needsupdate;
3072: foreach my $which (keys(%allchecked)) {
3073: $env{'form.multi'.$which} =~ s/,$//;
3074: if ($env{'form.multi'.$which}) {
3075: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3076: if (ref($allchecked{$which}) eq 'HASH') {
3077: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3078: }
3079: }
3080: }
3081: if ($needsupdate) {
3082: my $haschanges = 0;
3083: my %curr_groups = &Apache::longroup::coursegroups();
3084: my $total = scalar(@LONCAPA::map::order) - 1;
3085: for (my $i=$total; $i>=0; $i--) {
3086: my $res = $LONCAPA::map::order[$i];
3087: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3088: $name=&LONCAPA::map::qtescape($name);
3089: $url=&LONCAPA::map::qtescape($url);
1.484.2.57 raeburn 3090: next unless $url;
1.484.2.30 raeburn 3091: my %denied =
3092: &action_restrictions($coursenum,$coursedom,$url,
3093: $env{'form.folderpath'},\%curr_groups);
3094: foreach my $which (keys(%allchecked)) {
3095: next if ($denied{$which});
3096: next unless ($allchecked{$which}{$res});
3097: if ($which eq 'remove') {
3098: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3099: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3100: &Apache::lonnet::removeuploadedurl($url);
3101: } else {
3102: &LONCAPA::map::makezombie($res);
3103: }
3104: splice(@LONCAPA::map::order,$i,1);
3105: $haschanges ++;
3106: } elsif ($which eq 'cut') {
3107: &LONCAPA::map::makezombie($res);
3108: splice(@LONCAPA::map::order,$i,1);
3109: $haschanges ++;
3110: }
3111: }
3112: }
3113: if ($haschanges) {
3114: ($errtext,$fatal) =
3115: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3116: return $errtext if ($fatal);
3117: }
3118: }
3119: }
3120:
1.329 droeschl 3121: # Group import/search
3122: if ($env{'form.importdetail'}) {
3123: my @imports;
3124: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3125: if (defined($item)) {
3126: my ($name,$url,$residx)=
1.484.2.26 raeburn 3127: map { &unescape($_); } split(/\=/,$item);
3128: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1.484.2.30 raeburn 3129: my ($suffix,$errortxt,$locknotfreed) =
1.484.2.26 raeburn 3130: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.484.2.15 raeburn 3131: if ($locknotfreed) {
3132: $r->print($locknotfreed);
3133: }
3134: if ($suffix) {
1.484.2.19 raeburn 3135: $url =~ s/_new\./_$suffix./;
1.484.2.15 raeburn 3136: } else {
3137: return $errortxt;
3138: }
1.484.2.26 raeburn 3139: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3140: my $type = $1;
3141: my ($suffix,$errortxt,$locknotfreed) =
3142: &new_timebased_suffix($coursedom,$coursenum,$type);
3143: if ($locknotfreed) {
3144: $r->print($locknotfreed);
3145: }
3146: if ($suffix) {
3147: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3148: } else {
3149: return $errortxt;
3150: }
1.484.2.27 raeburn 3151: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3152: if ($supplementalflag) {
3153: next unless ($1 eq 'supplemental');
3154: if ($folder eq 'supplemental') {
3155: next unless ($2 eq 'default');
3156: } else {
3157: next unless ($folder eq 'supplemental_'.$2);
3158: }
3159: } else {
3160: next unless ($1 eq 'docs');
3161: if ($folder eq 'default') {
3162: next unless ($2 eq 'default');
3163: } else {
3164: next unless ($folder eq 'default_'.$2);
3165: }
3166: }
1.484.2.15 raeburn 3167: }
1.329 droeschl 3168: push(@imports, [$name, $url, $residx]);
3169: }
3170: }
1.484.2.23 raeburn 3171: ($errtext,$fatal,my $fixuperrors) =
3172: &group_import($coursenum, $coursedom, $folder,$container,
3173: 'londocs',@imports);
1.329 droeschl 3174: return $errtext if ($fatal);
1.484.2.23 raeburn 3175: if ($fixuperrors) {
3176: $r->print($fixuperrors);
3177: }
1.329 droeschl 3178: }
3179: # Loading a complete map
3180: if ($env{'form.loadmap'}) {
3181: if ($env{'form.importmap'}=~/\w/) {
3182: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3183: my ($title,$url,$ext,$type)=split(/\:/,$res);
3184: my $idx=&LONCAPA::map::getresidx($url);
3185: $LONCAPA::map::resources[$idx]=$res;
3186: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3187: }
3188: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3189: $folder.'.'.$container,1);
1.329 droeschl 3190: return $errtext if ($fatal);
3191: } else {
3192: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3193:
1.329 droeschl 3194: }
3195: }
3196: &log_differences($plain);
3197: }
3198: # ---------------------------------------------------------------- End commands
3199: # ---------------------------------------------------------------- Print screen
3200: my $idx=0;
3201: my $shown=0;
3202: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3203: $r->print('<div class="LC_Box">'.
1.432 raeburn 3204: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3205: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3206: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3207: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3208: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3209: '</ol>');
1.381 bisitz 3210: if ($randompick>=0) {
3211: $r->print('<p class="LC_warning">'
3212: .&mt('Caution: this folder is set to randomly pick a subset'
3213: .' of resources. Adding or removing resources from this'
3214: .' folder will change the set of resources that the'
3215: .' students see, resulting in spurious or missing credit'
3216: .' for completed problems, not limited to ones you'
3217: .' modify. Do not modify the contents of this folder if'
3218: .' it is in active student use.')
3219: .'</p>'
3220: );
3221: }
3222: if ($is_random_order) {
3223: $r->print('<p class="LC_warning">'
3224: .&mt('Caution: this folder is set to randomly order its'
3225: .' contents. Adding or removing resources from this folder'
3226: .' will change the order of resources shown.')
3227: .'</p>'
3228: );
3229: }
3230: $r->print('</div>');
1.364 bisitz 3231: }
1.381 bisitz 3232:
1.484.2.30 raeburn 3233: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3234: %filters = (
3235: canremove => [],
3236: cancut => [],
3237: cancopy => [],
3238: hiddenresource => [],
3239: encrypturl => [],
3240: randomorder => [],
3241: randompick => [],
3242: );
3243: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3244: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3245: foreach my $res (@LONCAPA::map::order) {
3246: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3247: $name=&LONCAPA::map::qtescape($name);
3248: $url=&LONCAPA::map::qtescape($url);
3249: unless ($name) { $name=(split(/\//,$url))[-1]; }
3250: unless ($name) { $idx++; next; }
1.484.2.29 raeburn 3251: push(@allidx,$res);
3252: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3253: push(@allmapidx,$res);
3254: }
1.484.2.67 raeburn 3255:
1.381 bisitz 3256: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 3257: $coursenum,$coursedom,$crstype,
1.484.2.30 raeburn 3258: $pathitem,$supplementalflag,$container,
1.484.2.70 raeburn 3259: \%filters,\%curr_groups,$canedit,
1.484.2.80 raeburn 3260: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3261: $idx++;
3262: $shown++;
1.329 droeschl 3263: }
1.424 onken 3264: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3265:
1.484.2.30 raeburn 3266: my $need_save;
1.484.2.67 raeburn 3267: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3268: my $toolslink;
1.484.2.67 raeburn 3269: if ($allowed) {
1.484.2.31 raeburn 3270: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3271: .&Apache::loncommon::help_open_menu('Navigation Screen',
3272: 'Navigation_Screen',undef,'RAT')
3273: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3274: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3275: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3276: .'id="LC_content_toolbar_edittoplevel" '
3277: .'class="LC_toolbarItem" '
3278: .'title="'.&mt('Supplemental Content Editor').'">'
3279: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3280: }
1.484.2.19 raeburn 3281: if ($shown) {
3282: if ($allowed) {
3283: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3284: .&Apache::loncommon::start_data_table(undef,'contentlist')
3285: .&Apache::loncommon::start_data_table_header_row()
3286: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3287: .'<th colspan="2">'.&mt('Actions').'</th>'
3288: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3289: if ($folder !~ /^supplemental/) {
3290: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3291: }
1.484.2.29 raeburn 3292: $to_show .= &Apache::loncommon::end_data_table_header_row();
3293: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3294: $lists{'canhide'} = join(',',@allidx);
3295: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3296: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3297: 'randomorder','randompick');
3298: foreach my $item (@possfilters) {
3299: if (ref($filters{$item}) eq 'ARRAY') {
3300: if (@{$filters{$item}} > 0) {
3301: $lists{$item} = join(',',@{$filters{$item}});
3302: }
3303: }
3304: }
1.484.2.29 raeburn 3305: if (@allidx > 0) {
3306: my $path;
3307: if ($env{'form.folderpath'}) {
3308: $path =
3309: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3310: }
1.484.2.30 raeburn 3311: if (@allidx > 1) {
3312: $to_show .=
3313: &Apache::loncommon::continue_data_table_row().
3314: '<td colspan="2"> </td>'.
3315: '<td>'.
1.484.2.67 raeburn 3316: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3317: '</td>'.
3318: '<td> </td>'.
3319: '<td> </td>'.
3320: '<td colspan="4">'.
1.484.2.67 raeburn 3321: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3322: '</td>'.
3323: &Apache::loncommon::end_data_table_row();
3324: $need_save = 1;
3325: }
1.484.2.29 raeburn 3326: }
3327: }
3328: $to_show .= $output.' '
1.484.2.19 raeburn 3329: .&Apache::loncommon::end_data_table()
3330: .'<br style="line-height:2px;" />'
3331: .&Apache::loncommon::end_scrollbox();
3332: } else {
3333: $to_show .= $toolslink
3334: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3335: .$output.' '
3336: .&Apache::loncommon::end_data_table();
3337: }
3338: } else {
3339: if (!$allowed) {
3340: $to_show .= $toolslink;
1.393 raeburn 3341: }
1.484.2.67 raeburn 3342: my $noresmsg;
3343: if ($allowed && $hiddentop && !$supplementalflag) {
3344: $noresmsg = &mt('Main Content Hidden');
3345: } else {
3346: $noresmsg = &mt('Currently empty');
3347: }
1.484.2.19 raeburn 3348: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3349: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3350: .$noresmsg
1.484.2.19 raeburn 3351: .'</div>'
3352: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3353: }
3354: } else {
1.484.2.19 raeburn 3355: if ($shown) {
3356: $to_show = '<div>'
3357: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3358: .$output
3359: .&Apache::loncommon::end_data_table()
3360: .'</div>';
3361: } else {
3362: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3363: .&mt('Currently empty')
1.484.2.19 raeburn 3364: .'</div>'
3365: }
1.458 raeburn 3366: }
3367: my $tid = 1;
3368: if ($supplementalflag) {
3369: $tid = 2;
1.329 droeschl 3370: }
3371: if ($allowed) {
1.484 raeburn 3372: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3373: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3374: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3375: if ($canedit) {
1.484.2.67 raeburn 3376: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3377: }
1.460 raeburn 3378: } else {
3379: $r->print($to_show);
1.329 droeschl 3380: }
3381: return;
3382: }
3383:
1.484.2.30 raeburn 3384: sub multiple_check_form {
1.484.2.67 raeburn 3385: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3386: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3387: my $disabled;
3388: unless ($canedit) {
3389: $disabled = 'disabled="disabled"';
3390: }
1.484.2.30 raeburn 3391: my $output =
3392: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3393: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3394: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3395: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3396: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3397: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3398: if ($caller eq 'settings') {
3399: $output .=
3400: '<table><tr>'.
3401: '<td class="LC_docs_entry_parameter">'.
3402: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3403: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3404: '</label></span></td>'.
3405: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3406: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
1.484.2.30 raeburn 3407: '</span></td>'.
3408: '</tr>'."\n".
3409: '<tr>'.
3410: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3411: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
1.484.2.30 raeburn 3412: '</label></span>'.
3413: '</td></tr></table>'."\n";
3414: } else {
3415: $output .=
3416: '<table><tr>'.
3417: '<td class="LC_docs_entry_parameter">'.
3418: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3419: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3420: '</label></span></td>'.
3421: '<td class="LC_docs_entry_parameter">'.
3422: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3423: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3424: '</label></span></td>'."\n".
3425: '<td class="LC_docs_entry_parameter">'.
3426: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3427: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3428: '</label></span></td>'.
3429: '</tr></table>'."\n";
3430: }
3431: $output .=
3432: '</fieldset>'.
3433: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3434: if ($caller eq 'settings') {
3435: $output .=
3436: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3437: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3438: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3439: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3440: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3441: } elsif ($caller eq 'actions') {
3442: $output .=
3443: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3444: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3445: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3446: }
3447: $output .=
3448: '</form>'.
3449: '</div>';
3450: return $output;
3451: }
3452:
1.329 droeschl 3453: sub process_file_upload {
1.484.2.36 raeburn 3454: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3455: # upload a file, if present
1.484.2.36 raeburn 3456: my $filesize = length($env{'form.uploaddoc'});
3457: if (!$filesize) {
3458: $$upload_output = '<div class="LC_error">'.
3459: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3460: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3461: $filesize).'<br />'.
3462: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3463: '</div>';
3464: return;
3465: }
3466: my $quotatype = 'unofficial';
3467: if ($crstype eq 'Community') {
3468: $quotatype = 'community';
1.484.2.51 raeburn 3469: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3470: $quotatype = 'official';
1.484.2.45 raeburn 3471: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3472: $quotatype = 'textbook';
1.484.2.36 raeburn 3473: }
3474: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3475: $filesize = int($filesize/1000); #expressed in kb
3476: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3477: $env{'form.uploaddoc.filename'},$filesize,
3478: 'upload',$quotatype);
1.484.2.36 raeburn 3479: return if ($$upload_output);
3480: }
1.440 raeburn 3481: my ($parseaction,$showupload,$nextphase,$mimetype);
3482: if ($env{'form.parserflag'}) {
1.329 droeschl 3483: $parseaction = 'parse';
3484: }
3485: my $folder=$env{'form.folder'};
3486: if ($folder eq '') {
3487: $folder='default';
3488: }
3489: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3490: my $errtext='';
3491: my $fatal=0;
3492: my $container='sequence';
1.484.2.19 raeburn 3493: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3494: $container='page';
3495: }
3496: ($errtext,$fatal)=
1.484.2.27 raeburn 3497: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3498: if ($#LONCAPA::map::order<1) {
3499: $LONCAPA::map::order[0]=1;
3500: $LONCAPA::map::resources[1]='';
3501: }
3502: my $destination = 'docs/';
3503: if ($folder =~ /^supplemental/) {
3504: $destination = 'supplemental/';
3505: }
3506: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3507: $destination .= 'default/';
3508: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3509: $destination .= $2.'/';
3510: }
1.484.2.27 raeburn 3511: if ($fatal) {
3512: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3513: return;
3514: }
1.440 raeburn 3515: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3516: my $newidx=&LONCAPA::map::getresidx();
3517: $destination .= $newidx;
1.439 raeburn 3518: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3519: $parseaction,$allfiles,
1.440 raeburn 3520: $codebase,undef,undef,undef,undef,
3521: undef,undef,\$mimetype);
3522: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3523: my $stored = $1;
3524: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3525: $stored.'</span>').'</p>';
3526: } else {
3527: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3528:
1.457 raeburn 3529: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3530: return;
3531: }
1.329 droeschl 3532: my $ext='false';
3533: if ($url=~m{^http://}) { $ext='true'; }
3534: $url = &LONCAPA::map::qtunescape($url);
3535: my $comment=$env{'form.comment'};
3536: $comment = &LONCAPA::map::qtunescape($comment);
3537: if ($folder=~/^supplemental/) {
3538: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3539: $env{'user.domain'}.'___&&&___'.$comment;
3540: }
3541:
3542: $LONCAPA::map::resources[$newidx]=
3543: $comment.':'.$url.':'.$ext.':normal:res';
3544: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3545: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3546: $folder.'.'.$container,1);
1.329 droeschl 3547: if ($fatal) {
1.457 raeburn 3548: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3549: return;
1.329 droeschl 3550: } else {
1.440 raeburn 3551: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3552: $$upload_output = $showupload;
1.384 raeburn 3553: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3554: if ($total_embedded > 0) {
1.440 raeburn 3555: my $uploadphase = 'upload_embedded';
3556: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3557: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3558: my ($embedded,$num) =
3559: &Apache::loncommon::ask_for_embedded_content(
3560: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3561: if ($embedded) {
3562: if ($num) {
3563: $$upload_output .=
3564: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3565: $nextphase = $uploadphase;
3566: } else {
3567: $$upload_output .= $embedded;
3568: }
3569: } else {
3570: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3571: }
1.329 droeschl 3572: } else {
1.440 raeburn 3573: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3574: }
1.457 raeburn 3575: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3576: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3577: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3578: $nextphase = 'decompress_uploaded';
3579: my $position = scalar(@LONCAPA::map::order)-1;
3580: my $noextract = &return_to_editor();
3581: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3582: my %archiveitems = (
3583: folderpath => $env{'form.folderpath'},
3584: cmd => $nextphase,
3585: newidx => $newidx,
3586: position => $position,
3587: phase => $nextphase,
1.477 raeburn 3588: comment => $comment,
1.480 raeburn 3589: );
3590: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3591: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3592: $$upload_output = $showupload.
3593: &Apache::loncommon::decompress_form($mimetype,
3594: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3595: \%archiveitems,\@current);
1.329 droeschl 3596: }
3597: }
3598: }
1.440 raeburn 3599: return $nextphase;
1.329 droeschl 3600: }
3601:
1.480 raeburn 3602: sub get_dir_list {
3603: my ($url,$coursenum,$coursedom,$newidx) = @_;
3604: my ($destination,$dir_root) = &embedded_destination();
3605: my ($dirlistref,$listerror) =
3606: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3607: my @dir_lines;
3608: my $dirptr=16384;
3609: if (ref($dirlistref) eq 'ARRAY') {
3610: foreach my $dir_line (sort
3611: {
3612: my ($afile)=split('&',$a,2);
3613: my ($bfile)=split('&',$b,2);
3614: return (lc($afile) cmp lc($bfile));
3615: } (@{$dirlistref})) {
3616: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3617: $filename =~ s/\s+$//;
3618: next if ($filename =~ /^\.\.?$/);
3619: my $isdir = 0;
3620: if ($dirptr&$testdir) {
3621: $isdir = 1;
3622: }
3623: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3624: }
3625: }
3626: return @dir_lines;
3627: }
3628:
1.329 droeschl 3629: sub is_supplemental_title {
3630: my ($title) = @_;
3631: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3632: }
3633:
3634: # --------------------------------------------------------------- An entry line
3635:
3636: sub entryline {
1.484.2.12 raeburn 3637: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3638: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.484.2.80 raeburn 3639: $canedit,$isencrypted,$navmapref,$hostname)=@_;
1.484.2.52 raeburn 3640: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3641: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3642: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3643: } else {
3644: $title=&HTML::Entities::encode($title,'"<>&\'');
3645: $renametitle=$title;
3646: $foldertitle=$title;
3647: }
3648:
1.484.2.67 raeburn 3649: my ($disabled,$readonly,$js_lt);
3650: unless ($canedit) {
3651: $disabled = 'disabled="disabled"';
3652: $readonly = 1;
3653: }
3654:
1.329 droeschl 3655: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3656:
1.329 droeschl 3657: $renametitle=~s/\\/\\\\/g;
3658: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3659: $renametitle=~s/"/%22/g;
1.329 droeschl 3660: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3661: $oldtitle = $renametitle;
3662: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3663: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3664: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3665: # Edit commands
1.484.2.28 raeburn 3666: my ($esc_path, $path, $symb);
1.329 droeschl 3667: if ($env{'form.folderpath'}) {
3668: $esc_path=&escape($env{'form.folderpath'});
3669: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3670: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3671: }
1.484.2.16 raeburn 3672: my $isexternal;
1.484.2.19 raeburn 3673: if ($residx) {
1.484.2.12 raeburn 3674: my $currurl = $url;
3675: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3676: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3677: $isexternal = 1;
3678: }
1.484.2.19 raeburn 3679: if (!$supplementalflag) {
3680: my $path = 'uploaded/'.
3681: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3682: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3683: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3684: $residx,
3685: &Apache::lonnet::declutter($currurl));
3686: }
1.484.2.12 raeburn 3687: }
1.484.2.30 raeburn 3688: my ($renamelink,%lt,$ishash);
3689: if (ref($filtersref) eq 'HASH') {
3690: $ishash = 1;
3691: }
3692:
1.329 droeschl 3693: if ($allowed) {
1.484.2.30 raeburn 3694: $form_start = '
3695: <form action="/adm/coursedocs" method="post">
3696: ';
3697: $form_common=(<<END);
3698: <input type="hidden" name="folderpath" value="$path" />
3699: <input type="hidden" name="symb" value="$symb" />
3700: END
3701: $form_param=(<<END);
3702: <input type="hidden" name="setparms" value="$orderidx" />
3703: <input type="hidden" name="changeparms" value="0" />
3704: END
3705: $form_end = '</form>';
3706:
1.329 droeschl 3707: my $incindex=$index+1;
3708: my $selectbox='';
1.471 raeburn 3709: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3710: ((split(/\:/,
1.344 bisitz 3711: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3712: ne '') &&
1.329 droeschl 3713: ((split(/\:/,
1.344 bisitz 3714: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3715: ne '')) {
3716: $selectbox=
3717: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3718: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3719: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3720: if ($i==$incindex) {
1.358 bisitz 3721: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3722: } else {
3723: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3724: }
3725: }
3726: $selectbox.='</select>';
3727: }
1.484.2.12 raeburn 3728: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3729: 'up' => 'Move Up',
3730: 'dw' => 'Move Down',
3731: 'rm' => 'Remove',
3732: 'ct' => 'Cut',
3733: 'rn' => 'Rename',
1.484.2.12 raeburn 3734: 'cp' => 'Copy',
3735: 'ex' => 'External Resource',
3736: 'ed' => 'Edit',
3737: 'pr' => 'Preview',
3738: 'sv' => 'Save',
3739: 'ul' => 'URL',
1.484.2.67 raeburn 3740: 'ti' => 'Title',
3741: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3742: );
1.484.2.30 raeburn 3743: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3744: $env{'form.folderpath'},
3745: $currgroups);
1.484.2.19 raeburn 3746: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3747: my $skip_confirm = 0;
1.484.2.63 raeburn 3748: my $confirm_removal = 0;
1.329 droeschl 3749: if ( $folder =~ /^supplemental/
3750: || ($url =~ m{( /smppg$
3751: |/syllabus$
3752: |/aboutme$
3753: |/navmaps$
3754: |/bulletinboard$
1.484.2.16 raeburn 3755: |\.html$)}x)
1.484.2.19 raeburn 3756: || $isexternal) {
1.329 droeschl 3757: $skip_confirm = 1;
3758: }
1.484.2.63 raeburn 3759: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3760: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3761: $confirm_removal = 1;
3762: }
1.484.2.19 raeburn 3763:
1.484.2.30 raeburn 3764: if ($denied{'copy'}) {
3765: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3766: <span style="visibility: hidden;">$lt{'cp'}</span>
3767: ENDCOPY
3768: } else {
1.484.2.30 raeburn 3769: my $formname = 'edit_copy_'.$orderidx;
3770: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3771: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3772: <form name="$formname" method="post" action="/adm/coursedocs">
3773: $form_common
1.484.2.67 raeburn 3774: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.484.2.30 raeburn 3775: $form_end
1.329 droeschl 3776: ENDCOPY
1.484.2.30 raeburn 3777: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3778: push(@{$filtersref->{'cancopy'}},$orderidx);
3779: }
1.329 droeschl 3780: }
1.484.2.30 raeburn 3781: if ($denied{'cut'}) {
1.484.2.16 raeburn 3782: $cutlink=(<<ENDCUT);
3783: <span style="visibility: hidden;">$lt{'ct'}</span>
3784: ENDCUT
3785: } else {
1.484.2.30 raeburn 3786: my $formname = 'edit_cut_'.$orderidx;
3787: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3788: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3789: <form name="$formname" method="post" action="/adm/coursedocs">
3790: $form_common
3791: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3792: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.484.2.30 raeburn 3793: $form_end
1.329 droeschl 3794: ENDCUT
1.484.2.30 raeburn 3795: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3796: push(@{$filtersref->{'cancut'}},$orderidx);
3797: }
1.329 droeschl 3798: }
1.484.2.30 raeburn 3799: if ($denied{'remove'}) {
1.484.2.16 raeburn 3800: $removelink=(<<ENDREM);
3801: <span style="visibility: hidden;">$lt{'rm'}</a>
3802: ENDREM
3803: } else {
1.484.2.30 raeburn 3804: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3805: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.484.2.9 raeburn 3806: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3807: <form name="$formname" method="post" action="/adm/coursedocs">
3808: $form_common
3809: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3810: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3811: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.484.2.30 raeburn 3812: $form_end
1.484.2.9 raeburn 3813: ENDREM
1.484.2.30 raeburn 3814: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3815: push(@{$filtersref->{'canremove'}},$orderidx);
3816: }
1.484.2.9 raeburn 3817: }
1.484.2.35 raeburn 3818: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3819: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3820: ENDREN
1.484.2.67 raeburn 3821: my ($uplink,$downlink);
3822: if ($canedit) {
3823: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3824: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3825: } else {
3826: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3827: $downlink = $uplink;
3828: }
1.329 droeschl 3829: $line.=(<<END);
3830: <td>
1.379 bisitz 3831: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3832: <a href="$uplink">
1.484.2.12 raeburn 3833: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3834: </a>
3835: </div>
3836: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3837: <a href="$downlink">
1.484.2.12 raeburn 3838: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3839: </a>
3840: </div>
1.329 droeschl 3841: </td>
3842: <td>
3843: $form_start
1.484.2.30 raeburn 3844: $form_param
1.478 raeburn 3845: $form_common
1.329 droeschl 3846: $selectbox
3847: $form_end
3848: </td>
1.484.2.30 raeburn 3849: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3850: $removelink
1.329 droeschl 3851: $cutlink
3852: $copylink
3853: </td>
3854: END
3855: }
3856: # Figure out what kind of a resource this is
3857: my ($extension)=($url=~/\.(\w+)$/);
3858: my $uploaded=($url=~/^\/*uploaded\//);
3859: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3860: my $isfolder;
3861: my $ispage;
3862: my $containerarg;
1.484.2.67 raeburn 3863: my $folderurl;
1.329 droeschl 3864: if ($uploaded) {
1.472 raeburn 3865: if (($extension eq 'sequence') || ($extension eq 'page')) {
3866: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3867: $containerarg = $1;
1.472 raeburn 3868: if ($extension eq 'sequence') {
3869: $icon=$iconpath.'navmap.folder.closed.gif';
3870: $isfolder=1;
3871: } else {
3872: $icon=$iconpath.'page.gif';
3873: $ispage=1;
3874: }
1.484.2.67 raeburn 3875: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3876: if ($allowed) {
3877: $url='/adm/coursedocs?';
3878: } else {
3879: $url='/adm/supplemental?';
3880: }
1.329 droeschl 3881: } else {
3882: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3883: }
3884: }
1.364 bisitz 3885:
1.484.2.70 raeburn 3886: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3887: my $orig_url = $url;
1.340 raeburn 3888: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.87 raeburn 3889: if ($container eq 'page') {
3890: $url=~s{^http(|s)(:|:)//}{/ext/};
3891: } else {
3892: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
3893: }
1.484.2.12 raeburn 3894: if (!$supplementalflag && $residx && $symb) {
3895: if ((!$isfolder) && (!$ispage)) {
3896: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1.484.2.87 raeburn 3897: if (($url =~ m{^ext/}) && ($container eq 'page')) {
3898: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
3899: } else {
3900: $url=&Apache::lonnet::clutter($url);
3901: }
1.484.2.12 raeburn 3902: if ($url=~/^\/*uploaded\//) {
3903: $url=~/\.(\w+)$/;
3904: my $embstyle=&Apache::loncommon::fileembstyle($1);
3905: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3906: $url='/adm/wrapper'.$url;
3907: } elsif ($embstyle eq 'ssi') {
3908: #do nothing with these
3909: } elsif ($url!~/\.(sequence|page)$/) {
3910: $url='/adm/coursedocs/showdoc'.$url;
3911: }
1.484.2.70 raeburn 3912: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
3913: my $wrapped = $1;
3914: my $exturl = $2;
1.484.2.87 raeburn 3915: if (($wrapped eq '') && ($container ne 'page')) {
1.484.2.70 raeburn 3916: $url='/adm/wrapper'.$url;
3917: }
3918: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
3919: $nomodal = 1;
3920: }
3921: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
3922: if (($ENV{'SERVER_PORT'} == 443) &&
3923: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 3924: unless (&Apache::lonnet::uses_sts()) {
3925: $url .= '?usehttp=1';
3926: }
1.484.2.70 raeburn 3927: $nomodal = 1;
3928: }
1.484.2.19 raeburn 3929: }
1.484.2.12 raeburn 3930: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3931: my $shownsymb = $symb;
3932: if ($isexternal) {
1.484.2.88 raeburn 3933: $url =~ s/\#[^#]+$//;
1.484.2.87 raeburn 3934: if ($container eq 'page') {
3935: $url = &Apache::lonnet::clutter($url);
3936: }
1.484.2.66 raeburn 3937: }
1.484.2.67 raeburn 3938: unless ($env{'request.role.adv'}) {
3939: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3940: $url = '';
3941: }
3942: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3943: $url = '';
3944: $hiddenres = 1;
3945: }
3946: }
3947: if ($url ne '') {
1.484.2.75 raeburn 3948: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3949: }
3950: } elsif (!$env{'request.role.adv'}) {
3951: my $checkencrypt;
3952: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3953: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3954: $checkencrypt = 1;
1.484.2.70 raeburn 3955: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3956: unless (ref($$navmapref)) {
3957: $$navmapref = Apache::lonnavmaps::navmap->new();
3958: }
3959: if (ref($$navmapref)) {
3960: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3961: $checkencrypt = 1;
3962: }
3963: }
3964: }
3965: if ($checkencrypt) {
3966: my $shownsymb = &Apache::lonenc::encrypted($symb);
3967: my $shownurl = &Apache::lonenc::encrypted($url);
3968: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.484.2.80 raeburn 3969: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.484.2.67 raeburn 3970: if ($env{'request.enc'} ne '') {
3971: delete($env{'request.enc'});
3972: }
3973: } else {
3974: $url='';
3975: }
3976: } else {
3977: $url='';
3978: }
1.484.2.12 raeburn 3979: } else {
3980: $url='';
3981: }
1.484.2.19 raeburn 3982: }
1.484.2.66 raeburn 3983: } elsif ($supplementalflag) {
3984: if ($isexternal) {
3985: if ($url =~ /^([^#]+)#([^#]+)$/) {
3986: $url = $1;
3987: $anchor = $2;
1.484.2.70 raeburn 3988: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
1.484.2.80 raeburn 3989: unless (&Apache::lonnet::uses_sts()) {
3990: if ($hostname ne '') {
3991: $url = 'http://'.$hostname.$url;
3992: }
3993: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
3994: }
1.484.2.70 raeburn 3995: $nomodal = 1;
3996: }
3997: }
3998: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
3999: if (($ENV{'SERVER_PORT'} == 443) &&
4000: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.484.2.80 raeburn 4001: unless (&Apache::lonnet::uses_sts()) {
4002: if ($hostname ne '') {
4003: $url = 'http://'.$hostname.$url;
4004: }
4005: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4006: }
1.484.2.70 raeburn 4007: $nomodal = 1;
1.484.2.66 raeburn 4008: }
4009: }
1.329 droeschl 4010: }
1.484.2.67 raeburn 4011: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4012: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 4013: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4014: my $foldername=&escape($foldertitle);
4015: my $folderpath=$env{'form.folderpath'};
4016: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 4017: if (!$allowed && $supplementalflag) {
4018: $folderpath.=$containerarg.'&'.$foldername;
4019: $url.='folderpath='.&escape($folderpath);
4020: } else {
4021: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4022: 'parameter_randompick'))[0];
1.484.2.67 raeburn 4023: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4024: 'parameter_randomorder'))[0]=~/^yes$/i);
4025: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4026: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4027: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4028: 'parameter_encrypturl'))[0]=~/^yes$/i);
4029: unless ($hiddenmap) {
1.484.2.70 raeburn 4030: if (ref($navmapref)) {
4031: unless (ref($$navmapref)) {
4032: $$navmapref = Apache::lonnavmaps::navmap->new();
4033: }
4034: if (ref($$navmapref)) {
4035: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4036: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4037: unless (@resources) {
4038: $hiddenmap = 1;
4039: unless ($env{'request.role.adv'}) {
4040: $url = '';
4041: $hiddenfolder = 1;
4042: }
1.484.2.67 raeburn 4043: }
4044: }
4045: }
4046: }
4047: }
4048: unless ($encryptmap) {
1.484.2.70 raeburn 4049: if ((ref($navmapref)) && (ref($$navmapref))) {
4050: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4051: $encryptmap = 1;
4052: }
1.484.2.67 raeburn 4053: }
4054: }
4055:
4056: # Append randompick number, hidden, and encrypted with ":" to foldername,
4057: # so it gets transferred between levels
4058: $folderpath.=$containerarg.'&'.$foldername.
4059: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4060: unless ($url eq '') {
4061: $url.='folderpath='.&escape($folderpath);
4062: }
1.484.2.19 raeburn 4063: my $rpckchk;
4064: if ($rpicknum) {
4065: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 4066: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4067: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4068: }
1.484.2.19 raeburn 4069: }
1.484.2.29 raeburn 4070: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 4071: $rand_pick_text =
1.478 raeburn 4072: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4073: $form_param."\n".
1.478 raeburn 4074: $form_common."\n".
1.484.2.67 raeburn 4075: '<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 4076: if ($rpicknum ne '') {
4077: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4078: }
1.484.2.29 raeburn 4079: $rand_pick_text .= '</span></span>'.
4080: $form_end;
1.484.2.30 raeburn 4081: my $ro_set;
1.484.2.67 raeburn 4082: if ($randorder) {
1.484.2.30 raeburn 4083: $ro_set = 'checked="checked"';
4084: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4085: push(@{$filtersref->{'randomorder'}},$orderidx);
4086: }
4087: }
1.484.2.41 raeburn 4088: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 4089: $rand_order_text =
1.484.2.29 raeburn 4090: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 4091: $form_param."\n".
1.484.2.29 raeburn 4092: $form_common."\n".
1.484.2.67 raeburn 4093: '<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 4094: $form_end;
1.484.2.19 raeburn 4095: }
1.484.2.18 raeburn 4096: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 4097: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 4098: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 4099: if ($title) {
4100: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4101: }
4102: if ($isexternal && $orderidx) {
4103: $url .= '&idx='.$orderidx;
4104: }
1.484.2.66 raeburn 4105: if ($anchor ne '') {
4106: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4107: }
1.329 droeschl 4108: }
1.484.2.19 raeburn 4109: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 4110: if ($allowed) {
1.484.2.19 raeburn 4111: my $fileloc =
1.484.2.12 raeburn 4112: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 4113: if ($isexternal) {
4114: ($editlink,$extresform) =
1.484.2.67 raeburn 4115: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4116: undef,undef,undef,$disabled);
1.484.2.19 raeburn 4117: } elsif (!$isfolder && !$ispage) {
4118: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 4119: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 4120: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 4121: my $suppanchor;
4122: if ($supplementalflag) {
4123: $suppanchor = $anchor;
4124: }
1.484.2.19 raeburn 4125: my $jscall =
1.484.2.12 raeburn 4126: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4127: $switchserver,
1.484.2.14 raeburn 4128: $forceedit,
1.484.2.19 raeburn 4129: undef,$symb,
4130: &escape($env{'form.folderpath'}),
1.484.2.80 raeburn 4131: $renametitle,$hostname,
4132: '','',1,$suppanchor);
1.484.2.12 raeburn 4133: if ($jscall) {
1.484.2.19 raeburn 4134: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4135: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 4136: }
4137: }
4138: }
1.484.2.19 raeburn 4139: $tdalign = ' align="right" valign="top"';
4140: $tdwidth = ' width="80%"';
1.329 droeschl 4141: }
1.408 raeburn 4142: my $reinit;
4143: if ($crstype eq 'Community') {
4144: $reinit = &mt('(re-initialize community to access)');
4145: } else {
4146: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 4147: }
4148: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70 raeburn 4149: my $link;
1.472 raeburn 4150: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4151: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4152: } elsif ($url) {
1.484.2.66 raeburn 4153: if ($anchor ne '') {
4154: if ($supplementalflag) {
4155: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4156: } else {
4157: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4158: }
4159: }
1.484.2.80 raeburn 4160:
4161: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4162: $link = 'http://'.$hostname.$url;
4163: } else {
4164: $link = $url;
4165: }
4166: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
1.484.2.70 raeburn 4167: if ($nomodal) {
4168: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4169: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4170: } else {
4171: $line.=&Apache::loncommon::modal_link($link,
4172: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4173: }
1.469 www 4174: } else {
4175: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4176: }
1.484.2.19 raeburn 4177: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4178: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4179: $line.='<a href="'.$url.'">'.$title.'</a>';
4180: } elsif ($url) {
1.484.2.70 raeburn 4181: if ($nomodal) {
4182: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4183: $title.'</a>';
4184: } else {
4185: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4186: }
1.484.2.67 raeburn 4187: } elsif (($hiddenfolder) || ($hiddenres)) {
1.484.2.72 raeburn 4188: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4189: } else {
4190: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4191: }
1.484.2.19 raeburn 4192: $line.="$extresform</td>";
1.478 raeburn 4193: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4194: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4195: if (($allowed) && ($folder!~/^supplemental/)) {
4196: my %lt=&Apache::lonlocal::texthash(
4197: 'hd' => 'Hidden',
4198: 'ec' => 'URL hidden');
1.484.2.30 raeburn 4199: my ($enctext,$hidtext);
4200: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4201: $enctext = ' checked="checked"';
4202: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4203: push(@{$filtersref->{'encrypturl'}},$orderidx);
4204: }
4205: }
4206: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4207: $hidtext = ' checked="checked"';
4208: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4209: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4210: }
4211: }
1.484.2.29 raeburn 4212: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4213: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4214: $line.=(<<ENDPARMS);
4215: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 4216: <form action="/adm/coursedocs" method="post" name="$formhidden">
4217: $form_param
1.478 raeburn 4218: $form_common
1.484.2.67 raeburn 4219: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4220: $form_end
1.458 raeburn 4221: <br />
1.484.2.29 raeburn 4222: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4223: $form_param
1.478 raeburn 4224: $form_common
1.484.2.67 raeburn 4225: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4226: $form_end
4227: </td>
1.478 raeburn 4228: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4229: $rand_order_text</td>
1.329 droeschl 4230: ENDPARMS
4231: }
1.379 bisitz 4232: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4233: return $line;
4234: }
4235:
1.484.2.30 raeburn 4236: sub action_restrictions {
4237: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4238: my %denied = (
4239: cut => 0,
4240: copy => 0,
4241: remove => 0,
4242: );
4243: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4244: # no copy for published maps
4245: $denied{'copy'} = 1;
1.484.2.82 raeburn 4246: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4247: unless ($1 eq 'simpleproblem') {
4248: $denied{'copy'} = 1;
4249: }
4250: $denied{'cut'} = 1;
1.484.2.30 raeburn 4251: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4252: if ($folderpath =~ /^default&[^\&]+$/) {
4253: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4254: $denied{'remove'} = 1;
4255: }
4256: $denied{'cut'} = 1;
4257: $denied{'copy'} = 1;
4258: }
4259: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4260: my $group = $1;
4261: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4262: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4263: $denied{'remove'} = 1;
4264: }
4265: }
4266: $denied{'cut'} = 1;
4267: $denied{'copy'} = 1;
4268: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4269: my $group = $1;
4270: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4271: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4272: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4273: if (keys(%groupsettings) > 0) {
4274: $denied{'remove'} = 1;
4275: }
4276: $denied{'cut'} = 1;
4277: $denied{'copy'} = 1;
4278: }
4279: }
4280: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4281: my $group = $1;
4282: if ($url =~ /group_boards_\Q$group\E/) {
4283: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4284: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4285: if (keys(%groupsettings) > 0) {
4286: if (ref($groupsettings{'functions'}) eq 'HASH') {
4287: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4288: $denied{'remove'} = 1;
4289: }
4290: }
4291: }
4292: $denied{'cut'} = 1;
4293: $denied{'copy'} = 1;
4294: }
4295: }
4296: }
4297: return %denied;
4298: }
4299:
1.484.2.26 raeburn 4300: sub new_timebased_suffix {
1.484.2.30 raeburn 4301: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4302: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4303: if ($type eq 'paste') {
4304: $prefix = $type;
4305: $namespace = 'courseeditor';
1.484.2.56 raeburn 4306: $idtype = 'addcode';
1.484.2.30 raeburn 4307: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4308: $prefix = 'docs';
4309: if ($area eq 'supplemental') {
4310: $prefix = 'supp';
4311: }
4312: $prefix .= $container;
4313: $namespace = 'uploadedmaps';
4314: } else {
4315: $prefix = $type;
4316: $namespace = 'templated';
1.484.2.15 raeburn 4317: }
4318: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4319: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4320: if (!$suffix) {
1.484.2.30 raeburn 4321: if ($type eq 'paste') {
4322: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4323: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4324: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4325: } elsif ($type eq 'smppg') {
4326: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4327: } else {
1.484.2.42 raeburn 4328: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4329: }
1.484.2.15 raeburn 4330: if ($error) {
4331: $errtext .= '<br />'.$error;
4332: }
4333: }
4334: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4335: $locknotfreed =
4336: '<div class="LC_error">'.
4337: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4338: if ($type eq 'paste') {
1.484.2.57 raeburn 4339: if ($freedlock eq 'nolock') {
4340: $locknotfreed =
4341: '<div class="LC_error">'.
4342: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4343:
1.484.2.60 raeburn 4344: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4345: } else {
4346: $locknotfreed .=
4347: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4348: }
1.484.2.30 raeburn 4349: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4350: $locknotfreed .=
4351: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4352: } elsif ($type eq 'smppg') {
4353: $locknotfreed .=
4354: &mt('This will prevent creation of additional simple pages in this course.');
4355: } else {
4356: $locknotfreed .=
1.484.2.42 raeburn 4357: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4358: }
1.484.2.30 raeburn 4359: unless ($type eq 'paste') {
4360: $locknotfreed .=
1.484.2.38 raeburn 4361: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4362: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4363: }
4364: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4365: }
4366: return ($suffix,$errtext,$locknotfreed);
4367: }
4368:
1.329 droeschl 4369: =pod
4370:
4371: =item tiehash()
4372:
4373: tie the hash
4374:
4375: =cut
4376:
4377: sub tiehash {
4378: my ($mode)=@_;
4379: $hashtied=0;
4380: if ($env{'request.course.fn'}) {
4381: if ($mode eq 'write') {
4382: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4383: &GDBM_WRCREAT(),0640)) {
4384: $hashtied=2;
4385: }
4386: } else {
4387: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4388: &GDBM_READER(),0640)) {
4389: $hashtied=1;
4390: }
4391: }
1.364 bisitz 4392: }
1.329 droeschl 4393: }
4394:
4395: sub untiehash {
4396: if ($hashtied) { untie %hash; }
4397: $hashtied=0;
4398: return OK;
4399: }
4400:
4401:
4402:
4403:
4404: sub checkonthis {
1.484.2.78 raeburn 4405: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4406: $url=&unescape($url);
4407: $alreadyseen{$url}=1;
4408: $r->rflush();
4409: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4410: $r->print("\n<br />");
4411: if ($level==0) {
4412: $r->print("<br />");
4413: }
4414: for (my $i=0;$i<=$level*5;$i++) {
4415: $r->print(' ');
4416: }
4417: $r->print('<a href="'.$url.'" target="cat">'.
4418: ($title?$title:$url).'</a> ');
4419: if ($url=~/^\/res\//) {
1.484.2.78 raeburn 4420: my $updated;
4421: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4422: ($url !~ /\.\d+\.\w+$/)) {
4423: $updated = &Apache::lonnet::remove_stale_resfile($url);
4424: }
1.329 droeschl 4425: my $result=&Apache::lonnet::repcopy(
4426: &Apache::lonnet::filelocation('',$url));
4427: if ($result eq 'ok') {
4428: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.484.2.78 raeburn 4429: if ($updated) {
4430: $r->print('<br />');
4431: for (my $i=0;$i<=$level*5;$i++) {
4432: $r->print(' ');
4433: }
4434: $r->print('- '.&mt('Outdated copy removed'));
4435: }
1.329 droeschl 4436: $r->rflush();
4437: &Apache::lonnet::countacc($url);
4438: $url=~/\.(\w+)$/;
4439: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4440: $r->print('<br />');
4441: $r->rflush();
4442: for (my $i=0;$i<=$level*5;$i++) {
4443: $r->print(' ');
4444: }
4445: $r->print('- '.&mt('Rendering:').' ');
4446: my ($errorcount,$warningcount)=split(/:/,
4447: &Apache::lonnet::ssi_body($url,
4448: ('grade_target'=>'web',
4449: 'return_only_error_and_warning_counts' => 1)));
4450: if (($errorcount) ||
4451: ($warningcount)) {
4452: if ($errorcount) {
1.369 bisitz 4453: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4454: &mt('[quant,_1,error]',$errorcount).'</span>');
4455: }
4456: if ($warningcount) {
4457: $r->print('<span class="LC_warning">'.
4458: &mt('[quant,_1,warning]',$warningcount).'</span>');
4459: }
4460: } else {
4461: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4462: }
4463: $r->rflush();
4464: }
4465: my $dependencies=
4466: &Apache::lonnet::metadata($url,'dependencies');
4467: foreach my $dep (split(/\,/,$dependencies)) {
4468: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.484.2.78 raeburn 4469: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4470: }
4471: }
4472: } elsif ($result eq 'unavailable') {
4473: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4474: } elsif ($result eq 'not_found') {
4475: unless ($url=~/\$/) {
1.484.2.19 raeburn 4476: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4477: } else {
1.366 bisitz 4478: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4479: }
4480: } else {
4481: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4482: }
1.484.2.78 raeburn 4483: if (($updated) && ($result ne 'ok')) {
4484: $r->print('<br />'.&mt('Outdated copy removed'));
4485: }
1.329 droeschl 4486: }
4487: }
4488: }
4489:
4490:
4491:
4492: =pod
4493:
4494: =item list_symbs()
4495:
1.484.2.3 raeburn 4496: List Content Identifiers
1.329 droeschl 4497:
4498: =cut
4499:
4500: sub list_symbs {
4501: my ($r) = @_;
4502:
1.408 raeburn 4503: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4504: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4505: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4506: $r->print(&startContentScreen('tools'));
1.329 droeschl 4507: my $navmap = Apache::lonnavmaps::navmap->new();
4508: if (!defined($navmap)) {
4509: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4510: '<div class="LC_error">'.
4511: &mt('Unable to retrieve information about course contents').
4512: '</div>');
1.408 raeburn 4513: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4514: } else {
1.484 raeburn 4515: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4516: &Apache::loncommon::start_data_table().
4517: &Apache::loncommon::start_data_table_header_row().
4518: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4519: &Apache::loncommon::end_data_table_header_row()."\n");
4520: my $count;
1.329 droeschl 4521: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4522: $r->print(&Apache::loncommon::start_data_table_row().
4523: '<td>'.$res->compTitle().'</td>'.
4524: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4525: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4526: $count ++;
4527: }
4528: if (!$count) {
4529: $r->print(&Apache::loncommon::start_data_table_row().
4530: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4531: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4532: }
1.484 raeburn 4533: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4534: }
1.484.2.19 raeburn 4535: $r->print(&endContentScreen());
1.329 droeschl 4536: }
4537:
1.484.2.78 raeburn 4538: sub contentverifyform {
4539: my ($r) = @_;
4540: my $crstype = &Apache::loncommon::course_type();
4541: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4542: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4543: $r->print(&startContentScreen('tools'));
4544: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4545: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4546: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4547: ' <span class="LC_nobreak">'.
4548: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4549: &mt('No').'</label>'.(' 'x2).
4550: '<label><input type="radio" name="checkstale" value="1" />'.
4551: &mt('Yes').'</label></span></p><p>'.
4552: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4553: '<input type="hidden" value="1" name="tools" />'.
4554: '<input type="hidden" value="1" name="verify" /></p></form>');
4555: $r->print(&endContentScreen());
4556: return;
4557: }
1.329 droeschl 4558:
4559: sub verifycontent {
1.484.2.78 raeburn 4560: my ($r,$checkstale) = @_;
1.408 raeburn 4561: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4562: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4563: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4564: $r->print(&startContentScreen('tools'));
4565: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4566: $hashtied=0;
4567: undef %alreadyseen;
4568: %alreadyseen=();
4569: &tiehash();
1.484 raeburn 4570:
1.329 droeschl 4571: foreach my $key (keys(%hash)) {
4572: if ($hash{$key}=~/\.(page|sequence)$/) {
4573: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4574: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4575: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4576: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4577: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4578: }
4579: }
4580: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.484.2.78 raeburn 4581: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4582: }
4583: }
4584: &untiehash();
1.442 www 4585: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4586: $r->print(&endContentScreen());
1.329 droeschl 4587: }
4588:
4589:
4590: sub devalidateversioncache {
4591: my $src=shift;
4592: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4593: &Apache::lonnet::clutter($src));
4594: }
4595:
4596: sub checkversions {
1.484.2.67 raeburn 4597: my ($r,$canedit) = @_;
1.408 raeburn 4598: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4599: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4600: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4601: $r->print(&startContentScreen('tools'));
1.442 www 4602:
1.329 droeschl 4603: my $header='';
4604: my $startsel='';
4605: my $monthsel='';
4606: my $weeksel='';
4607: my $daysel='';
4608: my $allsel='';
4609: my %changes=();
4610: my $starttime=0;
4611: my $haschanged=0;
4612: my %setversions=&Apache::lonnet::dump('resourceversions',
4613: $env{'course.'.$env{'request.course.id'}.'.domain'},
4614: $env{'course.'.$env{'request.course.id'}.'.num'});
4615:
4616: $hashtied=0;
4617: &tiehash();
1.484.2.67 raeburn 4618: if ($canedit) {
4619: my %newsetversions=();
4620: if ($env{'form.setmostrecent'}) {
4621: $haschanged=1;
4622: foreach my $key (keys(%hash)) {
4623: if ($key=~/^ids\_(\/res\/.+)$/) {
4624: $newsetversions{$1}='mostrecent';
4625: &devalidateversioncache($1);
4626: }
1.329 droeschl 4627: }
1.484.2.67 raeburn 4628: } elsif ($env{'form.setcurrent'}) {
4629: $haschanged=1;
4630: foreach my $key (keys(%hash)) {
4631: if ($key=~/^ids\_(\/res\/.+)$/) {
4632: my $getvers=&Apache::lonnet::getversion($1);
4633: if ($getvers>0) {
4634: $newsetversions{$1}=$getvers;
4635: &devalidateversioncache($1);
4636: }
4637: }
1.329 droeschl 4638: }
1.484.2.67 raeburn 4639: } elsif ($env{'form.setversions'}) {
4640: $haschanged=1;
4641: foreach my $key (keys(%env)) {
4642: if ($key=~/^form\.set_version_(.+)$/) {
4643: my $src=$1;
4644: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4645: $newsetversions{$src}=$env{$key};
4646: &devalidateversioncache($src);
4647: }
4648: }
1.329 droeschl 4649: }
1.484.2.67 raeburn 4650: }
4651: if ($haschanged) {
4652: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4653: $env{'course.'.$env{'request.course.id'}.'.domain'},
4654: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4655: $r->print(&Apache::loncommon::confirmwrapper(
4656: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4657: } else {
4658: $r->print(&Apache::loncommon::confirmwrapper(
4659: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4660: }
4661: &mark_hash_old();
4662: }
4663: &changewarning($r,'');
1.329 droeschl 4664: }
4665: if ($env{'form.timerange'} eq 'all') {
4666: # show all documents
1.484.2.34 raeburn 4667: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4668: $allsel=' selected="selected"';
1.329 droeschl 4669: foreach my $key (keys(%hash)) {
4670: if ($key=~/^ids\_(\/res\/.+)$/) {
4671: my $src=$1;
4672: $changes{$src}=1;
4673: }
4674: }
4675: } else {
4676: # show documents which changed
4677: %changes=&Apache::lonnet::dump
4678: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4679: $env{'course.'.$env{'request.course.id'}.'.num'});
4680: my $firstkey=(keys(%changes))[0];
4681: unless ($firstkey=~/^error\:/) {
4682: unless ($env{'form.timerange'}) {
4683: $env{'form.timerange'}=604800;
4684: }
4685: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4686: .&mt('seconds');
4687: if ($env{'form.timerange'}==-1) {
4688: $seltext='since start of course';
1.484.2.19 raeburn 4689: $startsel=' selected="selected"';
1.329 droeschl 4690: $env{'form.timerange'}=time;
4691: }
4692: $starttime=time-$env{'form.timerange'};
4693: if ($env{'form.timerange'}==2592000) {
4694: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4695: $monthsel=' selected="selected"';
1.329 droeschl 4696: } elsif ($env{'form.timerange'}==604800) {
4697: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4698: $weeksel=' selected="selected"';
1.329 droeschl 4699: } elsif ($env{'form.timerange'}==86400) {
4700: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4701: $daysel=' selected="selected"';
1.329 droeschl 4702: }
4703: $header=&mt('Content changed').' '.$seltext;
4704: } else {
4705: $header=&mt('No content modifications yet.');
4706: }
4707: }
4708: %setversions=&Apache::lonnet::dump('resourceversions',
4709: $env{'course.'.$env{'request.course.id'}.'.domain'},
4710: $env{'course.'.$env{'request.course.id'}.'.num'});
4711: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4712: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4713: 'lm' => 'Version changes since last Month',
4714: 'lw' => 'Version changes since last Week',
4715: 'sy' => 'Version changes since Yesterday',
4716: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4717: 'cd' => 'Change display',
1.329 droeschl 4718: 'sd' => 'Display',
4719: 'fi' => 'File',
4720: 'md' => 'Modification Date',
4721: 'mr' => 'Most recently published Version',
1.408 raeburn 4722: 've' => 'Version used in '.$crstype,
4723: 'vu' => 'Set Version to be used in '.$crstype,
4724: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4725: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4726: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4727: 'di' => 'Differences',
1.484 raeburn 4728: 'save' => 'Save changes',
4729: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4730: 'act' => 'Actions');
1.484.2.67 raeburn 4731: my ($disabled,$readonly);
4732: unless ($canedit) {
4733: $disabled = 'disabled="disabled"';
4734: $readonly = 1;
4735: }
1.329 droeschl 4736: $r->print(<<ENDHEADERS);
1.484 raeburn 4737: <h4 class="LC_info">$header</h4>
1.329 droeschl 4738: <form action="/adm/coursedocs" method="post">
4739: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4740: <div class="LC_left_float">
1.479 golterma 4741: <fieldset>
1.484 raeburn 4742: <legend>$lt{'cd'}</legend>
1.329 droeschl 4743: <select name="timerange">
1.484.2.19 raeburn 4744: <option value='all'$allsel>$lt{'al'}</option>
4745: <option value="-1"$startsel>$lt{'st'}</option>
4746: <option value="2592000"$monthsel>$lt{'lm'}</option>
4747: <option value="604800"$weeksel>$lt{'lw'}</option>
4748: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4749: </select>
4750: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4751: </fieldset>
4752: </div>
4753: <div class="LC_left_float">
4754: <fieldset>
4755: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4756: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4757: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4758: </fieldset>
4759: </div>
4760: <br clear="all" />
4761: <hr />
4762: <h4>$lt{'vers'}</h4>
1.329 droeschl 4763: ENDHEADERS
1.479 golterma 4764: #number of columns for version history
1.484.2.44 raeburn 4765: my %changedbytime;
4766: foreach my $key (keys(%changes)) {
4767: #excludes not versionable problems from resource version history:
4768: next if ($key =~ /^\/res\/lib\/templates/);
4769: my $chg;
4770: if ($env{'form.timerange'} eq 'all') {
4771: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4772: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4773: } else {
4774: $chg = $changes{$key};
4775: next if ($chg < $starttime);
4776: }
4777: push(@{$changedbytime{$chg}},$key);
4778: }
4779: if (keys(%changedbytime) == 0) {
4780: &untiehash();
4781: $r->print(&mt('No content changes in imported content in specified time frame').
4782: &endContentScreen());
4783: return;
4784: }
1.479 golterma 4785: $r->print(
1.484.2.67 raeburn 4786: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4787: &Apache::loncommon::start_data_table().
4788: &Apache::loncommon::start_data_table_header_row().
4789: '<th>'.&mt('Resources').'</th>'.
4790: "<th>$lt{'mr'}</th>".
4791: "<th>$lt{'ve'}</th>".
4792: "<th>$lt{'vu'}</th>".
4793: '<th>'.&mt('History').'</th>'.
4794: &Apache::loncommon::end_data_table_header_row()
4795: );
1.484.2.44 raeburn 4796: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4797: foreach my $key (sort(@{$changedbytime{$chg}})) {
4798: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4799: my $currentversion=&Apache::lonnet::getversion($key);
4800: if ($currentversion<0) {
4801: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4802: }
4803: my $linkurl=&Apache::lonnet::clutter($key);
4804: $r->print(
4805: &Apache::loncommon::start_data_table_row().
4806: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4807: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4808: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4809: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4810: '<td align="right">'
4811: );
4812: # Used in course
4813: my $usedversion=$hash{'version_'.$linkurl};
4814: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4815: if ($usedversion != $currentversion) {
1.479 golterma 4816: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4817: } else {
1.479 golterma 4818: $r->print($usedversion);
4819: }
1.329 droeschl 4820: } else {
1.484.2.19 raeburn 4821: $r->print($currentversion);
1.329 droeschl 4822: }
1.484.2.44 raeburn 4823: $r->print('</td><td title="'.$lt{'vu'}.'">');
4824: # Set version
4825: $r->print(&Apache::loncommon::select_form(
4826: $setversions{$linkurl},
4827: 'set_version_'.$linkurl,
4828: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4829: '' => '',
4830: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4831: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4832: my $lastold=1;
4833: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4834: my $url=$root.'.'.$prevvers.'.'.$extension;
4835: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4836: $lastold=$prevvers;
4837: }
4838: }
4839: $r->print('</td>');
4840: # List all available versions
4841: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4842: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4843: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4844: $r->print(
1.484.2.44 raeburn 4845: '<span class="LC_nobreak">'
4846: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4847: .&mt('Version [_1]',$prevvers).'</a>'
4848: .' ('.&Apache::lonlocal::locallocaltime(
4849: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4850: .')');
4851: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4852: $r->print(
4853: ' <a href="/adm/diff?filename='.
4854: &Apache::lonnet::clutter($root.'.'.$extension).
4855: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4856: '" target="diffs">'.&mt('Diffs').'</a>');
4857: }
4858: $r->print('</span><br />');
1.329 droeschl 4859: }
1.484.2.44 raeburn 4860: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4861: }
1.329 droeschl 4862: }
1.484.2.19 raeburn 4863: $r->print(
4864: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4865: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4866: '</form>'
4867: );
1.329 droeschl 4868:
4869: &untiehash();
1.484.2.19 raeburn 4870: $r->print(&endContentScreen());
1.484.2.44 raeburn 4871: return;
1.329 droeschl 4872: }
4873:
4874: sub mark_hash_old {
4875: my $retie_hash=0;
4876: if ($hashtied) {
4877: $retie_hash=1;
4878: &untiehash();
4879: }
4880: &tiehash('write');
4881: $hash{'old'}=1;
4882: &untiehash();
4883: if ($retie_hash) { &tiehash(); }
4884: }
4885:
4886: sub is_hash_old {
4887: my $untie_hash=0;
4888: if (!$hashtied) {
4889: $untie_hash=1;
4890: &tiehash();
4891: }
4892: my $return=$hash{'old'};
4893: if ($untie_hash) { &untiehash(); }
4894: return $return;
4895: }
4896:
4897: sub changewarning {
4898: my ($r,$postexec,$message,$url)=@_;
4899: if (!&is_hash_old()) { return; }
4900: my $pathvar='folderpath';
4901: my $path=&escape($env{'form.folderpath'});
4902: if (!defined($url)) {
4903: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4904: }
4905: my $course_type = &Apache::loncommon::course_type();
4906: if (!defined($message)) {
4907: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4908: }
4909: $r->print("\n\n".
1.372 bisitz 4910: '<script type="text/javascript">'."\n".
4911: '// <![CDATA['."\n".
4912: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4913: '// ]]>'."\n".
1.369 bisitz 4914: '</script>'."\n".
1.375 tempelho 4915: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4916: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4917: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4918: &mt($message,' <input type="hidden" name="'.
4919: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4920: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4921: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4922: }
4923:
4924:
4925: sub init_breadcrumbs {
1.484.2.44 raeburn 4926: my ($form,$text,$help)=@_;
1.329 droeschl 4927: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4928: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4929: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4930: faq=>273,
4931: bug=>'Instructor Interface',
1.484.2.44 raeburn 4932: help => $help});
1.329 droeschl 4933: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4934: text=>$text,
4935: faq=>273,
4936: bug=>'Instructor Interface'});
4937: }
4938:
1.441 www 4939: # subroutine to list form elements
4940: sub create_list_elements {
4941: my @formarr = @_;
4942: my $list = '';
1.484.2.12 raeburn 4943: foreach my $button (@formarr){
4944: foreach my $picture (keys(%{$button})) {
4945: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4946: }
4947: }
4948: return $list;
4949: }
1.329 droeschl 4950:
1.441 www 4951: # subroutine to create ul from list elements
4952: sub create_form_ul {
4953: my $list = shift;
4954: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4955: return $ul;
4956: }
1.329 droeschl 4957:
1.442 www 4958: #
4959: # Start tabs
4960: #
4961:
4962: sub startContentScreen {
1.484 raeburn 4963: my ($mode) = @_;
4964: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4965: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4966: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4967: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4968: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4969: } else {
1.484.2.34 raeburn 4970: $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 4971: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4972: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4973: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4974: }
4975: $output .= "\n".'</ul>'."\n";
4976: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4977: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4978: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4979: return $output;
1.442 www 4980: }
4981:
4982: #
4983: # End tabs
4984: #
4985:
4986: sub endContentScreen {
1.484 raeburn 4987: return '</div></div></div>';
1.442 www 4988: }
1.329 droeschl 4989:
1.446 www 4990: sub supplemental_base {
1.484.2.33 raeburn 4991: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4992: }
4993:
1.329 droeschl 4994: sub handler {
4995: my $r = shift;
4996: &Apache::loncommon::content_type($r,'text/html');
4997: $r->send_http_header;
4998: return OK if $r->header_only;
1.484 raeburn 4999:
5000: # get course data
1.408 raeburn 5001: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5002: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5003: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5004:
5005: # graphics settings
5006: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5007:
1.443 www 5008: #
1.329 droeschl 5009: # --------------------------------------------- Initialize help topics for this
5010: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5011: 'Adding_External_Resource','Navigate_Content',
5012: 'Adding_Folders','Docs_Overview', 'Load_Map',
5013: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 5014: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 5015: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
5016: 'Dropbox','Simple_Problem') {
1.329 droeschl 5017: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5018: }
5019: # Composite help files
5020: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5021: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5022: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5023: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5024: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5025: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5026: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5027: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5028: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5029: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 5030:
1.484.2.67 raeburn 5031: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 5032: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5033: unless ($r->uri eq '/adm/supplemental') {
5034: # does this user have privileges to modify content.
1.484.2.67 raeburn 5035: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5036: $allowed = 1;
5037: $canedit = 1;
5038: $canview = 1;
5039: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5040: $allowed = 1;
5041: $canview = 1;
5042: }
5043: }
5044: unless ($canedit) {
5045: $disabled = ' disabled="disabled"';
1.472 raeburn 5046: }
1.484.2.53 raeburn 5047: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.484.2.78 raeburn 5048: if ($env{'form.inhibitmenu'}) {
5049: unless ($env{'form.inhibitmenu'} eq 'yes') {
5050: delete($env{'form.inhibitmenu'});
5051: }
5052: }
5053:
1.484.2.53 raeburn 5054: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 5055: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.484.2.78 raeburn 5056: if (!$canedit) {
5057: &verifycontent($r);
5058: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5059: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5060: text=>'Results',
5061: faq=>273,
5062: bug=>'Instructor Interface'});
5063: &verifycontent($r,$env{'form.checkstale'});
5064: } else {
5065: &contentverifyform($r);
5066: }
1.329 droeschl 5067: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5068: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5069: &list_symbs($r);
5070: } elsif ($allowed && $env{'form.docslog'}) {
5071: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5072: my $folder = $env{'form.folder'};
5073: if ($folder eq '') {
5074: $folder='default';
5075: }
1.484.2.67 raeburn 5076: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5077: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 5078: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 5079: &checkversions($r,$canedit);
5080: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 5081: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5082: &dumpcourse($r);
5083: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 5084: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5085: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5086: } else {
1.445 www 5087: #
5088: # Done catching special calls
1.484 raeburn 5089: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5090: # Get the parameters that may be needed
5091: #
5092: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 5093: ['folderpath',
5094: 'forcesupplement','forcestandard',
5095: 'tools','symb','command','supppath']);
1.445 www 5096:
1.484.2.78 raeburn 5097: foreach my $item ('forcesupplement','forcestandard','tools') {
5098: next if ($env{'form.'.$item} eq '');
5099: unless ($env{'form.'.$item} eq '1') {
5100: delete($env{'form.'.$item});
5101: }
5102: }
5103:
5104: if ($env{'form.command'}) {
5105: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5106: delete($env{'form.command'});
5107: }
5108: }
5109:
5110: if ($env{'form.symb'}) {
5111: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5112: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5113: delete($env{'form.symb'});
5114: }
5115: }
5116:
1.445 www 5117: # standard=1: this is a "new-style" course with an uploaded map as top level
5118: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5119:
5120: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5121:
1.484 raeburn 5122: # Decide whether this should display supplemental or main content or utilities
1.445 www 5123: # supplementalflag=1: show supplemental documents
5124: # supplementalflag=0: show standard documents
1.484 raeburn 5125: # toolsflag=1: show utilities
1.445 www 5126:
1.484.2.39 raeburn 5127: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5128: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5129: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5130: $supplementalflag=0;
5131: }
5132: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5133: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5134: unless ($allowed) { $supplementalflag=1; }
5135: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5136: my $toolsflag=0;
5137: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5138:
1.484.2.78 raeburn 5139: if ($env{'form.folderpath'} ne '') {
5140: my @items = split(/\&/,$env{'form.folderpath'});
5141: my $badpath;
5142: for (my $i=0; $i<@items; $i++) {
5143: my $odd = $i%2;
5144: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5145: $badpath = 1;
5146: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5147: $badpath = 1;
5148: }
5149: last if ($badpath);
5150: }
5151: if ($badpath) {
5152: delete($env{'form.folderpath'});
5153: }
5154: }
5155:
5156: if ($env{'form.supppath'} ne '') {
5157: my @items = split(/\&/,$env{'form.supppath'});
5158: my $badpath;
5159: for (my $i=0; $i<@items; $i++) {
5160: my $odd = $i%2;
5161: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5162: $badpath = 1;
5163: }
5164: last if ($badpath);
5165: }
5166: if ($badpath) {
5167: delete($env{'form.supppath'});
5168: }
5169: }
5170:
1.329 droeschl 5171: my $script='';
5172: my $showdoc=0;
1.457 raeburn 5173: my $addentries = {};
1.475 raeburn 5174: my $container;
1.329 droeschl 5175: my $containertag;
1.484.2.17 raeburn 5176: my $pathitem;
1.484.2.67 raeburn 5177: my $hiddentop;
5178: my $navmap;
5179: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5180:
1.464 www 5181: # Do we directly jump somewhere?
1.484.2.21 raeburn 5182: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5183: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 5184: $env{'form.folderpath'}=
1.484.2.67 raeburn 5185: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 5186: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5187: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5188: } elsif ($env{'form.supppath'} ne '') {
5189: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 5190: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5191: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5192: }
1.472 raeburn 5193: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 5194: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 5195: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5196: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 5197: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 5198: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5199: } elsif ($env{'form.command'} eq 'contents') {
5200: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5201: } elsif ($env{'form.command'} eq 'home') {
5202: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5203: }
5204:
1.484.2.23 raeburn 5205:
1.445 www 5206: # Where do we store these for when we come back?
5207: my $stored_folderpath='docs_folderpath';
5208: if ($supplementalflag) {
5209: $stored_folderpath='docs_sup_folderpath';
5210: }
1.464 www 5211:
1.484.2.19 raeburn 5212: # No folderpath, and in edit mode, see if we have something stored
5213: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5214: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 5215: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 5216:
5217: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5218: if ($supplementalflag) {
5219: undef($env{'form.folderpath'}) if ($1 eq 'default');
5220: } else {
5221: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5222: }
5223: } else {
1.484.2.19 raeburn 5224: undef($env{'form.folderpath'});
5225: }
1.329 droeschl 5226: }
1.446 www 5227:
5228: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5229: if (!$allowed) {
1.446 www 5230: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5231: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5232: }
5233: }
1.446 www 5234: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5235: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5236: $env{'form.folderpath'} = &supplemental_base()
5237: .'&'.
1.329 droeschl 5238: $env{'form.folderpath'};
5239: }
1.484.2.67 raeburn 5240: # If allowed and user's role is not advanced check folderpath is not hidden
5241: if (($allowed) && (!$env{'request.role.adv'}) &&
5242: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5243: my $folderurl;
5244: my @pathitems = split(/\&/,$env{'form.folderpath'});
5245: my $folder = $pathitems[-2];
5246: if ($folder eq '') {
5247: undef($env{'form.folderpath'});
5248: } else {
5249: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.484.2.87 raeburn 5250: if ((split(/\:/,$pathitems[-1]))[5]) {
1.484.2.67 raeburn 5251: $folderurl .= '.page';
5252: } else {
5253: $folderurl .= '.sequence';
5254: }
5255: unless (ref($navmap)) {
5256: $navmap = Apache::lonnavmaps::navmap->new();
5257: }
5258: if (ref($navmap)) {
5259: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5260: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5261: unless (@resources) {
5262: undef($env{'form.folderpath'});
5263: }
5264: }
5265: }
5266: }
5267: }
5268:
5269:
1.446 www 5270: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 5271: unless ($env{'form.folderpath'}) {
1.446 www 5272: if ($supplementalflag) {
5273: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 5274: } elsif ($allowed) {
5275: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5276: }
1.472 raeburn 5277: }
1.446 www 5278:
1.445 www 5279: # Store this
1.484 raeburn 5280: unless ($toolsflag) {
1.484.2.67 raeburn 5281: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 5282: &Apache::loncommon::store_course_settings($stored_folderpath,
5283: {'folderpath' => 'scalar'});
5284: }
5285: my $folderpath;
1.484 raeburn 5286: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 5287: $folderpath = $env{'form.folderpath'};
5288: my (@folders)=split('&',$env{'form.folderpath'});
5289: $env{'form.foldername'}=&unescape(pop(@folders));
5290: if ($env{'form.foldername'} =~ /\:1$/) {
5291: $container = 'page';
5292: } else {
5293: $container = 'sequence';
5294: }
5295: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5296: } else {
1.484.2.19 raeburn 5297: if ($env{'form.folder'} eq '' ||
5298: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 5299: if ($env{'form.folder'} eq 'supplemental') {
5300: $folderpath=&supplemental_base();
5301: } elsif (!$hiddentop) {
5302: $folderpath='default&'.
5303: &escape(&mt('Main Content').':::::');
5304: }
1.484 raeburn 5305: }
5306: }
1.484.2.19 raeburn 5307: $containertag = '<input type="hidden" name="folderpath" value="" />';
5308: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5309: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5310: $showdoc='/'.$1;
5311: }
5312: if ($showdoc) { # got called in sequence from course
5313: $allowed=0;
5314: } else {
1.484.2.67 raeburn 5315: if ($canedit) {
1.484 raeburn 5316: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5317: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5318: }
5319: }
1.329 droeschl 5320: }
5321:
1.344 bisitz 5322: # get personal data
1.329 droeschl 5323: my $uname=$env{'user.name'};
5324: my $udom=$env{'user.domain'};
5325: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5326:
5327: if ($allowed) {
1.484 raeburn 5328: if ($toolsflag) {
5329: $script .= &inject_data_js();
5330: my ($home,$other,%outhash)=&authorhosts();
5331: if (!$home && $other) {
5332: my @hosts;
5333: foreach my $aurole (keys(%outhash)) {
5334: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5335: push(@hosts,$outhash{$aurole});
5336: }
5337: }
5338: $script .= &dump_switchserver_js(@hosts);
5339: }
1.458 raeburn 5340: } else {
1.484.2.43 raeburn 5341: my $tid = 1;
1.484 raeburn 5342: my @tabids;
5343: if ($supplementalflag) {
5344: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5345: $tid = 2;
1.484 raeburn 5346: } else {
5347: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5348: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5349: unshift(@tabids,'001');
5350: push(@tabids,('dd1','ee1'));
5351: }
1.458 raeburn 5352: }
1.484 raeburn 5353: my $tabidstr = join("','",@tabids);
1.484.2.80 raeburn 5354: my $hostname = $r->hostname();
1.484.2.68 raeburn 5355: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.80 raeburn 5356: $canedit,$hostname,\$navmap).
1.484 raeburn 5357: &history_tab_js().
5358: &inject_data_js().
1.484.2.43 raeburn 5359: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5360: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5361: $addentries = {
1.484.2.3 raeburn 5362: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5363: };
1.458 raeburn 5364: }
1.484.2.30 raeburn 5365: $script .= &paste_popup_js();
1.484.2.12 raeburn 5366: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5367: &mt('Switch server?');
1.484.2.19 raeburn 5368:
5369:
1.329 droeschl 5370: }
5371: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5372: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5373: .'// <![CDATA['."\n"
5374: .$script."\n"
5375: .'// ]]>'."\n"
1.484.2.81 raeburn 5376: .'</script>'."\n"
5377: .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5378:
5379: # Breadcrumbs
5380: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5381:
5382: if ($showdoc) {
5383: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5384: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5385: } elsif ($toolsflag) {
1.484.2.67 raeburn 5386: my ($breadtext,$breadtitle);
5387: $breadtext = "$crstype Editor";
5388: if ($canedit) {
5389: $breadtitle = 'Editing '.$crstype.' Contents';
5390: } else {
5391: $breadtext .= ' (View-only mode)';
5392: $breadtitle = 'Viewing '.$crstype.' Contents';
5393: }
1.484.2.44 raeburn 5394: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5395: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5396: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5397: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5398: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5399: $breadtitle)
1.484.2.44 raeburn 5400: );
1.484.2.19 raeburn 5401: } elsif ($r->uri eq '/adm/supplemental') {
5402: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5403: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5404: {'bread_crumbs' => $brcrum,}));
5405: } else {
1.484.2.67 raeburn 5406: my ($breadtext,$breadtitle,$helpitem);
5407: $breadtext = "$crstype Editor";
5408: if ($canedit) {
5409: $breadtitle = 'Editing '.$crstype.' Contents';
5410: $helpitem = 'Docs_Adding_Course_Doc';
5411: } else {
5412: $breadtext .= ' (View-only mode)';
5413: $breadtitle = 'Viewing '.$crstype.' Contents';
5414: $helpitem = 'Docs_Viewing_Course_Doc';
5415: }
1.392 raeburn 5416: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5417: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5418: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5419: {'add_entries' => $addentries}
5420: )
1.392 raeburn 5421: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5422: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5423: $breadtitle,
5424: $helpitem)
1.392 raeburn 5425: );
5426: }
1.364 bisitz 5427:
1.329 droeschl 5428: my %allfiles = ();
5429: my %codebase = ();
1.440 raeburn 5430: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5431: if ($canedit) {
1.329 droeschl 5432: if (($env{'form.uploaddoc.filename'}) &&
5433: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5434: my $context = $1;
5435: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5436: undef($hadchanges);
1.440 raeburn 5437: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5438: \%allfiles,\%codebase,$context,$crstype);
1.484.2.73 raeburn 5439: undef($navmap);
1.329 droeschl 5440: if ($hadchanges) {
5441: &mark_hash_old();
5442: }
1.440 raeburn 5443: $r->print($upload_output);
5444: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5445: # Process file upload - phase two - upload embedded objects
5446: $uploadphase = 'check_embedded';
5447: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5448: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5449: $env{'form.newidx'});
5450: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5451: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5452: my ($destination,$dir_root) = &embedded_destination();
5453: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5454: my $actionurl = '/adm/coursedocs';
5455: my ($result,$flag) =
5456: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5457: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5458: $actionurl);
5459: $r->print($result.&return_to_editor());
5460: } elsif ($env{'form.phase'} eq 'check_embedded') {
5461: # Process file upload - phase three - modify references in HTML file
5462: $uploadphase = 'modified_orightml';
5463: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5464: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5465: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5466: my $result =
5467: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5468: $docuname,$docudom,undef,
5469: $dir_root);
5470: $r->print($result.&return_to_editor());
1.476 raeburn 5471: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5472: $uploadphase = 'decompress_phase_one';
5473: $r->print(&decompression_phase_one().
5474: &return_to_editor());
5475: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5476: $uploadphase = 'decompress_phase_two';
5477: $r->print(&decompression_phase_two().
5478: &return_to_editor());
1.329 droeschl 5479: }
5480: }
5481:
1.484 raeburn 5482: if ($allowed && $toolsflag) {
5483: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5484: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5485: $r->print(&endContentScreen());
5486: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5487: # -----------------------------------------------------------------------------
5488: my %lt=&Apache::lonlocal::texthash(
5489: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5490: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5491: 'upld' => 'Upload Content',
1.329 droeschl 5492: 'srch' => 'Search',
5493: 'impo' => 'Import',
1.484.2.19 raeburn 5494: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5495: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5496: 'selm' => 'Select Map',
5497: 'load' => 'Load Map',
5498: 'newf' => 'New Folder',
5499: 'newp' => 'New Composite Page',
5500: 'syll' => 'Syllabus',
1.425 raeburn 5501: 'navc' => 'Table of Contents',
1.343 biermanm 5502: 'sipa' => 'Simple Course Page',
1.329 droeschl 5503: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5504: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5505: 'drbx' => 'Drop Box',
1.451 www 5506: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5507: 'bull' => 'Discussion Board',
1.347 weissno 5508: 'mypi' => 'My Personal Information Page',
1.353 weissno 5509: 'grpo' => 'Group Portfolio',
1.329 droeschl 5510: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5511: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5512: 'imsf' => 'IMS Upload',
5513: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5514: 'cms' => 'Origin of IMS package',
5515: 'se' => 'Select',
1.484.2.19 raeburn 5516: 'file' => 'File',
1.329 droeschl 5517: 'title' => 'Title',
5518: 'comment' => 'Comment',
1.403 raeburn 5519: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5520: 'bb5' => 'Blackboard 5',
5521: 'bb6' => 'Blackboard 6',
5522: 'angel5' => 'ANGEL 5.5',
5523: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5524: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5525: );
1.329 droeschl 5526: # -----------------------------------------------------------------------------
1.484.2.82 raeburn 5527: # Calculate free quota space for a user or course. A javascript function checks
5528: # file size to determine if upload should be allowed.
1.484.2.64 raeburn 5529: my $quotatype = 'unofficial';
5530: if ($crstype eq 'Community') {
5531: $quotatype = 'community';
5532: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5533: $quotatype = 'official';
5534: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5535: $quotatype = 'textbook';
5536: }
5537: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5538: 'course',$quotatype); # expressed in MB
5539: my $current_disk_usage = 0;
5540: foreach my $subdir ('docs','supplemental') {
5541: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5542: "userfiles/$subdir",1); # expressed in kB
5543: }
5544: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5545: my $usage = $current_disk_usage/1024; # in MB
5546: my $quota = $disk_quota;
5547: my $percent;
5548: if ($disk_quota == 0) {
5549: $percent = 100.0;
5550: } else {
1.484.2.69 raeburn 5551: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5552: }
5553: $usage = sprintf("%.2f",$usage);
5554: $quota = sprintf("%.2f",$quota);
5555: $percent = sprintf("%.0f",$percent);
5556: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5557: $percent.'%',$quota.' MB').'</p>';
5558:
1.329 droeschl 5559: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5560: $quotainfo
1.329 droeschl 5561: $lt{'file'}:<br />
1.484.2.81 raeburn 5562: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
5563: <input type="hidden" id="LC_free_space" value="$free_space" />
1.329 droeschl 5564: FIUP
5565:
5566: my $checkbox=(<<CHBO);
5567: <!-- <label>$lt{'parse'}?
5568: <input type="checkbox" name="parserflag" />
5569: </label> -->
5570: <label>
1.484.2.67 raeburn 5571: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5572: </label>
5573: CHBO
1.484.2.12 raeburn 5574: my $imsfolder = $env{'form.folder'};
5575: if ($imsfolder eq '') {
1.484.2.19 raeburn 5576: $imsfolder = 'default';
1.484.2.12 raeburn 5577: }
5578: my $imspform=(<<IMSFORM);
5579: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5580: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5581: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5582: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5583: <legend>$lt{'imsf'}</legend>
5584: $fileupload
5585: <br />
5586: <p>
1.484.2.19 raeburn 5587: $lt{'cms'}:
1.484.2.67 raeburn 5588: <select name="source" $disabled>
1.484.2.12 raeburn 5589: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5590: <option value="bb5">$lt{'bb5'}</option>
5591: <option value="bb6">$lt{'bb6'}</option>
5592: <option value="angel5">$lt{'angel5'}</option>
5593: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5594: </select>
5595: <input type="hidden" name="folder" value="$imsfolder" />
5596: </p>
5597: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5598: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5599: </fieldset>
5600: </form>
5601: IMSFORM
5602:
1.484.2.19 raeburn 5603: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5604: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5605: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5606: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5607: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5608: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5609: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5610: $fileupload
5611: <br />
5612: $lt{'title'}:<br />
1.484.2.67 raeburn 5613: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5614: $pathitem
1.329 droeschl 5615: <input type="hidden" name="cmd" value="upload_default" />
5616: <br />
1.458 raeburn 5617: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5618: $checkbox
5619: </span>
1.484.2.12 raeburn 5620: <br clear="all" />
1.484.2.67 raeburn 5621: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5622: </fieldset>
5623: </form>
1.383 tempelho 5624: FUFORM
1.329 droeschl 5625:
1.484.2.67 raeburn 5626: my $mapimportjs;
5627: if ($canedit) {
5628: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5629: } else {
5630: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5631: }
1.484.2.19 raeburn 5632: my $importpubform=(<<SEDFFORM);
5633: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5634: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5635: <form action="/adm/coursedocs" method="post" name="mapimportform">
5636: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5637: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5638: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5639: $lt{'copm'}<br />
5640: <span class="LC_nobreak">
1.484.2.19 raeburn 5641: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5642: onfocus="this.blur();$mapimportjs" $disabled />
5643: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5644: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5645: </fieldset>
5646: </form>
5647:
1.383 tempelho 5648: SEDFFORM
1.484.2.67 raeburn 5649:
5650: my $fromstoredjs;
5651: if ($canedit) {
5652: $fromstoredjs = 'open_StoredLinks_Import()';
5653: } else {
5654: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5655: }
5656:
1.484.2.19 raeburn 5657: my @importpubforma = (
5658: { '<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 5659: { '<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 5660: { '<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 5661: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5662: );
5663: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5664: my $extresourcesform =
5665: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5666: $help{'Adding_External_Resource'},
5667: undef,undef,$disabled);
1.329 droeschl 5668: if ($allowed) {
1.484.2.7 raeburn 5669: my $folder = $env{'form.folder'};
5670: if ($folder eq '') {
5671: $folder='default';
5672: }
1.484.2.67 raeburn 5673: if ($canedit) {
5674: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5675: if ($output) {
5676: $r->print($output);
5677: }
1.484.2.30 raeburn 5678: }
1.337 ehlerst 5679: $r->print(<<HIDDENFORM);
5680: <form name="renameform" method="post" action="/adm/coursedocs">
5681: <input type="hidden" name="title" />
5682: <input type="hidden" name="cmd" />
5683: <input type="hidden" name="markcopy" />
5684: <input type="hidden" name="copyfolder" />
5685: $containertag
5686: </form>
1.484 raeburn 5687:
1.337 ehlerst 5688: HIDDENFORM
1.484.2.17 raeburn 5689: $r->print(&makesimpleeditform($pathitem)."\n".
5690: &makedocslogform($pathitem."\n".
1.484 raeburn 5691: '<input type="hidden" name="folder" value="'.
5692: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5693: }
1.442 www 5694:
5695: # Generate the tabs
1.484.2.19 raeburn 5696: my ($mode,$needs_end);
1.472 raeburn 5697: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5698: my @folders = split('&',$env{'form.folderpath'});
5699: unless (@folders > 2) {
5700: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5701: $needs_end = 1;
5702: }
1.472 raeburn 5703: } else {
1.484 raeburn 5704: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5705: $needs_end = 1;
1.472 raeburn 5706: }
1.443 www 5707:
1.442 www 5708: #
5709:
5710: my $savefolderpath;
1.484.2.86 raeburn 5711: my $hostname = $r->hostname();
1.442 www 5712:
1.395 raeburn 5713: if ($allowed) {
1.329 droeschl 5714: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5715: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5716: $folder='default';
1.356 tempelho 5717: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5718: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5719: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5720: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5721: }
5722: my $postexec='';
5723: if ($folder eq 'default') {
1.372 bisitz 5724: $r->print('<script type="text/javascript">'."\n"
5725: .'// <![CDATA['."\n"
5726: .'this.window.name="loncapaclient";'."\n"
5727: .'// ]]>'."\n"
5728: .'</script>'."\n"
1.369 bisitz 5729: );
1.329 droeschl 5730: } else {
5731: #$postexec='self.close();';
5732: }
1.484.2.15 raeburn 5733: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5734: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5735: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5736:
5737: my $newnavform=(<<NNFORM);
5738: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5739: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5740: $pathitem
1.329 droeschl 5741: <input type="hidden" name="importdetail"
5742: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5743: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5744: $help{'Navigate_Content'}
5745: </form>
5746: NNFORM
5747: my $newsmppageform=(<<NSPFORM);
5748: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5749: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5750: $pathitem
1.329 droeschl 5751: <input type="hidden" name="importdetail" value="" />
1.423 onken 5752: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5753: $help{'Simple Page'}
1.329 droeschl 5754: </form>
5755: NSPFORM
5756:
5757: my $newsmpproblemform=(<<NSPROBFORM);
5758: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5759: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5760: $pathitem
1.329 droeschl 5761: <input type="hidden" name="importdetail" value="" />
1.423 onken 5762: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5763: $help{'Simple_Problem'}
1.329 droeschl 5764: </form>
5765:
5766: NSPROBFORM
5767:
5768: my $newdropboxform=(<<NDBFORM);
5769: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5770: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5771: $pathitem
1.329 droeschl 5772: <input type="hidden" name="importdetail" value="" />
1.423 onken 5773: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5774: $help{'Dropbox'}
1.344 bisitz 5775: </form>
1.329 droeschl 5776: NDBFORM
5777:
5778: my $newexuploadform=(<<NEXUFORM);
5779: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5780: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5781: $pathitem
1.329 droeschl 5782: <input type="hidden" name="importdetail" value="" />
1.423 onken 5783: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5784: $help{'Score_Upload_Form'}
5785: </form>
5786: NEXUFORM
5787:
5788: my $newbulform=(<<NBFORM);
5789: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5790: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5791: $pathitem
1.329 droeschl 5792: <input type="hidden" name="importdetail" value="" />
1.423 onken 5793: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5794: $help{'Bulletin Board'}
5795: </form>
5796: NBFORM
5797:
5798: my $newaboutmeform=(<<NAMFORM);
5799: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5800: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5801: $pathitem
1.329 droeschl 5802: <input type="hidden" name="importdetail"
5803: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5804: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5805: $help{'My Personal Information Page'}
1.329 droeschl 5806: </form>
5807: NAMFORM
5808:
5809: my $newaboutsomeoneform=(<<NASOFORM);
5810: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5811: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5812: $pathitem
1.329 droeschl 5813: <input type="hidden" name="importdetail" value="" />
1.423 onken 5814: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5815: </form>
5816: NASOFORM
5817:
5818: my $newrosterform=(<<NROSTFORM);
5819: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5820: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5821: $pathitem
1.329 droeschl 5822: <input type="hidden" name="importdetail"
5823: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5824: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5825: $help{'Course_Roster'}
1.329 droeschl 5826: </form>
5827: NROSTFORM
5828:
1.484.2.27 raeburn 5829: my $newwebpage;
5830: if ($folder =~ /^default_?(\d*)$/) {
5831: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5832: if ($1) {
5833: $newwebpage .= $1;
5834: } else {
5835: $newwebpage .= 'default';
5836: }
5837: $newwebpage .= '/new.html';
5838: }
5839: my $newwebpageform =(<<NWEBFORM);
5840: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5841: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5842: $pathitem
5843: <input type="hidden" name="importdetail" value="$newwebpage" />
5844: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5845: $help{'Web_Page'}
1.484.2.27 raeburn 5846: </form>
5847: NWEBFORM
1.484.2.30 raeburn 5848:
1.484.2.27 raeburn 5849:
1.342 ehlerst 5850: my $specialdocumentsform;
1.383 tempelho 5851: my @specialdocumentsforma;
1.451 www 5852: my $gradingform;
5853: my @gradingforma;
5854: my $communityform;
5855: my @communityforma;
1.351 ehlerst 5856: my $newfolderform;
1.390 tempelho 5857: my $newfolderb;
1.342 ehlerst 5858:
1.451 www 5859: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5860:
1.329 droeschl 5861: my $newpageform=(<<NPFORM);
5862: <form action="/adm/coursedocs" method="post" name="newpage">
5863: <input type="hidden" name="folderpath" value="$path" />
5864: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5865: <input type="hidden" name="active" value="ee" />
1.423 onken 5866: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5867: $help{'Adding_Pages'}
1.329 droeschl 5868: </form>
5869: NPFORM
1.390 tempelho 5870:
5871:
1.351 ehlerst 5872: $newfolderform=(<<NFFORM);
1.329 droeschl 5873: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5874: $pathitem
1.329 droeschl 5875: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5876: <input type="hidden" name="active" value="" />
1.422 onken 5877: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5878: </form>
5879: NFFORM
5880:
5881: my $newsylform=(<<NSYLFORM);
5882: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5883: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5884: $pathitem
1.329 droeschl 5885: <input type="hidden" name="importdetail"
5886: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5887: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5888: $help{'Syllabus'}
1.383 tempelho 5889:
1.329 droeschl 5890: </form>
5891: NSYLFORM
1.364 bisitz 5892:
1.329 droeschl 5893: my $newgroupfileform=(<<NGFFORM);
5894: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5895: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5896: $pathitem
1.329 droeschl 5897: <input type="hidden" name="importdetail"
5898: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5899: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5900: $help{'Group Portfolio'}
1.329 droeschl 5901: </form>
5902: NGFFORM
1.484.2.89! raeburn 5903: if ($container eq 'page') {
! 5904: @specialdocumentsforma=(
! 5905: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
! 5906: );
! 5907: } else {
! 5908: @specialdocumentsforma=(
1.421 onken 5909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.484.2.67 raeburn 5910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5911: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5912: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5913: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.484.2.89! raeburn 5914: );
! 5915: }
1.451 www 5916: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5917:
1.434 raeburn 5918:
5919: my @importdoc = (
1.484.2.19 raeburn 5920: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5921: );
5922: unless ($container eq 'page') {
5923: push(@importdoc,
5924: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5925: );
5926: }
5927: push(@importdoc,
1.484.2.38 raeburn 5928: {'<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 5929: );
1.484.2.12 raeburn 5930: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5931:
1.451 www 5932: @gradingforma=(
5933: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5934: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5935: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5936:
5937: );
5938: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5939:
5940: @communityforma=(
5941: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5942: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5943: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5944: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5945: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5946: );
5947: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5948:
1.330 tempelho 5949: my %orderhash = (
1.484.2.36 raeburn 5950: 'aa' => ['Upload',$fileuploadform],
5951: 'bb' => ['Import',$importpubform],
5952: 'cc' => ['Grading',$gradingform],
1.484.2.89! raeburn 5953: 'ee' => ['Other',$specialdocumentsform],
1.330 tempelho 5954: );
1.484.2.19 raeburn 5955: unless ($container eq 'page') {
1.434 raeburn 5956: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5957: $orderhash{'dd'} = ['Collaboration',$communityform];
1.434 raeburn 5958: }
5959:
1.341 ehlerst 5960: $hadchanges=0;
1.484 raeburn 5961: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5962: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5963: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 5964: $canedit,$hostname,\$navmap,$hiddentop);
1.484.2.67 raeburn 5965: undef($navmap);
1.443 www 5966: if ($error) {
5967: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5968: }
5969: if ($hadchanges) {
1.484.2.73 raeburn 5970: unless (&is_hash_old()) {
5971: &mark_hash_old();
5972: }
1.443 www 5973: }
1.341 ehlerst 5974:
1.443 www 5975: &changewarning($r,'');
5976: }
1.458 raeburn 5977: }
1.442 www 5978:
1.443 www 5979: # Supplemental documents start here
5980:
1.329 droeschl 5981: my $folder=$env{'form.folder'};
1.443 www 5982: unless ($supplementalflag) {
1.329 droeschl 5983: $folder='supplemental';
5984: }
5985: if ($folder =~ /^supplemental$/ &&
5986: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5987: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5988: } elsif ($allowed) {
1.356 tempelho 5989: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5990: }
1.484.2.17 raeburn 5991: $pathitem = '<input type="hidden" name="folderpath" value="'.
5992: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5993: if ($allowed) {
5994: my $folderseq=
1.484.2.15 raeburn 5995: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5996:
5997: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5998: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5999: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6000: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 6001: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 6002: <legend>$lt{'upfi'}</legend>
1.371 tempelho 6003: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6004: $fileupload
6005: <br />
6006: <br />
6007: <span class="LC_nobreak">
6008: $checkbox
6009: </span>
6010: <br /><br />
6011: $lt{'comment'}:<br />
1.383 tempelho 6012: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6013: <br />
1.484.2.19 raeburn 6014: $pathitem
1.329 droeschl 6015: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 6016: <input type='submit' value="$lt{'upld'}" />
6017: </form>
1.484.2.19 raeburn 6018: SUPDOCFORM
1.329 droeschl 6019:
6020: my $supnewfolderform=(<<SNFFORM);
6021: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 6022: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 6023: $pathitem
1.329 droeschl 6024: <input type="hidden" name="importdetail" value="" />
1.423 onken 6025: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6026: $help{'Adding_Folders'}
1.329 droeschl 6027: </form>
6028: SNFFORM
1.383 tempelho 6029:
1.484.2.19 raeburn 6030: my $supextform =
6031: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 6032: $help{'Adding_External_Resource'},
6033: undef,undef,$disabled);
1.329 droeschl 6034:
6035: my $supnewsylform=(<<SNSFORM);
6036: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6037: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6038: $pathitem
1.329 droeschl 6039: <input type="hidden" name="importdetail"
6040: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 6041: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6042: $help{'Syllabus'}
6043: </form>
6044: SNSFORM
6045:
6046: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6047: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6048: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 6049: $pathitem
1.329 droeschl 6050: <input type="hidden" name="importdetail"
6051: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 6052: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6053: $help{'My Personal Information Page'}
1.329 droeschl 6054: </form>
6055: SNAMFORM
6056:
1.484.2.27 raeburn 6057: my $supwebpage;
6058: if ($folder =~ /^supplemental_?(\d*)$/) {
6059: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6060: if ($1) {
6061: $supwebpage .= $1;
6062: } else {
6063: $supwebpage .= 'default';
6064: }
6065: $supwebpage .= '/new.html';
6066: }
6067: my $supwebpageform =(<<SWEBFORM);
6068: <form action="/adm/coursedocs" method="post" name="supwebpage">
6069: <input type="hidden" name="active" value="cc" />
6070: $pathitem
6071: <input type="hidden" name="importdetail" value="$supwebpage" />
6072: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 6073: $help{'Web_Page'}
1.484.2.27 raeburn 6074: </form>
6075: SWEBFORM
6076:
1.333 muellerd 6077:
1.383 tempelho 6078: my @specialdocs = (
1.484.2.67 raeburn 6079: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6080: =>$supnewsylform},
1.484.2.67 raeburn 6081: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6082: =>$supnewaboutmeform},
1.484.2.27 raeburn 6083: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6084:
1.383 tempelho 6085: );
1.417 droeschl 6086: my @supimportdoc = (
1.484.2.19 raeburn 6087: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 6088: =>$supextform},
6089: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6090: =>$supupdocform},
1.484.2.19 raeburn 6091: );
6092:
1.484.2.12 raeburn 6093: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6094: my %suporderhash = (
1.390 tempelho 6095: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 6096: 'ee' => ['Upload',$supupdocform],
6097: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6098: );
1.443 www 6099: if ($supplementalflag) {
1.458 raeburn 6100: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 6101: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.484.2.85 raeburn 6102: $canedit,$hostname);
1.443 www 6103: if ($error) {
6104: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 6105: } else {
6106: if ($suppchanges) {
6107: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6108: my @ids=&Apache::lonnet::current_machine_ids();
6109: foreach my $server (keys(%servers)) {
6110: next if (grep(/^\Q$server\E$/,@ids));
6111: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 6112: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6113: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 6114: }
6115: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6116: undef($suppchanges);
6117: }
1.443 www 6118: }
1.393 raeburn 6119: }
1.443 www 6120: } elsif ($supplementalflag) {
1.458 raeburn 6121: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.85 raeburn 6122: $supplementalflag,'',$iconpath,$pathitem,'',$hostname);
1.393 raeburn 6123: if ($error) {
6124: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6125: }
1.393 raeburn 6126: }
1.389 tempelho 6127:
1.484.2.19 raeburn 6128: if ($needs_end) {
6129: $r->print(&endContentScreen());
6130: }
1.383 tempelho 6131:
1.329 droeschl 6132: if ($allowed) {
6133: $r->print('
6134: <form method="post" name="extimport" action="/adm/coursedocs">
6135: <input type="hidden" name="title" />
6136: <input type="hidden" name="url" />
6137: <input type="hidden" name="useform" />
6138: <input type="hidden" name="residx" />
6139: </form>');
6140: }
1.484 raeburn 6141: } elsif ($showdoc) {
1.329 droeschl 6142: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6143: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 6144: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6145: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6146: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6147: }
6148: }
6149: $r->print(&Apache::loncommon::end_page());
6150: return OK;
1.364 bisitz 6151: }
1.329 droeschl 6152:
1.440 raeburn 6153: sub embedded_form_elems {
6154: my ($phase,$primaryurl,$newidx) = @_;
6155: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.484.2.78 raeburn 6156: $newidx =~s /\D+//g;
1.440 raeburn 6157: return <<STATE;
6158: <input type="hidden" name="folderpath" value="$folderpath" />
6159: <input type="hidden" name="cmd" value="upload_embedded" />
6160: <input type="hidden" name="newidx" value="$newidx" />
6161: <input type="hidden" name="phase" value="$phase" />
6162: <input type="hidden" name="primaryurl" value="$primaryurl" />
6163: STATE
6164: }
6165:
6166: sub embedded_destination {
6167: my $folder=$env{'form.folder'};
6168: my $destination = 'docs/';
6169: if ($folder =~ /^supplemental/) {
6170: $destination = 'supplemental/';
6171: }
6172: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6173: $destination .= 'default/';
6174: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6175: $destination .= $2.'/';
6176: }
1.484.2.78 raeburn 6177: my $newidx = $env{'form.newidx'};
6178: $newidx =~s /\D+//g;
6179: if ($newidx) {
6180: $destination .= $newidx;
6181: }
1.440 raeburn 6182: my $dir_root = '/userfiles';
6183: return ($destination,$dir_root);
6184: }
6185:
6186: sub return_to_editor {
6187: my $actionurl = '/adm/coursedocs';
6188: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6189: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6190: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6191: '</a></p>';
6192: }
6193:
1.476 raeburn 6194: sub decompression_info {
6195: my ($destination,$dir_root) = &embedded_destination();
6196: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6197: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6198: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6199: my $container='sequence';
1.480 raeburn 6200: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 6201: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 6202: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6203: $container='page';
6204: }
1.480 raeburn 6205: unshift(@hiddens,$pathitem);
6206: foreach my $item (@hiddens) {
1.484.2.78 raeburn 6207: if ($item eq 'newidx') {
6208: next if ($env{'form.'.$item} =~ /\D/);
6209: }
1.480 raeburn 6210: if ($env{'form.'.$item}) {
6211: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 6212: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6213: }
1.477 raeburn 6214: }
1.476 raeburn 6215: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6216: $hiddenelem);
6217: }
6218:
6219: sub decompression_phase_one {
6220: my ($dir,$file,$warning,$error,$output);
6221: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6222: &decompression_info();
1.484.2.7 raeburn 6223: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6224: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6225: } else {
6226: my $file = $1;
1.481 raeburn 6227: $output =
6228: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6229: $destination,$dir_root,
6230: $hiddenelem);
6231: if ($env{'form.autoextract_camtasia'}) {
6232: $output .= &remove_archive($docudom,$docuname,$container);
6233: }
1.476 raeburn 6234: }
6235: if ($error) {
6236: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6237: $error.'</p>'."\n";
6238: }
6239: if ($warning) {
6240: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6241: }
6242: return $output;
6243: }
6244:
6245: sub decompression_phase_two {
6246: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6247: &decompression_info();
1.481 raeburn 6248: my $output;
1.480 raeburn 6249: if ($env{'form.archivedelete'}) {
1.481 raeburn 6250: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6251: }
6252: $output .=
1.481 raeburn 6253: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6254: $destination,$dir_root,$hiddenelem);
6255: return $output;
6256: }
6257:
1.480 raeburn 6258: sub remove_archive {
6259: my ($docudom,$docuname,$container) = @_;
6260: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6261: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6262: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6263: if ($fatal) {
6264: if ($container eq 'page') {
6265: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6266: } else {
6267: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6268: }
1.484.2.54 raeburn 6269: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6270: } else {
6271: my $currcmd = $env{'form.cmd'};
6272: my $position = $env{'form.position'};
1.484.2.54 raeburn 6273: my $archiveidx = $position;
6274: if ($position > 0) {
6275: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6276: $archiveidx = $position-1;
6277: }
6278: $env{'form.cmd'} = 'remove_'.$archiveidx;
6279: my ($title,$url,@rrest) =
6280: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6281: if ($url eq $env{'form.archiveurl'}) {
6282: if (&handle_edit_cmd($docuname,$docudom)) {
6283: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6284: if ($fatal) {
6285: if ($container eq 'page') {
6286: $delwarning = &mt('An error occurred updating the contents of the current page.');
6287: } else {
6288: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6289: }
1.480 raeburn 6290: } else {
1.484.2.54 raeburn 6291: $delresult = &mt('Archive file removed.');
1.480 raeburn 6292: }
6293: }
1.484.2.54 raeburn 6294: } else {
6295: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6296: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6297: }
6298: }
6299: $env{'form.cmd'} = $currcmd;
6300: }
6301: if ($delwarning) {
6302: $output = '<p class="LC_warning">'.
6303: $delwarning.
6304: '</p>';
6305: }
6306: if ($delresult) {
6307: $output .= '<p class="LC_info">'.
6308: $delresult.
6309: '</p>';
6310: }
1.481 raeburn 6311: return $output;
1.480 raeburn 6312: }
6313:
1.484 raeburn 6314: sub generate_admin_menu {
1.484.2.67 raeburn 6315: my ($crstype,$canedit) = @_;
1.484 raeburn 6316: my $lc_crstype = lc($crstype);
6317: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 6318: my %lt= ( # do not translate here
1.484 raeburn 6319: 'vc' => 'Verify Content',
6320: 'cv' => 'Check/Set Resource Versions',
6321: 'ls' => 'List Resource Identifiers',
6322: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 6323: 'dcd' => "Copy $crstype Content to Authoring Space",
6324: );
1.484 raeburn 6325: my ($candump,$dumpurl);
6326: if ($home + $other > 0) {
6327: $candump = 'F';
6328: if ($home) {
6329: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6330: } else {
6331: my @hosts;
6332: foreach my $aurole (keys(%outhash)) {
6333: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6334: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 6335: }
1.484 raeburn 6336: }
6337: if (@hosts == 1) {
6338: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6339: '&role='.
6340: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6341: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6342: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6343: } else {
6344: $dumpurl = "javascript:choose_switchserver_window()";
6345: }
6346: }
6347: }
6348: my @menu=
6349: ({ categorytitle=>'Administration',
6350: items =>[
6351: { linktext => $lt{'vc'},
6352: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6353: permission => 'F',
1.484.2.44 raeburn 6354: help => 'Docs_Verify_Content',
1.484 raeburn 6355: icon => 'verify.png',
6356: linktitle => 'Verify contents can be retrieved/rendered',
6357: },
6358: { linktext => $lt{'cv'},
6359: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6360: permission => 'F',
1.484.2.44 raeburn 6361: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6362: icon => 'resversion.png',
6363: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6364: },
6365: { linktext => $lt{'ls'},
6366: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6367: permission => 'F',
6368: #help => '',
6369: icon => 'symbs.png',
6370: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6371: },
6372: ]
1.484.2.67 raeburn 6373: });
6374: if ($canedit) {
6375: push(@menu,
1.484 raeburn 6376: { categorytitle=>'Export',
6377: items =>[
6378: { linktext => $lt{'imse'},
6379: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6380: permission => 'F',
6381: help => 'Docs_Export_Course_Docs',
6382: icon => 'imsexport.png',
6383: linktitle => $lt{'imse'},
6384: },
6385: { linktext => $lt{'dcd'},
6386: url => $dumpurl,
6387: permission => $candump,
1.484.2.44 raeburn 6388: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6389: icon => 'dump.png',
6390: linktitle => $lt{'dcd'},
6391: },
6392: ]
6393: });
1.484.2.67 raeburn 6394: }
1.484 raeburn 6395: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6396: '<input type="hidden" id="dummy" />'."\n".
6397: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6398: '</form>';
1.329 droeschl 6399: }
6400:
6401: sub generate_edit_table {
1.484.2.30 raeburn 6402: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6403: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6404: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6405: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6406: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6407: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6408: $activetab = $env{'form.active'};
6409: }
1.484.2.67 raeburn 6410: unless ($canedit) {
6411: $disabled = ' disabled="disabled"';
6412: }
1.472 raeburn 6413: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6414: my $backtext = &mt('Exit Editor');
1.458 raeburn 6415: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6416: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6417: '<li class="goback">'.
1.484.2.32 raeburn 6418: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6419: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6420: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6421: '<li>'.
6422: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6423: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6424: if ($env{'form.docslog'}) {
6425: $form .= '<li class="active">';
6426: } else {
6427: $form .= '<li>';
6428: }
6429: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6430: &mt('History').'</a></li>'."\n";
6431: if ($env{'form.docslog'}) {
6432: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6433: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6434: }
1.458 raeburn 6435: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6436: if($name ne '00'){
1.371 tempelho 6437: if($activetab eq '' || $activetab ne $name){
6438: $active = '';
6439: }elsif($activetab eq $name){
6440: $active = 'class="active"';
6441: }
1.458 raeburn 6442: $form .= '<li style="float:right" '.$active
1.484 raeburn 6443: .' 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 6444: } else {
1.484.2.43 raeburn 6445: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6446:
6447: }
1.329 droeschl 6448: }
1.484 raeburn 6449: $form .= '</ul>'."\n";
6450: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6451:
6452: if ($to_show ne '') {
1.484.2.30 raeburn 6453: my $saveform;
6454: if ($need_save) {
6455: my $button = &mt('Make changes');
6456: my $path;
6457: if ($env{'form.folderpath'}) {
6458: $path =
6459: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6460: }
6461: $saveform = <<"END";
6462: <div id="multisave" style="display:none; clear:both;" >
6463: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6464: <input type="hidden" name="folderpath" value="$path" />
6465: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6466: <input type="hidden" name="allhiddenresource" value="" />
6467: <input type="hidden" name="allencrypturl" value="" />
6468: <input type="hidden" name="allrandompick" value="" />
6469: <input type="hidden" name="allrandomorder" value="" />
6470: <input type="hidden" name="changeparms" value="" />
6471: <input type="hidden" name="multiremove" value="" />
6472: <input type="hidden" name="multicut" value="" />
6473: <input type="hidden" name="multicopy" value="" />
6474: <input type="hidden" name="multichange" value="" />
6475: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6476: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6477: </form>
6478: </div>
6479: END
6480: }
6481: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6482: }
1.363 ehlerst 6483: foreach my $field (keys(%orderhash)){
1.390 tempelho 6484: if($field ne '00'){
1.422 onken 6485: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6486: $active = 'style="display: none;float:left"';
1.422 onken 6487: }elsif($activetab eq $field){
1.458 raeburn 6488: $active = 'style="display:block;float:left"';
1.422 onken 6489: }
6490: $form .= '<div id="'.$field.$tid.'"'
6491: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6492: .'</div>'."\n";
1.363 ehlerst 6493: }
6494: }
1.484 raeburn 6495: unless ($env{'form.docslog'}) {
6496: $form .= '</div></div>'."\n";
6497: }
1.329 droeschl 6498: return $form;
6499: }
6500:
6501: sub editing_js {
1.484.2.80 raeburn 6502: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
6503: $canedit,$hostname,$navmapref) = @_;
1.484.2.61 raeburn 6504: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6505: p_mnf => 'Name of New Folder',
6506: t_mnf => 'New Folder',
6507: p_mnp => 'Name of New Page',
6508: t_mnp => 'New Page',
1.451 www 6509: p_mxu => 'Title for the External Score',
1.349 biermanm 6510: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6511: p_msb => 'Title for the Problem',
6512: p_mdb => 'Title for the Drop Box',
1.336 schafran 6513: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6514: p_mwp => 'Title for Web Page',
1.348 weissno 6515: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6516: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6517: p_mab_alrt1 => 'Not a valid user:domain',
6518: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6519: p_chn => 'New Title',
6520: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6521: p_rmr2a => 'Remove',
6522: p_rmr2b => '?',
6523: p_rmr3a => 'Remove those',
6524: p_rmr3b => 'items?',
6525: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6526: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6527: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6528: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6529: p_ctr2a => 'Cut',
6530: p_ctr2b => '?',
6531: p_ctr3a => 'Cut those',
6532: p_ctr3b => 'items?',
1.478 raeburn 6533: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6534: imsfile => 'You must choose an IMS package for import',
6535: imscms => 'You must select which Course Management System was the source of the IMS package',
6536: invurl => 'Invalid URL',
6537: titbl => 'Title is blank',
1.484.2.30 raeburn 6538: more => '(More ...)',
6539: less => '(Less ...)',
6540: noor => 'No actions selected or changes to settings specified.',
6541: noch => 'No changes to settings specified.',
6542: noac => 'No actions selected.',
1.484.2.67 raeburn 6543: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6544: );
6545:
1.484.2.61 raeburn 6546: &js_escape(\%js_lt);
1.433 raeburn 6547: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6548: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6549: my $main_container_page;
1.484.2.19 raeburn 6550: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6551: $main_container_page = 1;
1.434 raeburn 6552: }
1.484.2.67 raeburn 6553: my $backtourl;
6554: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6555: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6556:
1.484.2.21 raeburn 6557: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6558: my $caller = $1;
6559: if ($caller =~ /^supplemental/) {
6560: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6561: } else {
6562: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6563: $res = &Apache::lonnet::clutter($res);
6564: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6565: my ($url,$anchor);
6566: if ($res =~ /^([^#]+)#([^#]+)$/) {
6567: $url = $1;
6568: $anchor = $2;
6569: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6570: $caller = $1.&escape('#').$anchor;
6571: }
1.484.2.67 raeburn 6572: } else {
6573: $url = $res;
1.484.2.66 raeburn 6574: }
1.484.2.83 raeburn 6575: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
6576: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
6577: $backtourl .= '?navmap=1';
6578: } else {
6579: $backtourl .= '?symb='.
6580: &HTML::Entities::encode($caller,'<>&"');
6581: }
1.484.2.80 raeburn 6582: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
6583: if (($ENV{'SERVER_PORT'} == 443) &&
6584: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
6585: unless (&Apache::lonnet::uses_sts()) {
6586: if ($hostname ne '') {
6587: $backtourl = 'http://'.$hostname.$backtourl;
6588: }
6589: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6590: }
6591: }
6592: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
6593: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
6594: unless (&Apache::lonnet::uses_sts()) {
6595: if ($hostname ne '') {
6596: $backtourl = 'http://'.$hostname.$backtourl;
6597: }
6598: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
6599: }
6600: }
6601: }
1.484.2.66 raeburn 6602: if ($anchor ne '') {
6603: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6604: }
1.484.2.57 raeburn 6605: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6606: } else {
6607: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6608: }
6609: }
6610: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6611: $backtourl = '/adm/menu';
6612: } elsif ($supplementalflag) {
1.472 raeburn 6613: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6614: } else {
6615: $backtourl = '/adm/navmaps';
1.472 raeburn 6616: }
6617:
1.484.2.19 raeburn 6618: my $fieldsets = "'ext','doc'";
6619: unless ($main_container_page) {
6620: $fieldsets .=",'ims'";
6621: }
1.484.2.12 raeburn 6622: if ($supplementalflag) {
6623: $fieldsets = "'suppext','suppdoc'";
6624: }
6625:
1.484.2.67 raeburn 6626: my $jsmakefunctions;
6627: if ($canedit) {
6628: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6629: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6630: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6631: if (foldername) {
6632: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6633: targetform.submit();
6634: }
6635: }
6636:
6637: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6638: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6639: if (pagename) {
6640: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6641: targetform.submit();
6642: }
6643: }
6644:
6645: function makeexamupload() {
1.484.2.61 raeburn 6646: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6647: if (title) {
1.329 droeschl 6648: this.document.forms.newexamupload.importdetail.value=
6649: escape(title)+'=/res/lib/templates/examupload.problem';
6650: this.document.forms.newexamupload.submit();
6651: }
6652: }
6653:
6654: function makesmppage() {
1.484.2.61 raeburn 6655: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6656: if (title) {
1.329 droeschl 6657: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6658: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6659: this.document.forms.newsmppg.submit();
6660: }
6661: }
6662:
1.484.2.27 raeburn 6663: function makewebpage(type) {
1.484.2.61 raeburn 6664: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6665: var formname;
6666: if (type == 'supp') {
6667: formname = this.document.forms.supwebpage;
6668: } else {
6669: formname = this.document.forms.newwebpage;
6670: }
6671: if (title) {
6672: var webpage = formname.importdetail.value;
6673: formname.importdetail.value = escape(title)+'='+webpage;
6674: formname.submit();
6675: }
6676: }
6677:
1.329 droeschl 6678: function makesmpproblem() {
1.484.2.61 raeburn 6679: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6680: if (title) {
1.329 droeschl 6681: this.document.forms.newsmpproblem.importdetail.value=
6682: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6683: this.document.forms.newsmpproblem.submit();
6684: }
6685: }
6686:
6687: function makedropbox() {
1.484.2.61 raeburn 6688: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6689: if (title) {
1.329 droeschl 6690: this.document.forms.newdropbox.importdetail.value=
6691: escape(title)+'=/res/lib/templates/DropBox.problem';
6692: this.document.forms.newdropbox.submit();
6693: }
6694: }
6695:
6696: function makebulboard() {
1.484.2.61 raeburn 6697: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6698: if (title) {
6699: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6700: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6701: this.document.forms.newbul.submit();
6702: }
6703: }
6704:
6705: function makeabout() {
1.484.2.61 raeburn 6706: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6707: if (user) {
6708: var comp=new Array();
6709: comp=user.split(':');
6710: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6711: if ((comp[0]) && (comp[1])) {
6712: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6713: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6714: this.document.forms.newaboutsomeone.submit();
6715: } else {
6716: alert("$js_lt{'p_mab_alrt1'}");
6717: }
6718: } else {
6719: alert("$js_lt{'p_mab_alrt2'}");
6720: }
6721: }
1.335 ehlerst 6722: }
1.484.2.67 raeburn 6723:
6724: function makenew(targetform) {
6725: targetform.submit();
1.335 ehlerst 6726: }
1.484.2.67 raeburn 6727:
6728: function changename(folderpath,index,oldtitle) {
6729: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6730: if (title) {
6731: this.document.forms.renameform.markcopy.value='';
6732: this.document.forms.renameform.title.value=title;
6733: this.document.forms.renameform.cmd.value='rename_'+index;
6734: this.document.forms.renameform.folderpath.value=folderpath;
6735: this.document.forms.renameform.submit();
6736: }
1.329 droeschl 6737: }
6738:
1.484.2.67 raeburn 6739: ENDNEWSCRIPT
6740: } else {
6741: $jsmakefunctions = <<ENDNEWSCRIPT;
6742:
6743: function makenewfolder() {
6744: alert("$js_lt{'edri'}");
6745: }
6746:
6747: function makenewpage() {
6748: alert("$js_lt{'edri'}");
6749: }
6750:
6751: function makeexamupload() {
6752: alert("$js_lt{'edri'}");
6753: }
6754:
6755: function makesmppage() {
6756: alert("$js_lt{'edri'}");
6757: }
6758:
6759: function makewebpage(type) {
6760: alert("$js_lt{'edri'}");
6761: }
6762:
6763: function makesmpproblem() {
6764: alert("$js_lt{'edri'}");
6765: }
6766:
6767: function makedropbox() {
6768: alert("$js_lt{'edri'}");
6769: }
6770:
6771: function makebulboard() {
6772: alert("$js_lt{'edri'}");
6773: }
6774:
6775: function makeabout() {
6776: alert("$js_lt{'edri'}");
6777: }
6778:
6779: function changename() {
6780: alert("$js_lt{'edri'}");
6781: }
6782:
6783: function makenew() {
6784: alert("$js_lt{'edri'}");
6785: }
6786:
6787: function groupimport() {
6788: alert("$js_lt{'edri'}");
6789: }
6790:
6791: function groupsearch() {
6792: alert("$js_lt{'edri'}");
6793: }
6794:
6795: function groupopen(url,recover) {
6796: var options="scrollbars=1,resizable=1,menubar=0";
6797: idxflag=1;
6798: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6799: idx.focus();
6800: }
6801:
6802: ENDNEWSCRIPT
6803:
6804: }
6805: return <<ENDSCRIPT;
6806:
6807: $jsmakefunctions
6808:
1.484.2.13 raeburn 6809: function toggleUpload(caller) {
6810: var blocks = Array($fieldsets);
6811: for (var i=0; i<blocks.length; i++) {
6812: var disp = 'none';
6813: if (caller == blocks[i]) {
6814: var curr = document.getElementById('upload'+caller+'form').style.display;
6815: if (curr == 'none') {
6816: disp='block';
6817: }
6818: }
6819: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6820: }
6821: resize_scrollbox('contentscroll','1','1');
6822: return;
6823: }
6824:
1.484.2.19 raeburn 6825: function toggleMap(caller) {
1.484.2.13 raeburn 6826: var disp = 'none';
1.484.2.19 raeburn 6827: if (document.getElementById('importmapform')) {
6828: if (caller == 'map') {
6829: var curr = document.getElementById('importmapform').style.display;
6830: if (curr == 'none') {
6831: disp='block';
6832: }
1.484.2.12 raeburn 6833: }
1.484.2.19 raeburn 6834: document.getElementById('importmapform').style.display=disp;
6835: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6836: }
1.484.2.19 raeburn 6837: return;
1.329 droeschl 6838: }
6839:
1.484.2.12 raeburn 6840: function makeims(imsform) {
6841: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6842: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6843: return;
6844: }
6845: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6846: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6847: return;
6848: }
6849: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6850: imsform.submit();
6851: }
6852:
1.478 raeburn 6853: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6854: var pickitem;
6855: var picknumitem;
6856: var picknumtext;
6857: if (index == 'all') {
6858: pickitem = document.getElementById('randompickall');
6859: picknumitem = document.getElementById('rpicknumall');
6860: picknumtext = document.getElementById('rpicktextall');
6861: } else {
6862: pickitem = document.getElementById('randompick_'+index);
6863: picknumitem = document.getElementById('rpicknum_'+index);
6864: picknumtext = document.getElementById('randompicknum_'+index);
6865: }
1.478 raeburn 6866: if (pickitem.checked) {
1.484.2.61 raeburn 6867: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6868: if (picknum == '' || picknum == null) {
6869: if (caller == 'check') {
6870: pickitem.checked=false;
1.484.2.29 raeburn 6871: if (index == 'all') {
6872: picknumtext.innerHTML = '';
6873: if (caller == 'link') {
6874: propagateState(targetform,'rpicknum');
6875: }
6876: } else {
1.484.2.30 raeburn 6877: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6878: }
1.478 raeburn 6879: }
6880: } else {
6881: picknum.toString();
6882: var regexdigit=/^\\d+\$/;
6883: if (regexdigit.test(picknum)) {
6884: picknumitem.value = picknum;
1.484.2.29 raeburn 6885: if (index == 'all') {
1.484.2.30 raeburn 6886: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6887: if (caller == 'link') {
6888: propagateState(targetform,'rpicknum');
6889: }
6890: } else {
6891: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6892: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6893: }
1.478 raeburn 6894: } else {
6895: if (caller == 'check') {
1.484.2.29 raeburn 6896: if (index == 'all') {
6897: picknumtext.innerHTML = '';
6898: if (caller == 'link') {
6899: propagateState(targetform,'rpicknum');
6900: }
6901: } else {
6902: pickitem.checked=false;
1.484.2.30 raeburn 6903: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6904: }
1.478 raeburn 6905: }
6906: return;
6907: }
6908: }
6909: } else {
1.484.2.29 raeburn 6910: picknumitem.value = '';
6911: picknumtext.innerHTML = '';
6912: if (index == 'all') {
6913: if (caller == 'link') {
6914: propagateState(targetform,'rpicknum');
6915: }
6916: } else {
1.484.2.30 raeburn 6917: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6918: }
6919: }
6920: }
6921:
6922: function propagateState(form,param) {
6923: if (document.getElementById(param+'all')) {
6924: var setcheck = 0;
6925: var rpick = 0;
6926: if (param == 'rpicknum') {
6927: if (document.getElementById('randompickall')) {
6928: if (document.getElementById('randompickall').checked) {
6929: if (document.getElementById('rpicknumall')) {
6930: rpick = document.getElementById('rpicknumall').value;
6931: }
6932: }
6933: }
6934: } else {
6935: if (document.getElementById(param+'all').checked) {
6936: setcheck = 1;
6937: }
6938: }
1.484.2.30 raeburn 6939: var allidxlist;
6940: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6941: if (document.getElementById('all'+param+'idx')) {
6942: allidxlist = document.getElementById('all'+param+'idx').value;
6943: }
6944: var actions = new Array ('remove','cut','copy');
6945: for (var i=0; i<actions.length; i++) {
6946: if (actions[i] != param) {
6947: if (document.getElementById(actions[i]+'all')) {
6948: document.getElementById(actions[i]+'all').checked = false;
6949: }
6950: }
6951: }
6952: }
1.484.2.29 raeburn 6953: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6954: allidxlist = form.allidx.value;
6955: }
6956: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6957: allidxlist = form.allmapidx.value;
6958: }
6959: if ((allidxlist != '') && (allidxlist != null)) {
6960: var allidxs = allidxlist.split(',');
6961: if (allidxs.length > 1) {
6962: for (var i=0; i<allidxs.length; i++) {
6963: if (document.getElementById(param+'_'+allidxs[i])) {
6964: if (param == 'rpicknum') {
6965: if (document.getElementById('randompick_'+allidxs[i])) {
6966: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6967: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6968: if (rpick > 0) {
6969: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6970: } else {
6971: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6972: }
6973: }
6974: }
6975: } else {
1.484.2.29 raeburn 6976: if (setcheck == 1) {
6977: document.getElementById(param+'_'+allidxs[i]).checked = true;
6978: } else {
6979: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6980: if (param == 'randompick') {
6981: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6982: }
1.484.2.29 raeburn 6983: }
6984: }
6985: }
6986: }
1.484.2.30 raeburn 6987: if (setcheck == 1) {
6988: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6989: var actions = new Array('copy','cut','remove');
6990: for (var i=0; i<actions.length; i++) {
6991: var otheractions;
6992: var otheridxs;
6993: if (actions[i] === param) {
6994: continue;
6995: } else {
6996: if (document.getElementById('all'+actions[i]+'idx')) {
6997: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6998: otheridxs = otheractions.split(',');
6999: if (otheridxs.length > 1) {
7000: for (var j=0; j<otheridxs.length; j++) {
7001: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7002: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7003: }
1.484.2.29 raeburn 7004: }
7005: }
7006: }
7007: }
1.484.2.30 raeburn 7008: }
1.484.2.29 raeburn 7009: }
7010: }
7011: }
7012: }
1.478 raeburn 7013: }
1.484.2.29 raeburn 7014: return;
7015: }
7016:
1.484.2.63 raeburn 7017: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 7018: var canedit = '$canedit';
7019: if (canedit == '') {
7020: alert("$js_lt{'edri'}");
7021: return;
7022: }
1.484.2.30 raeburn 7023: var dosettings;
7024: var doaction;
7025: var control = document.togglemultsettings;
7026: if (context == 'actions') {
7027: control = document.togglemultactions;
7028: doaction = 1;
7029: } else {
7030: dosettings = 1;
7031: }
7032: if (control) {
7033: if (control.showmultpick.length) {
7034: for (var i=0; i<control.showmultpick.length; i++) {
7035: if (control.showmultpick[i].checked) {
7036: if (control.showmultpick[i].value == 1) {
7037: if (context == 'settings') {
7038: dosettings = 0;
7039: } else {
7040: doaction = 0;
7041: }
7042: }
7043: }
7044: }
7045: }
7046: }
7047: if (context == 'settings') {
7048: if (dosettings == 1) {
7049: targetform.changeparms.value=param;
7050: targetform.submit();
7051: }
7052: }
7053: if (context == 'actions') {
7054: if (doaction == 1) {
7055: targetform.cmd.value=param+'_'+index;
7056: targetform.folderpath.value=folderpath;
7057: targetform.markcopy.value=idx+':'+param;
7058: targetform.copyfolder.value=folder+'.'+container;
7059: if (param == 'remove') {
1.484.2.63 raeburn 7060: var doremove = 0;
7061: if (skip_confirm) {
7062: if (confirm_removal) {
7063: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7064: doremove = 1;
7065: }
7066: } else {
7067: doremove = 1;
7068: }
7069: } else {
7070: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7071: doremove = 1;
7072: }
7073: }
7074: if (doremove) {
1.484.2.30 raeburn 7075: targetform.markcopy.value='';
7076: targetform.copyfolder.value='';
1.484.2.29 raeburn 7077: targetform.submit();
7078: }
7079: }
1.484.2.30 raeburn 7080: if (param == 'cut') {
1.484.2.61 raeburn 7081: 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 7082: targetform.submit();
7083: return;
7084: }
7085: }
7086: if (param == 'copy') {
7087: targetform.submit();
7088: return;
7089: }
7090: targetform.markcopy.value='';
7091: targetform.copyfolder.value='';
7092: targetform.cmd.value='';
7093: targetform.folderpath.value='';
7094: return;
7095: } else {
7096: if (document.getElementById(param+'_'+idx)) {
7097: item = document.getElementById(param+'_'+idx);
7098: if (item.type == 'checkbox') {
7099: if (item.checked) {
7100: item.checked = false;
7101: } else {
7102: item.checked = true;
7103: singleCheck(item,idx,param);
7104: }
7105: }
7106: }
7107: }
7108: }
7109: return;
7110: }
7111:
7112: function singleCheck(caller,idx,action) {
7113: actions = new Array('cut','copy','remove');
7114: if (caller.checked) {
7115: for (var i=0; i<actions.length; i++) {
7116: if (actions[i] != action) {
7117: if (document.getElementById(actions[i]+'_'+idx)) {
7118: if (document.getElementById(actions[i]+'_'+idx).checked) {
7119: document.getElementById(actions[i]+'_'+idx).checked = false;
7120: }
7121: }
7122: }
1.484.2.29 raeburn 7123: }
7124: }
7125: return;
1.478 raeburn 7126: }
7127:
1.334 muellerd 7128: function unselectInactive(nav) {
1.335 ehlerst 7129: currentNav = document.getElementById(nav);
7130: currentLis = currentNav.getElementsByTagName('LI');
7131: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7132: if (currentLis[i].className == 'goback') {
7133: currentLis[i].className = 'goback';
7134: } else {
7135: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7136: currentLis[i].className = 'right';
1.472 raeburn 7137: } else {
1.374 tempelho 7138: currentLis[i].className = 'i';
1.472 raeburn 7139: }
7140: }
1.335 ehlerst 7141: }
1.332 tempelho 7142: }
7143:
1.334 muellerd 7144: function hideAll(current, nav, data) {
1.335 ehlerst 7145: unselectInactive(nav);
1.484.2.43 raeburn 7146: if (current) {
7147: if (current.className == 'right'){
1.374 tempelho 7148: current.className = 'right active'
1.484.2.43 raeburn 7149: } else {
1.374 tempelho 7150: current.className = 'active';
1.484.2.43 raeburn 7151: }
1.374 tempelho 7152: }
1.335 ehlerst 7153: currentData = document.getElementById(data);
7154: currentDivs = currentData.getElementsByTagName('DIV');
7155: for (i = 0; i < currentDivs.length; i++) {
7156: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7157: currentDivs[i].style.display = 'none';
1.330 tempelho 7158: }
7159: }
1.335 ehlerst 7160: }
1.330 tempelho 7161:
1.374 tempelho 7162: function openTabs(pageId) {
7163: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7164: if(tabnav.length > 2 ){
1.389 tempelho 7165: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7166: currentLis = currentNav.getElementsByTagName('LI');
7167: for(i = 0; i< currentLis.length; i++){
7168: if(currentLis[i].className == 'active') {
1.375 tempelho 7169: funcString = currentLis[i].onclick.toString();
7170: tab = funcString.split('"');
1.420 onken 7171: if(tab.length < 2) {
7172: tab = funcString.split("'");
7173: }
1.375 tempelho 7174: currentData = document.getElementById(tab[1]);
7175: currentData.style.display = 'block';
1.374 tempelho 7176: }
7177: }
7178: }
7179: }
7180:
1.334 muellerd 7181: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 7182: currstate = current.className;
1.334 muellerd 7183: hideAll(current, nav, data);
1.375 tempelho 7184: openTabs(pageId);
1.334 muellerd 7185: unselectInactive(nav);
1.484.2.43 raeburn 7186: if ((currstate == 'active') || (currstate == 'right active')) {
7187: if (currstate == 'active') {
7188: current.className = '';
7189: } else {
7190: current.className = 'right';
7191: }
7192: activeTab = '';
7193: toggleUpload();
7194: toggleMap();
7195: resize_scrollbox('contentscroll','1','0');
7196: return;
7197: } else {
7198: current.className = 'active';
7199: }
1.330 tempelho 7200: currentData = document.getElementById(pageId);
7201: currentData.style.display = 'block';
1.458 raeburn 7202: activeTab = pageId;
1.484.2.12 raeburn 7203: toggleUpload();
1.484.2.14 raeburn 7204: toggleMap();
1.433 raeburn 7205: if (nav == 'mainnav') {
7206: var storedpath = "$docs_folderpath";
1.434 raeburn 7207: var storedpage = "$main_container_page";
1.433 raeburn 7208: var reg = new RegExp("^supplemental");
7209: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7210: if (storedpage == 1) {
7211: document.simpleedit.folderpath.value = '';
7212: document.uploaddocument.folderpath.value = '';
7213: } else {
7214: if (reg.test(storedpath)) {
7215: document.simpleedit.folderpath.value = '$toplevelmain';
7216: document.uploaddocument.folderpath.value = '$toplevelmain';
7217: document.newext.folderpath.value = '$toplevelmain';
7218: } else {
7219: document.simpleedit.folderpath.value = storedpath;
7220: document.uploaddocument.folderpath.value = storedpath;
7221: document.newext.folderpath.value = storedpath;
7222: }
1.433 raeburn 7223: }
7224: } else {
1.434 raeburn 7225: if (reg.test(storedpath)) {
7226: document.simpleedit.folderpath.value = storedpath;
7227: document.supuploaddocument.folderpath.value = storedpath;
7228: document.supnewext.folderpath.value = storedpath;
7229: } else {
1.433 raeburn 7230: document.simpleedit.folderpath.value = '$toplevelsupp';
7231: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7232: document.supnewext.folderpath.value = '$toplevelsupp';
7233: }
7234: }
7235: }
1.484.2.3 raeburn 7236: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 7237: return false;
7238: }
1.329 droeschl 7239:
1.472 raeburn 7240: function toContents(jumpto) {
7241: var newurl = '$backtourl';
1.484.2.21 raeburn 7242: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 7243: newurl = newurl+'?postdata='+jumpto;
7244: }
7245: location.href=newurl;
7246: }
7247:
1.484.2.30 raeburn 7248: function togglePick(caller,value) {
7249: var disp = 'none';
7250: if (document.getElementById('multi'+caller)) {
7251: var curr = document.getElementById('multi'+caller).style.display;
7252: if (value == 1) {
7253: disp='block';
7254: }
7255: if (curr == disp) {
7256: return;
7257: }
7258: document.getElementById('multi'+caller).style.display=disp;
7259: if (value == 1) {
1.484.2.61 raeburn 7260: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7261: } else {
7262: document.getElementById('more'+caller).innerHTML = '';
7263: }
7264: if (caller == 'actions') {
7265: setClass(value);
7266: setBoxes(value);
7267: }
7268: }
7269: var showButton = multiSettings();
7270: if (showButton != 1) {
7271: showButton = multiActions();
7272: }
7273: if (document.getElementById('multisave')) {
7274: if (showButton == 1) {
7275: document.getElementById('multisave').style.display='block';
7276: } else {
7277: document.getElementById('multisave').style.display='none';
7278: }
7279: }
7280: resize_scrollbox('contentscroll','1','1');
7281: return;
7282: }
7283:
7284: function toggleCheckUncheck(caller,more) {
7285: if (more == 1) {
1.484.2.61 raeburn 7286: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 7287: document.getElementById('allfields'+caller).style.display='block';
7288: } else {
1.484.2.61 raeburn 7289: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 7290: document.getElementById('allfields'+caller).style.display='none';
7291: }
7292: resize_scrollbox('contentscroll','1','1');
7293: }
7294:
7295: function multiSettings() {
7296: var inuse = 0;
7297: var settingsform = document.togglemultsettings;
7298: if (settingsform.showmultpick.length > 1) {
7299: for (var i=0; i<settingsform.showmultpick.length; i++) {
7300: if (settingsform.showmultpick[i].checked) {
7301: if (settingsform.showmultpick[i].value == 1) {
7302: inuse = 1;
7303: }
7304: }
7305: }
7306: }
7307: return inuse;
7308: }
7309:
7310: function multiActions() {
7311: var inuse = 0;
7312: var actionsform = document.togglemultactions;
7313: if (actionsform.showmultpick.length > 1) {
7314: for (var i=0; i<actionsform.showmultpick.length; i++) {
7315: if (actionsform.showmultpick[i].checked) {
7316: if (actionsform.showmultpick[i].value == 1) {
7317: inuse = 1;
7318: }
7319: }
7320: }
7321: }
7322: return inuse;
7323: }
7324:
7325: function checkSubmits() {
7326: var numchanges = 0;
7327: var form = document.saveactions;
7328: var doactions = multiActions();
7329: var cutwarnings = 0;
7330: var remwarnings = 0;
1.484.2.63 raeburn 7331: var removalinfo = 0;
1.484.2.30 raeburn 7332: if (doactions == 1) {
7333: var remidxlist = document.cumulativeactions.allremoveidx.value;
7334: if ((remidxlist != '') && (remidxlist != null)) {
7335: var remidxs = remidxlist.split(',');
7336: for (var i=0; i<remidxs.length; i++) {
7337: if (document.getElementById('remove_'+remidxs[i])) {
7338: if (document.getElementById('remove_'+remidxs[i]).checked) {
7339: form.multiremove.value += remidxs[i]+',';
7340: numchanges ++;
7341: if (document.getElementById('skip_remove_'+remidxs[i])) {
7342: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
7343: remwarnings ++;
7344: }
7345: }
1.484.2.63 raeburn 7346: if (document.getElementById('confirm_removal_'+remidxs[i])) {
7347: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
7348: removalinfo ++;
7349: }
7350: }
1.484.2.30 raeburn 7351: }
7352: }
7353: }
7354: }
7355: var cutidxlist = document.cumulativeactions.allcutidx.value;
7356: if ((cutidxlist != '') && (cutidxlist != null)) {
7357: var cutidxs = cutidxlist.split(',');
7358: for (var i=0; i<cutidxs.length; i++) {
7359: if (document.getElementById('cut_'+cutidxs[i])) {
7360: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
7361: form.multicut.value += cutidxs[i]+',';
7362: numchanges ++;
7363: if (document.getElementById('skip_cut_'+cutidxs[i])) {
7364: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
7365: cutwarnings ++;
7366: }
7367: }
7368: }
7369: }
7370: }
7371: }
7372: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7373: if ((copyidxlist != '') && (copyidxlist != null)) {
7374: var copyidxs = copyidxlist.split(',');
7375: for (var i=0; i<copyidxs.length; i++) {
7376: if (document.getElementById('copy_'+copyidxs[i])) {
7377: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7378: form.multicopy.value += copyidxs[i]+',';
7379: numchanges ++;
7380: }
7381: }
7382: }
7383: }
7384: if (numchanges > 0) {
7385: form.multichange.value = numchanges;
7386: }
7387: }
7388: var dosettings = multiSettings();
7389: var haschanges = 0;
7390: if (dosettings == 1) {
7391: form.allencrypturl.value = '';
7392: form.allhiddenresource.value = '';
7393: form.changeparms.value = 'all';
7394: var patt=new RegExp(",\$");
7395: var allidxlist = document.cumulativesettings.allidx.value;
7396: if ((allidxlist != '') && (allidxlist != null)) {
7397: var allidxs = allidxlist.split(',');
7398: if (allidxs.length > 1) {
7399: for (var i=0; i<allidxs.length; i++) {
7400: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7401: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7402: form.allhiddenresource.value += allidxs[i]+',';
7403: }
7404: }
7405: if (document.getElementById('encrypturl_'+allidxs[i])) {
7406: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7407: form.allencrypturl.value += allidxs[i]+',';
7408: }
1.484.2.29 raeburn 7409: }
7410: }
1.484.2.30 raeburn 7411: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7412: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7413: }
7414: }
7415: form.allrandompick.value = '';
7416: form.allrandomorder.value = '';
7417: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7418: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7419: var allmapidxs = allmapidxlist.split(',');
7420: for (var i=0; i<allmapidxs.length; i++) {
7421: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7422: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7423: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7424: if ((randompick.checked) && (rpicknum.value != '')) {
7425: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7426: }
7427: if (randorder.checked) {
7428: form.allrandomorder.value += allmapidxs[i]+',';
7429: }
7430: }
7431: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7432: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7433: }
7434: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7435: haschanges = 1;
7436: }
7437: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7438: haschanges = 1;
7439: }
7440: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7441: haschanges = 1;
7442: }
7443: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7444: haschanges = 1;
7445: }
7446: }
7447: if (doactions == 1) {
7448: if (numchanges > 0) {
1.484.2.63 raeburn 7449: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7450: if (remwarnings > 0) {
1.484.2.61 raeburn 7451: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7452: return false;
7453: }
7454: }
1.484.2.63 raeburn 7455: if (removalinfo > 0) {
7456: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7457: return false;
7458: }
7459: }
1.484.2.30 raeburn 7460: if (cutwarnings > 0) {
1.484.2.61 raeburn 7461: 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 7462: return false;
1.484.2.29 raeburn 7463: }
7464: }
7465: }
1.484.2.30 raeburn 7466: form.submit();
7467: return true;
7468: }
7469: }
7470: if (dosettings == 1) {
7471: if (haschanges == 1) {
7472: form.submit();
7473: return true;
1.484.2.29 raeburn 7474: }
7475: }
1.484.2.30 raeburn 7476: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7477: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7478: } else {
7479: if (dosettings == 1) {
1.484.2.61 raeburn 7480: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7481: } else {
1.484.2.61 raeburn 7482: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7483: }
7484: }
7485: return false;
7486: }
7487:
7488: function setClass(value) {
7489: var cutclass = 'LC_docs_cut';
7490: var copyclass = 'LC_docs_copy';
7491: var removeclass = 'LC_docs_remove';
7492: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7493: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7494: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7495: var links = document.getElementsByTagName('a');
7496: for (var i=0; i<links.length; i++) {
7497: var classes = links[i].className;
7498: if (cutreg.test(classes)) {
7499: links[i].className = cutclass;
7500: if (value == 1) {
7501: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7502: }
1.484.2.30 raeburn 7503: } else {
7504: if (copyreg.test(classes)) {
7505: links[i].className = copyclass;
7506: if (value == 1) {
7507: links[i].className += " LC_menubuttons_link";
7508: }
7509: } else {
7510: if (removereg.test(classes)) {
7511: links[i].className = removeclass;
7512: if (value == 1) {
7513: links[i].className += " LC_menubuttons_link";
7514: }
7515: }
1.484.2.29 raeburn 7516: }
7517: }
7518: }
1.484.2.30 raeburn 7519: return;
1.484.2.29 raeburn 7520: }
7521:
1.484.2.30 raeburn 7522: function setBoxes(value) {
7523: var remidxlist = document.cumulativeactions.allremoveidx.value;
7524: if ((remidxlist != '') && (remidxlist != null)) {
7525: var remidxs = remidxlist.split(',');
7526: for (var i=0; i<remidxs.length; i++) {
7527: if (document.getElementById('remove_'+remidxs[i])) {
7528: var item = document.getElementById('remove_'+remidxs[i]);
7529: if (value == 1) {
7530: item.className = 'LC_docs_remove';
7531: } else {
7532: item.className = 'LC_hidden';
7533: }
7534: }
1.484.2.29 raeburn 7535: }
7536: }
1.484.2.30 raeburn 7537: var cutidxlist = document.cumulativeactions.allcutidx.value;
7538: if ((cutidxlist != '') && (cutidxlist != null)) {
7539: var cutidxs = cutidxlist.split(',');
7540: for (var i=0; i<cutidxs.length; i++) {
7541: if (document.getElementById('cut_'+cutidxs[i])) {
7542: var item = document.getElementById('cut_'+cutidxs[i]);
7543: if (value == 1) {
7544: item.className = 'LC_docs_cut';
7545: } else {
7546: item.className = 'LC_hidden';
7547: }
7548: }
7549: }
7550: }
7551: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7552: if ((copyidxlist != '') && (copyidxlist != null)) {
7553: var copyidxs = copyidxlist.split(',');
7554: for (var i=0; i<copyidxs.length; i++) {
7555: if (document.getElementById('copy_'+copyidxs[i])) {
7556: var item = document.getElementById('copy_'+copyidxs[i]);
7557: if (value == 1) {
7558: item.className = 'LC_docs_copy';
7559: } else {
7560: item.className = 'LC_hidden';
7561: }
7562: }
1.484.2.29 raeburn 7563: }
7564: }
7565: return;
7566: }
7567:
1.484.2.67 raeburn 7568: ENDSCRIPT
1.329 droeschl 7569: }
1.457 raeburn 7570:
1.483 raeburn 7571: sub history_tab_js {
7572: return <<"ENDHIST";
7573: function toggleHistoryDisp(choice) {
7574: document.docslogform.docslog.value = choice;
7575: document.docslogform.submit();
7576: return;
7577: }
7578:
7579: ENDHIST
7580: }
7581:
1.484 raeburn 7582: sub inject_data_js {
7583: return <<ENDINJECT;
7584:
7585: function injectData(current, hiddenField, name, value) {
7586: currentElement = document.getElementById(hiddenField);
7587: currentElement.name = name;
7588: currentElement.value = value;
7589: current.submit();
7590: }
7591:
7592: ENDINJECT
7593: }
7594:
7595: sub dump_switchserver_js {
7596: my @hosts = @_;
1.484.2.61 raeburn 7597: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7598: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7599: swit => 'Switch server?',
1.484.2.61 raeburn 7600: );
7601: my %html_js_lt = &Apache::lonlocal::texthash(
7602: swit => 'Switch server?',
1.484.2.43 raeburn 7603: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7604: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7605: chos => 'Choose server',
7606: );
1.484.2.61 raeburn 7607: &js_escape(\%js_lt);
7608: &html_escape(\%html_js_lt);
7609: &js_escape(\%html_js_lt);
1.484 raeburn 7610: my $role = $env{'request.role'};
7611: my $js = <<"ENDSWJS";
7612: <script type="text/javascript">
7613: function write_switchserver() {
7614: var server;
7615: if (document.setserver.posshosts.length > 0) {
7616: for (var i=0; i<document.setserver.posshosts.length; i++) {
7617: if (document.setserver.posshosts[i].checked) {
7618: server = document.setserver.posshosts[i].value;
7619: }
7620: }
7621: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7622: }
7623: window.close();
7624: }
7625: </script>
7626:
7627: ENDSWJS
7628:
7629: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7630: {'only_body' => 1,
7631: 'js_ready' => 1,});
7632: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7633:
7634: my $hostpicker;
7635: my $count = 0;
7636: foreach my $host (sort(@hosts)) {
7637: my $checked;
7638: if ($count == 0) {
7639: $checked = ' checked="checked"';
7640: }
7641: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7642: $host.'"'.$checked.' />'.$host.'</label> ';
7643: $count++;
7644: }
7645:
7646: return <<"ENDSWITCHJS";
7647:
7648: function dump_needs_switchserver(url) {
7649: if (url!='' && url!= null) {
1.484.2.61 raeburn 7650: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7651: go(url);
7652: }
7653: }
7654: return;
7655: }
7656:
7657: function choose_switchserver_window() {
7658: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7659: newWindow.document.open();
7660: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7661: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7662: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7663: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7664: '<form name="setserver" method="post" action="" \\/>\\n'+
7665: '$hostpicker\\n'+
7666: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7667: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7668: 'onclick="write_switchserver();" \\/>\\n'+
7669: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7670: newWindow.document.writeln('$endpage');
7671: newWindow.document.close();
7672: newWindow.focus();
7673: }
7674:
7675: ENDSWITCHJS
7676: }
7677:
7678: sub makedocslogform {
7679: my ($formelems,$docslog) = @_;
7680: return <<"LOGSFORM";
7681: <form action="/adm/coursedocs" method="post" name="docslogform">
7682: <input type="hidden" name="docslog" value="$docslog" />
7683: $formelems
7684: </form>
7685: LOGSFORM
7686: }
7687:
7688: sub makesimpleeditform {
7689: my ($formelems) = @_;
7690: return <<"SIMPFORM";
7691: <form name="simpleedit" method="post" action="/adm/coursedocs">
7692: <input type="hidden" name="importdetail" value="" />
7693: $formelems
7694: </form>
7695: SIMPFORM
7696: }
7697:
1.329 droeschl 7698: 1;
7699: __END__
7700:
7701:
7702: =head1 NAME
7703:
7704: Apache::londocs.pm
7705:
7706: =head1 SYNOPSIS
7707:
7708: This is part of the LearningOnline Network with CAPA project
7709: described at http://www.lon-capa.org.
7710:
7711: =head1 SUBROUTINES
7712:
7713: =over
7714:
7715: =item %help=()
7716:
7717: Available help topics
7718:
7719: =item mapread()
7720:
1.344 bisitz 7721: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7722: @order and @resources, determines status
7723: sets @order - pointer to resources in right order
7724: sets @resources - array with the resources with correct idx
7725:
7726: =item authorhosts()
7727:
7728: Return hash with valid author names
7729:
7730: =item clean()
7731:
7732: =item dumpcourse()
7733:
7734: Actually dump course
7735:
7736: =item group_import()
7737:
7738: Imports the given (name, url) resources into the course
7739: coursenum, coursedom, and folder must precede the list
7740:
7741: =item breadcrumbs()
7742:
7743: =item log_docs()
7744:
7745: =item docs_change_log()
7746:
7747: =item update_paste_buffer()
7748:
7749: =item print_paste_buffer()
7750:
7751: =item do_paste_from_buffer()
7752:
1.484.2.30 raeburn 7753: =item do_buffer_empty()
7754:
7755: =item clear_from_buffer()
7756:
1.484.2.7 raeburn 7757: =item get_newmap_url()
7758:
7759: =item dbcopy()
7760:
7761: =item uniqueness_check()
7762:
7763: =item contained_map_check()
7764:
7765: =item url_paste_fixups()
7766:
7767: =item apply_fixups()
7768:
7769: =item copy_dependencies()
7770:
1.329 droeschl 7771: =item update_parameter()
7772:
7773: =item handle_edit_cmd()
7774:
7775: =item editor()
7776:
7777: =item process_file_upload()
7778:
7779: =item process_secondary_uploads()
7780:
7781: =item is_supplemental_title()
7782:
7783: =item entryline()
7784:
7785: =item tiehash()
7786:
7787: =item untiehash()
7788:
7789: =item checkonthis()
7790:
7791: check on this
7792:
7793: =item verifycontent()
7794:
7795: Verify Content
7796:
1.484.2.78 raeburn 7797: =item devalidateversioncache()
7798:
7799: =item checkversions()
1.329 droeschl 7800:
7801: Check Versions
7802:
7803: =item mark_hash_old()
7804:
7805: =item is_hash_old()
7806:
7807: =item changewarning()
7808:
7809: =item init_breadcrumbs()
7810:
7811: Breadcrumbs for special functions
7812:
1.484 raeburn 7813: =item create_list_elements()
7814:
7815: =item create_form_ul()
7816:
7817: =item startContentScreen()
7818:
7819: =item endContentScreen()
7820:
7821: =item supplemental_base()
7822:
7823: =item embedded_form_elems()
7824:
7825: =item embedded_destination()
7826:
7827: =item return_to_editor()
7828:
7829: =item decompression_info()
7830:
7831: =item decompression_phase_one()
7832:
7833: =item decompression_phase_two()
7834:
7835: =item remove_archive()
7836:
7837: =item generate_admin_menu()
7838:
7839: =item generate_edit_table()
7840:
7841: =item editing_js()
7842:
7843: =item history_tab_js()
7844:
7845: =item inject_data_js()
7846:
7847: =item dump_switchserver_js()
7848:
1.484.2.3 raeburn 7849: =item resize_scrollbox_js()
1.484 raeburn 7850:
7851: =item makedocslogform()
7852:
1.484.2.3 raeburn 7853: =item makesimpleeditform()
7854:
1.329 droeschl 7855: =back
7856:
7857: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>