Annotation of loncom/interface/londocs.pm, revision 1.484.2.70
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.70! raeburn 4: # $Id: londocs.pm,v 1.484.2.69 2017/01/24 15:54:02 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.70! raeburn 3068: \%filters,\%curr_groups,$canedit,
! 3069: $isencrypted,$navmapref);
1.381 bisitz 3070: $idx++;
3071: $shown++;
1.329 droeschl 3072: }
1.424 onken 3073: &Apache::loncommon::end_data_table_count();
1.484.2.19 raeburn 3074:
1.484.2.30 raeburn 3075: my $need_save;
1.484.2.67 raeburn 3076: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.484.2.31 raeburn 3077: my $toolslink;
1.484.2.67 raeburn 3078: if ($allowed) {
1.484.2.31 raeburn 3079: $toolslink = '<table><tr><td>'
1.484.2.19 raeburn 3080: .&Apache::loncommon::help_open_menu('Navigation Screen',
3081: 'Navigation_Screen',undef,'RAT')
3082: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3083: .'<td align="left"><ul id="LC_toolbar">'
1.484.2.21 raeburn 3084: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.484.2.19 raeburn 3085: .'id="LC_content_toolbar_edittoplevel" '
3086: .'class="LC_toolbarItem" '
3087: .'title="'.&mt('Supplemental Content Editor').'">'
3088: .'</a></li></ul></td></tr></table><br />';
1.484.2.31 raeburn 3089: }
1.484.2.19 raeburn 3090: if ($shown) {
3091: if ($allowed) {
3092: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3093: .&Apache::loncommon::start_data_table(undef,'contentlist')
3094: .&Apache::loncommon::start_data_table_header_row()
3095: .'<th colspan="2">'.&mt('Move').'</th>'
1.484.2.30 raeburn 3096: .'<th colspan="2">'.&mt('Actions').'</th>'
3097: .'<th>'.&mt('Document').'</th>';
1.484.2.19 raeburn 3098: if ($folder !~ /^supplemental/) {
3099: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
3100: }
1.484.2.29 raeburn 3101: $to_show .= &Apache::loncommon::end_data_table_header_row();
3102: if ($folder !~ /^supplemental/) {
1.484.2.30 raeburn 3103: $lists{'canhide'} = join(',',@allidx);
3104: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3105: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3106: 'randomorder','randompick');
3107: foreach my $item (@possfilters) {
3108: if (ref($filters{$item}) eq 'ARRAY') {
3109: if (@{$filters{$item}} > 0) {
3110: $lists{$item} = join(',',@{$filters{$item}});
3111: }
3112: }
3113: }
1.484.2.29 raeburn 3114: if (@allidx > 0) {
3115: my $path;
3116: if ($env{'form.folderpath'}) {
3117: $path =
3118: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3119: }
1.484.2.30 raeburn 3120: if (@allidx > 1) {
3121: $to_show .=
3122: &Apache::loncommon::continue_data_table_row().
3123: '<td colspan="2"> </td>'.
3124: '<td>'.
1.484.2.67 raeburn 3125: &multiple_check_form('actions',\%lists,$canedit).
1.484.2.30 raeburn 3126: '</td>'.
3127: '<td> </td>'.
3128: '<td> </td>'.
3129: '<td colspan="4">'.
1.484.2.67 raeburn 3130: &multiple_check_form('settings',\%lists,$canedit).
1.484.2.30 raeburn 3131: '</td>'.
3132: &Apache::loncommon::end_data_table_row();
3133: $need_save = 1;
3134: }
1.484.2.29 raeburn 3135: }
3136: }
3137: $to_show .= $output.' '
1.484.2.19 raeburn 3138: .&Apache::loncommon::end_data_table()
3139: .'<br style="line-height:2px;" />'
3140: .&Apache::loncommon::end_scrollbox();
3141: } else {
3142: $to_show .= $toolslink
3143: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3144: .$output.' '
3145: .&Apache::loncommon::end_data_table();
3146: }
3147: } else {
3148: if (!$allowed) {
3149: $to_show .= $toolslink;
1.393 raeburn 3150: }
1.484.2.67 raeburn 3151: my $noresmsg;
3152: if ($allowed && $hiddentop && !$supplementalflag) {
3153: $noresmsg = &mt('Main Content Hidden');
3154: } else {
3155: $noresmsg = &mt('Currently empty');
3156: }
1.484.2.19 raeburn 3157: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3158: .'<div class="LC_info" id="contentlist">'
1.484.2.67 raeburn 3159: .$noresmsg
1.484.2.19 raeburn 3160: .'</div>'
3161: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3162: }
3163: } else {
1.484.2.19 raeburn 3164: if ($shown) {
3165: $to_show = '<div>'
3166: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3167: .$output
3168: .&Apache::loncommon::end_data_table()
3169: .'</div>';
3170: } else {
3171: $to_show = '<div class="LC_info" id="contentlist">'
1.484.2.34 raeburn 3172: .&mt('Currently empty')
1.484.2.19 raeburn 3173: .'</div>'
3174: }
1.458 raeburn 3175: }
3176: my $tid = 1;
3177: if ($supplementalflag) {
3178: $tid = 2;
1.329 droeschl 3179: }
3180: if ($allowed) {
1.484 raeburn 3181: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.484.2.30 raeburn 3182: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.484.2.67 raeburn 3183: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
1.484.2.68 raeburn 3184: if ($canedit) {
1.484.2.67 raeburn 3185: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3186: }
1.460 raeburn 3187: } else {
3188: $r->print($to_show);
1.329 droeschl 3189: }
3190: return;
3191: }
3192:
1.484.2.30 raeburn 3193: sub multiple_check_form {
1.484.2.67 raeburn 3194: my ($caller,$listsref,$canedit) = @_;
1.484.2.30 raeburn 3195: return unless (ref($listsref) eq 'HASH');
1.484.2.67 raeburn 3196: my $disabled;
3197: unless ($canedit) {
3198: $disabled = 'disabled="disabled"';
3199: }
1.484.2.30 raeburn 3200: my $output =
3201: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3202: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3203: '<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>'.
3204: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3205: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3206: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3207: if ($caller eq 'settings') {
3208: $output .=
3209: '<table><tr>'.
3210: '<td class="LC_docs_entry_parameter">'.
3211: '<span class="LC_nobreak"><label>'.
1.484.2.67 raeburn 3212: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.484.2.30 raeburn 3213: '</label></span></td>'.
3214: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3215: '<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 3216: '</span></td>'.
3217: '</tr>'."\n".
3218: '<tr>'.
3219: '<td class="LC_docs_entry_parameter">'.
1.484.2.67 raeburn 3220: '<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 3221: '</label></span>'.
3222: '</td></tr></table>'."\n";
3223: } else {
3224: $output .=
3225: '<table><tr>'.
3226: '<td class="LC_docs_entry_parameter">'.
3227: '<span class="LC_nobreak LC_docs_remove">'.
1.484.2.67 raeburn 3228: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.484.2.30 raeburn 3229: '</label></span></td>'.
3230: '<td class="LC_docs_entry_parameter">'.
3231: '<span class="LC_nobreak LC_docs_cut">'.
1.484.2.67 raeburn 3232: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.484.2.30 raeburn 3233: '</label></span></td>'."\n".
3234: '<td class="LC_docs_entry_parameter">'.
3235: '<span class="LC_nobreak LC_docs_copy">'.
1.484.2.67 raeburn 3236: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'.$disabled.' />'.&mt('Copy').
1.484.2.30 raeburn 3237: '</label></span></td>'.
3238: '</tr></table>'."\n";
3239: }
3240: $output .=
3241: '</fieldset>'.
3242: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3243: if ($caller eq 'settings') {
3244: $output .=
3245: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3246: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3247: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3248: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3249: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3250: } elsif ($caller eq 'actions') {
3251: $output .=
3252: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3253: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3254: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3255: }
3256: $output .=
3257: '</form>'.
3258: '</div>';
3259: return $output;
3260: }
3261:
1.329 droeschl 3262: sub process_file_upload {
1.484.2.36 raeburn 3263: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3264: # upload a file, if present
1.484.2.36 raeburn 3265: my $filesize = length($env{'form.uploaddoc'});
3266: if (!$filesize) {
3267: $$upload_output = '<div class="LC_error">'.
3268: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3269: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3270: $filesize).'<br />'.
3271: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3272: '</div>';
3273: return;
3274: }
3275: my $quotatype = 'unofficial';
3276: if ($crstype eq 'Community') {
3277: $quotatype = 'community';
1.484.2.51 raeburn 3278: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.484.2.36 raeburn 3279: $quotatype = 'official';
1.484.2.45 raeburn 3280: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3281: $quotatype = 'textbook';
1.484.2.36 raeburn 3282: }
3283: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3284: $filesize = int($filesize/1000); #expressed in kb
3285: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.484.2.51 raeburn 3286: $env{'form.uploaddoc.filename'},$filesize,
3287: 'upload',$quotatype);
1.484.2.36 raeburn 3288: return if ($$upload_output);
3289: }
1.440 raeburn 3290: my ($parseaction,$showupload,$nextphase,$mimetype);
3291: if ($env{'form.parserflag'}) {
1.329 droeschl 3292: $parseaction = 'parse';
3293: }
3294: my $folder=$env{'form.folder'};
3295: if ($folder eq '') {
3296: $folder='default';
3297: }
3298: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3299: my $errtext='';
3300: my $fatal=0;
3301: my $container='sequence';
1.484.2.19 raeburn 3302: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3303: $container='page';
3304: }
3305: ($errtext,$fatal)=
1.484.2.27 raeburn 3306: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3307: if ($#LONCAPA::map::order<1) {
3308: $LONCAPA::map::order[0]=1;
3309: $LONCAPA::map::resources[1]='';
3310: }
3311: my $destination = 'docs/';
3312: if ($folder =~ /^supplemental/) {
3313: $destination = 'supplemental/';
3314: }
3315: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3316: $destination .= 'default/';
3317: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3318: $destination .= $2.'/';
3319: }
1.484.2.27 raeburn 3320: if ($fatal) {
3321: $$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>';
3322: return;
3323: }
1.440 raeburn 3324: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3325: my $newidx=&LONCAPA::map::getresidx();
3326: $destination .= $newidx;
1.439 raeburn 3327: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3328: $parseaction,$allfiles,
1.440 raeburn 3329: $codebase,undef,undef,undef,undef,
3330: undef,undef,\$mimetype);
3331: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3332: my $stored = $1;
3333: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3334: $stored.'</span>').'</p>';
3335: } else {
3336: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3337:
1.457 raeburn 3338: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3339: return;
3340: }
1.329 droeschl 3341: my $ext='false';
3342: if ($url=~m{^http://}) { $ext='true'; }
3343: $url = &LONCAPA::map::qtunescape($url);
3344: my $comment=$env{'form.comment'};
3345: $comment = &LONCAPA::map::qtunescape($comment);
3346: if ($folder=~/^supplemental/) {
3347: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3348: $env{'user.domain'}.'___&&&___'.$comment;
3349: }
3350:
3351: $LONCAPA::map::resources[$newidx]=
3352: $comment.':'.$url.':'.$ext.':normal:res';
3353: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3354: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 3355: $folder.'.'.$container,1);
1.329 droeschl 3356: if ($fatal) {
1.457 raeburn 3357: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3358: return;
1.329 droeschl 3359: } else {
1.440 raeburn 3360: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3361: $$upload_output = $showupload;
1.384 raeburn 3362: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3363: if ($total_embedded > 0) {
1.440 raeburn 3364: my $uploadphase = 'upload_embedded';
3365: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3366: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3367: my ($embedded,$num) =
3368: &Apache::loncommon::ask_for_embedded_content(
3369: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3370: if ($embedded) {
3371: if ($num) {
3372: $$upload_output .=
3373: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3374: $nextphase = $uploadphase;
3375: } else {
3376: $$upload_output .= $embedded;
3377: }
3378: } else {
3379: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3380: }
1.329 droeschl 3381: } else {
1.440 raeburn 3382: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3383: }
1.457 raeburn 3384: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.484.2.51 raeburn 3385: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3386: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3387: $nextphase = 'decompress_uploaded';
3388: my $position = scalar(@LONCAPA::map::order)-1;
3389: my $noextract = &return_to_editor();
3390: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3391: my %archiveitems = (
3392: folderpath => $env{'form.folderpath'},
3393: cmd => $nextphase,
3394: newidx => $newidx,
3395: position => $position,
3396: phase => $nextphase,
1.477 raeburn 3397: comment => $comment,
1.480 raeburn 3398: );
3399: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3400: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3401: $$upload_output = $showupload.
3402: &Apache::loncommon::decompress_form($mimetype,
3403: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3404: \%archiveitems,\@current);
1.329 droeschl 3405: }
3406: }
3407: }
1.440 raeburn 3408: return $nextphase;
1.329 droeschl 3409: }
3410:
1.480 raeburn 3411: sub get_dir_list {
3412: my ($url,$coursenum,$coursedom,$newidx) = @_;
3413: my ($destination,$dir_root) = &embedded_destination();
3414: my ($dirlistref,$listerror) =
3415: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3416: my @dir_lines;
3417: my $dirptr=16384;
3418: if (ref($dirlistref) eq 'ARRAY') {
3419: foreach my $dir_line (sort
3420: {
3421: my ($afile)=split('&',$a,2);
3422: my ($bfile)=split('&',$b,2);
3423: return (lc($afile) cmp lc($bfile));
3424: } (@{$dirlistref})) {
3425: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3426: $filename =~ s/\s+$//;
3427: next if ($filename =~ /^\.\.?$/);
3428: my $isdir = 0;
3429: if ($dirptr&$testdir) {
3430: $isdir = 1;
3431: }
3432: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3433: }
3434: }
3435: return @dir_lines;
3436: }
3437:
1.329 droeschl 3438: sub is_supplemental_title {
3439: my ($title) = @_;
3440: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3441: }
3442:
3443: # --------------------------------------------------------------- An entry line
3444:
3445: sub entryline {
1.484.2.12 raeburn 3446: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.67 raeburn 3447: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3448: $canedit,$isencrypted,$navmapref)=@_;
1.484.2.52 raeburn 3449: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3450: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 3451: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3452: } else {
3453: $title=&HTML::Entities::encode($title,'"<>&\'');
3454: $renametitle=$title;
3455: $foldertitle=$title;
3456: }
3457:
1.484.2.67 raeburn 3458: my ($disabled,$readonly,$js_lt);
3459: unless ($canedit) {
3460: $disabled = 'disabled="disabled"';
3461: $readonly = 1;
3462: }
3463:
1.329 droeschl 3464: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3465:
1.329 droeschl 3466: $renametitle=~s/\\/\\\\/g;
3467: $renametitle=~s/\"\;/\\\"/g;
1.484.2.55 raeburn 3468: $renametitle=~s/"/%22/g;
1.329 droeschl 3469: $renametitle=~s/ /%20/g;
1.484.2.52 raeburn 3470: $oldtitle = $renametitle;
3471: $renametitle=~s/\'\;/\\\'/g;
1.379 bisitz 3472: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3473: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3474: # Edit commands
1.484.2.28 raeburn 3475: my ($esc_path, $path, $symb);
1.329 droeschl 3476: if ($env{'form.folderpath'}) {
3477: $esc_path=&escape($env{'form.folderpath'});
3478: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3479: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3480: }
1.484.2.16 raeburn 3481: my $isexternal;
1.484.2.19 raeburn 3482: if ($residx) {
1.484.2.12 raeburn 3483: my $currurl = $url;
3484: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3485: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3486: $isexternal = 1;
3487: }
1.484.2.19 raeburn 3488: if (!$supplementalflag) {
3489: my $path = 'uploaded/'.
3490: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3491: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3492: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3493: $residx,
3494: &Apache::lonnet::declutter($currurl));
3495: }
1.484.2.12 raeburn 3496: }
1.484.2.30 raeburn 3497: my ($renamelink,%lt,$ishash);
3498: if (ref($filtersref) eq 'HASH') {
3499: $ishash = 1;
3500: }
3501:
1.329 droeschl 3502: if ($allowed) {
1.484.2.30 raeburn 3503: $form_start = '
3504: <form action="/adm/coursedocs" method="post">
3505: ';
3506: $form_common=(<<END);
3507: <input type="hidden" name="folderpath" value="$path" />
3508: <input type="hidden" name="symb" value="$symb" />
3509: END
3510: $form_param=(<<END);
3511: <input type="hidden" name="setparms" value="$orderidx" />
3512: <input type="hidden" name="changeparms" value="0" />
3513: END
3514: $form_end = '</form>';
3515:
1.329 droeschl 3516: my $incindex=$index+1;
3517: my $selectbox='';
1.471 raeburn 3518: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3519: ((split(/\:/,
1.344 bisitz 3520: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3521: ne '') &&
1.329 droeschl 3522: ((split(/\:/,
1.344 bisitz 3523: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3524: ne '')) {
3525: $selectbox=
3526: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.484.2.67 raeburn 3527: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3528: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3529: if ($i==$incindex) {
1.358 bisitz 3530: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3531: } else {
3532: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3533: }
3534: }
3535: $selectbox.='</select>';
3536: }
1.484.2.12 raeburn 3537: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3538: 'up' => 'Move Up',
3539: 'dw' => 'Move Down',
3540: 'rm' => 'Remove',
3541: 'ct' => 'Cut',
3542: 'rn' => 'Rename',
1.484.2.12 raeburn 3543: 'cp' => 'Copy',
3544: 'ex' => 'External Resource',
3545: 'ed' => 'Edit',
3546: 'pr' => 'Preview',
3547: 'sv' => 'Save',
3548: 'ul' => 'URL',
1.484.2.67 raeburn 3549: 'ti' => 'Title',
3550: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.12 raeburn 3551: );
1.484.2.30 raeburn 3552: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3553: $env{'form.folderpath'},
3554: $currgroups);
1.484.2.19 raeburn 3555: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3556: my $skip_confirm = 0;
1.484.2.63 raeburn 3557: my $confirm_removal = 0;
1.329 droeschl 3558: if ( $folder =~ /^supplemental/
3559: || ($url =~ m{( /smppg$
3560: |/syllabus$
3561: |/aboutme$
3562: |/navmaps$
3563: |/bulletinboard$
1.484.2.16 raeburn 3564: |\.html$)}x)
1.484.2.19 raeburn 3565: || $isexternal) {
1.329 droeschl 3566: $skip_confirm = 1;
3567: }
1.484.2.63 raeburn 3568: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3569: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3570: $confirm_removal = 1;
3571: }
1.484.2.19 raeburn 3572:
1.484.2.30 raeburn 3573: if ($denied{'copy'}) {
3574: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3575: <span style="visibility: hidden;">$lt{'cp'}</span>
3576: ENDCOPY
3577: } else {
1.484.2.30 raeburn 3578: my $formname = 'edit_copy_'.$orderidx;
3579: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3580: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3581: <form name="$formname" method="post" action="/adm/coursedocs">
3582: $form_common
1.484.2.67 raeburn 3583: <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 3584: $form_end
1.329 droeschl 3585: ENDCOPY
1.484.2.30 raeburn 3586: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3587: push(@{$filtersref->{'cancopy'}},$orderidx);
3588: }
1.329 droeschl 3589: }
1.484.2.30 raeburn 3590: if ($denied{'cut'}) {
1.484.2.16 raeburn 3591: $cutlink=(<<ENDCUT);
3592: <span style="visibility: hidden;">$lt{'ct'}</span>
3593: ENDCUT
3594: } else {
1.484.2.30 raeburn 3595: my $formname = 'edit_cut_'.$orderidx;
3596: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3597: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3598: <form name="$formname" method="post" action="/adm/coursedocs">
3599: $form_common
3600: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.484.2.67 raeburn 3601: <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 3602: $form_end
1.329 droeschl 3603: ENDCUT
1.484.2.30 raeburn 3604: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3605: push(@{$filtersref->{'cancut'}},$orderidx);
3606: }
1.329 droeschl 3607: }
1.484.2.30 raeburn 3608: if ($denied{'remove'}) {
1.484.2.16 raeburn 3609: $removelink=(<<ENDREM);
3610: <span style="visibility: hidden;">$lt{'rm'}</a>
3611: ENDREM
3612: } else {
1.484.2.30 raeburn 3613: my $formname = 'edit_remove_'.$orderidx;
1.484.2.63 raeburn 3614: 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 3615: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3616: <form name="$formname" method="post" action="/adm/coursedocs">
3617: $form_common
3618: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.484.2.63 raeburn 3619: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.484.2.67 raeburn 3620: <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 3621: $form_end
1.484.2.9 raeburn 3622: ENDREM
1.484.2.30 raeburn 3623: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3624: push(@{$filtersref->{'canremove'}},$orderidx);
3625: }
1.484.2.9 raeburn 3626: }
1.484.2.35 raeburn 3627: $renamelink=(<<ENDREN);
1.484.2.52 raeburn 3628: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3629: ENDREN
1.484.2.67 raeburn 3630: my ($uplink,$downlink);
3631: if ($canedit) {
3632: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3633: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
3634: } else {
3635: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
3636: $downlink = $uplink;
3637: }
1.329 droeschl 3638: $line.=(<<END);
3639: <td>
1.379 bisitz 3640: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3641: <a href="$uplink">
1.484.2.12 raeburn 3642: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3643: </a>
3644: </div>
3645: <div class="LC_docs_entry_move">
1.484.2.67 raeburn 3646: <a href="$downlink">
1.484.2.12 raeburn 3647: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3648: </a>
3649: </div>
1.329 droeschl 3650: </td>
3651: <td>
3652: $form_start
1.484.2.30 raeburn 3653: $form_param
1.478 raeburn 3654: $form_common
1.329 droeschl 3655: $selectbox
3656: $form_end
3657: </td>
1.484.2.30 raeburn 3658: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3659: $removelink
1.329 droeschl 3660: $cutlink
3661: $copylink
3662: </td>
3663: END
3664: }
3665: # Figure out what kind of a resource this is
3666: my ($extension)=($url=~/\.(\w+)$/);
3667: my $uploaded=($url=~/^\/*uploaded\//);
3668: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3669: my $isfolder;
3670: my $ispage;
3671: my $containerarg;
1.484.2.67 raeburn 3672: my $folderurl;
1.329 droeschl 3673: if ($uploaded) {
1.472 raeburn 3674: if (($extension eq 'sequence') || ($extension eq 'page')) {
3675: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3676: $containerarg = $1;
1.472 raeburn 3677: if ($extension eq 'sequence') {
3678: $icon=$iconpath.'navmap.folder.closed.gif';
3679: $isfolder=1;
3680: } else {
3681: $icon=$iconpath.'page.gif';
3682: $ispage=1;
3683: }
1.484.2.67 raeburn 3684: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 3685: if ($allowed) {
3686: $url='/adm/coursedocs?';
3687: } else {
3688: $url='/adm/supplemental?';
3689: }
1.329 droeschl 3690: } else {
3691: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3692: }
3693: }
1.364 bisitz 3694:
1.484.2.70! raeburn 3695: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 3696: my $orig_url = $url;
1.340 raeburn 3697: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3698: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3699: if (!$supplementalflag && $residx && $symb) {
3700: if ((!$isfolder) && (!$ispage)) {
3701: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3702: $url=&Apache::lonnet::clutter($url);
3703: if ($url=~/^\/*uploaded\//) {
3704: $url=~/\.(\w+)$/;
3705: my $embstyle=&Apache::loncommon::fileembstyle($1);
3706: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3707: $url='/adm/wrapper'.$url;
3708: } elsif ($embstyle eq 'ssi') {
3709: #do nothing with these
3710: } elsif ($url!~/\.(sequence|page)$/) {
3711: $url='/adm/coursedocs/showdoc'.$url;
3712: }
1.484.2.70! raeburn 3713: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
! 3714: my $wrapped = $1;
! 3715: my $exturl = $2;
! 3716: if ($wrapped eq '') {
! 3717: $url='/adm/wrapper'.$url;
! 3718: }
! 3719: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
! 3720: $nomodal = 1;
! 3721: }
! 3722: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
! 3723: if (($ENV{'SERVER_PORT'} == 443) &&
! 3724: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 3725: $nomodal = 1;
! 3726: }
1.484.2.19 raeburn 3727: }
1.484.2.12 raeburn 3728: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.66 raeburn 3729: my $shownsymb = $symb;
3730: if ($isexternal) {
3731: if ($url =~ /^([^#]+)#([^#]+)$/) {
3732: $url = $1;
3733: $anchor = $2;
3734: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
3735: $shownsymb = $1.&escape('#').$anchor;
3736: }
3737: }
3738: }
1.484.2.67 raeburn 3739: unless ($env{'request.role.adv'}) {
3740: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3741: $url = '';
3742: }
3743: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
3744: $url = '';
3745: $hiddenres = 1;
3746: }
3747: }
3748: if ($url ne '') {
3749: $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3750: }
3751: } elsif (!$env{'request.role.adv'}) {
3752: my $checkencrypt;
3753: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
3754: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
3755: $checkencrypt = 1;
1.484.2.70! raeburn 3756: } elsif (ref($navmapref)) {
1.484.2.67 raeburn 3757: unless (ref($$navmapref)) {
3758: $$navmapref = Apache::lonnavmaps::navmap->new();
3759: }
3760: if (ref($$navmapref)) {
3761: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
3762: $checkencrypt = 1;
3763: }
3764: }
3765: }
3766: if ($checkencrypt) {
3767: my $shownsymb = &Apache::lonenc::encrypted($symb);
3768: my $shownurl = &Apache::lonenc::encrypted($url);
3769: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
3770: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
3771: if ($env{'request.enc'} ne '') {
3772: delete($env{'request.enc'});
3773: }
3774: } else {
3775: $url='';
3776: }
3777: } else {
3778: $url='';
3779: }
1.484.2.12 raeburn 3780: } else {
3781: $url='';
3782: }
1.484.2.19 raeburn 3783: }
1.484.2.66 raeburn 3784: } elsif ($supplementalflag) {
3785: if ($isexternal) {
3786: if ($url =~ /^([^#]+)#([^#]+)$/) {
3787: $url = $1;
3788: $anchor = $2;
1.484.2.70! raeburn 3789: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
! 3790: $nomodal = 1;
! 3791: }
! 3792: }
! 3793: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
! 3794: if (($ENV{'SERVER_PORT'} == 443) &&
! 3795: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
! 3796: $nomodal = 1;
1.484.2.66 raeburn 3797: }
3798: }
1.329 droeschl 3799: }
1.484.2.67 raeburn 3800: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
3801: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.484.2.19 raeburn 3802: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3803: my $foldername=&escape($foldertitle);
3804: my $folderpath=$env{'form.folderpath'};
3805: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3806: if (!$allowed && $supplementalflag) {
3807: $folderpath.=$containerarg.'&'.$foldername;
3808: $url.='folderpath='.&escape($folderpath);
3809: } else {
3810: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3811: 'parameter_randompick'))[0];
1.484.2.67 raeburn 3812: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
3813: 'parameter_randomorder'))[0]=~/^yes$/i);
3814: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
3815: 'parameter_hiddenresource'))[0]=~/^yes$/i);
3816: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
3817: 'parameter_encrypturl'))[0]=~/^yes$/i);
3818: unless ($hiddenmap) {
1.484.2.70! raeburn 3819: if (ref($navmapref)) {
! 3820: unless (ref($$navmapref)) {
! 3821: $$navmapref = Apache::lonnavmaps::navmap->new();
! 3822: }
! 3823: if (ref($$navmapref)) {
! 3824: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
! 3825: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
! 3826: unless (@resources) {
! 3827: $hiddenmap = 1;
! 3828: unless ($env{'request.role.adv'}) {
! 3829: $url = '';
! 3830: $hiddenfolder = 1;
! 3831: }
1.484.2.67 raeburn 3832: }
3833: }
3834: }
3835: }
3836: }
3837: unless ($encryptmap) {
1.484.2.70! raeburn 3838: if ((ref($navmapref)) && (ref($$navmapref))) {
! 3839: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
! 3840: $encryptmap = 1;
! 3841: }
1.484.2.67 raeburn 3842: }
3843: }
3844:
3845: # Append randompick number, hidden, and encrypted with ":" to foldername,
3846: # so it gets transferred between levels
3847: $folderpath.=$containerarg.'&'.$foldername.
3848: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
3849: unless ($url eq '') {
3850: $url.='folderpath='.&escape($folderpath);
3851: }
1.484.2.19 raeburn 3852: my $rpckchk;
3853: if ($rpicknum) {
3854: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3855: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3856: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3857: }
1.484.2.19 raeburn 3858: }
1.484.2.29 raeburn 3859: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3860: $rand_pick_text =
1.478 raeburn 3861: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3862: $form_param."\n".
1.478 raeburn 3863: $form_common."\n".
1.484.2.67 raeburn 3864: '<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 3865: if ($rpicknum ne '') {
3866: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3867: }
1.484.2.29 raeburn 3868: $rand_pick_text .= '</span></span>'.
3869: $form_end;
1.484.2.30 raeburn 3870: my $ro_set;
1.484.2.67 raeburn 3871: if ($randorder) {
1.484.2.30 raeburn 3872: $ro_set = 'checked="checked"';
3873: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3874: push(@{$filtersref->{'randomorder'}},$orderidx);
3875: }
3876: }
1.484.2.41 raeburn 3877: $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3878: $rand_order_text =
1.484.2.29 raeburn 3879: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3880: $form_param."\n".
1.484.2.29 raeburn 3881: $form_common."\n".
1.484.2.67 raeburn 3882: '<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 3883: $form_end;
1.484.2.19 raeburn 3884: }
1.484.2.18 raeburn 3885: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3886: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3887: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3888: if ($title) {
3889: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3890: }
3891: if ($isexternal && $orderidx) {
3892: $url .= '&idx='.$orderidx;
3893: }
1.484.2.66 raeburn 3894: if ($anchor ne '') {
3895: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3896: }
1.329 droeschl 3897: }
1.484.2.19 raeburn 3898: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3899: if ($allowed) {
1.484.2.19 raeburn 3900: my $fileloc =
1.484.2.12 raeburn 3901: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3902: if ($isexternal) {
3903: ($editlink,$extresform) =
1.484.2.67 raeburn 3904: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
3905: undef,undef,undef,$disabled);
1.484.2.19 raeburn 3906: } elsif (!$isfolder && !$ispage) {
3907: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3908: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3909: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.484.2.66 raeburn 3910: my $suppanchor;
3911: if ($supplementalflag) {
3912: $suppanchor = $anchor;
3913: }
1.484.2.19 raeburn 3914: my $jscall =
1.484.2.12 raeburn 3915: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3916: $switchserver,
1.484.2.14 raeburn 3917: $forceedit,
1.484.2.19 raeburn 3918: undef,$symb,
3919: &escape($env{'form.folderpath'}),
1.484.2.66 raeburn 3920: $renametitle,'','',1,$suppanchor);
1.484.2.12 raeburn 3921: if ($jscall) {
1.484.2.19 raeburn 3922: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3923: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3924: }
3925: }
3926: }
1.484.2.19 raeburn 3927: $tdalign = ' align="right" valign="top"';
3928: $tdwidth = ' width="80%"';
1.329 droeschl 3929: }
1.408 raeburn 3930: my $reinit;
3931: if ($crstype eq 'Community') {
3932: $reinit = &mt('(re-initialize community to access)');
3933: } else {
3934: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3935: }
3936: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.484.2.70! raeburn 3937: my $link;
1.472 raeburn 3938: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3939: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3940: } elsif ($url) {
1.484.2.66 raeburn 3941: if ($anchor ne '') {
3942: if ($supplementalflag) {
3943: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
3944: } else {
3945: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
3946: }
3947: }
1.484.2.70! raeburn 3948: $link = &js_escape($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
! 3949: (($anchor ne '')?$anchor:''));
! 3950: if ($nomodal) {
! 3951: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
! 3952: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
! 3953: } else {
! 3954: $line.=&Apache::loncommon::modal_link($link,
! 3955: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
! 3956: }
1.469 www 3957: } else {
3958: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3959: }
1.484.2.19 raeburn 3960: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3961: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3962: $line.='<a href="'.$url.'">'.$title.'</a>';
3963: } elsif ($url) {
1.484.2.70! raeburn 3964: if ($nomodal) {
! 3965: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
! 3966: $title.'</a>';
! 3967: } else {
! 3968: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
! 3969: }
1.484.2.67 raeburn 3970: } elsif (($hiddenfolder) || ($hiddenres)) {
3971: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
1.469 www 3972: } else {
3973: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3974: }
1.484.2.19 raeburn 3975: $line.="$extresform</td>";
1.478 raeburn 3976: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3977: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 3978: if (($allowed) && ($folder!~/^supplemental/)) {
3979: my %lt=&Apache::lonlocal::texthash(
3980: 'hd' => 'Hidden',
3981: 'ec' => 'URL hidden');
1.484.2.30 raeburn 3982: my ($enctext,$hidtext);
3983: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
3984: $enctext = ' checked="checked"';
3985: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
3986: push(@{$filtersref->{'encrypturl'}},$orderidx);
3987: }
3988: }
3989: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3990: $hidtext = ' checked="checked"';
3991: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3992: push(@{$filtersref->{'hiddenresource'}},$orderidx);
3993: }
3994: }
1.484.2.29 raeburn 3995: my $formhidden = 'edit_hiddenresource_'.$orderidx;
3996: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 3997: $line.=(<<ENDPARMS);
3998: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 3999: <form action="/adm/coursedocs" method="post" name="$formhidden">
4000: $form_param
1.478 raeburn 4001: $form_common
1.484.2.67 raeburn 4002: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4003: $form_end
1.458 raeburn 4004: <br />
1.484.2.29 raeburn 4005: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 4006: $form_param
1.478 raeburn 4007: $form_common
1.484.2.67 raeburn 4008: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4009: $form_end
4010: </td>
1.478 raeburn 4011: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4012: $rand_order_text</td>
1.329 droeschl 4013: ENDPARMS
4014: }
1.379 bisitz 4015: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4016: return $line;
4017: }
4018:
1.484.2.30 raeburn 4019: sub action_restrictions {
4020: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4021: my %denied = (
4022: cut => 0,
4023: copy => 0,
4024: remove => 0,
4025: );
4026: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4027: # no copy for published maps
4028: $denied{'copy'} = 1;
4029: } elsif ($url=~m{^/res/lib/templates/}) {
4030: $denied{'copy'} = 1;
4031: $denied{'cut'} = 1;
4032: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4033: if ($folderpath =~ /^default&[^\&]+$/) {
4034: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4035: $denied{'remove'} = 1;
4036: }
4037: $denied{'cut'} = 1;
4038: $denied{'copy'} = 1;
4039: }
4040: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4041: my $group = $1;
4042: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4043: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4044: $denied{'remove'} = 1;
4045: }
4046: }
4047: $denied{'cut'} = 1;
4048: $denied{'copy'} = 1;
4049: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4050: my $group = $1;
4051: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4052: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4053: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4054: if (keys(%groupsettings) > 0) {
4055: $denied{'remove'} = 1;
4056: }
4057: $denied{'cut'} = 1;
4058: $denied{'copy'} = 1;
4059: }
4060: }
4061: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4062: my $group = $1;
4063: if ($url =~ /group_boards_\Q$group\E/) {
4064: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4065: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4066: if (keys(%groupsettings) > 0) {
4067: if (ref($groupsettings{'functions'}) eq 'HASH') {
4068: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4069: $denied{'remove'} = 1;
4070: }
4071: }
4072: }
4073: $denied{'cut'} = 1;
4074: $denied{'copy'} = 1;
4075: }
4076: }
4077: }
4078: return %denied;
4079: }
4080:
1.484.2.26 raeburn 4081: sub new_timebased_suffix {
1.484.2.30 raeburn 4082: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 4083: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 4084: if ($type eq 'paste') {
4085: $prefix = $type;
4086: $namespace = 'courseeditor';
1.484.2.56 raeburn 4087: $idtype = 'addcode';
1.484.2.30 raeburn 4088: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4089: $prefix = 'docs';
4090: if ($area eq 'supplemental') {
4091: $prefix = 'supp';
4092: }
4093: $prefix .= $container;
4094: $namespace = 'uploadedmaps';
4095: } else {
4096: $prefix = $type;
4097: $namespace = 'templated';
1.484.2.15 raeburn 4098: }
4099: my ($suffix,$freedlock,$error) =
1.484.2.56 raeburn 4100: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.484.2.15 raeburn 4101: if (!$suffix) {
1.484.2.30 raeburn 4102: if ($type eq 'paste') {
4103: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4104: } elsif ($type eq 'map') {
1.484.2.26 raeburn 4105: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4106: } elsif ($type eq 'smppg') {
4107: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4108: } else {
1.484.2.42 raeburn 4109: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.484.2.26 raeburn 4110: }
1.484.2.15 raeburn 4111: if ($error) {
4112: $errtext .= '<br />'.$error;
4113: }
4114: }
4115: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 4116: $locknotfreed =
4117: '<div class="LC_error">'.
4118: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 4119: if ($type eq 'paste') {
1.484.2.57 raeburn 4120: if ($freedlock eq 'nolock') {
4121: $locknotfreed =
4122: '<div class="LC_error">'.
4123: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4124:
1.484.2.60 raeburn 4125: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.484.2.57 raeburn 4126: } else {
4127: $locknotfreed .=
4128: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4129: }
1.484.2.30 raeburn 4130: } elsif ($type eq 'map') {
1.484.2.57 raeburn 4131: $locknotfreed .=
4132: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.484.2.26 raeburn 4133: } elsif ($type eq 'smppg') {
4134: $locknotfreed .=
4135: &mt('This will prevent creation of additional simple pages in this course.');
4136: } else {
4137: $locknotfreed .=
1.484.2.42 raeburn 4138: &mt('This will prevent creation of additional discussion boards in this course.');
1.484.2.26 raeburn 4139: }
1.484.2.30 raeburn 4140: unless ($type eq 'paste') {
4141: $locknotfreed .=
1.484.2.38 raeburn 4142: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4143: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.484.2.30 raeburn 4144: }
4145: $locknotfreed .= '</div>';
1.484.2.15 raeburn 4146: }
4147: return ($suffix,$errtext,$locknotfreed);
4148: }
4149:
1.329 droeschl 4150: =pod
4151:
4152: =item tiehash()
4153:
4154: tie the hash
4155:
4156: =cut
4157:
4158: sub tiehash {
4159: my ($mode)=@_;
4160: $hashtied=0;
4161: if ($env{'request.course.fn'}) {
4162: if ($mode eq 'write') {
4163: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4164: &GDBM_WRCREAT(),0640)) {
4165: $hashtied=2;
4166: }
4167: } else {
4168: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4169: &GDBM_READER(),0640)) {
4170: $hashtied=1;
4171: }
4172: }
1.364 bisitz 4173: }
1.329 droeschl 4174: }
4175:
4176: sub untiehash {
4177: if ($hashtied) { untie %hash; }
4178: $hashtied=0;
4179: return OK;
4180: }
4181:
4182:
4183:
4184:
4185: sub checkonthis {
4186: my ($r,$url,$level,$title)=@_;
4187: $url=&unescape($url);
4188: $alreadyseen{$url}=1;
4189: $r->rflush();
4190: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4191: $r->print("\n<br />");
4192: if ($level==0) {
4193: $r->print("<br />");
4194: }
4195: for (my $i=0;$i<=$level*5;$i++) {
4196: $r->print(' ');
4197: }
4198: $r->print('<a href="'.$url.'" target="cat">'.
4199: ($title?$title:$url).'</a> ');
4200: if ($url=~/^\/res\//) {
4201: my $result=&Apache::lonnet::repcopy(
4202: &Apache::lonnet::filelocation('',$url));
4203: if ($result eq 'ok') {
4204: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4205: $r->rflush();
4206: &Apache::lonnet::countacc($url);
4207: $url=~/\.(\w+)$/;
4208: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4209: $r->print('<br />');
4210: $r->rflush();
4211: for (my $i=0;$i<=$level*5;$i++) {
4212: $r->print(' ');
4213: }
4214: $r->print('- '.&mt('Rendering:').' ');
4215: my ($errorcount,$warningcount)=split(/:/,
4216: &Apache::lonnet::ssi_body($url,
4217: ('grade_target'=>'web',
4218: 'return_only_error_and_warning_counts' => 1)));
4219: if (($errorcount) ||
4220: ($warningcount)) {
4221: if ($errorcount) {
1.369 bisitz 4222: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4223: &mt('[quant,_1,error]',$errorcount).'</span>');
4224: }
4225: if ($warningcount) {
4226: $r->print('<span class="LC_warning">'.
4227: &mt('[quant,_1,warning]',$warningcount).'</span>');
4228: }
4229: } else {
4230: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4231: }
4232: $r->rflush();
4233: }
4234: my $dependencies=
4235: &Apache::lonnet::metadata($url,'dependencies');
4236: foreach my $dep (split(/\,/,$dependencies)) {
4237: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4238: &checkonthis($r,$dep,$level+1);
4239: }
4240: }
4241: } elsif ($result eq 'unavailable') {
4242: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4243: } elsif ($result eq 'not_found') {
4244: unless ($url=~/\$/) {
1.484.2.19 raeburn 4245: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4246: } else {
1.366 bisitz 4247: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4248: }
4249: } else {
4250: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4251: }
4252: }
4253: }
4254: }
4255:
4256:
4257:
4258: =pod
4259:
4260: =item list_symbs()
4261:
1.484.2.3 raeburn 4262: List Content Identifiers
1.329 droeschl 4263:
4264: =cut
4265:
4266: sub list_symbs {
4267: my ($r) = @_;
4268:
1.408 raeburn 4269: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4270: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4271: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4272: $r->print(&startContentScreen('tools'));
1.329 droeschl 4273: my $navmap = Apache::lonnavmaps::navmap->new();
4274: if (!defined($navmap)) {
4275: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4276: '<div class="LC_error">'.
4277: &mt('Unable to retrieve information about course contents').
4278: '</div>');
1.408 raeburn 4279: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4280: } else {
1.484 raeburn 4281: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4282: &Apache::loncommon::start_data_table().
4283: &Apache::loncommon::start_data_table_header_row().
4284: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4285: &Apache::loncommon::end_data_table_header_row()."\n");
4286: my $count;
1.329 droeschl 4287: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4288: $r->print(&Apache::loncommon::start_data_table_row().
4289: '<td>'.$res->compTitle().'</td>'.
4290: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 4291: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4292: $count ++;
4293: }
4294: if (!$count) {
4295: $r->print(&Apache::loncommon::start_data_table_row().
4296: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4297: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4298: }
1.484 raeburn 4299: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4300: }
1.484.2.19 raeburn 4301: $r->print(&endContentScreen());
1.329 droeschl 4302: }
4303:
4304:
4305: sub verifycontent {
4306: my ($r) = @_;
1.408 raeburn 4307: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 4308: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4309: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4310: $r->print(&startContentScreen('tools'));
4311: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4312: $hashtied=0;
4313: undef %alreadyseen;
4314: %alreadyseen=();
4315: &tiehash();
1.484 raeburn 4316:
1.329 droeschl 4317: foreach my $key (keys(%hash)) {
4318: if ($hash{$key}=~/\.(page|sequence)$/) {
4319: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4320: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4321: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4322: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4323: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4324: }
4325: }
4326: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4327: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4328: }
4329: }
4330: &untiehash();
1.442 www 4331: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 4332: $r->print(&endContentScreen());
1.329 droeschl 4333: }
4334:
4335:
4336: sub devalidateversioncache {
4337: my $src=shift;
4338: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4339: &Apache::lonnet::clutter($src));
4340: }
4341:
4342: sub checkversions {
1.484.2.67 raeburn 4343: my ($r,$canedit) = @_;
1.408 raeburn 4344: my $crstype = &Apache::loncommon::course_type();
1.484.2.44 raeburn 4345: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4346: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4347: $r->print(&startContentScreen('tools'));
1.442 www 4348:
1.329 droeschl 4349: my $header='';
4350: my $startsel='';
4351: my $monthsel='';
4352: my $weeksel='';
4353: my $daysel='';
4354: my $allsel='';
4355: my %changes=();
4356: my $starttime=0;
4357: my $haschanged=0;
4358: my %setversions=&Apache::lonnet::dump('resourceversions',
4359: $env{'course.'.$env{'request.course.id'}.'.domain'},
4360: $env{'course.'.$env{'request.course.id'}.'.num'});
4361:
4362: $hashtied=0;
4363: &tiehash();
1.484.2.67 raeburn 4364: if ($canedit) {
4365: my %newsetversions=();
4366: if ($env{'form.setmostrecent'}) {
4367: $haschanged=1;
4368: foreach my $key (keys(%hash)) {
4369: if ($key=~/^ids\_(\/res\/.+)$/) {
4370: $newsetversions{$1}='mostrecent';
4371: &devalidateversioncache($1);
4372: }
1.329 droeschl 4373: }
1.484.2.67 raeburn 4374: } elsif ($env{'form.setcurrent'}) {
4375: $haschanged=1;
4376: foreach my $key (keys(%hash)) {
4377: if ($key=~/^ids\_(\/res\/.+)$/) {
4378: my $getvers=&Apache::lonnet::getversion($1);
4379: if ($getvers>0) {
4380: $newsetversions{$1}=$getvers;
4381: &devalidateversioncache($1);
4382: }
4383: }
1.329 droeschl 4384: }
1.484.2.67 raeburn 4385: } elsif ($env{'form.setversions'}) {
4386: $haschanged=1;
4387: foreach my $key (keys(%env)) {
4388: if ($key=~/^form\.set_version_(.+)$/) {
4389: my $src=$1;
4390: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4391: $newsetversions{$src}=$env{$key};
4392: &devalidateversioncache($src);
4393: }
4394: }
1.329 droeschl 4395: }
1.484.2.67 raeburn 4396: }
4397: if ($haschanged) {
4398: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4399: $env{'course.'.$env{'request.course.id'}.'.domain'},
4400: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4401: $r->print(&Apache::loncommon::confirmwrapper(
4402: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4403: } else {
4404: $r->print(&Apache::loncommon::confirmwrapper(
4405: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
4406: }
4407: &mark_hash_old();
4408: }
4409: &changewarning($r,'');
1.329 droeschl 4410: }
4411: if ($env{'form.timerange'} eq 'all') {
4412: # show all documents
1.484.2.34 raeburn 4413: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 4414: $allsel=' selected="selected"';
1.329 droeschl 4415: foreach my $key (keys(%hash)) {
4416: if ($key=~/^ids\_(\/res\/.+)$/) {
4417: my $src=$1;
4418: $changes{$src}=1;
4419: }
4420: }
4421: } else {
4422: # show documents which changed
4423: %changes=&Apache::lonnet::dump
4424: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4425: $env{'course.'.$env{'request.course.id'}.'.num'});
4426: my $firstkey=(keys(%changes))[0];
4427: unless ($firstkey=~/^error\:/) {
4428: unless ($env{'form.timerange'}) {
4429: $env{'form.timerange'}=604800;
4430: }
4431: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4432: .&mt('seconds');
4433: if ($env{'form.timerange'}==-1) {
4434: $seltext='since start of course';
1.484.2.19 raeburn 4435: $startsel=' selected="selected"';
1.329 droeschl 4436: $env{'form.timerange'}=time;
4437: }
4438: $starttime=time-$env{'form.timerange'};
4439: if ($env{'form.timerange'}==2592000) {
4440: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4441: $monthsel=' selected="selected"';
1.329 droeschl 4442: } elsif ($env{'form.timerange'}==604800) {
4443: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4444: $weeksel=' selected="selected"';
1.329 droeschl 4445: } elsif ($env{'form.timerange'}==86400) {
4446: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 4447: $daysel=' selected="selected"';
1.329 droeschl 4448: }
4449: $header=&mt('Content changed').' '.$seltext;
4450: } else {
4451: $header=&mt('No content modifications yet.');
4452: }
4453: }
4454: %setversions=&Apache::lonnet::dump('resourceversions',
4455: $env{'course.'.$env{'request.course.id'}.'.domain'},
4456: $env{'course.'.$env{'request.course.id'}.'.num'});
4457: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4458: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4459: 'lm' => 'Version changes since last Month',
4460: 'lw' => 'Version changes since last Week',
4461: 'sy' => 'Version changes since Yesterday',
4462: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4463: 'cd' => 'Change display',
1.329 droeschl 4464: 'sd' => 'Display',
4465: 'fi' => 'File',
4466: 'md' => 'Modification Date',
4467: 'mr' => 'Most recently published Version',
1.408 raeburn 4468: 've' => 'Version used in '.$crstype,
4469: 'vu' => 'Set Version to be used in '.$crstype,
4470: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4471: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4472: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4473: 'di' => 'Differences',
1.484 raeburn 4474: 'save' => 'Save changes',
4475: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4476: 'act' => 'Actions');
1.484.2.67 raeburn 4477: my ($disabled,$readonly);
4478: unless ($canedit) {
4479: $disabled = 'disabled="disabled"';
4480: $readonly = 1;
4481: }
1.329 droeschl 4482: $r->print(<<ENDHEADERS);
1.484 raeburn 4483: <h4 class="LC_info">$header</h4>
1.329 droeschl 4484: <form action="/adm/coursedocs" method="post">
4485: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4486: <div class="LC_left_float">
1.479 golterma 4487: <fieldset>
1.484 raeburn 4488: <legend>$lt{'cd'}</legend>
1.329 droeschl 4489: <select name="timerange">
1.484.2.19 raeburn 4490: <option value='all'$allsel>$lt{'al'}</option>
4491: <option value="-1"$startsel>$lt{'st'}</option>
4492: <option value="2592000"$monthsel>$lt{'lm'}</option>
4493: <option value="604800"$weeksel>$lt{'lw'}</option>
4494: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4495: </select>
4496: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4497: </fieldset>
4498: </div>
4499: <div class="LC_left_float">
4500: <fieldset>
4501: <legend>$lt{'act'}</legend>
1.484.2.67 raeburn 4502: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4503: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4504: </fieldset>
4505: </div>
4506: <br clear="all" />
4507: <hr />
4508: <h4>$lt{'vers'}</h4>
1.329 droeschl 4509: ENDHEADERS
1.479 golterma 4510: #number of columns for version history
1.484.2.44 raeburn 4511: my %changedbytime;
4512: foreach my $key (keys(%changes)) {
4513: #excludes not versionable problems from resource version history:
4514: next if ($key =~ /^\/res\/lib\/templates/);
4515: my $chg;
4516: if ($env{'form.timerange'} eq 'all') {
4517: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4518: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4519: } else {
4520: $chg = $changes{$key};
4521: next if ($chg < $starttime);
4522: }
4523: push(@{$changedbytime{$chg}},$key);
4524: }
4525: if (keys(%changedbytime) == 0) {
4526: &untiehash();
4527: $r->print(&mt('No content changes in imported content in specified time frame').
4528: &endContentScreen());
4529: return;
4530: }
1.479 golterma 4531: $r->print(
1.484.2.67 raeburn 4532: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4533: &Apache::loncommon::start_data_table().
4534: &Apache::loncommon::start_data_table_header_row().
4535: '<th>'.&mt('Resources').'</th>'.
4536: "<th>$lt{'mr'}</th>".
4537: "<th>$lt{'ve'}</th>".
4538: "<th>$lt{'vu'}</th>".
4539: '<th>'.&mt('History').'</th>'.
4540: &Apache::loncommon::end_data_table_header_row()
4541: );
1.484.2.44 raeburn 4542: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4543: foreach my $key (sort(@{$changedbytime{$chg}})) {
4544: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4545: my $currentversion=&Apache::lonnet::getversion($key);
4546: if ($currentversion<0) {
4547: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4548: }
4549: my $linkurl=&Apache::lonnet::clutter($key);
4550: $r->print(
4551: &Apache::loncommon::start_data_table_row().
4552: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
4553: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
4554: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
4555: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
4556: '<td align="right">'
4557: );
4558: # Used in course
4559: my $usedversion=$hash{'version_'.$linkurl};
4560: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.484.2.19 raeburn 4561: if ($usedversion != $currentversion) {
1.479 golterma 4562: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 4563: } else {
1.479 golterma 4564: $r->print($usedversion);
4565: }
1.329 droeschl 4566: } else {
1.484.2.19 raeburn 4567: $r->print($currentversion);
1.329 droeschl 4568: }
1.484.2.44 raeburn 4569: $r->print('</td><td title="'.$lt{'vu'}.'">');
4570: # Set version
4571: $r->print(&Apache::loncommon::select_form(
4572: $setversions{$linkurl},
4573: 'set_version_'.$linkurl,
4574: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4575: '' => '',
4576: 'mostrecent' => &mt('most recent'),
1.484.2.67 raeburn 4577: map {$_,$_} (1..$currentversion)},'',$readonly));
1.484.2.44 raeburn 4578: my $lastold=1;
4579: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4580: my $url=$root.'.'.$prevvers.'.'.$extension;
4581: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4582: $lastold=$prevvers;
4583: }
4584: }
4585: $r->print('</td>');
4586: # List all available versions
4587: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4588: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4589: my $url=$root.'.'.$prevvers.'.'.$extension;
1.484.2.19 raeburn 4590: $r->print(
1.484.2.44 raeburn 4591: '<span class="LC_nobreak">'
4592: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4593: .&mt('Version [_1]',$prevvers).'</a>'
4594: .' ('.&Apache::lonlocal::locallocaltime(
4595: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4596: .')');
4597: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4598: $r->print(
4599: ' <a href="/adm/diff?filename='.
4600: &Apache::lonnet::clutter($root.'.'.$extension).
4601: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4602: '" target="diffs">'.&mt('Diffs').'</a>');
4603: }
4604: $r->print('</span><br />');
1.329 droeschl 4605: }
1.484.2.44 raeburn 4606: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.484.2.19 raeburn 4607: }
1.329 droeschl 4608: }
1.484.2.19 raeburn 4609: $r->print(
4610: &Apache::loncommon::end_data_table().
1.484.2.67 raeburn 4611: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.484.2.19 raeburn 4612: '</form>'
4613: );
1.329 droeschl 4614:
4615: &untiehash();
1.484.2.19 raeburn 4616: $r->print(&endContentScreen());
1.484.2.44 raeburn 4617: return;
1.329 droeschl 4618: }
4619:
4620: sub mark_hash_old {
4621: my $retie_hash=0;
4622: if ($hashtied) {
4623: $retie_hash=1;
4624: &untiehash();
4625: }
4626: &tiehash('write');
4627: $hash{'old'}=1;
4628: &untiehash();
4629: if ($retie_hash) { &tiehash(); }
4630: }
4631:
4632: sub is_hash_old {
4633: my $untie_hash=0;
4634: if (!$hashtied) {
4635: $untie_hash=1;
4636: &tiehash();
4637: }
4638: my $return=$hash{'old'};
4639: if ($untie_hash) { &untiehash(); }
4640: return $return;
4641: }
4642:
4643: sub changewarning {
4644: my ($r,$postexec,$message,$url)=@_;
4645: if (!&is_hash_old()) { return; }
4646: my $pathvar='folderpath';
4647: my $path=&escape($env{'form.folderpath'});
4648: if (!defined($url)) {
4649: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4650: }
4651: my $course_type = &Apache::loncommon::course_type();
4652: if (!defined($message)) {
4653: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4654: }
4655: $r->print("\n\n".
1.372 bisitz 4656: '<script type="text/javascript">'."\n".
4657: '// <![CDATA['."\n".
4658: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4659: '// ]]>'."\n".
1.369 bisitz 4660: '</script>'."\n".
1.375 tempelho 4661: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4662: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4663: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4664: &mt($message,' <input type="hidden" name="'.
4665: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4666: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4667: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4668: }
4669:
4670:
4671: sub init_breadcrumbs {
1.484.2.44 raeburn 4672: my ($form,$text,$help)=@_;
1.329 droeschl 4673: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4674: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4675: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4676: faq=>273,
4677: bug=>'Instructor Interface',
1.484.2.44 raeburn 4678: help => $help});
1.329 droeschl 4679: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4680: text=>$text,
4681: faq=>273,
4682: bug=>'Instructor Interface'});
4683: }
4684:
1.441 www 4685: # subroutine to list form elements
4686: sub create_list_elements {
4687: my @formarr = @_;
4688: my $list = '';
1.484.2.12 raeburn 4689: foreach my $button (@formarr){
4690: foreach my $picture (keys(%{$button})) {
4691: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4692: }
4693: }
4694: return $list;
4695: }
1.329 droeschl 4696:
1.441 www 4697: # subroutine to create ul from list elements
4698: sub create_form_ul {
4699: my $list = shift;
4700: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4701: return $ul;
4702: }
1.329 droeschl 4703:
1.442 www 4704: #
4705: # Start tabs
4706: #
4707:
4708: sub startContentScreen {
1.484 raeburn 4709: my ($mode) = @_;
4710: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4711: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4712: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4713: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4714: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4715: } else {
1.484.2.34 raeburn 4716: $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 4717: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4718: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4719: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4720: }
4721: $output .= "\n".'</ul>'."\n";
4722: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4723: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4724: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4725: return $output;
1.442 www 4726: }
4727:
4728: #
4729: # End tabs
4730: #
4731:
4732: sub endContentScreen {
1.484 raeburn 4733: return '</div></div></div>';
1.442 www 4734: }
1.329 droeschl 4735:
1.446 www 4736: sub supplemental_base {
1.484.2.33 raeburn 4737: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4738: }
4739:
1.329 droeschl 4740: sub handler {
4741: my $r = shift;
4742: &Apache::loncommon::content_type($r,'text/html');
4743: $r->send_http_header;
4744: return OK if $r->header_only;
1.484 raeburn 4745:
4746: # get course data
1.408 raeburn 4747: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4748: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4749: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4750:
4751: # graphics settings
4752: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4753:
1.443 www 4754: #
1.329 droeschl 4755: # --------------------------------------------- Initialize help topics for this
4756: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4757: 'Adding_External_Resource','Navigate_Content',
4758: 'Adding_Folders','Docs_Overview', 'Load_Map',
4759: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4760: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.44 raeburn 4761: 'Uploading_From_Harddrive','Course_Roster','Web_Page',
4762: 'Dropbox','Simple_Problem') {
1.329 droeschl 4763: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4764: }
4765: # Composite help files
4766: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4767: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4768: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4769: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4770: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4771: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4772: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4773: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4774: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4775: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4776:
1.484.2.67 raeburn 4777: my ($allowed,$canedit,$canview,$disabled);
1.472 raeburn 4778: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4779: unless ($r->uri eq '/adm/supplemental') {
4780: # does this user have privileges to modify content.
1.484.2.67 raeburn 4781: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
4782: $allowed = 1;
4783: $canedit = 1;
4784: $canview = 1;
4785: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
4786: $allowed = 1;
4787: $canview = 1;
4788: }
4789: }
4790: unless ($canedit) {
4791: $disabled = ' disabled="disabled"';
1.472 raeburn 4792: }
1.484.2.53 raeburn 4793: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
4794: if ($allowed && $env{'form.verify'}) {
1.484.2.44 raeburn 4795: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.329 droeschl 4796: &verifycontent($r);
4797: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4798: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4799: &list_symbs($r);
4800: } elsif ($allowed && $env{'form.docslog'}) {
4801: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4802: my $folder = $env{'form.folder'};
4803: if ($folder eq '') {
4804: $folder='default';
4805: }
1.484.2.67 raeburn 4806: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 4807: } elsif ($allowed && $env{'form.versions'}) {
1.484.2.44 raeburn 4808: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.484.2.67 raeburn 4809: &checkversions($r,$canedit);
4810: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.484.2.43 raeburn 4811: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4812: &dumpcourse($r);
4813: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4814: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4815: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4816: } else {
1.445 www 4817: #
4818: # Done catching special calls
1.484 raeburn 4819: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4820: # Get the parameters that may be needed
4821: #
4822: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4823: ['folderpath',
4824: 'forcesupplement','forcestandard',
4825: 'tools','symb','command','supppath']);
1.445 www 4826:
4827: # standard=1: this is a "new-style" course with an uploaded map as top level
4828: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4829:
4830: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4831:
1.484 raeburn 4832: # Decide whether this should display supplemental or main content or utilities
1.445 www 4833: # supplementalflag=1: show supplemental documents
4834: # supplementalflag=0: show standard documents
1.484 raeburn 4835: # toolsflag=1: show utilities
1.445 www 4836:
1.484.2.39 raeburn 4837: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4838: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4839: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4840: $supplementalflag=0;
4841: }
4842: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4843: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4844: unless ($allowed) { $supplementalflag=1; }
4845: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4846: my $toolsflag=0;
4847: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4848:
1.329 droeschl 4849: my $script='';
4850: my $showdoc=0;
1.457 raeburn 4851: my $addentries = {};
1.475 raeburn 4852: my $container;
1.329 droeschl 4853: my $containertag;
1.484.2.17 raeburn 4854: my $pathitem;
1.484.2.67 raeburn 4855: my $hiddentop;
4856: my $navmap;
4857: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 4858:
1.464 www 4859: # Do we directly jump somewhere?
1.484.2.21 raeburn 4860: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4861: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 4862: $env{'form.folderpath'}=
1.484.2.67 raeburn 4863: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.484.2.21 raeburn 4864: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4865: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4866: } elsif ($env{'form.supppath'} ne '') {
4867: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 4868: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4869: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4870: }
1.472 raeburn 4871: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.67 raeburn 4872: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.484.2.21 raeburn 4873: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4874: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.67 raeburn 4875: $env{'form.folderpath'} = &supplemental_base();
1.484.2.21 raeburn 4876: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4877: } elsif ($env{'form.command'} eq 'contents') {
4878: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4879: } elsif ($env{'form.command'} eq 'home') {
4880: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4881: }
4882:
1.484.2.23 raeburn 4883:
1.445 www 4884: # Where do we store these for when we come back?
4885: my $stored_folderpath='docs_folderpath';
4886: if ($supplementalflag) {
4887: $stored_folderpath='docs_sup_folderpath';
4888: }
1.464 www 4889:
1.484.2.19 raeburn 4890: # No folderpath, and in edit mode, see if we have something stored
4891: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4892: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 4893: {'folderpath' => 'scalar'});
1.484.2.67 raeburn 4894:
4895: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4896: if ($supplementalflag) {
4897: undef($env{'form.folderpath'}) if ($1 eq 'default');
4898: } else {
4899: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
4900: }
4901: } else {
1.484.2.19 raeburn 4902: undef($env{'form.folderpath'});
4903: }
1.329 droeschl 4904: }
1.446 www 4905:
4906: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4907: if (!$allowed) {
1.446 www 4908: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4909: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4910: }
4911: }
1.446 www 4912: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4913: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4914: $env{'form.folderpath'} = &supplemental_base()
4915: .'&'.
1.329 droeschl 4916: $env{'form.folderpath'};
4917: }
1.484.2.67 raeburn 4918: # If allowed and user's role is not advanced check folderpath is not hidden
4919: if (($allowed) && (!$env{'request.role.adv'}) &&
4920: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
4921: my $folderurl;
4922: my @pathitems = split(/\&/,$env{'form.folderpath'});
4923: my $folder = $pathitems[-2];
4924: if ($folder eq '') {
4925: undef($env{'form.folderpath'});
4926: } else {
4927: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
4928: if ((split(/\:/,$pathitems[-1]))[4]) {
4929: $folderurl .= '.page';
4930: } else {
4931: $folderurl .= '.sequence';
4932: }
4933: unless (ref($navmap)) {
4934: $navmap = Apache::lonnavmaps::navmap->new();
4935: }
4936: if (ref($navmap)) {
4937: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4938: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
4939: unless (@resources) {
4940: undef($env{'form.folderpath'});
4941: }
4942: }
4943: }
4944: }
4945: }
4946:
4947:
1.446 www 4948: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 4949: unless ($env{'form.folderpath'}) {
1.446 www 4950: if ($supplementalflag) {
4951: $env{'form.folderpath'}=&supplemental_base();
1.484.2.67 raeburn 4952: } elsif ($allowed) {
4953: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 4954: }
1.472 raeburn 4955: }
1.446 www 4956:
1.445 www 4957: # Store this
1.484 raeburn 4958: unless ($toolsflag) {
1.484.2.67 raeburn 4959: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.484.2.19 raeburn 4960: &Apache::loncommon::store_course_settings($stored_folderpath,
4961: {'folderpath' => 'scalar'});
4962: }
4963: my $folderpath;
1.484 raeburn 4964: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 4965: $folderpath = $env{'form.folderpath'};
4966: my (@folders)=split('&',$env{'form.folderpath'});
4967: $env{'form.foldername'}=&unescape(pop(@folders));
4968: if ($env{'form.foldername'} =~ /\:1$/) {
4969: $container = 'page';
4970: } else {
4971: $container = 'sequence';
4972: }
4973: $env{'form.folder'}=pop(@folders);
1.484 raeburn 4974: } else {
1.484.2.19 raeburn 4975: if ($env{'form.folder'} eq '' ||
4976: $env{'form.folder'} eq 'supplemental') {
1.484.2.67 raeburn 4977: if ($env{'form.folder'} eq 'supplemental') {
4978: $folderpath=&supplemental_base();
4979: } elsif (!$hiddentop) {
4980: $folderpath='default&'.
4981: &escape(&mt('Main Content').':::::');
4982: }
1.484 raeburn 4983: }
4984: }
1.484.2.19 raeburn 4985: $containertag = '<input type="hidden" name="folderpath" value="" />';
4986: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 4987: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4988: $showdoc='/'.$1;
4989: }
4990: if ($showdoc) { # got called in sequence from course
4991: $allowed=0;
4992: } else {
1.484.2.67 raeburn 4993: if ($canedit) {
1.484 raeburn 4994: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4995: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 4996: }
4997: }
1.329 droeschl 4998: }
4999:
1.344 bisitz 5000: # get personal data
1.329 droeschl 5001: my $uname=$env{'user.name'};
5002: my $udom=$env{'user.domain'};
5003: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5004:
5005: if ($allowed) {
1.484 raeburn 5006: if ($toolsflag) {
5007: $script .= &inject_data_js();
5008: my ($home,$other,%outhash)=&authorhosts();
5009: if (!$home && $other) {
5010: my @hosts;
5011: foreach my $aurole (keys(%outhash)) {
5012: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5013: push(@hosts,$outhash{$aurole});
5014: }
5015: }
5016: $script .= &dump_switchserver_js(@hosts);
5017: }
1.458 raeburn 5018: } else {
1.484.2.43 raeburn 5019: my $tid = 1;
1.484 raeburn 5020: my @tabids;
5021: if ($supplementalflag) {
5022: @tabids = ('002','ee2','ff2');
1.484.2.43 raeburn 5023: $tid = 2;
1.484 raeburn 5024: } else {
5025: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 5026: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5027: unshift(@tabids,'001');
5028: push(@tabids,('dd1','ee1'));
5029: }
1.458 raeburn 5030: }
1.484 raeburn 5031: my $tabidstr = join("','",@tabids);
1.484.2.68 raeburn 5032: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
1.484.2.67 raeburn 5033: $canedit,\$navmap).
1.484 raeburn 5034: &history_tab_js().
5035: &inject_data_js().
1.484.2.43 raeburn 5036: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.484.2.19 raeburn 5037: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 5038: $addentries = {
1.484.2.3 raeburn 5039: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5040: };
1.458 raeburn 5041: }
1.484.2.30 raeburn 5042: $script .= &paste_popup_js();
1.484.2.12 raeburn 5043: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5044: &mt('Switch server?');
1.484.2.19 raeburn 5045:
5046:
1.329 droeschl 5047: }
5048: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5049: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5050: .'// <![CDATA['."\n"
5051: .$script."\n"
5052: .'// ]]>'."\n"
5053: .'</script>'."\n";
1.385 bisitz 5054:
5055: # Breadcrumbs
5056: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 5057:
5058: if ($showdoc) {
5059: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5060: {'force_register' => $showdoc,}));
1.484.2.44 raeburn 5061: } elsif ($toolsflag) {
1.484.2.67 raeburn 5062: my ($breadtext,$breadtitle);
5063: $breadtext = "$crstype Editor";
5064: if ($canedit) {
5065: $breadtitle = 'Editing '.$crstype.' Contents';
5066: } else {
5067: $breadtext .= ' (View-only mode)';
5068: $breadtitle = 'Viewing '.$crstype.' Contents';
5069: }
1.484.2.44 raeburn 5070: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5071: href=>"/adm/coursedocs",text=>$breadtext});
1.484.2.44 raeburn 5072: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5073: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5074: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5075: $breadtitle)
1.484.2.44 raeburn 5076: );
1.484.2.19 raeburn 5077: } elsif ($r->uri eq '/adm/supplemental') {
5078: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5079: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5080: {'bread_crumbs' => $brcrum,}));
5081: } else {
1.484.2.67 raeburn 5082: my ($breadtext,$breadtitle,$helpitem);
5083: $breadtext = "$crstype Editor";
5084: if ($canedit) {
5085: $breadtitle = 'Editing '.$crstype.' Contents';
5086: $helpitem = 'Docs_Adding_Course_Doc';
5087: } else {
5088: $breadtext .= ' (View-only mode)';
5089: $breadtitle = 'Viewing '.$crstype.' Contents';
5090: $helpitem = 'Docs_Viewing_Course_Doc';
5091: }
1.392 raeburn 5092: &Apache::lonhtmlcommon::add_breadcrumb({
1.484.2.67 raeburn 5093: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5094: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 5095: {'add_entries' => $addentries}
5096: )
1.392 raeburn 5097: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5098: .&Apache::lonhtmlcommon::breadcrumbs(
1.484.2.67 raeburn 5099: $breadtitle,
5100: $helpitem)
1.392 raeburn 5101: );
5102: }
1.364 bisitz 5103:
1.329 droeschl 5104: my %allfiles = ();
5105: my %codebase = ();
1.440 raeburn 5106: my ($upload_result,$upload_output,$uploadphase);
1.484.2.67 raeburn 5107: if ($canedit) {
1.329 droeschl 5108: if (($env{'form.uploaddoc.filename'}) &&
5109: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5110: my $context = $1;
5111: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5112: undef($hadchanges);
1.440 raeburn 5113: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36 raeburn 5114: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 5115: if ($hadchanges) {
5116: &mark_hash_old();
5117: }
1.440 raeburn 5118: $r->print($upload_output);
5119: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5120: # Process file upload - phase two - upload embedded objects
5121: $uploadphase = 'check_embedded';
5122: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5123: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5124: $env{'form.newidx'});
5125: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5126: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5127: my ($destination,$dir_root) = &embedded_destination();
5128: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5129: my $actionurl = '/adm/coursedocs';
5130: my ($result,$flag) =
5131: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5132: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5133: $actionurl);
5134: $r->print($result.&return_to_editor());
5135: } elsif ($env{'form.phase'} eq 'check_embedded') {
5136: # Process file upload - phase three - modify references in HTML file
5137: $uploadphase = 'modified_orightml';
5138: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5139: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5140: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5141: my $result =
5142: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5143: $docuname,$docudom,undef,
5144: $dir_root);
5145: $r->print($result.&return_to_editor());
1.476 raeburn 5146: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5147: $uploadphase = 'decompress_phase_one';
5148: $r->print(&decompression_phase_one().
5149: &return_to_editor());
5150: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5151: $uploadphase = 'decompress_phase_two';
5152: $r->print(&decompression_phase_two().
5153: &return_to_editor());
1.329 droeschl 5154: }
5155: }
5156:
1.484 raeburn 5157: if ($allowed && $toolsflag) {
5158: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5159: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5160: $r->print(&endContentScreen());
5161: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5162: # -----------------------------------------------------------------------------
5163: my %lt=&Apache::lonlocal::texthash(
5164: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5165: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5166: 'upld' => 'Upload Content',
1.329 droeschl 5167: 'srch' => 'Search',
5168: 'impo' => 'Import',
1.484.2.19 raeburn 5169: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5170: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5171: 'selm' => 'Select Map',
5172: 'load' => 'Load Map',
5173: 'newf' => 'New Folder',
5174: 'newp' => 'New Composite Page',
5175: 'syll' => 'Syllabus',
1.425 raeburn 5176: 'navc' => 'Table of Contents',
1.343 biermanm 5177: 'sipa' => 'Simple Course Page',
1.329 droeschl 5178: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5179: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5180: 'drbx' => 'Drop Box',
1.451 www 5181: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5182: 'bull' => 'Discussion Board',
1.347 weissno 5183: 'mypi' => 'My Personal Information Page',
1.353 weissno 5184: 'grpo' => 'Group Portfolio',
1.329 droeschl 5185: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5186: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5187: 'imsf' => 'IMS Upload',
5188: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5189: 'cms' => 'Origin of IMS package',
5190: 'se' => 'Select',
1.484.2.19 raeburn 5191: 'file' => 'File',
1.329 droeschl 5192: 'title' => 'Title',
5193: 'comment' => 'Comment',
1.403 raeburn 5194: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5195: 'bb5' => 'Blackboard 5',
5196: 'bb6' => 'Blackboard 6',
5197: 'angel5' => 'ANGEL 5.5',
5198: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5199: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5200: );
1.329 droeschl 5201: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5202: # Calculate free quota space for a user or course.
5203: my $quotatype = 'unofficial';
5204: if ($crstype eq 'Community') {
5205: $quotatype = 'community';
5206: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5207: $quotatype = 'official';
5208: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5209: $quotatype = 'textbook';
5210: }
5211: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5212: 'course',$quotatype); # expressed in MB
5213: my $current_disk_usage = 0;
5214: foreach my $subdir ('docs','supplemental') {
5215: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5216: "userfiles/$subdir",1); # expressed in kB
5217: }
5218: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5219: my $usage = $current_disk_usage/1024; # in MB
5220: my $quota = $disk_quota;
5221: my $percent;
5222: if ($disk_quota == 0) {
5223: $percent = 100.0;
5224: } else {
1.484.2.69 raeburn 5225: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5226: }
5227: $usage = sprintf("%.2f",$usage);
5228: $quota = sprintf("%.2f",$quota);
5229: $percent = sprintf("%.0f",$percent);
5230: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5231: $percent.'%',$quota.' MB').'</p>';
5232:
1.329 droeschl 5233: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5234: $quotainfo
1.329 droeschl 5235: $lt{'file'}:<br />
1.484.2.67 raeburn 5236: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5237: FIUP
5238:
5239: my $checkbox=(<<CHBO);
5240: <!-- <label>$lt{'parse'}?
5241: <input type="checkbox" name="parserflag" />
5242: </label> -->
5243: <label>
1.484.2.67 raeburn 5244: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5245: </label>
5246: CHBO
1.484.2.12 raeburn 5247: my $imsfolder = $env{'form.folder'};
5248: if ($imsfolder eq '') {
1.484.2.19 raeburn 5249: $imsfolder = 'default';
1.484.2.12 raeburn 5250: }
5251: my $imspform=(<<IMSFORM);
5252: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5253: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5254: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5255: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5256: <legend>$lt{'imsf'}</legend>
5257: $fileupload
5258: <br />
5259: <p>
1.484.2.19 raeburn 5260: $lt{'cms'}:
1.484.2.67 raeburn 5261: <select name="source" $disabled>
1.484.2.12 raeburn 5262: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5263: <option value="bb5">$lt{'bb5'}</option>
5264: <option value="bb6">$lt{'bb6'}</option>
5265: <option value="angel5">$lt{'angel5'}</option>
5266: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5267: </select>
5268: <input type="hidden" name="folder" value="$imsfolder" />
5269: </p>
5270: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5271: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5272: </fieldset>
5273: </form>
5274: IMSFORM
5275:
1.484.2.19 raeburn 5276: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5277: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5278: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5279: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5280: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5281: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5282: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5283: $fileupload
5284: <br />
5285: $lt{'title'}:<br />
1.484.2.67 raeburn 5286: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5287: $pathitem
1.329 droeschl 5288: <input type="hidden" name="cmd" value="upload_default" />
5289: <br />
1.458 raeburn 5290: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5291: $checkbox
5292: </span>
1.484.2.12 raeburn 5293: <br clear="all" />
1.484.2.67 raeburn 5294: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5295: </fieldset>
5296: </form>
1.383 tempelho 5297: FUFORM
1.329 droeschl 5298:
1.484.2.67 raeburn 5299: my $mapimportjs;
5300: if ($canedit) {
5301: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5302: } else {
5303: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5304: }
1.484.2.19 raeburn 5305: my $importpubform=(<<SEDFFORM);
5306: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5307: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5308: <form action="/adm/coursedocs" method="post" name="mapimportform">
5309: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5310: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5311: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5312: $lt{'copm'}<br />
5313: <span class="LC_nobreak">
1.484.2.19 raeburn 5314: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5315: onfocus="this.blur();$mapimportjs" $disabled />
5316: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5317: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5318: </fieldset>
5319: </form>
5320:
1.383 tempelho 5321: SEDFFORM
1.484.2.67 raeburn 5322:
5323: my $fromstoredjs;
5324: if ($canedit) {
5325: $fromstoredjs = 'open_StoredLinks_Import()';
5326: } else {
5327: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5328: }
5329:
1.484.2.19 raeburn 5330: my @importpubforma = (
5331: { '<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 5332: { '<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 5333: { '<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 5334: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5335: );
5336: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5337: my $extresourcesform =
5338: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5339: $help{'Adding_External_Resource'},
5340: undef,undef,$disabled);
1.329 droeschl 5341: if ($allowed) {
1.484.2.7 raeburn 5342: my $folder = $env{'form.folder'};
5343: if ($folder eq '') {
5344: $folder='default';
5345: }
1.484.2.67 raeburn 5346: if ($canedit) {
5347: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5348: if ($output) {
5349: $r->print($output);
5350: }
1.484.2.30 raeburn 5351: }
1.337 ehlerst 5352: $r->print(<<HIDDENFORM);
5353: <form name="renameform" method="post" action="/adm/coursedocs">
5354: <input type="hidden" name="title" />
5355: <input type="hidden" name="cmd" />
5356: <input type="hidden" name="markcopy" />
5357: <input type="hidden" name="copyfolder" />
5358: $containertag
5359: </form>
1.484 raeburn 5360:
1.337 ehlerst 5361: HIDDENFORM
1.484.2.17 raeburn 5362: $r->print(&makesimpleeditform($pathitem)."\n".
5363: &makedocslogform($pathitem."\n".
1.484 raeburn 5364: '<input type="hidden" name="folder" value="'.
5365: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5366: }
1.442 www 5367:
5368: # Generate the tabs
1.484.2.19 raeburn 5369: my ($mode,$needs_end);
1.472 raeburn 5370: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5371: my @folders = split('&',$env{'form.folderpath'});
5372: unless (@folders > 2) {
5373: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5374: $needs_end = 1;
5375: }
1.472 raeburn 5376: } else {
1.484 raeburn 5377: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5378: $needs_end = 1;
1.472 raeburn 5379: }
1.443 www 5380:
1.442 www 5381: #
5382:
5383: my $savefolderpath;
5384:
1.395 raeburn 5385: if ($allowed) {
1.329 droeschl 5386: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5387: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5388: $folder='default';
1.356 tempelho 5389: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5390: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5391: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5392: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5393: }
5394: my $postexec='';
5395: if ($folder eq 'default') {
1.372 bisitz 5396: $r->print('<script type="text/javascript">'."\n"
5397: .'// <![CDATA['."\n"
5398: .'this.window.name="loncapaclient";'."\n"
5399: .'// ]]>'."\n"
5400: .'</script>'."\n"
1.369 bisitz 5401: );
1.329 droeschl 5402: } else {
5403: #$postexec='self.close();';
5404: }
1.484.2.15 raeburn 5405: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5406: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5407: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5408:
5409: my $newnavform=(<<NNFORM);
5410: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5411: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5412: $pathitem
1.329 droeschl 5413: <input type="hidden" name="importdetail"
5414: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5415: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5416: $help{'Navigate_Content'}
5417: </form>
5418: NNFORM
5419: my $newsmppageform=(<<NSPFORM);
5420: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5421: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5422: $pathitem
1.329 droeschl 5423: <input type="hidden" name="importdetail" value="" />
1.423 onken 5424: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5425: $help{'Simple Page'}
1.329 droeschl 5426: </form>
5427: NSPFORM
5428:
5429: my $newsmpproblemform=(<<NSPROBFORM);
5430: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5431: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5432: $pathitem
1.329 droeschl 5433: <input type="hidden" name="importdetail" value="" />
1.423 onken 5434: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5435: $help{'Simple_Problem'}
1.329 droeschl 5436: </form>
5437:
5438: NSPROBFORM
5439:
5440: my $newdropboxform=(<<NDBFORM);
5441: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5442: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5443: $pathitem
1.329 droeschl 5444: <input type="hidden" name="importdetail" value="" />
1.423 onken 5445: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5446: $help{'Dropbox'}
1.344 bisitz 5447: </form>
1.329 droeschl 5448: NDBFORM
5449:
5450: my $newexuploadform=(<<NEXUFORM);
5451: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5452: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5453: $pathitem
1.329 droeschl 5454: <input type="hidden" name="importdetail" value="" />
1.423 onken 5455: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5456: $help{'Score_Upload_Form'}
5457: </form>
5458: NEXUFORM
5459:
5460: my $newbulform=(<<NBFORM);
5461: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5462: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5463: $pathitem
1.329 droeschl 5464: <input type="hidden" name="importdetail" value="" />
1.423 onken 5465: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5466: $help{'Bulletin Board'}
5467: </form>
5468: NBFORM
5469:
5470: my $newaboutmeform=(<<NAMFORM);
5471: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5472: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5473: $pathitem
1.329 droeschl 5474: <input type="hidden" name="importdetail"
5475: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5476: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5477: $help{'My Personal Information Page'}
1.329 droeschl 5478: </form>
5479: NAMFORM
5480:
5481: my $newaboutsomeoneform=(<<NASOFORM);
5482: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5483: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5484: $pathitem
1.329 droeschl 5485: <input type="hidden" name="importdetail" value="" />
1.423 onken 5486: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5487: </form>
5488: NASOFORM
5489:
5490: my $newrosterform=(<<NROSTFORM);
5491: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5492: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5493: $pathitem
1.329 droeschl 5494: <input type="hidden" name="importdetail"
5495: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5496: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5497: $help{'Course_Roster'}
1.329 droeschl 5498: </form>
5499: NROSTFORM
5500:
1.484.2.27 raeburn 5501: my $newwebpage;
5502: if ($folder =~ /^default_?(\d*)$/) {
5503: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5504: if ($1) {
5505: $newwebpage .= $1;
5506: } else {
5507: $newwebpage .= 'default';
5508: }
5509: $newwebpage .= '/new.html';
5510: }
5511: my $newwebpageform =(<<NWEBFORM);
5512: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5513: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5514: $pathitem
5515: <input type="hidden" name="importdetail" value="$newwebpage" />
5516: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5517: $help{'Web_Page'}
1.484.2.27 raeburn 5518: </form>
5519: NWEBFORM
1.484.2.30 raeburn 5520:
1.484.2.27 raeburn 5521:
1.342 ehlerst 5522: my $specialdocumentsform;
1.383 tempelho 5523: my @specialdocumentsforma;
1.451 www 5524: my $gradingform;
5525: my @gradingforma;
5526: my $communityform;
5527: my @communityforma;
1.351 ehlerst 5528: my $newfolderform;
1.390 tempelho 5529: my $newfolderb;
1.342 ehlerst 5530:
1.451 www 5531: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5532:
1.329 droeschl 5533: my $newpageform=(<<NPFORM);
5534: <form action="/adm/coursedocs" method="post" name="newpage">
5535: <input type="hidden" name="folderpath" value="$path" />
5536: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5537: <input type="hidden" name="active" value="ee" />
1.423 onken 5538: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5539: $help{'Adding_Pages'}
1.329 droeschl 5540: </form>
5541: NPFORM
1.390 tempelho 5542:
5543:
1.351 ehlerst 5544: $newfolderform=(<<NFFORM);
1.329 droeschl 5545: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5546: $pathitem
1.329 droeschl 5547: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5548: <input type="hidden" name="active" value="" />
1.422 onken 5549: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5550: </form>
5551: NFFORM
5552:
5553: my $newsylform=(<<NSYLFORM);
5554: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5555: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5556: $pathitem
1.329 droeschl 5557: <input type="hidden" name="importdetail"
5558: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5559: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5560: $help{'Syllabus'}
1.383 tempelho 5561:
1.329 droeschl 5562: </form>
5563: NSYLFORM
1.364 bisitz 5564:
1.329 droeschl 5565: my $newgroupfileform=(<<NGFFORM);
5566: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5567: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5568: $pathitem
1.329 droeschl 5569: <input type="hidden" name="importdetail"
5570: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5571: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5572: $help{'Group Portfolio'}
1.329 droeschl 5573: </form>
5574: NGFFORM
1.383 tempelho 5575: @specialdocumentsforma=(
1.421 onken 5576: {'<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 5577: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5578: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5579: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5580: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5581: );
5582: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5583:
1.434 raeburn 5584:
5585: my @importdoc = (
1.484.2.19 raeburn 5586: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5587: );
5588: unless ($container eq 'page') {
5589: push(@importdoc,
5590: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5591: );
5592: }
5593: push(@importdoc,
1.484.2.38 raeburn 5594: {'<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 5595: );
1.484.2.12 raeburn 5596: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5597:
1.451 www 5598: @gradingforma=(
5599: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5600: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5601: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5602:
5603: );
5604: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5605:
5606: @communityforma=(
5607: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5611: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5612: );
5613: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5614:
1.330 tempelho 5615: my %orderhash = (
1.484.2.36 raeburn 5616: 'aa' => ['Upload',$fileuploadform],
5617: 'bb' => ['Import',$importpubform],
5618: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5619: );
1.484.2.19 raeburn 5620: unless ($container eq 'page') {
1.434 raeburn 5621: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5622: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5623: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5624: }
5625:
1.341 ehlerst 5626: $hadchanges=0;
1.484 raeburn 5627: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5628: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5629: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5630: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5631: undef($navmap);
1.443 www 5632: if ($error) {
5633: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5634: }
5635: if ($hadchanges) {
5636: &mark_hash_old();
5637: }
1.341 ehlerst 5638:
1.443 www 5639: &changewarning($r,'');
5640: }
1.458 raeburn 5641: }
1.442 www 5642:
1.443 www 5643: # Supplemental documents start here
5644:
1.329 droeschl 5645: my $folder=$env{'form.folder'};
1.443 www 5646: unless ($supplementalflag) {
1.329 droeschl 5647: $folder='supplemental';
5648: }
5649: if ($folder =~ /^supplemental$/ &&
5650: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5651: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5652: } elsif ($allowed) {
1.356 tempelho 5653: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5654: }
1.484.2.17 raeburn 5655: $pathitem = '<input type="hidden" name="folderpath" value="'.
5656: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5657: if ($allowed) {
5658: my $folderseq=
1.484.2.15 raeburn 5659: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5660:
5661: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5662: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5663: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5664: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5665: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5666: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5667: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5668: $fileupload
5669: <br />
5670: <br />
5671: <span class="LC_nobreak">
5672: $checkbox
5673: </span>
5674: <br /><br />
5675: $lt{'comment'}:<br />
1.383 tempelho 5676: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5677: <br />
1.484.2.19 raeburn 5678: $pathitem
1.329 droeschl 5679: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5680: <input type='submit' value="$lt{'upld'}" />
5681: </form>
1.484.2.19 raeburn 5682: SUPDOCFORM
1.329 droeschl 5683:
5684: my $supnewfolderform=(<<SNFFORM);
5685: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5686: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5687: $pathitem
1.329 droeschl 5688: <input type="hidden" name="importdetail" value="" />
1.423 onken 5689: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5690: $help{'Adding_Folders'}
1.329 droeschl 5691: </form>
5692: SNFFORM
1.383 tempelho 5693:
1.484.2.19 raeburn 5694: my $supextform =
5695: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5696: $help{'Adding_External_Resource'},
5697: undef,undef,$disabled);
1.329 droeschl 5698:
5699: my $supnewsylform=(<<SNSFORM);
5700: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5701: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5702: $pathitem
1.329 droeschl 5703: <input type="hidden" name="importdetail"
5704: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5705: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5706: $help{'Syllabus'}
5707: </form>
5708: SNSFORM
5709:
5710: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5711: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5712: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5713: $pathitem
1.329 droeschl 5714: <input type="hidden" name="importdetail"
5715: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5716: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5717: $help{'My Personal Information Page'}
1.329 droeschl 5718: </form>
5719: SNAMFORM
5720:
1.484.2.27 raeburn 5721: my $supwebpage;
5722: if ($folder =~ /^supplemental_?(\d*)$/) {
5723: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5724: if ($1) {
5725: $supwebpage .= $1;
5726: } else {
5727: $supwebpage .= 'default';
5728: }
5729: $supwebpage .= '/new.html';
5730: }
5731: my $supwebpageform =(<<SWEBFORM);
5732: <form action="/adm/coursedocs" method="post" name="supwebpage">
5733: <input type="hidden" name="active" value="cc" />
5734: $pathitem
5735: <input type="hidden" name="importdetail" value="$supwebpage" />
5736: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5737: $help{'Web_Page'}
1.484.2.27 raeburn 5738: </form>
5739: SWEBFORM
5740:
1.333 muellerd 5741:
1.383 tempelho 5742: my @specialdocs = (
1.484.2.67 raeburn 5743: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5744: =>$supnewsylform},
1.484.2.67 raeburn 5745: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5746: =>$supnewaboutmeform},
1.484.2.27 raeburn 5747: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5748:
1.383 tempelho 5749: );
1.417 droeschl 5750: my @supimportdoc = (
1.484.2.19 raeburn 5751: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5752: =>$supextform},
5753: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5754: =>$supupdocform},
1.484.2.19 raeburn 5755: );
5756:
1.484.2.12 raeburn 5757: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5758: my %suporderhash = (
1.390 tempelho 5759: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5760: 'ee' => ['Upload',$supupdocform],
5761: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5762: );
1.443 www 5763: if ($supplementalflag) {
1.458 raeburn 5764: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5765: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5766: $canedit);
1.443 www 5767: if ($error) {
5768: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5769: } else {
5770: if ($suppchanges) {
5771: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5772: my @ids=&Apache::lonnet::current_machine_ids();
5773: foreach my $server (keys(%servers)) {
5774: next if (grep(/^\Q$server\E$/,@ids));
5775: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5776: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5777: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5778: }
5779: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5780: undef($suppchanges);
5781: }
1.443 www 5782: }
1.393 raeburn 5783: }
1.443 www 5784: } elsif ($supplementalflag) {
1.458 raeburn 5785: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5786: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5787: if ($error) {
5788: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5789: }
1.393 raeburn 5790: }
1.389 tempelho 5791:
1.484.2.19 raeburn 5792: if ($needs_end) {
5793: $r->print(&endContentScreen());
5794: }
1.383 tempelho 5795:
1.329 droeschl 5796: if ($allowed) {
5797: $r->print('
5798: <form method="post" name="extimport" action="/adm/coursedocs">
5799: <input type="hidden" name="title" />
5800: <input type="hidden" name="url" />
5801: <input type="hidden" name="useform" />
5802: <input type="hidden" name="residx" />
5803: </form>');
5804: }
1.484 raeburn 5805: } elsif ($showdoc) {
1.329 droeschl 5806: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5807: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5808: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5809: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5810: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5811: }
5812: }
5813: $r->print(&Apache::loncommon::end_page());
5814: return OK;
1.364 bisitz 5815: }
1.329 droeschl 5816:
1.440 raeburn 5817: sub embedded_form_elems {
5818: my ($phase,$primaryurl,$newidx) = @_;
5819: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5820: return <<STATE;
5821: <input type="hidden" name="folderpath" value="$folderpath" />
5822: <input type="hidden" name="cmd" value="upload_embedded" />
5823: <input type="hidden" name="newidx" value="$newidx" />
5824: <input type="hidden" name="phase" value="$phase" />
5825: <input type="hidden" name="primaryurl" value="$primaryurl" />
5826: STATE
5827: }
5828:
5829: sub embedded_destination {
5830: my $folder=$env{'form.folder'};
5831: my $destination = 'docs/';
5832: if ($folder =~ /^supplemental/) {
5833: $destination = 'supplemental/';
5834: }
5835: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5836: $destination .= 'default/';
5837: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5838: $destination .= $2.'/';
5839: }
5840: $destination .= $env{'form.newidx'};
5841: my $dir_root = '/userfiles';
5842: return ($destination,$dir_root);
5843: }
5844:
5845: sub return_to_editor {
5846: my $actionurl = '/adm/coursedocs';
5847: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5848: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5849: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5850: '</a></p>';
5851: }
5852:
1.476 raeburn 5853: sub decompression_info {
5854: my ($destination,$dir_root) = &embedded_destination();
5855: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5856: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5857: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5858: my $container='sequence';
1.480 raeburn 5859: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 5860: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 5861: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5862: $container='page';
5863: }
1.480 raeburn 5864: unshift(@hiddens,$pathitem);
5865: foreach my $item (@hiddens) {
5866: if ($env{'form.'.$item}) {
5867: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 5868: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5869: }
1.477 raeburn 5870: }
1.476 raeburn 5871: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5872: $hiddenelem);
5873: }
5874:
5875: sub decompression_phase_one {
5876: my ($dir,$file,$warning,$error,$output);
5877: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5878: &decompression_info();
1.484.2.7 raeburn 5879: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5880: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5881: } else {
5882: my $file = $1;
1.481 raeburn 5883: $output =
5884: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5885: $destination,$dir_root,
5886: $hiddenelem);
5887: if ($env{'form.autoextract_camtasia'}) {
5888: $output .= &remove_archive($docudom,$docuname,$container);
5889: }
1.476 raeburn 5890: }
5891: if ($error) {
5892: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5893: $error.'</p>'."\n";
5894: }
5895: if ($warning) {
5896: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5897: }
5898: return $output;
5899: }
5900:
5901: sub decompression_phase_two {
5902: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5903: &decompression_info();
1.481 raeburn 5904: my $output;
1.480 raeburn 5905: if ($env{'form.archivedelete'}) {
1.481 raeburn 5906: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5907: }
5908: $output .=
1.481 raeburn 5909: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5910: $destination,$dir_root,$hiddenelem);
5911: return $output;
5912: }
5913:
1.480 raeburn 5914: sub remove_archive {
5915: my ($docudom,$docuname,$container) = @_;
5916: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5917: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5918: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5919: if ($fatal) {
5920: if ($container eq 'page') {
5921: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5922: } else {
5923: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5924: }
1.484.2.54 raeburn 5925: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5926: } else {
5927: my $currcmd = $env{'form.cmd'};
5928: my $position = $env{'form.position'};
1.484.2.54 raeburn 5929: my $archiveidx = $position;
5930: if ($position > 0) {
5931: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5932: $archiveidx = $position-1;
5933: }
5934: $env{'form.cmd'} = 'remove_'.$archiveidx;
5935: my ($title,$url,@rrest) =
5936: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5937: if ($url eq $env{'form.archiveurl'}) {
5938: if (&handle_edit_cmd($docuname,$docudom)) {
5939: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5940: if ($fatal) {
5941: if ($container eq 'page') {
5942: $delwarning = &mt('An error occurred updating the contents of the current page.');
5943: } else {
5944: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5945: }
1.480 raeburn 5946: } else {
1.484.2.54 raeburn 5947: $delresult = &mt('Archive file removed.');
1.480 raeburn 5948: }
5949: }
1.484.2.54 raeburn 5950: } else {
5951: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5952: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5953: }
5954: }
5955: $env{'form.cmd'} = $currcmd;
5956: }
5957: if ($delwarning) {
5958: $output = '<p class="LC_warning">'.
5959: $delwarning.
5960: '</p>';
5961: }
5962: if ($delresult) {
5963: $output .= '<p class="LC_info">'.
5964: $delresult.
5965: '</p>';
5966: }
1.481 raeburn 5967: return $output;
1.480 raeburn 5968: }
5969:
1.484 raeburn 5970: sub generate_admin_menu {
1.484.2.67 raeburn 5971: my ($crstype,$canedit) = @_;
1.484 raeburn 5972: my $lc_crstype = lc($crstype);
5973: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 5974: my %lt= ( # do not translate here
1.484 raeburn 5975: 'vc' => 'Verify Content',
5976: 'cv' => 'Check/Set Resource Versions',
5977: 'ls' => 'List Resource Identifiers',
5978: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 5979: 'dcd' => "Copy $crstype Content to Authoring Space",
5980: );
1.484 raeburn 5981: my ($candump,$dumpurl);
5982: if ($home + $other > 0) {
5983: $candump = 'F';
5984: if ($home) {
5985: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5986: } else {
5987: my @hosts;
5988: foreach my $aurole (keys(%outhash)) {
5989: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5990: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 5991: }
1.484 raeburn 5992: }
5993: if (@hosts == 1) {
5994: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5995: '&role='.
5996: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5997: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5998: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5999: } else {
6000: $dumpurl = "javascript:choose_switchserver_window()";
6001: }
6002: }
6003: }
6004: my @menu=
6005: ({ categorytitle=>'Administration',
6006: items =>[
6007: { linktext => $lt{'vc'},
6008: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6009: permission => 'F',
1.484.2.44 raeburn 6010: help => 'Docs_Verify_Content',
1.484 raeburn 6011: icon => 'verify.png',
6012: linktitle => 'Verify contents can be retrieved/rendered',
6013: },
6014: { linktext => $lt{'cv'},
6015: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6016: permission => 'F',
1.484.2.44 raeburn 6017: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6018: icon => 'resversion.png',
6019: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6020: },
6021: { linktext => $lt{'ls'},
6022: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6023: permission => 'F',
6024: #help => '',
6025: icon => 'symbs.png',
6026: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6027: },
6028: ]
1.484.2.67 raeburn 6029: });
6030: if ($canedit) {
6031: push(@menu,
1.484 raeburn 6032: { categorytitle=>'Export',
6033: items =>[
6034: { linktext => $lt{'imse'},
6035: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6036: permission => 'F',
6037: help => 'Docs_Export_Course_Docs',
6038: icon => 'imsexport.png',
6039: linktitle => $lt{'imse'},
6040: },
6041: { linktext => $lt{'dcd'},
6042: url => $dumpurl,
6043: permission => $candump,
1.484.2.44 raeburn 6044: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6045: icon => 'dump.png',
6046: linktitle => $lt{'dcd'},
6047: },
6048: ]
6049: });
1.484.2.67 raeburn 6050: }
1.484 raeburn 6051: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6052: '<input type="hidden" id="dummy" />'."\n".
6053: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6054: '</form>';
1.329 droeschl 6055: }
6056:
6057: sub generate_edit_table {
1.484.2.30 raeburn 6058: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6059: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6060: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6061: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6062: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6063: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6064: $activetab = $env{'form.active'};
6065: }
1.484.2.67 raeburn 6066: unless ($canedit) {
6067: $disabled = ' disabled="disabled"';
6068: }
1.472 raeburn 6069: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6070: my $backtext = &mt('Exit Editor');
1.458 raeburn 6071: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6072: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6073: '<li class="goback">'.
1.484.2.32 raeburn 6074: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6075: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6076: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6077: '<li>'.
6078: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6079: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6080: if ($env{'form.docslog'}) {
6081: $form .= '<li class="active">';
6082: } else {
6083: $form .= '<li>';
6084: }
6085: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6086: &mt('History').'</a></li>'."\n";
6087: if ($env{'form.docslog'}) {
6088: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6089: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6090: }
1.458 raeburn 6091: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6092: if($name ne '00'){
1.371 tempelho 6093: if($activetab eq '' || $activetab ne $name){
6094: $active = '';
6095: }elsif($activetab eq $name){
6096: $active = 'class="active"';
6097: }
1.458 raeburn 6098: $form .= '<li style="float:right" '.$active
1.484 raeburn 6099: .' 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 6100: } else {
1.484.2.43 raeburn 6101: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6102:
6103: }
1.329 droeschl 6104: }
1.484 raeburn 6105: $form .= '</ul>'."\n";
6106: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6107:
6108: if ($to_show ne '') {
1.484.2.30 raeburn 6109: my $saveform;
6110: if ($need_save) {
6111: my $button = &mt('Make changes');
6112: my $path;
6113: if ($env{'form.folderpath'}) {
6114: $path =
6115: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6116: }
6117: $saveform = <<"END";
6118: <div id="multisave" style="display:none; clear:both;" >
6119: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6120: <input type="hidden" name="folderpath" value="$path" />
6121: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6122: <input type="hidden" name="allhiddenresource" value="" />
6123: <input type="hidden" name="allencrypturl" value="" />
6124: <input type="hidden" name="allrandompick" value="" />
6125: <input type="hidden" name="allrandomorder" value="" />
6126: <input type="hidden" name="changeparms" value="" />
6127: <input type="hidden" name="multiremove" value="" />
6128: <input type="hidden" name="multicut" value="" />
6129: <input type="hidden" name="multicopy" value="" />
6130: <input type="hidden" name="multichange" value="" />
6131: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6132: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6133: </form>
6134: </div>
6135: END
6136: }
6137: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6138: }
1.363 ehlerst 6139: foreach my $field (keys(%orderhash)){
1.390 tempelho 6140: if($field ne '00'){
1.422 onken 6141: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6142: $active = 'style="display: none;float:left"';
1.422 onken 6143: }elsif($activetab eq $field){
1.458 raeburn 6144: $active = 'style="display:block;float:left"';
1.422 onken 6145: }
6146: $form .= '<div id="'.$field.$tid.'"'
6147: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6148: .'</div>'."\n";
1.363 ehlerst 6149: }
6150: }
1.484 raeburn 6151: unless ($env{'form.docslog'}) {
6152: $form .= '</div></div>'."\n";
6153: }
1.329 droeschl 6154: return $form;
6155: }
6156:
6157: sub editing_js {
1.484.2.67 raeburn 6158: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6159: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6160: p_mnf => 'Name of New Folder',
6161: t_mnf => 'New Folder',
6162: p_mnp => 'Name of New Page',
6163: t_mnp => 'New Page',
1.451 www 6164: p_mxu => 'Title for the External Score',
1.349 biermanm 6165: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6166: p_msb => 'Title for the Problem',
6167: p_mdb => 'Title for the Drop Box',
1.336 schafran 6168: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6169: p_mwp => 'Title for Web Page',
1.348 weissno 6170: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6171: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6172: p_mab_alrt1 => 'Not a valid user:domain',
6173: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6174: p_chn => 'New Title',
6175: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6176: p_rmr2a => 'Remove',
6177: p_rmr2b => '?',
6178: p_rmr3a => 'Remove those',
6179: p_rmr3b => 'items?',
6180: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6181: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6182: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6183: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6184: p_ctr2a => 'Cut',
6185: p_ctr2b => '?',
6186: p_ctr3a => 'Cut those',
6187: p_ctr3b => 'items?',
1.478 raeburn 6188: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6189: imsfile => 'You must choose an IMS package for import',
6190: imscms => 'You must select which Course Management System was the source of the IMS package',
6191: invurl => 'Invalid URL',
6192: titbl => 'Title is blank',
1.484.2.30 raeburn 6193: more => '(More ...)',
6194: less => '(Less ...)',
6195: noor => 'No actions selected or changes to settings specified.',
6196: noch => 'No changes to settings specified.',
6197: noac => 'No actions selected.',
1.484.2.67 raeburn 6198: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6199: );
6200:
1.484.2.61 raeburn 6201: &js_escape(\%js_lt);
1.433 raeburn 6202: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6203: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6204: my $main_container_page;
1.484.2.19 raeburn 6205: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6206: $main_container_page = 1;
1.434 raeburn 6207: }
1.484.2.67 raeburn 6208: my $backtourl;
6209: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6210: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6211:
1.484.2.21 raeburn 6212: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6213: my $caller = $1;
6214: if ($caller =~ /^supplemental/) {
6215: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6216: } else {
6217: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6218: $res = &Apache::lonnet::clutter($res);
6219: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6220: my ($url,$anchor);
6221: if ($res =~ /^([^#]+)#([^#]+)$/) {
6222: $url = $1;
6223: $anchor = $2;
6224: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6225: $caller = $1.&escape('#').$anchor;
6226: }
1.484.2.67 raeburn 6227: } else {
6228: $url = $res;
1.484.2.66 raeburn 6229: }
6230: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6231: &HTML::Entities::encode($caller,'<>&"');
1.484.2.66 raeburn 6232: if ($anchor ne '') {
6233: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6234: }
1.484.2.57 raeburn 6235: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6236: } else {
6237: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6238: }
6239: }
6240: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6241: $backtourl = '/adm/menu';
6242: } elsif ($supplementalflag) {
1.472 raeburn 6243: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6244: } else {
6245: $backtourl = '/adm/navmaps';
1.472 raeburn 6246: }
6247:
1.484.2.19 raeburn 6248: my $fieldsets = "'ext','doc'";
6249: unless ($main_container_page) {
6250: $fieldsets .=",'ims'";
6251: }
1.484.2.12 raeburn 6252: if ($supplementalflag) {
6253: $fieldsets = "'suppext','suppdoc'";
6254: }
6255:
1.484.2.67 raeburn 6256: my $jsmakefunctions;
6257: if ($canedit) {
6258: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6259: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6260: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6261: if (foldername) {
6262: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6263: targetform.submit();
6264: }
6265: }
6266:
6267: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6268: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6269: if (pagename) {
6270: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6271: targetform.submit();
6272: }
6273: }
6274:
6275: function makeexamupload() {
1.484.2.61 raeburn 6276: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6277: if (title) {
1.329 droeschl 6278: this.document.forms.newexamupload.importdetail.value=
6279: escape(title)+'=/res/lib/templates/examupload.problem';
6280: this.document.forms.newexamupload.submit();
6281: }
6282: }
6283:
6284: function makesmppage() {
1.484.2.61 raeburn 6285: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6286: if (title) {
1.329 droeschl 6287: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6288: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6289: this.document.forms.newsmppg.submit();
6290: }
6291: }
6292:
1.484.2.27 raeburn 6293: function makewebpage(type) {
1.484.2.61 raeburn 6294: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6295: var formname;
6296: if (type == 'supp') {
6297: formname = this.document.forms.supwebpage;
6298: } else {
6299: formname = this.document.forms.newwebpage;
6300: }
6301: if (title) {
6302: var webpage = formname.importdetail.value;
6303: formname.importdetail.value = escape(title)+'='+webpage;
6304: formname.submit();
6305: }
6306: }
6307:
1.329 droeschl 6308: function makesmpproblem() {
1.484.2.61 raeburn 6309: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6310: if (title) {
1.329 droeschl 6311: this.document.forms.newsmpproblem.importdetail.value=
6312: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6313: this.document.forms.newsmpproblem.submit();
6314: }
6315: }
6316:
6317: function makedropbox() {
1.484.2.61 raeburn 6318: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6319: if (title) {
1.329 droeschl 6320: this.document.forms.newdropbox.importdetail.value=
6321: escape(title)+'=/res/lib/templates/DropBox.problem';
6322: this.document.forms.newdropbox.submit();
6323: }
6324: }
6325:
6326: function makebulboard() {
1.484.2.61 raeburn 6327: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6328: if (title) {
6329: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6330: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6331: this.document.forms.newbul.submit();
6332: }
6333: }
6334:
6335: function makeabout() {
1.484.2.61 raeburn 6336: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6337: if (user) {
6338: var comp=new Array();
6339: comp=user.split(':');
6340: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6341: if ((comp[0]) && (comp[1])) {
6342: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6343: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6344: this.document.forms.newaboutsomeone.submit();
6345: } else {
6346: alert("$js_lt{'p_mab_alrt1'}");
6347: }
6348: } else {
6349: alert("$js_lt{'p_mab_alrt2'}");
6350: }
6351: }
1.335 ehlerst 6352: }
1.484.2.67 raeburn 6353:
6354: function makenew(targetform) {
6355: targetform.submit();
1.335 ehlerst 6356: }
1.484.2.67 raeburn 6357:
6358: function changename(folderpath,index,oldtitle) {
6359: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6360: if (title) {
6361: this.document.forms.renameform.markcopy.value='';
6362: this.document.forms.renameform.title.value=title;
6363: this.document.forms.renameform.cmd.value='rename_'+index;
6364: this.document.forms.renameform.folderpath.value=folderpath;
6365: this.document.forms.renameform.submit();
6366: }
1.329 droeschl 6367: }
6368:
1.484.2.67 raeburn 6369: ENDNEWSCRIPT
6370: } else {
6371: $jsmakefunctions = <<ENDNEWSCRIPT;
6372:
6373: function makenewfolder() {
6374: alert("$js_lt{'edri'}");
6375: }
6376:
6377: function makenewpage() {
6378: alert("$js_lt{'edri'}");
6379: }
6380:
6381: function makeexamupload() {
6382: alert("$js_lt{'edri'}");
6383: }
6384:
6385: function makesmppage() {
6386: alert("$js_lt{'edri'}");
6387: }
6388:
6389: function makewebpage(type) {
6390: alert("$js_lt{'edri'}");
6391: }
6392:
6393: function makesmpproblem() {
6394: alert("$js_lt{'edri'}");
6395: }
6396:
6397: function makedropbox() {
6398: alert("$js_lt{'edri'}");
6399: }
6400:
6401: function makebulboard() {
6402: alert("$js_lt{'edri'}");
6403: }
6404:
6405: function makeabout() {
6406: alert("$js_lt{'edri'}");
6407: }
6408:
6409: function changename() {
6410: alert("$js_lt{'edri'}");
6411: }
6412:
6413: function makenew() {
6414: alert("$js_lt{'edri'}");
6415: }
6416:
6417: function groupimport() {
6418: alert("$js_lt{'edri'}");
6419: }
6420:
6421: function groupsearch() {
6422: alert("$js_lt{'edri'}");
6423: }
6424:
6425: function groupopen(url,recover) {
6426: var options="scrollbars=1,resizable=1,menubar=0";
6427: idxflag=1;
6428: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6429: idx.focus();
6430: }
6431:
6432: ENDNEWSCRIPT
6433:
6434: }
6435: return <<ENDSCRIPT;
6436:
6437: $jsmakefunctions
6438:
1.484.2.13 raeburn 6439: function toggleUpload(caller) {
6440: var blocks = Array($fieldsets);
6441: for (var i=0; i<blocks.length; i++) {
6442: var disp = 'none';
6443: if (caller == blocks[i]) {
6444: var curr = document.getElementById('upload'+caller+'form').style.display;
6445: if (curr == 'none') {
6446: disp='block';
6447: }
6448: }
6449: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6450: }
6451: resize_scrollbox('contentscroll','1','1');
6452: return;
6453: }
6454:
1.484.2.19 raeburn 6455: function toggleMap(caller) {
1.484.2.13 raeburn 6456: var disp = 'none';
1.484.2.19 raeburn 6457: if (document.getElementById('importmapform')) {
6458: if (caller == 'map') {
6459: var curr = document.getElementById('importmapform').style.display;
6460: if (curr == 'none') {
6461: disp='block';
6462: }
1.484.2.12 raeburn 6463: }
1.484.2.19 raeburn 6464: document.getElementById('importmapform').style.display=disp;
6465: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6466: }
1.484.2.19 raeburn 6467: return;
1.329 droeschl 6468: }
6469:
1.484.2.12 raeburn 6470: function makeims(imsform) {
6471: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6472: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6473: return;
6474: }
6475: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6476: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6477: return;
6478: }
6479: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6480: imsform.submit();
6481: }
6482:
1.478 raeburn 6483: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6484: var pickitem;
6485: var picknumitem;
6486: var picknumtext;
6487: if (index == 'all') {
6488: pickitem = document.getElementById('randompickall');
6489: picknumitem = document.getElementById('rpicknumall');
6490: picknumtext = document.getElementById('rpicktextall');
6491: } else {
6492: pickitem = document.getElementById('randompick_'+index);
6493: picknumitem = document.getElementById('rpicknum_'+index);
6494: picknumtext = document.getElementById('randompicknum_'+index);
6495: }
1.478 raeburn 6496: if (pickitem.checked) {
1.484.2.61 raeburn 6497: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6498: if (picknum == '' || picknum == null) {
6499: if (caller == 'check') {
6500: pickitem.checked=false;
1.484.2.29 raeburn 6501: if (index == 'all') {
6502: picknumtext.innerHTML = '';
6503: if (caller == 'link') {
6504: propagateState(targetform,'rpicknum');
6505: }
6506: } else {
1.484.2.30 raeburn 6507: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6508: }
1.478 raeburn 6509: }
6510: } else {
6511: picknum.toString();
6512: var regexdigit=/^\\d+\$/;
6513: if (regexdigit.test(picknum)) {
6514: picknumitem.value = picknum;
1.484.2.29 raeburn 6515: if (index == 'all') {
1.484.2.30 raeburn 6516: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6517: if (caller == 'link') {
6518: propagateState(targetform,'rpicknum');
6519: }
6520: } else {
6521: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6522: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6523: }
1.478 raeburn 6524: } else {
6525: if (caller == 'check') {
1.484.2.29 raeburn 6526: if (index == 'all') {
6527: picknumtext.innerHTML = '';
6528: if (caller == 'link') {
6529: propagateState(targetform,'rpicknum');
6530: }
6531: } else {
6532: pickitem.checked=false;
1.484.2.30 raeburn 6533: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6534: }
1.478 raeburn 6535: }
6536: return;
6537: }
6538: }
6539: } else {
1.484.2.29 raeburn 6540: picknumitem.value = '';
6541: picknumtext.innerHTML = '';
6542: if (index == 'all') {
6543: if (caller == 'link') {
6544: propagateState(targetform,'rpicknum');
6545: }
6546: } else {
1.484.2.30 raeburn 6547: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6548: }
6549: }
6550: }
6551:
6552: function propagateState(form,param) {
6553: if (document.getElementById(param+'all')) {
6554: var setcheck = 0;
6555: var rpick = 0;
6556: if (param == 'rpicknum') {
6557: if (document.getElementById('randompickall')) {
6558: if (document.getElementById('randompickall').checked) {
6559: if (document.getElementById('rpicknumall')) {
6560: rpick = document.getElementById('rpicknumall').value;
6561: }
6562: }
6563: }
6564: } else {
6565: if (document.getElementById(param+'all').checked) {
6566: setcheck = 1;
6567: }
6568: }
1.484.2.30 raeburn 6569: var allidxlist;
6570: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6571: if (document.getElementById('all'+param+'idx')) {
6572: allidxlist = document.getElementById('all'+param+'idx').value;
6573: }
6574: var actions = new Array ('remove','cut','copy');
6575: for (var i=0; i<actions.length; i++) {
6576: if (actions[i] != param) {
6577: if (document.getElementById(actions[i]+'all')) {
6578: document.getElementById(actions[i]+'all').checked = false;
6579: }
6580: }
6581: }
6582: }
1.484.2.29 raeburn 6583: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6584: allidxlist = form.allidx.value;
6585: }
6586: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6587: allidxlist = form.allmapidx.value;
6588: }
6589: if ((allidxlist != '') && (allidxlist != null)) {
6590: var allidxs = allidxlist.split(',');
6591: if (allidxs.length > 1) {
6592: for (var i=0; i<allidxs.length; i++) {
6593: if (document.getElementById(param+'_'+allidxs[i])) {
6594: if (param == 'rpicknum') {
6595: if (document.getElementById('randompick_'+allidxs[i])) {
6596: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6597: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6598: if (rpick > 0) {
6599: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6600: } else {
6601: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6602: }
6603: }
6604: }
6605: } else {
1.484.2.29 raeburn 6606: if (setcheck == 1) {
6607: document.getElementById(param+'_'+allidxs[i]).checked = true;
6608: } else {
6609: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6610: if (param == 'randompick') {
6611: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6612: }
1.484.2.29 raeburn 6613: }
6614: }
6615: }
6616: }
1.484.2.30 raeburn 6617: if (setcheck == 1) {
6618: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6619: var actions = new Array('copy','cut','remove');
6620: for (var i=0; i<actions.length; i++) {
6621: var otheractions;
6622: var otheridxs;
6623: if (actions[i] === param) {
6624: continue;
6625: } else {
6626: if (document.getElementById('all'+actions[i]+'idx')) {
6627: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6628: otheridxs = otheractions.split(',');
6629: if (otheridxs.length > 1) {
6630: for (var j=0; j<otheridxs.length; j++) {
6631: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6632: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6633: }
1.484.2.29 raeburn 6634: }
6635: }
6636: }
6637: }
1.484.2.30 raeburn 6638: }
1.484.2.29 raeburn 6639: }
6640: }
6641: }
6642: }
1.478 raeburn 6643: }
1.484.2.29 raeburn 6644: return;
6645: }
6646:
1.484.2.63 raeburn 6647: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6648: var canedit = '$canedit';
6649: if (canedit == '') {
6650: alert("$js_lt{'edri'}");
6651: return;
6652: }
1.484.2.30 raeburn 6653: var dosettings;
6654: var doaction;
6655: var control = document.togglemultsettings;
6656: if (context == 'actions') {
6657: control = document.togglemultactions;
6658: doaction = 1;
6659: } else {
6660: dosettings = 1;
6661: }
6662: if (control) {
6663: if (control.showmultpick.length) {
6664: for (var i=0; i<control.showmultpick.length; i++) {
6665: if (control.showmultpick[i].checked) {
6666: if (control.showmultpick[i].value == 1) {
6667: if (context == 'settings') {
6668: dosettings = 0;
6669: } else {
6670: doaction = 0;
6671: }
6672: }
6673: }
6674: }
6675: }
6676: }
6677: if (context == 'settings') {
6678: if (dosettings == 1) {
6679: targetform.changeparms.value=param;
6680: targetform.submit();
6681: }
6682: }
6683: if (context == 'actions') {
6684: if (doaction == 1) {
6685: targetform.cmd.value=param+'_'+index;
6686: targetform.folderpath.value=folderpath;
6687: targetform.markcopy.value=idx+':'+param;
6688: targetform.copyfolder.value=folder+'.'+container;
6689: if (param == 'remove') {
1.484.2.63 raeburn 6690: var doremove = 0;
6691: if (skip_confirm) {
6692: if (confirm_removal) {
6693: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6694: doremove = 1;
6695: }
6696: } else {
6697: doremove = 1;
6698: }
6699: } else {
6700: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6701: doremove = 1;
6702: }
6703: }
6704: if (doremove) {
1.484.2.30 raeburn 6705: targetform.markcopy.value='';
6706: targetform.copyfolder.value='';
1.484.2.29 raeburn 6707: targetform.submit();
6708: }
6709: }
1.484.2.30 raeburn 6710: if (param == 'cut') {
1.484.2.61 raeburn 6711: 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 6712: targetform.submit();
6713: return;
6714: }
6715: }
6716: if (param == 'copy') {
6717: targetform.submit();
6718: return;
6719: }
6720: targetform.markcopy.value='';
6721: targetform.copyfolder.value='';
6722: targetform.cmd.value='';
6723: targetform.folderpath.value='';
6724: return;
6725: } else {
6726: if (document.getElementById(param+'_'+idx)) {
6727: item = document.getElementById(param+'_'+idx);
6728: if (item.type == 'checkbox') {
6729: if (item.checked) {
6730: item.checked = false;
6731: } else {
6732: item.checked = true;
6733: singleCheck(item,idx,param);
6734: }
6735: }
6736: }
6737: }
6738: }
6739: return;
6740: }
6741:
6742: function singleCheck(caller,idx,action) {
6743: actions = new Array('cut','copy','remove');
6744: if (caller.checked) {
6745: for (var i=0; i<actions.length; i++) {
6746: if (actions[i] != action) {
6747: if (document.getElementById(actions[i]+'_'+idx)) {
6748: if (document.getElementById(actions[i]+'_'+idx).checked) {
6749: document.getElementById(actions[i]+'_'+idx).checked = false;
6750: }
6751: }
6752: }
1.484.2.29 raeburn 6753: }
6754: }
6755: return;
1.478 raeburn 6756: }
6757:
1.334 muellerd 6758: function unselectInactive(nav) {
1.335 ehlerst 6759: currentNav = document.getElementById(nav);
6760: currentLis = currentNav.getElementsByTagName('LI');
6761: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6762: if (currentLis[i].className == 'goback') {
6763: currentLis[i].className = 'goback';
6764: } else {
6765: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6766: currentLis[i].className = 'right';
1.472 raeburn 6767: } else {
1.374 tempelho 6768: currentLis[i].className = 'i';
1.472 raeburn 6769: }
6770: }
1.335 ehlerst 6771: }
1.332 tempelho 6772: }
6773:
1.334 muellerd 6774: function hideAll(current, nav, data) {
1.335 ehlerst 6775: unselectInactive(nav);
1.484.2.43 raeburn 6776: if (current) {
6777: if (current.className == 'right'){
1.374 tempelho 6778: current.className = 'right active'
1.484.2.43 raeburn 6779: } else {
1.374 tempelho 6780: current.className = 'active';
1.484.2.43 raeburn 6781: }
1.374 tempelho 6782: }
1.335 ehlerst 6783: currentData = document.getElementById(data);
6784: currentDivs = currentData.getElementsByTagName('DIV');
6785: for (i = 0; i < currentDivs.length; i++) {
6786: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6787: currentDivs[i].style.display = 'none';
1.330 tempelho 6788: }
6789: }
1.335 ehlerst 6790: }
1.330 tempelho 6791:
1.374 tempelho 6792: function openTabs(pageId) {
6793: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6794: if(tabnav.length > 2 ){
1.389 tempelho 6795: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6796: currentLis = currentNav.getElementsByTagName('LI');
6797: for(i = 0; i< currentLis.length; i++){
6798: if(currentLis[i].className == 'active') {
1.375 tempelho 6799: funcString = currentLis[i].onclick.toString();
6800: tab = funcString.split('"');
1.420 onken 6801: if(tab.length < 2) {
6802: tab = funcString.split("'");
6803: }
1.375 tempelho 6804: currentData = document.getElementById(tab[1]);
6805: currentData.style.display = 'block';
1.374 tempelho 6806: }
6807: }
6808: }
6809: }
6810:
1.334 muellerd 6811: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6812: currstate = current.className;
1.334 muellerd 6813: hideAll(current, nav, data);
1.375 tempelho 6814: openTabs(pageId);
1.334 muellerd 6815: unselectInactive(nav);
1.484.2.43 raeburn 6816: if ((currstate == 'active') || (currstate == 'right active')) {
6817: if (currstate == 'active') {
6818: current.className = '';
6819: } else {
6820: current.className = 'right';
6821: }
6822: activeTab = '';
6823: toggleUpload();
6824: toggleMap();
6825: resize_scrollbox('contentscroll','1','0');
6826: return;
6827: } else {
6828: current.className = 'active';
6829: }
1.330 tempelho 6830: currentData = document.getElementById(pageId);
6831: currentData.style.display = 'block';
1.458 raeburn 6832: activeTab = pageId;
1.484.2.12 raeburn 6833: toggleUpload();
1.484.2.14 raeburn 6834: toggleMap();
1.433 raeburn 6835: if (nav == 'mainnav') {
6836: var storedpath = "$docs_folderpath";
1.434 raeburn 6837: var storedpage = "$main_container_page";
1.433 raeburn 6838: var reg = new RegExp("^supplemental");
6839: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6840: if (storedpage == 1) {
6841: document.simpleedit.folderpath.value = '';
6842: document.uploaddocument.folderpath.value = '';
6843: } else {
6844: if (reg.test(storedpath)) {
6845: document.simpleedit.folderpath.value = '$toplevelmain';
6846: document.uploaddocument.folderpath.value = '$toplevelmain';
6847: document.newext.folderpath.value = '$toplevelmain';
6848: } else {
6849: document.simpleedit.folderpath.value = storedpath;
6850: document.uploaddocument.folderpath.value = storedpath;
6851: document.newext.folderpath.value = storedpath;
6852: }
1.433 raeburn 6853: }
6854: } else {
1.434 raeburn 6855: if (reg.test(storedpath)) {
6856: document.simpleedit.folderpath.value = storedpath;
6857: document.supuploaddocument.folderpath.value = storedpath;
6858: document.supnewext.folderpath.value = storedpath;
6859: } else {
1.433 raeburn 6860: document.simpleedit.folderpath.value = '$toplevelsupp';
6861: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6862: document.supnewext.folderpath.value = '$toplevelsupp';
6863: }
6864: }
6865: }
1.484.2.3 raeburn 6866: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6867: return false;
6868: }
1.329 droeschl 6869:
1.472 raeburn 6870: function toContents(jumpto) {
6871: var newurl = '$backtourl';
1.484.2.21 raeburn 6872: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6873: newurl = newurl+'?postdata='+jumpto;
6874: }
6875: location.href=newurl;
6876: }
6877:
1.484.2.30 raeburn 6878: function togglePick(caller,value) {
6879: var disp = 'none';
6880: if (document.getElementById('multi'+caller)) {
6881: var curr = document.getElementById('multi'+caller).style.display;
6882: if (value == 1) {
6883: disp='block';
6884: }
6885: if (curr == disp) {
6886: return;
6887: }
6888: document.getElementById('multi'+caller).style.display=disp;
6889: if (value == 1) {
1.484.2.61 raeburn 6890: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6891: } else {
6892: document.getElementById('more'+caller).innerHTML = '';
6893: }
6894: if (caller == 'actions') {
6895: setClass(value);
6896: setBoxes(value);
6897: }
6898: }
6899: var showButton = multiSettings();
6900: if (showButton != 1) {
6901: showButton = multiActions();
6902: }
6903: if (document.getElementById('multisave')) {
6904: if (showButton == 1) {
6905: document.getElementById('multisave').style.display='block';
6906: } else {
6907: document.getElementById('multisave').style.display='none';
6908: }
6909: }
6910: resize_scrollbox('contentscroll','1','1');
6911: return;
6912: }
6913:
6914: function toggleCheckUncheck(caller,more) {
6915: if (more == 1) {
1.484.2.61 raeburn 6916: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 6917: document.getElementById('allfields'+caller).style.display='block';
6918: } else {
1.484.2.61 raeburn 6919: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6920: document.getElementById('allfields'+caller).style.display='none';
6921: }
6922: resize_scrollbox('contentscroll','1','1');
6923: }
6924:
6925: function multiSettings() {
6926: var inuse = 0;
6927: var settingsform = document.togglemultsettings;
6928: if (settingsform.showmultpick.length > 1) {
6929: for (var i=0; i<settingsform.showmultpick.length; i++) {
6930: if (settingsform.showmultpick[i].checked) {
6931: if (settingsform.showmultpick[i].value == 1) {
6932: inuse = 1;
6933: }
6934: }
6935: }
6936: }
6937: return inuse;
6938: }
6939:
6940: function multiActions() {
6941: var inuse = 0;
6942: var actionsform = document.togglemultactions;
6943: if (actionsform.showmultpick.length > 1) {
6944: for (var i=0; i<actionsform.showmultpick.length; i++) {
6945: if (actionsform.showmultpick[i].checked) {
6946: if (actionsform.showmultpick[i].value == 1) {
6947: inuse = 1;
6948: }
6949: }
6950: }
6951: }
6952: return inuse;
6953: }
6954:
6955: function checkSubmits() {
6956: var numchanges = 0;
6957: var form = document.saveactions;
6958: var doactions = multiActions();
6959: var cutwarnings = 0;
6960: var remwarnings = 0;
1.484.2.63 raeburn 6961: var removalinfo = 0;
1.484.2.30 raeburn 6962: if (doactions == 1) {
6963: var remidxlist = document.cumulativeactions.allremoveidx.value;
6964: if ((remidxlist != '') && (remidxlist != null)) {
6965: var remidxs = remidxlist.split(',');
6966: for (var i=0; i<remidxs.length; i++) {
6967: if (document.getElementById('remove_'+remidxs[i])) {
6968: if (document.getElementById('remove_'+remidxs[i]).checked) {
6969: form.multiremove.value += remidxs[i]+',';
6970: numchanges ++;
6971: if (document.getElementById('skip_remove_'+remidxs[i])) {
6972: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6973: remwarnings ++;
6974: }
6975: }
1.484.2.63 raeburn 6976: if (document.getElementById('confirm_removal_'+remidxs[i])) {
6977: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
6978: removalinfo ++;
6979: }
6980: }
1.484.2.30 raeburn 6981: }
6982: }
6983: }
6984: }
6985: var cutidxlist = document.cumulativeactions.allcutidx.value;
6986: if ((cutidxlist != '') && (cutidxlist != null)) {
6987: var cutidxs = cutidxlist.split(',');
6988: for (var i=0; i<cutidxs.length; i++) {
6989: if (document.getElementById('cut_'+cutidxs[i])) {
6990: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6991: form.multicut.value += cutidxs[i]+',';
6992: numchanges ++;
6993: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6994: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6995: cutwarnings ++;
6996: }
6997: }
6998: }
6999: }
7000: }
7001: }
7002: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7003: if ((copyidxlist != '') && (copyidxlist != null)) {
7004: var copyidxs = copyidxlist.split(',');
7005: for (var i=0; i<copyidxs.length; i++) {
7006: if (document.getElementById('copy_'+copyidxs[i])) {
7007: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7008: form.multicopy.value += copyidxs[i]+',';
7009: numchanges ++;
7010: }
7011: }
7012: }
7013: }
7014: if (numchanges > 0) {
7015: form.multichange.value = numchanges;
7016: }
7017: }
7018: var dosettings = multiSettings();
7019: var haschanges = 0;
7020: if (dosettings == 1) {
7021: form.allencrypturl.value = '';
7022: form.allhiddenresource.value = '';
7023: form.changeparms.value = 'all';
7024: var patt=new RegExp(",\$");
7025: var allidxlist = document.cumulativesettings.allidx.value;
7026: if ((allidxlist != '') && (allidxlist != null)) {
7027: var allidxs = allidxlist.split(',');
7028: if (allidxs.length > 1) {
7029: for (var i=0; i<allidxs.length; i++) {
7030: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7031: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7032: form.allhiddenresource.value += allidxs[i]+',';
7033: }
7034: }
7035: if (document.getElementById('encrypturl_'+allidxs[i])) {
7036: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7037: form.allencrypturl.value += allidxs[i]+',';
7038: }
1.484.2.29 raeburn 7039: }
7040: }
1.484.2.30 raeburn 7041: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7042: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7043: }
7044: }
7045: form.allrandompick.value = '';
7046: form.allrandomorder.value = '';
7047: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7048: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7049: var allmapidxs = allmapidxlist.split(',');
7050: for (var i=0; i<allmapidxs.length; i++) {
7051: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7052: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7053: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7054: if ((randompick.checked) && (rpicknum.value != '')) {
7055: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7056: }
7057: if (randorder.checked) {
7058: form.allrandomorder.value += allmapidxs[i]+',';
7059: }
7060: }
7061: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7062: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7063: }
7064: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7065: haschanges = 1;
7066: }
7067: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7068: haschanges = 1;
7069: }
7070: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7071: haschanges = 1;
7072: }
7073: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7074: haschanges = 1;
7075: }
7076: }
7077: if (doactions == 1) {
7078: if (numchanges > 0) {
1.484.2.63 raeburn 7079: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7080: if (remwarnings > 0) {
1.484.2.61 raeburn 7081: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7082: return false;
7083: }
7084: }
1.484.2.63 raeburn 7085: if (removalinfo > 0) {
7086: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7087: return false;
7088: }
7089: }
1.484.2.30 raeburn 7090: if (cutwarnings > 0) {
1.484.2.61 raeburn 7091: 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 7092: return false;
1.484.2.29 raeburn 7093: }
7094: }
7095: }
1.484.2.30 raeburn 7096: form.submit();
7097: return true;
7098: }
7099: }
7100: if (dosettings == 1) {
7101: if (haschanges == 1) {
7102: form.submit();
7103: return true;
1.484.2.29 raeburn 7104: }
7105: }
1.484.2.30 raeburn 7106: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7107: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7108: } else {
7109: if (dosettings == 1) {
1.484.2.61 raeburn 7110: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7111: } else {
1.484.2.61 raeburn 7112: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7113: }
7114: }
7115: return false;
7116: }
7117:
7118: function setClass(value) {
7119: var cutclass = 'LC_docs_cut';
7120: var copyclass = 'LC_docs_copy';
7121: var removeclass = 'LC_docs_remove';
7122: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7123: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7124: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7125: var links = document.getElementsByTagName('a');
7126: for (var i=0; i<links.length; i++) {
7127: var classes = links[i].className;
7128: if (cutreg.test(classes)) {
7129: links[i].className = cutclass;
7130: if (value == 1) {
7131: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7132: }
1.484.2.30 raeburn 7133: } else {
7134: if (copyreg.test(classes)) {
7135: links[i].className = copyclass;
7136: if (value == 1) {
7137: links[i].className += " LC_menubuttons_link";
7138: }
7139: } else {
7140: if (removereg.test(classes)) {
7141: links[i].className = removeclass;
7142: if (value == 1) {
7143: links[i].className += " LC_menubuttons_link";
7144: }
7145: }
1.484.2.29 raeburn 7146: }
7147: }
7148: }
1.484.2.30 raeburn 7149: return;
1.484.2.29 raeburn 7150: }
7151:
1.484.2.30 raeburn 7152: function setBoxes(value) {
7153: var remidxlist = document.cumulativeactions.allremoveidx.value;
7154: if ((remidxlist != '') && (remidxlist != null)) {
7155: var remidxs = remidxlist.split(',');
7156: for (var i=0; i<remidxs.length; i++) {
7157: if (document.getElementById('remove_'+remidxs[i])) {
7158: var item = document.getElementById('remove_'+remidxs[i]);
7159: if (value == 1) {
7160: item.className = 'LC_docs_remove';
7161: } else {
7162: item.className = 'LC_hidden';
7163: }
7164: }
1.484.2.29 raeburn 7165: }
7166: }
1.484.2.30 raeburn 7167: var cutidxlist = document.cumulativeactions.allcutidx.value;
7168: if ((cutidxlist != '') && (cutidxlist != null)) {
7169: var cutidxs = cutidxlist.split(',');
7170: for (var i=0; i<cutidxs.length; i++) {
7171: if (document.getElementById('cut_'+cutidxs[i])) {
7172: var item = document.getElementById('cut_'+cutidxs[i]);
7173: if (value == 1) {
7174: item.className = 'LC_docs_cut';
7175: } else {
7176: item.className = 'LC_hidden';
7177: }
7178: }
7179: }
7180: }
7181: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7182: if ((copyidxlist != '') && (copyidxlist != null)) {
7183: var copyidxs = copyidxlist.split(',');
7184: for (var i=0; i<copyidxs.length; i++) {
7185: if (document.getElementById('copy_'+copyidxs[i])) {
7186: var item = document.getElementById('copy_'+copyidxs[i]);
7187: if (value == 1) {
7188: item.className = 'LC_docs_copy';
7189: } else {
7190: item.className = 'LC_hidden';
7191: }
7192: }
1.484.2.29 raeburn 7193: }
7194: }
7195: return;
7196: }
7197:
1.484.2.67 raeburn 7198: ENDSCRIPT
1.329 droeschl 7199: }
1.457 raeburn 7200:
1.483 raeburn 7201: sub history_tab_js {
7202: return <<"ENDHIST";
7203: function toggleHistoryDisp(choice) {
7204: document.docslogform.docslog.value = choice;
7205: document.docslogform.submit();
7206: return;
7207: }
7208:
7209: ENDHIST
7210: }
7211:
1.484 raeburn 7212: sub inject_data_js {
7213: return <<ENDINJECT;
7214:
7215: function injectData(current, hiddenField, name, value) {
7216: currentElement = document.getElementById(hiddenField);
7217: currentElement.name = name;
7218: currentElement.value = value;
7219: current.submit();
7220: }
7221:
7222: ENDINJECT
7223: }
7224:
7225: sub dump_switchserver_js {
7226: my @hosts = @_;
1.484.2.61 raeburn 7227: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7228: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7229: swit => 'Switch server?',
1.484.2.61 raeburn 7230: );
7231: my %html_js_lt = &Apache::lonlocal::texthash(
7232: swit => 'Switch server?',
1.484.2.43 raeburn 7233: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7234: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7235: chos => 'Choose server',
7236: );
1.484.2.61 raeburn 7237: &js_escape(\%js_lt);
7238: &html_escape(\%html_js_lt);
7239: &js_escape(\%html_js_lt);
1.484 raeburn 7240: my $role = $env{'request.role'};
7241: my $js = <<"ENDSWJS";
7242: <script type="text/javascript">
7243: function write_switchserver() {
7244: var server;
7245: if (document.setserver.posshosts.length > 0) {
7246: for (var i=0; i<document.setserver.posshosts.length; i++) {
7247: if (document.setserver.posshosts[i].checked) {
7248: server = document.setserver.posshosts[i].value;
7249: }
7250: }
7251: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7252: }
7253: window.close();
7254: }
7255: </script>
7256:
7257: ENDSWJS
7258:
7259: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7260: {'only_body' => 1,
7261: 'js_ready' => 1,});
7262: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7263:
7264: my $hostpicker;
7265: my $count = 0;
7266: foreach my $host (sort(@hosts)) {
7267: my $checked;
7268: if ($count == 0) {
7269: $checked = ' checked="checked"';
7270: }
7271: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7272: $host.'"'.$checked.' />'.$host.'</label> ';
7273: $count++;
7274: }
7275:
7276: return <<"ENDSWITCHJS";
7277:
7278: function dump_needs_switchserver(url) {
7279: if (url!='' && url!= null) {
1.484.2.61 raeburn 7280: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7281: go(url);
7282: }
7283: }
7284: return;
7285: }
7286:
7287: function choose_switchserver_window() {
7288: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7289: newWindow.document.open();
7290: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7291: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7292: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7293: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7294: '<form name="setserver" method="post" action="" \\/>\\n'+
7295: '$hostpicker\\n'+
7296: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7297: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7298: 'onclick="write_switchserver();" \\/>\\n'+
7299: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7300: newWindow.document.writeln('$endpage');
7301: newWindow.document.close();
7302: newWindow.focus();
7303: }
7304:
7305: ENDSWITCHJS
7306: }
7307:
7308: sub makedocslogform {
7309: my ($formelems,$docslog) = @_;
7310: return <<"LOGSFORM";
7311: <form action="/adm/coursedocs" method="post" name="docslogform">
7312: <input type="hidden" name="docslog" value="$docslog" />
7313: $formelems
7314: </form>
7315: LOGSFORM
7316: }
7317:
7318: sub makesimpleeditform {
7319: my ($formelems) = @_;
7320: return <<"SIMPFORM";
7321: <form name="simpleedit" method="post" action="/adm/coursedocs">
7322: <input type="hidden" name="importdetail" value="" />
7323: $formelems
7324: </form>
7325: SIMPFORM
7326: }
7327:
1.329 droeschl 7328: 1;
7329: __END__
7330:
7331:
7332: =head1 NAME
7333:
7334: Apache::londocs.pm
7335:
7336: =head1 SYNOPSIS
7337:
7338: This is part of the LearningOnline Network with CAPA project
7339: described at http://www.lon-capa.org.
7340:
7341: =head1 SUBROUTINES
7342:
7343: =over
7344:
7345: =item %help=()
7346:
7347: Available help topics
7348:
7349: =item mapread()
7350:
1.344 bisitz 7351: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7352: @order and @resources, determines status
7353: sets @order - pointer to resources in right order
7354: sets @resources - array with the resources with correct idx
7355:
7356: =item authorhosts()
7357:
7358: Return hash with valid author names
7359:
7360: =item clean()
7361:
7362: =item dumpcourse()
7363:
7364: Actually dump course
7365:
7366: =item group_import()
7367:
7368: Imports the given (name, url) resources into the course
7369: coursenum, coursedom, and folder must precede the list
7370:
7371: =item breadcrumbs()
7372:
7373: =item log_docs()
7374:
7375: =item docs_change_log()
7376:
7377: =item update_paste_buffer()
7378:
7379: =item print_paste_buffer()
7380:
7381: =item do_paste_from_buffer()
7382:
1.484.2.30 raeburn 7383: =item do_buffer_empty()
7384:
7385: =item clear_from_buffer()
7386:
1.484.2.7 raeburn 7387: =item get_newmap_url()
7388:
7389: =item dbcopy()
7390:
7391: =item uniqueness_check()
7392:
7393: =item contained_map_check()
7394:
7395: =item url_paste_fixups()
7396:
7397: =item apply_fixups()
7398:
7399: =item copy_dependencies()
7400:
1.329 droeschl 7401: =item update_parameter()
7402:
7403: =item handle_edit_cmd()
7404:
7405: =item editor()
7406:
7407: =item process_file_upload()
7408:
7409: =item process_secondary_uploads()
7410:
7411: =item is_supplemental_title()
7412:
7413: =item entryline()
7414:
7415: =item tiehash()
7416:
7417: =item untiehash()
7418:
7419: =item checkonthis()
7420:
7421: check on this
7422:
7423: =item verifycontent()
7424:
7425: Verify Content
7426:
7427: =item devalidateversioncache() & checkversions()
7428:
7429: Check Versions
7430:
7431: =item mark_hash_old()
7432:
7433: =item is_hash_old()
7434:
7435: =item changewarning()
7436:
7437: =item init_breadcrumbs()
7438:
7439: Breadcrumbs for special functions
7440:
1.484 raeburn 7441: =item create_list_elements()
7442:
7443: =item create_form_ul()
7444:
7445: =item startContentScreen()
7446:
7447: =item endContentScreen()
7448:
7449: =item supplemental_base()
7450:
7451: =item embedded_form_elems()
7452:
7453: =item embedded_destination()
7454:
7455: =item return_to_editor()
7456:
7457: =item decompression_info()
7458:
7459: =item decompression_phase_one()
7460:
7461: =item decompression_phase_two()
7462:
7463: =item remove_archive()
7464:
7465: =item generate_admin_menu()
7466:
7467: =item generate_edit_table()
7468:
7469: =item editing_js()
7470:
7471: =item history_tab_js()
7472:
7473: =item inject_data_js()
7474:
7475: =item dump_switchserver_js()
7476:
1.484.2.3 raeburn 7477: =item resize_scrollbox_js()
1.484 raeburn 7478:
7479: =item makedocslogform()
7480:
1.484.2.3 raeburn 7481: =item makesimpleeditform()
7482:
1.329 droeschl 7483: =back
7484:
7485: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>