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