Annotation of loncom/interface/londocs.pm, revision 1.484.2.73
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.73! raeburn 4: # $Id: londocs.pm,v 1.484.2.72 2017/05/19 20:00:45 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);
1962: if (ref($dbref) eq 'HASH') {
1.484.2.71 raeburn 1963: $url = $dbref->{'src'};
1.484.2.26 raeburn 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)) {
1.484.2.72 raeburn 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.484.2.73! raeburn 5115: undef($navmap);
1.329 droeschl 5116: if ($hadchanges) {
5117: &mark_hash_old();
5118: }
1.440 raeburn 5119: $r->print($upload_output);
5120: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5121: # Process file upload - phase two - upload embedded objects
5122: $uploadphase = 'check_embedded';
5123: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5124: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5125: $env{'form.newidx'});
5126: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5127: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5128: my ($destination,$dir_root) = &embedded_destination();
5129: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5130: my $actionurl = '/adm/coursedocs';
5131: my ($result,$flag) =
5132: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5133: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5134: $actionurl);
5135: $r->print($result.&return_to_editor());
5136: } elsif ($env{'form.phase'} eq 'check_embedded') {
5137: # Process file upload - phase three - modify references in HTML file
5138: $uploadphase = 'modified_orightml';
5139: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5140: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5141: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 5142: my $result =
5143: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5144: $docuname,$docudom,undef,
5145: $dir_root);
5146: $r->print($result.&return_to_editor());
1.476 raeburn 5147: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5148: $uploadphase = 'decompress_phase_one';
5149: $r->print(&decompression_phase_one().
5150: &return_to_editor());
5151: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5152: $uploadphase = 'decompress_phase_two';
5153: $r->print(&decompression_phase_two().
5154: &return_to_editor());
1.329 droeschl 5155: }
5156: }
5157:
1.484 raeburn 5158: if ($allowed && $toolsflag) {
5159: $r->print(&startContentScreen('tools'));
1.484.2.67 raeburn 5160: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5161: $r->print(&endContentScreen());
5162: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5163: # -----------------------------------------------------------------------------
5164: my %lt=&Apache::lonlocal::texthash(
5165: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 5166: 'upfi' => 'Upload File',
1.484.2.36 raeburn 5167: 'upld' => 'Upload Content',
1.329 droeschl 5168: 'srch' => 'Search',
5169: 'impo' => 'Import',
1.484.2.19 raeburn 5170: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 5171: 'impm' => 'Import from Assembled Map',
1.329 droeschl 5172: 'selm' => 'Select Map',
5173: 'load' => 'Load Map',
5174: 'newf' => 'New Folder',
5175: 'newp' => 'New Composite Page',
5176: 'syll' => 'Syllabus',
1.425 raeburn 5177: 'navc' => 'Table of Contents',
1.343 biermanm 5178: 'sipa' => 'Simple Course Page',
1.329 droeschl 5179: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 5180: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 5181: 'drbx' => 'Drop Box',
1.451 www 5182: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5183: 'bull' => 'Discussion Board',
1.347 weissno 5184: 'mypi' => 'My Personal Information Page',
1.353 weissno 5185: 'grpo' => 'Group Portfolio',
1.329 droeschl 5186: 'rost' => 'Course Roster',
1.484.2.22 raeburn 5187: 'abou' => 'Personal Information Page for a User',
1.484.2.36 raeburn 5188: 'imsf' => 'IMS Upload',
5189: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 5190: 'cms' => 'Origin of IMS package',
5191: 'se' => 'Select',
1.484.2.19 raeburn 5192: 'file' => 'File',
1.329 droeschl 5193: 'title' => 'Title',
5194: 'comment' => 'Comment',
1.403 raeburn 5195: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.484.2.50 raeburn 5196: 'bb5' => 'Blackboard 5',
5197: 'bb6' => 'Blackboard 6',
5198: 'angel5' => 'ANGEL 5.5',
5199: 'webctce4' => 'WebCT 4 Campus Edition',
1.484.2.67 raeburn 5200: 'er' => 'Editing rights unavailable for your current role.',
1.484.2.50 raeburn 5201: );
1.329 droeschl 5202: # -----------------------------------------------------------------------------
1.484.2.64 raeburn 5203: # Calculate free quota space for a user or course.
5204: my $quotatype = 'unofficial';
5205: if ($crstype eq 'Community') {
5206: $quotatype = 'community';
5207: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5208: $quotatype = 'official';
5209: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5210: $quotatype = 'textbook';
5211: }
5212: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5213: 'course',$quotatype); # expressed in MB
5214: my $current_disk_usage = 0;
5215: foreach my $subdir ('docs','supplemental') {
5216: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5217: "userfiles/$subdir",1); # expressed in kB
5218: }
5219: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
5220: my $usage = $current_disk_usage/1024; # in MB
5221: my $quota = $disk_quota;
5222: my $percent;
5223: if ($disk_quota == 0) {
5224: $percent = 100.0;
5225: } else {
1.484.2.69 raeburn 5226: $percent = 100*($usage/$disk_quota);
1.484.2.64 raeburn 5227: }
5228: $usage = sprintf("%.2f",$usage);
5229: $quota = sprintf("%.2f",$quota);
5230: $percent = sprintf("%.0f",$percent);
5231: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5232: $percent.'%',$quota.' MB').'</p>';
5233:
1.329 droeschl 5234: my $fileupload=(<<FIUP);
1.484.2.64 raeburn 5235: $quotainfo
1.329 droeschl 5236: $lt{'file'}:<br />
1.484.2.67 raeburn 5237: <input type="file" name="uploaddoc" size="40" $disabled />
1.329 droeschl 5238: FIUP
5239:
5240: my $checkbox=(<<CHBO);
5241: <!-- <label>$lt{'parse'}?
5242: <input type="checkbox" name="parserflag" />
5243: </label> -->
5244: <label>
1.484.2.67 raeburn 5245: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5246: </label>
5247: CHBO
1.484.2.12 raeburn 5248: my $imsfolder = $env{'form.folder'};
5249: if ($imsfolder eq '') {
1.484.2.19 raeburn 5250: $imsfolder = 'default';
1.484.2.12 raeburn 5251: }
5252: my $imspform=(<<IMSFORM);
5253: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5254: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5255: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 5256: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 5257: <legend>$lt{'imsf'}</legend>
5258: $fileupload
5259: <br />
5260: <p>
1.484.2.19 raeburn 5261: $lt{'cms'}:
1.484.2.67 raeburn 5262: <select name="source" $disabled>
1.484.2.12 raeburn 5263: <option value="-1" selected="selected">$lt{'se'}</option>
1.484.2.50 raeburn 5264: <option value="bb5">$lt{'bb5'}</option>
5265: <option value="bb6">$lt{'bb6'}</option>
5266: <option value="angel5">$lt{'angel5'}</option>
5267: <option value="webctce4">$lt{'webctce4'}</option>
1.484.2.12 raeburn 5268: </select>
5269: <input type="hidden" name="folder" value="$imsfolder" />
5270: </p>
5271: <input type="hidden" name="phase" value="one" />
1.484.2.67 raeburn 5272: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.484.2.12 raeburn 5273: </fieldset>
5274: </form>
5275: IMSFORM
5276:
1.484.2.19 raeburn 5277: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 5278: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5279: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5280: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 5281: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 5282: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5283: <input type="hidden" name="active" value="aa" />
1.329 droeschl 5284: $fileupload
5285: <br />
5286: $lt{'title'}:<br />
1.484.2.67 raeburn 5287: <input type="text" size="60" name="comment" $disabled />
1.484.2.17 raeburn 5288: $pathitem
1.329 droeschl 5289: <input type="hidden" name="cmd" value="upload_default" />
5290: <br />
1.458 raeburn 5291: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5292: $checkbox
5293: </span>
1.484.2.12 raeburn 5294: <br clear="all" />
1.484.2.67 raeburn 5295: <input type="submit" value="$lt{'upld'}" $disabled />
1.484.2.12 raeburn 5296: </fieldset>
5297: </form>
1.383 tempelho 5298: FUFORM
1.329 droeschl 5299:
1.484.2.67 raeburn 5300: my $mapimportjs;
5301: if ($canedit) {
5302: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5303: } else {
5304: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5305: }
1.484.2.19 raeburn 5306: my $importpubform=(<<SEDFFORM);
5307: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 5308: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 5309: <form action="/adm/coursedocs" method="post" name="mapimportform">
5310: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 5311: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 5312: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 5313: $lt{'copm'}<br />
5314: <span class="LC_nobreak">
1.484.2.19 raeburn 5315: <input type="text" name="importmap" size="40" value=""
1.484.2.67 raeburn 5316: onfocus="this.blur();$mapimportjs" $disabled />
5317: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5318: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.484.2.13 raeburn 5319: </fieldset>
5320: </form>
5321:
1.383 tempelho 5322: SEDFFORM
1.484.2.67 raeburn 5323:
5324: my $fromstoredjs;
5325: if ($canedit) {
5326: $fromstoredjs = 'open_StoredLinks_Import()';
5327: } else {
5328: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5329: }
5330:
1.484.2.19 raeburn 5331: my @importpubforma = (
5332: { '<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 5333: { '<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 5334: { '<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 5335: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
5336: );
5337: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
5338: my $extresourcesform =
5339: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5340: $help{'Adding_External_Resource'},
5341: undef,undef,$disabled);
1.329 droeschl 5342: if ($allowed) {
1.484.2.7 raeburn 5343: my $folder = $env{'form.folder'};
5344: if ($folder eq '') {
5345: $folder='default';
5346: }
1.484.2.67 raeburn 5347: if ($canedit) {
5348: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5349: if ($output) {
5350: $r->print($output);
5351: }
1.484.2.30 raeburn 5352: }
1.337 ehlerst 5353: $r->print(<<HIDDENFORM);
5354: <form name="renameform" method="post" action="/adm/coursedocs">
5355: <input type="hidden" name="title" />
5356: <input type="hidden" name="cmd" />
5357: <input type="hidden" name="markcopy" />
5358: <input type="hidden" name="copyfolder" />
5359: $containertag
5360: </form>
1.484 raeburn 5361:
1.337 ehlerst 5362: HIDDENFORM
1.484.2.17 raeburn 5363: $r->print(&makesimpleeditform($pathitem)."\n".
5364: &makedocslogform($pathitem."\n".
1.484 raeburn 5365: '<input type="hidden" name="folder" value="'.
5366: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 5367: }
1.442 www 5368:
5369: # Generate the tabs
1.484.2.19 raeburn 5370: my ($mode,$needs_end);
1.472 raeburn 5371: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 5372: my @folders = split('&',$env{'form.folderpath'});
5373: unless (@folders > 2) {
5374: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
5375: $needs_end = 1;
5376: }
1.472 raeburn 5377: } else {
1.484 raeburn 5378: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 5379: $needs_end = 1;
1.472 raeburn 5380: }
1.443 www 5381:
1.442 www 5382: #
5383:
5384: my $savefolderpath;
5385:
1.395 raeburn 5386: if ($allowed) {
1.329 droeschl 5387: my $folder=$env{'form.folder'};
1.484.2.67 raeburn 5388: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 5389: $folder='default';
1.356 tempelho 5390: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 5391: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 5392: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 5393: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
5394: }
5395: my $postexec='';
5396: if ($folder eq 'default') {
1.372 bisitz 5397: $r->print('<script type="text/javascript">'."\n"
5398: .'// <![CDATA['."\n"
5399: .'this.window.name="loncapaclient";'."\n"
5400: .'// ]]>'."\n"
5401: .'</script>'."\n"
1.369 bisitz 5402: );
1.329 droeschl 5403: } else {
5404: #$postexec='self.close();';
5405: }
1.484.2.15 raeburn 5406: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
5407: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 5408: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
5409:
5410: my $newnavform=(<<NNFORM);
5411: <form action="/adm/coursedocs" method="post" name="newnav">
1.484.2.43 raeburn 5412: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5413: $pathitem
1.329 droeschl 5414: <input type="hidden" name="importdetail"
5415: value="$lt{'navc'}=/adm/navmaps" />
1.484.2.67 raeburn 5416: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 5417: $help{'Navigate_Content'}
5418: </form>
5419: NNFORM
5420: my $newsmppageform=(<<NSPFORM);
5421: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.484.2.43 raeburn 5422: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5423: $pathitem
1.329 droeschl 5424: <input type="hidden" name="importdetail" value="" />
1.423 onken 5425: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 5426: $help{'Simple Page'}
1.329 droeschl 5427: </form>
5428: NSPFORM
5429:
5430: my $newsmpproblemform=(<<NSPROBFORM);
5431: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 5432: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5433: $pathitem
1.329 droeschl 5434: <input type="hidden" name="importdetail" value="" />
1.423 onken 5435: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.484.2.44 raeburn 5436: $help{'Simple_Problem'}
1.329 droeschl 5437: </form>
5438:
5439: NSPROBFORM
5440:
5441: my $newdropboxform=(<<NDBFORM);
5442: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 5443: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5444: $pathitem
1.329 droeschl 5445: <input type="hidden" name="importdetail" value="" />
1.423 onken 5446: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.484.2.36 raeburn 5447: $help{'Dropbox'}
1.344 bisitz 5448: </form>
1.329 droeschl 5449: NDBFORM
5450:
5451: my $newexuploadform=(<<NEXUFORM);
5452: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 5453: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 5454: $pathitem
1.329 droeschl 5455: <input type="hidden" name="importdetail" value="" />
1.423 onken 5456: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 5457: $help{'Score_Upload_Form'}
5458: </form>
5459: NEXUFORM
5460:
5461: my $newbulform=(<<NBFORM);
5462: <form action="/adm/coursedocs" method="post" name="newbul">
1.484.2.43 raeburn 5463: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5464: $pathitem
1.329 droeschl 5465: <input type="hidden" name="importdetail" value="" />
1.423 onken 5466: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5467: $help{'Bulletin Board'}
5468: </form>
5469: NBFORM
5470:
5471: my $newaboutmeform=(<<NAMFORM);
5472: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.484.2.43 raeburn 5473: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5474: $pathitem
1.329 droeschl 5475: <input type="hidden" name="importdetail"
5476: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5477: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 5478: $help{'My Personal Information Page'}
1.329 droeschl 5479: </form>
5480: NAMFORM
5481:
5482: my $newaboutsomeoneform=(<<NASOFORM);
5483: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.484.2.43 raeburn 5484: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5485: $pathitem
1.329 droeschl 5486: <input type="hidden" name="importdetail" value="" />
1.423 onken 5487: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5488: </form>
5489: NASOFORM
5490:
5491: my $newrosterform=(<<NROSTFORM);
5492: <form action="/adm/coursedocs" method="post" name="newroster">
1.484.2.43 raeburn 5493: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5494: $pathitem
1.329 droeschl 5495: <input type="hidden" name="importdetail"
5496: value="$lt{'rost'}=/adm/viewclasslist" />
1.484.2.67 raeburn 5497: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.484.2.37 raeburn 5498: $help{'Course_Roster'}
1.329 droeschl 5499: </form>
5500: NROSTFORM
5501:
1.484.2.27 raeburn 5502: my $newwebpage;
5503: if ($folder =~ /^default_?(\d*)$/) {
5504: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5505: if ($1) {
5506: $newwebpage .= $1;
5507: } else {
5508: $newwebpage .= 'default';
5509: }
5510: $newwebpage .= '/new.html';
5511: }
5512: my $newwebpageform =(<<NWEBFORM);
5513: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.484.2.43 raeburn 5514: <input type="hidden" name="active" value="ee" />
1.484.2.27 raeburn 5515: $pathitem
5516: <input type="hidden" name="importdetail" value="$newwebpage" />
5517: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36 raeburn 5518: $help{'Web_Page'}
1.484.2.27 raeburn 5519: </form>
5520: NWEBFORM
1.484.2.30 raeburn 5521:
1.484.2.27 raeburn 5522:
1.342 ehlerst 5523: my $specialdocumentsform;
1.383 tempelho 5524: my @specialdocumentsforma;
1.451 www 5525: my $gradingform;
5526: my @gradingforma;
5527: my $communityform;
5528: my @communityforma;
1.351 ehlerst 5529: my $newfolderform;
1.390 tempelho 5530: my $newfolderb;
1.342 ehlerst 5531:
1.451 www 5532: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5533:
1.329 droeschl 5534: my $newpageform=(<<NPFORM);
5535: <form action="/adm/coursedocs" method="post" name="newpage">
5536: <input type="hidden" name="folderpath" value="$path" />
5537: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5538: <input type="hidden" name="active" value="ee" />
1.423 onken 5539: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5540: $help{'Adding_Pages'}
1.329 droeschl 5541: </form>
5542: NPFORM
1.390 tempelho 5543:
5544:
1.351 ehlerst 5545: $newfolderform=(<<NFFORM);
1.329 droeschl 5546: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 5547: $pathitem
1.329 droeschl 5548: <input type="hidden" name="importdetail" value="" />
1.484.2.43 raeburn 5549: <input type="hidden" name="active" value="" />
1.422 onken 5550: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5551: </form>
5552: NFFORM
5553:
5554: my $newsylform=(<<NSYLFORM);
5555: <form action="/adm/coursedocs" method="post" name="newsyl">
1.484.2.43 raeburn 5556: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 5557: $pathitem
1.329 droeschl 5558: <input type="hidden" name="importdetail"
5559: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5560: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 5561: $help{'Syllabus'}
1.383 tempelho 5562:
1.329 droeschl 5563: </form>
5564: NSYLFORM
1.364 bisitz 5565:
1.329 droeschl 5566: my $newgroupfileform=(<<NGFFORM);
5567: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.484.2.43 raeburn 5568: <input type="hidden" name="active" value="dd" />
1.484.2.17 raeburn 5569: $pathitem
1.329 droeschl 5570: <input type="hidden" name="importdetail"
5571: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.484.2.67 raeburn 5572: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 5573: $help{'Group Portfolio'}
1.329 droeschl 5574: </form>
5575: NGFFORM
1.383 tempelho 5576: @specialdocumentsforma=(
1.421 onken 5577: {'<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 5578: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
5579: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 5580: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 5581: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5582: );
5583: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5584:
1.434 raeburn 5585:
5586: my @importdoc = (
1.484.2.19 raeburn 5587: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5588: );
5589: unless ($container eq 'page') {
5590: push(@importdoc,
5591: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5592: );
5593: }
5594: push(@importdoc,
1.484.2.38 raeburn 5595: {'<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 5596: );
1.484.2.12 raeburn 5597: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5598:
1.451 www 5599: @gradingforma=(
5600: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5601: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5602: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5603:
5604: );
5605: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5606:
5607: @communityforma=(
5608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5609: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.484.2.67 raeburn 5611: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
5612: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 5613: );
5614: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5615:
1.330 tempelho 5616: my %orderhash = (
1.484.2.36 raeburn 5617: 'aa' => ['Upload',$fileuploadform],
5618: 'bb' => ['Import',$importpubform],
5619: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5620: );
1.484.2.19 raeburn 5621: unless ($container eq 'page') {
1.434 raeburn 5622: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5623: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36 raeburn 5624: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5625: }
5626:
1.341 ehlerst 5627: $hadchanges=0;
1.484 raeburn 5628: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5629: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5630: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.484.2.68 raeburn 5631: $canedit,\$navmap,$hiddentop);
1.484.2.67 raeburn 5632: undef($navmap);
1.443 www 5633: if ($error) {
5634: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5635: }
1.484.2.73! raeburn 5636: unless (&is_hash_old()) {
1.443 www 5637: if ($hadchanges) {
1.484.2.73! raeburn 5638: unless (&is_hash_old()) {
! 5639: &mark_hash_old();
! 5640: }
1.443 www 5641: }
1.341 ehlerst 5642:
1.443 www 5643: &changewarning($r,'');
5644: }
1.458 raeburn 5645: }
1.442 www 5646:
1.443 www 5647: # Supplemental documents start here
5648:
1.329 droeschl 5649: my $folder=$env{'form.folder'};
1.443 www 5650: unless ($supplementalflag) {
1.329 droeschl 5651: $folder='supplemental';
5652: }
5653: if ($folder =~ /^supplemental$/ &&
5654: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5655: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5656: } elsif ($allowed) {
1.356 tempelho 5657: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5658: }
1.484.2.17 raeburn 5659: $pathitem = '<input type="hidden" name="folderpath" value="'.
5660: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5661: if ($allowed) {
5662: my $folderseq=
1.484.2.15 raeburn 5663: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5664:
5665: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 5666: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5667: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5668: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 5669: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 5670: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5671: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5672: $fileupload
5673: <br />
5674: <br />
5675: <span class="LC_nobreak">
5676: $checkbox
5677: </span>
5678: <br /><br />
5679: $lt{'comment'}:<br />
1.383 tempelho 5680: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5681: <br />
1.484.2.19 raeburn 5682: $pathitem
1.329 droeschl 5683: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 5684: <input type='submit' value="$lt{'upld'}" />
5685: </form>
1.484.2.19 raeburn 5686: SUPDOCFORM
1.329 droeschl 5687:
5688: my $supnewfolderform=(<<SNFFORM);
5689: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.484.2.43 raeburn 5690: <input type="hidden" name="active" value="" />
1.484.2.17 raeburn 5691: $pathitem
1.329 droeschl 5692: <input type="hidden" name="importdetail" value="" />
1.423 onken 5693: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5694: $help{'Adding_Folders'}
1.329 droeschl 5695: </form>
5696: SNFFORM
1.383 tempelho 5697:
1.484.2.19 raeburn 5698: my $supextform =
5699: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.484.2.67 raeburn 5700: $help{'Adding_External_Resource'},
5701: undef,undef,$disabled);
1.329 droeschl 5702:
5703: my $supnewsylform=(<<SNSFORM);
5704: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5705: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5706: $pathitem
1.329 droeschl 5707: <input type="hidden" name="importdetail"
5708: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.484.2.67 raeburn 5709: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 5710: $help{'Syllabus'}
5711: </form>
5712: SNSFORM
5713:
5714: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5715: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5716: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 5717: $pathitem
1.329 droeschl 5718: <input type="hidden" name="importdetail"
5719: value="$plainname=/adm/$udom/$uname/aboutme" />
1.484.2.67 raeburn 5720: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 5721: $help{'My Personal Information Page'}
1.329 droeschl 5722: </form>
5723: SNAMFORM
5724:
1.484.2.27 raeburn 5725: my $supwebpage;
5726: if ($folder =~ /^supplemental_?(\d*)$/) {
5727: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5728: if ($1) {
5729: $supwebpage .= $1;
5730: } else {
5731: $supwebpage .= 'default';
5732: }
5733: $supwebpage .= '/new.html';
5734: }
5735: my $supwebpageform =(<<SWEBFORM);
5736: <form action="/adm/coursedocs" method="post" name="supwebpage">
5737: <input type="hidden" name="active" value="cc" />
5738: $pathitem
5739: <input type="hidden" name="importdetail" value="$supwebpage" />
5740: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36 raeburn 5741: $help{'Web_Page'}
1.484.2.27 raeburn 5742: </form>
5743: SWEBFORM
5744:
1.333 muellerd 5745:
1.383 tempelho 5746: my @specialdocs = (
1.484.2.67 raeburn 5747: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 5748: =>$supnewsylform},
1.484.2.67 raeburn 5749: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 5750: =>$supnewaboutmeform},
1.484.2.27 raeburn 5751: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5752:
1.383 tempelho 5753: );
1.417 droeschl 5754: my @supimportdoc = (
1.484.2.19 raeburn 5755: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 5756: =>$supextform},
5757: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5758: =>$supupdocform},
1.484.2.19 raeburn 5759: );
5760:
1.484.2.12 raeburn 5761: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5762: my %suporderhash = (
1.390 tempelho 5763: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36 raeburn 5764: 'ee' => ['Upload',$supupdocform],
5765: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5766: );
1.443 www 5767: if ($supplementalflag) {
1.458 raeburn 5768: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.67 raeburn 5769: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
5770: $canedit);
1.443 www 5771: if ($error) {
5772: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.484.2.37 raeburn 5773: } else {
5774: if ($suppchanges) {
5775: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5776: my @ids=&Apache::lonnet::current_machine_ids();
5777: foreach my $server (keys(%servers)) {
5778: next if (grep(/^\Q$server\E$/,@ids));
5779: my $hashid=$coursenum.':'.$coursedom;
1.484.2.42 raeburn 5780: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5781: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.484.2.37 raeburn 5782: }
5783: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5784: undef($suppchanges);
5785: }
1.443 www 5786: }
1.393 raeburn 5787: }
1.443 www 5788: } elsif ($supplementalflag) {
1.458 raeburn 5789: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 5790: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5791: if ($error) {
5792: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5793: }
1.393 raeburn 5794: }
1.389 tempelho 5795:
1.484.2.19 raeburn 5796: if ($needs_end) {
5797: $r->print(&endContentScreen());
5798: }
1.383 tempelho 5799:
1.329 droeschl 5800: if ($allowed) {
5801: $r->print('
5802: <form method="post" name="extimport" action="/adm/coursedocs">
5803: <input type="hidden" name="title" />
5804: <input type="hidden" name="url" />
5805: <input type="hidden" name="useform" />
5806: <input type="hidden" name="residx" />
5807: </form>');
5808: }
1.484 raeburn 5809: } elsif ($showdoc) {
1.329 droeschl 5810: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5811: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5812: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5813: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5814: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5815: }
5816: }
5817: $r->print(&Apache::loncommon::end_page());
5818: return OK;
1.364 bisitz 5819: }
1.329 droeschl 5820:
1.440 raeburn 5821: sub embedded_form_elems {
5822: my ($phase,$primaryurl,$newidx) = @_;
5823: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5824: return <<STATE;
5825: <input type="hidden" name="folderpath" value="$folderpath" />
5826: <input type="hidden" name="cmd" value="upload_embedded" />
5827: <input type="hidden" name="newidx" value="$newidx" />
5828: <input type="hidden" name="phase" value="$phase" />
5829: <input type="hidden" name="primaryurl" value="$primaryurl" />
5830: STATE
5831: }
5832:
5833: sub embedded_destination {
5834: my $folder=$env{'form.folder'};
5835: my $destination = 'docs/';
5836: if ($folder =~ /^supplemental/) {
5837: $destination = 'supplemental/';
5838: }
5839: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5840: $destination .= 'default/';
5841: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5842: $destination .= $2.'/';
5843: }
5844: $destination .= $env{'form.newidx'};
5845: my $dir_root = '/userfiles';
5846: return ($destination,$dir_root);
5847: }
5848:
5849: sub return_to_editor {
5850: my $actionurl = '/adm/coursedocs';
5851: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5852: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5853: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5854: '</a></p>';
5855: }
5856:
1.476 raeburn 5857: sub decompression_info {
5858: my ($destination,$dir_root) = &embedded_destination();
5859: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5860: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5861: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5862: my $container='sequence';
1.480 raeburn 5863: my ($pathitem,$hiddenelem);
1.484.2.54 raeburn 5864: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.484.2.19 raeburn 5865: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5866: $container='page';
5867: }
1.480 raeburn 5868: unshift(@hiddens,$pathitem);
5869: foreach my $item (@hiddens) {
5870: if ($env{'form.'.$item}) {
5871: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.484.2.54 raeburn 5872: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 5873: }
1.477 raeburn 5874: }
1.476 raeburn 5875: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5876: $hiddenelem);
5877: }
5878:
5879: sub decompression_phase_one {
5880: my ($dir,$file,$warning,$error,$output);
5881: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5882: &decompression_info();
1.484.2.7 raeburn 5883: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5884: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5885: } else {
5886: my $file = $1;
1.481 raeburn 5887: $output =
5888: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5889: $destination,$dir_root,
5890: $hiddenelem);
5891: if ($env{'form.autoextract_camtasia'}) {
5892: $output .= &remove_archive($docudom,$docuname,$container);
5893: }
1.476 raeburn 5894: }
5895: if ($error) {
5896: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5897: $error.'</p>'."\n";
5898: }
5899: if ($warning) {
5900: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5901: }
5902: return $output;
5903: }
5904:
5905: sub decompression_phase_two {
5906: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5907: &decompression_info();
1.481 raeburn 5908: my $output;
1.480 raeburn 5909: if ($env{'form.archivedelete'}) {
1.481 raeburn 5910: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5911: }
5912: $output .=
1.481 raeburn 5913: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5914: $destination,$dir_root,$hiddenelem);
5915: return $output;
5916: }
5917:
1.480 raeburn 5918: sub remove_archive {
5919: my ($docudom,$docuname,$container) = @_;
5920: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5921: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5922: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5923: if ($fatal) {
5924: if ($container eq 'page') {
5925: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5926: } else {
5927: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5928: }
1.484.2.54 raeburn 5929: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5930: } else {
5931: my $currcmd = $env{'form.cmd'};
5932: my $position = $env{'form.position'};
1.484.2.54 raeburn 5933: my $archiveidx = $position;
5934: if ($position > 0) {
5935: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
5936: $archiveidx = $position-1;
5937: }
5938: $env{'form.cmd'} = 'remove_'.$archiveidx;
5939: my ($title,$url,@rrest) =
5940: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
5941: if ($url eq $env{'form.archiveurl'}) {
5942: if (&handle_edit_cmd($docuname,$docudom)) {
5943: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
5944: if ($fatal) {
5945: if ($container eq 'page') {
5946: $delwarning = &mt('An error occurred updating the contents of the current page.');
5947: } else {
5948: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5949: }
1.480 raeburn 5950: } else {
1.484.2.54 raeburn 5951: $delresult = &mt('Archive file removed.');
1.480 raeburn 5952: }
5953: }
1.484.2.54 raeburn 5954: } else {
5955: $delwarning .= &mt('Archive file had unexpected item number in folder.').
5956: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 5957: }
5958: }
5959: $env{'form.cmd'} = $currcmd;
5960: }
5961: if ($delwarning) {
5962: $output = '<p class="LC_warning">'.
5963: $delwarning.
5964: '</p>';
5965: }
5966: if ($delresult) {
5967: $output .= '<p class="LC_info">'.
5968: $delresult.
5969: '</p>';
5970: }
1.481 raeburn 5971: return $output;
1.480 raeburn 5972: }
5973:
1.484 raeburn 5974: sub generate_admin_menu {
1.484.2.67 raeburn 5975: my ($crstype,$canedit) = @_;
1.484 raeburn 5976: my $lc_crstype = lc($crstype);
5977: my ($home,$other,%outhash)=&authorhosts();
1.484.2.43 raeburn 5978: my %lt= ( # do not translate here
1.484 raeburn 5979: 'vc' => 'Verify Content',
5980: 'cv' => 'Check/Set Resource Versions',
5981: 'ls' => 'List Resource Identifiers',
5982: 'imse' => 'Export contents to IMS Archive',
1.484.2.43 raeburn 5983: 'dcd' => "Copy $crstype Content to Authoring Space",
5984: );
1.484 raeburn 5985: my ($candump,$dumpurl);
5986: if ($home + $other > 0) {
5987: $candump = 'F';
5988: if ($home) {
5989: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5990: } else {
5991: my @hosts;
5992: foreach my $aurole (keys(%outhash)) {
5993: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5994: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 5995: }
1.484 raeburn 5996: }
5997: if (@hosts == 1) {
5998: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5999: '&role='.
6000: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6001: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6002: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6003: } else {
6004: $dumpurl = "javascript:choose_switchserver_window()";
6005: }
6006: }
6007: }
6008: my @menu=
6009: ({ categorytitle=>'Administration',
6010: items =>[
6011: { linktext => $lt{'vc'},
6012: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6013: permission => 'F',
1.484.2.44 raeburn 6014: help => 'Docs_Verify_Content',
1.484 raeburn 6015: icon => 'verify.png',
6016: linktitle => 'Verify contents can be retrieved/rendered',
6017: },
6018: { linktext => $lt{'cv'},
6019: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6020: permission => 'F',
1.484.2.44 raeburn 6021: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6022: icon => 'resversion.png',
6023: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6024: },
6025: { linktext => $lt{'ls'},
6026: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6027: permission => 'F',
6028: #help => '',
6029: icon => 'symbs.png',
6030: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6031: },
6032: ]
1.484.2.67 raeburn 6033: });
6034: if ($canedit) {
6035: push(@menu,
1.484 raeburn 6036: { categorytitle=>'Export',
6037: items =>[
6038: { linktext => $lt{'imse'},
6039: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6040: permission => 'F',
6041: help => 'Docs_Export_Course_Docs',
6042: icon => 'imsexport.png',
6043: linktitle => $lt{'imse'},
6044: },
6045: { linktext => $lt{'dcd'},
6046: url => $dumpurl,
6047: permission => $candump,
1.484.2.44 raeburn 6048: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6049: icon => 'dump.png',
6050: linktitle => $lt{'dcd'},
6051: },
6052: ]
6053: });
1.484.2.67 raeburn 6054: }
1.484 raeburn 6055: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6056: '<input type="hidden" id="dummy" />'."\n".
6057: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6058: '</form>';
1.329 droeschl 6059: }
6060:
6061: sub generate_edit_table {
1.484.2.30 raeburn 6062: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.484.2.67 raeburn 6063: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6064: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6065: my %orderhash = %{$orderhash_ref};
1.484.2.67 raeburn 6066: my ($form, $activetab, $active, $disabled);
1.484.2.43 raeburn 6067: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6068: $activetab = $env{'form.active'};
6069: }
1.484.2.67 raeburn 6070: unless ($canedit) {
6071: $disabled = ' disabled="disabled"';
6072: }
1.472 raeburn 6073: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 6074: my $backtext = &mt('Exit Editor');
1.458 raeburn 6075: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 6076: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6077: '<li class="goback">'.
1.484.2.32 raeburn 6078: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 6079: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6080: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6081: '<li>'.
6082: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6083: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 6084: if ($env{'form.docslog'}) {
6085: $form .= '<li class="active">';
6086: } else {
6087: $form .= '<li>';
6088: }
6089: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6090: &mt('History').'</a></li>'."\n";
6091: if ($env{'form.docslog'}) {
6092: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6093: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6094: }
1.458 raeburn 6095: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6096: if($name ne '00'){
1.371 tempelho 6097: if($activetab eq '' || $activetab ne $name){
6098: $active = '';
6099: }elsif($activetab eq $name){
6100: $active = 'class="active"';
6101: }
1.458 raeburn 6102: $form .= '<li style="float:right" '.$active
1.484 raeburn 6103: .' 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 6104: } else {
1.484.2.43 raeburn 6105: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6106:
6107: }
1.329 droeschl 6108: }
1.484 raeburn 6109: $form .= '</ul>'."\n";
6110: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6111:
6112: if ($to_show ne '') {
1.484.2.30 raeburn 6113: my $saveform;
6114: if ($need_save) {
6115: my $button = &mt('Make changes');
6116: my $path;
6117: if ($env{'form.folderpath'}) {
6118: $path =
6119: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6120: }
6121: $saveform = <<"END";
6122: <div id="multisave" style="display:none; clear:both;" >
6123: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
6124: <input type="hidden" name="folderpath" value="$path" />
6125: <input type="hidden" name="symb" value="$env{'form.symb'}" />
6126: <input type="hidden" name="allhiddenresource" value="" />
6127: <input type="hidden" name="allencrypturl" value="" />
6128: <input type="hidden" name="allrandompick" value="" />
6129: <input type="hidden" name="allrandomorder" value="" />
6130: <input type="hidden" name="changeparms" value="" />
6131: <input type="hidden" name="multiremove" value="" />
6132: <input type="hidden" name="multicut" value="" />
6133: <input type="hidden" name="multicopy" value="" />
6134: <input type="hidden" name="multichange" value="" />
6135: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.484.2.67 raeburn 6136: <input type="submit" name="savemultiples" value="$button" $disabled />
1.484.2.30 raeburn 6137: </form>
6138: </div>
6139: END
6140: }
6141: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 6142: }
1.363 ehlerst 6143: foreach my $field (keys(%orderhash)){
1.390 tempelho 6144: if($field ne '00'){
1.422 onken 6145: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 6146: $active = 'style="display: none;float:left"';
1.422 onken 6147: }elsif($activetab eq $field){
1.458 raeburn 6148: $active = 'style="display:block;float:left"';
1.422 onken 6149: }
6150: $form .= '<div id="'.$field.$tid.'"'
6151: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 6152: .'</div>'."\n";
1.363 ehlerst 6153: }
6154: }
1.484 raeburn 6155: unless ($env{'form.docslog'}) {
6156: $form .= '</div></div>'."\n";
6157: }
1.329 droeschl 6158: return $form;
6159: }
6160:
6161: sub editing_js {
1.484.2.67 raeburn 6162: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$canedit,$navmapref) = @_;
1.484.2.61 raeburn 6163: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 6164: p_mnf => 'Name of New Folder',
6165: t_mnf => 'New Folder',
6166: p_mnp => 'Name of New Page',
6167: t_mnp => 'New Page',
1.451 www 6168: p_mxu => 'Title for the External Score',
1.349 biermanm 6169: p_msp => 'Name of Simple Course Page',
1.329 droeschl 6170: p_msb => 'Title for the Problem',
6171: p_mdb => 'Title for the Drop Box',
1.336 schafran 6172: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 6173: p_mwp => 'Title for Web Page',
1.348 weissno 6174: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 6175: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 6176: p_mab_alrt1 => 'Not a valid user:domain',
6177: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
6178: p_chn => 'New Title',
6179: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.484.2.63 raeburn 6180: p_rmr2a => 'Remove',
6181: p_rmr2b => '?',
6182: p_rmr3a => 'Remove those',
6183: p_rmr3b => 'items?',
6184: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
6185: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 6186: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
6187: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.484.2.63 raeburn 6188: p_ctr2a => 'Cut',
6189: p_ctr2b => '?',
6190: p_ctr3a => 'Cut those',
6191: p_ctr3b => 'items?',
1.478 raeburn 6192: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 6193: imsfile => 'You must choose an IMS package for import',
6194: imscms => 'You must select which Course Management System was the source of the IMS package',
6195: invurl => 'Invalid URL',
6196: titbl => 'Title is blank',
1.484.2.30 raeburn 6197: more => '(More ...)',
6198: less => '(Less ...)',
6199: noor => 'No actions selected or changes to settings specified.',
6200: noch => 'No changes to settings specified.',
6201: noac => 'No actions selected.',
1.484.2.67 raeburn 6202: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 6203: );
6204:
1.484.2.61 raeburn 6205: &js_escape(\%js_lt);
1.433 raeburn 6206: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 6207: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
6208: my $main_container_page;
1.484.2.19 raeburn 6209: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
6210: $main_container_page = 1;
1.434 raeburn 6211: }
1.484.2.67 raeburn 6212: my $backtourl;
6213: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 6214: my $toplevelsupp = &supplemental_base();
1.433 raeburn 6215:
1.484.2.21 raeburn 6216: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
6217: my $caller = $1;
6218: if ($caller =~ /^supplemental/) {
6219: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
6220: } else {
6221: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
6222: $res = &Apache::lonnet::clutter($res);
6223: if (&Apache::lonnet::is_on_map($res)) {
1.484.2.66 raeburn 6224: my ($url,$anchor);
6225: if ($res =~ /^([^#]+)#([^#]+)$/) {
6226: $url = $1;
6227: $anchor = $2;
6228: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
6229: $caller = $1.&escape('#').$anchor;
6230: }
1.484.2.67 raeburn 6231: } else {
6232: $url = $res;
1.484.2.66 raeburn 6233: }
6234: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.
1.484.2.21 raeburn 6235: &HTML::Entities::encode($caller,'<>&"');
1.484.2.66 raeburn 6236: if ($anchor ne '') {
6237: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
6238: }
1.484.2.57 raeburn 6239: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.484.2.31 raeburn 6240: } else {
6241: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 6242: }
6243: }
6244: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
6245: $backtourl = '/adm/menu';
6246: } elsif ($supplementalflag) {
1.472 raeburn 6247: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 6248: } else {
6249: $backtourl = '/adm/navmaps';
1.472 raeburn 6250: }
6251:
1.484.2.19 raeburn 6252: my $fieldsets = "'ext','doc'";
6253: unless ($main_container_page) {
6254: $fieldsets .=",'ims'";
6255: }
1.484.2.12 raeburn 6256: if ($supplementalflag) {
6257: $fieldsets = "'suppext','suppdoc'";
6258: }
6259:
1.484.2.67 raeburn 6260: my $jsmakefunctions;
6261: if ($canedit) {
6262: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 6263: function makenewfolder(targetform,folderseq) {
1.484.2.65 raeburn 6264: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 6265: if (foldername) {
6266: targetform.importdetail.value=escape(foldername)+"="+folderseq;
6267: targetform.submit();
6268: }
6269: }
6270:
6271: function makenewpage(targetform,folderseq) {
1.484.2.61 raeburn 6272: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 6273: if (pagename) {
6274: targetform.importdetail.value=escape(pagename)+"="+folderseq;
6275: targetform.submit();
6276: }
6277: }
6278:
6279: function makeexamupload() {
1.484.2.61 raeburn 6280: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 6281: if (title) {
1.329 droeschl 6282: this.document.forms.newexamupload.importdetail.value=
6283: escape(title)+'=/res/lib/templates/examupload.problem';
6284: this.document.forms.newexamupload.submit();
6285: }
6286: }
6287:
6288: function makesmppage() {
1.484.2.61 raeburn 6289: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 6290: if (title) {
1.329 droeschl 6291: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 6292: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 6293: this.document.forms.newsmppg.submit();
6294: }
6295: }
6296:
1.484.2.27 raeburn 6297: function makewebpage(type) {
1.484.2.61 raeburn 6298: var title=prompt('$js_lt{"p_mwp"}');
1.484.2.27 raeburn 6299: var formname;
6300: if (type == 'supp') {
6301: formname = this.document.forms.supwebpage;
6302: } else {
6303: formname = this.document.forms.newwebpage;
6304: }
6305: if (title) {
6306: var webpage = formname.importdetail.value;
6307: formname.importdetail.value = escape(title)+'='+webpage;
6308: formname.submit();
6309: }
6310: }
6311:
1.329 droeschl 6312: function makesmpproblem() {
1.484.2.61 raeburn 6313: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 6314: if (title) {
1.329 droeschl 6315: this.document.forms.newsmpproblem.importdetail.value=
6316: escape(title)+'=/res/lib/templates/simpleproblem.problem';
6317: this.document.forms.newsmpproblem.submit();
6318: }
6319: }
6320:
6321: function makedropbox() {
1.484.2.61 raeburn 6322: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 6323: if (title) {
1.329 droeschl 6324: this.document.forms.newdropbox.importdetail.value=
6325: escape(title)+'=/res/lib/templates/DropBox.problem';
6326: this.document.forms.newdropbox.submit();
6327: }
6328: }
6329:
6330: function makebulboard() {
1.484.2.61 raeburn 6331: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 6332: if (title) {
6333: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 6334: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 6335: this.document.forms.newbul.submit();
6336: }
6337: }
6338:
6339: function makeabout() {
1.484.2.61 raeburn 6340: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 6341: if (user) {
6342: var comp=new Array();
6343: comp=user.split(':');
6344: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
6345: if ((comp[0]) && (comp[1])) {
6346: this.document.forms.newaboutsomeone.importdetail.value=
1.484.2.61 raeburn 6347: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.484.2.67 raeburn 6348: this.document.forms.newaboutsomeone.submit();
6349: } else {
6350: alert("$js_lt{'p_mab_alrt1'}");
6351: }
6352: } else {
6353: alert("$js_lt{'p_mab_alrt2'}");
6354: }
6355: }
1.335 ehlerst 6356: }
1.484.2.67 raeburn 6357:
6358: function makenew(targetform) {
6359: targetform.submit();
1.335 ehlerst 6360: }
1.484.2.67 raeburn 6361:
6362: function changename(folderpath,index,oldtitle) {
6363: var title=prompt('$js_lt{"p_chn"}',oldtitle);
6364: if (title) {
6365: this.document.forms.renameform.markcopy.value='';
6366: this.document.forms.renameform.title.value=title;
6367: this.document.forms.renameform.cmd.value='rename_'+index;
6368: this.document.forms.renameform.folderpath.value=folderpath;
6369: this.document.forms.renameform.submit();
6370: }
1.329 droeschl 6371: }
6372:
1.484.2.67 raeburn 6373: ENDNEWSCRIPT
6374: } else {
6375: $jsmakefunctions = <<ENDNEWSCRIPT;
6376:
6377: function makenewfolder() {
6378: alert("$js_lt{'edri'}");
6379: }
6380:
6381: function makenewpage() {
6382: alert("$js_lt{'edri'}");
6383: }
6384:
6385: function makeexamupload() {
6386: alert("$js_lt{'edri'}");
6387: }
6388:
6389: function makesmppage() {
6390: alert("$js_lt{'edri'}");
6391: }
6392:
6393: function makewebpage(type) {
6394: alert("$js_lt{'edri'}");
6395: }
6396:
6397: function makesmpproblem() {
6398: alert("$js_lt{'edri'}");
6399: }
6400:
6401: function makedropbox() {
6402: alert("$js_lt{'edri'}");
6403: }
6404:
6405: function makebulboard() {
6406: alert("$js_lt{'edri'}");
6407: }
6408:
6409: function makeabout() {
6410: alert("$js_lt{'edri'}");
6411: }
6412:
6413: function changename() {
6414: alert("$js_lt{'edri'}");
6415: }
6416:
6417: function makenew() {
6418: alert("$js_lt{'edri'}");
6419: }
6420:
6421: function groupimport() {
6422: alert("$js_lt{'edri'}");
6423: }
6424:
6425: function groupsearch() {
6426: alert("$js_lt{'edri'}");
6427: }
6428:
6429: function groupopen(url,recover) {
6430: var options="scrollbars=1,resizable=1,menubar=0";
6431: idxflag=1;
6432: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
6433: idx.focus();
6434: }
6435:
6436: ENDNEWSCRIPT
6437:
6438: }
6439: return <<ENDSCRIPT;
6440:
6441: $jsmakefunctions
6442:
1.484.2.13 raeburn 6443: function toggleUpload(caller) {
6444: var blocks = Array($fieldsets);
6445: for (var i=0; i<blocks.length; i++) {
6446: var disp = 'none';
6447: if (caller == blocks[i]) {
6448: var curr = document.getElementById('upload'+caller+'form').style.display;
6449: if (curr == 'none') {
6450: disp='block';
6451: }
6452: }
6453: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
6454: }
6455: resize_scrollbox('contentscroll','1','1');
6456: return;
6457: }
6458:
1.484.2.19 raeburn 6459: function toggleMap(caller) {
1.484.2.13 raeburn 6460: var disp = 'none';
1.484.2.19 raeburn 6461: if (document.getElementById('importmapform')) {
6462: if (caller == 'map') {
6463: var curr = document.getElementById('importmapform').style.display;
6464: if (curr == 'none') {
6465: disp='block';
6466: }
1.484.2.12 raeburn 6467: }
1.484.2.19 raeburn 6468: document.getElementById('importmapform').style.display=disp;
6469: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 6470: }
1.484.2.19 raeburn 6471: return;
1.329 droeschl 6472: }
6473:
1.484.2.12 raeburn 6474: function makeims(imsform) {
6475: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.484.2.61 raeburn 6476: alert("$js_lt{'imsfile'}");
1.484.2.12 raeburn 6477: return;
6478: }
6479: if (imsform.source.selectedIndex == 0) {
1.484.2.61 raeburn 6480: alert("$js_lt{'imscms'}");
1.484.2.12 raeburn 6481: return;
6482: }
6483: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
6484: imsform.submit();
6485: }
6486:
1.478 raeburn 6487: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 6488: var pickitem;
6489: var picknumitem;
6490: var picknumtext;
6491: if (index == 'all') {
6492: pickitem = document.getElementById('randompickall');
6493: picknumitem = document.getElementById('rpicknumall');
6494: picknumtext = document.getElementById('rpicktextall');
6495: } else {
6496: pickitem = document.getElementById('randompick_'+index);
6497: picknumitem = document.getElementById('rpicknum_'+index);
6498: picknumtext = document.getElementById('randompicknum_'+index);
6499: }
1.478 raeburn 6500: if (pickitem.checked) {
1.484.2.61 raeburn 6501: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 6502: if (picknum == '' || picknum == null) {
6503: if (caller == 'check') {
6504: pickitem.checked=false;
1.484.2.29 raeburn 6505: if (index == 'all') {
6506: picknumtext.innerHTML = '';
6507: if (caller == 'link') {
6508: propagateState(targetform,'rpicknum');
6509: }
6510: } else {
1.484.2.30 raeburn 6511: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6512: }
1.478 raeburn 6513: }
6514: } else {
6515: picknum.toString();
6516: var regexdigit=/^\\d+\$/;
6517: if (regexdigit.test(picknum)) {
6518: picknumitem.value = picknum;
1.484.2.29 raeburn 6519: if (index == 'all') {
1.484.2.30 raeburn 6520: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 6521: if (caller == 'link') {
6522: propagateState(targetform,'rpicknum');
6523: }
6524: } else {
6525: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 6526: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6527: }
1.478 raeburn 6528: } else {
6529: if (caller == 'check') {
1.484.2.29 raeburn 6530: if (index == 'all') {
6531: picknumtext.innerHTML = '';
6532: if (caller == 'link') {
6533: propagateState(targetform,'rpicknum');
6534: }
6535: } else {
6536: pickitem.checked=false;
1.484.2.30 raeburn 6537: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6538: }
1.478 raeburn 6539: }
6540: return;
6541: }
6542: }
6543: } else {
1.484.2.29 raeburn 6544: picknumitem.value = '';
6545: picknumtext.innerHTML = '';
6546: if (index == 'all') {
6547: if (caller == 'link') {
6548: propagateState(targetform,'rpicknum');
6549: }
6550: } else {
1.484.2.30 raeburn 6551: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 6552: }
6553: }
6554: }
6555:
6556: function propagateState(form,param) {
6557: if (document.getElementById(param+'all')) {
6558: var setcheck = 0;
6559: var rpick = 0;
6560: if (param == 'rpicknum') {
6561: if (document.getElementById('randompickall')) {
6562: if (document.getElementById('randompickall').checked) {
6563: if (document.getElementById('rpicknumall')) {
6564: rpick = document.getElementById('rpicknumall').value;
6565: }
6566: }
6567: }
6568: } else {
6569: if (document.getElementById(param+'all').checked) {
6570: setcheck = 1;
6571: }
6572: }
1.484.2.30 raeburn 6573: var allidxlist;
6574: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6575: if (document.getElementById('all'+param+'idx')) {
6576: allidxlist = document.getElementById('all'+param+'idx').value;
6577: }
6578: var actions = new Array ('remove','cut','copy');
6579: for (var i=0; i<actions.length; i++) {
6580: if (actions[i] != param) {
6581: if (document.getElementById(actions[i]+'all')) {
6582: document.getElementById(actions[i]+'all').checked = false;
6583: }
6584: }
6585: }
6586: }
1.484.2.29 raeburn 6587: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 6588: allidxlist = form.allidx.value;
6589: }
6590: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6591: allidxlist = form.allmapidx.value;
6592: }
6593: if ((allidxlist != '') && (allidxlist != null)) {
6594: var allidxs = allidxlist.split(',');
6595: if (allidxs.length > 1) {
6596: for (var i=0; i<allidxs.length; i++) {
6597: if (document.getElementById(param+'_'+allidxs[i])) {
6598: if (param == 'rpicknum') {
6599: if (document.getElementById('randompick_'+allidxs[i])) {
6600: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6601: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6602: if (rpick > 0) {
6603: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6604: } else {
6605: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6606: }
6607: }
6608: }
6609: } else {
1.484.2.29 raeburn 6610: if (setcheck == 1) {
6611: document.getElementById(param+'_'+allidxs[i]).checked = true;
6612: } else {
6613: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 6614: if (param == 'randompick') {
6615: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6616: }
1.484.2.29 raeburn 6617: }
6618: }
6619: }
6620: }
1.484.2.30 raeburn 6621: if (setcheck == 1) {
6622: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6623: var actions = new Array('copy','cut','remove');
6624: for (var i=0; i<actions.length; i++) {
6625: var otheractions;
6626: var otheridxs;
6627: if (actions[i] === param) {
6628: continue;
6629: } else {
6630: if (document.getElementById('all'+actions[i]+'idx')) {
6631: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6632: otheridxs = otheractions.split(',');
6633: if (otheridxs.length > 1) {
6634: for (var j=0; j<otheridxs.length; j++) {
6635: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6636: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6637: }
1.484.2.29 raeburn 6638: }
6639: }
6640: }
6641: }
1.484.2.30 raeburn 6642: }
1.484.2.29 raeburn 6643: }
6644: }
6645: }
6646: }
1.478 raeburn 6647: }
1.484.2.29 raeburn 6648: return;
6649: }
6650:
1.484.2.63 raeburn 6651: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.484.2.67 raeburn 6652: var canedit = '$canedit';
6653: if (canedit == '') {
6654: alert("$js_lt{'edri'}");
6655: return;
6656: }
1.484.2.30 raeburn 6657: var dosettings;
6658: var doaction;
6659: var control = document.togglemultsettings;
6660: if (context == 'actions') {
6661: control = document.togglemultactions;
6662: doaction = 1;
6663: } else {
6664: dosettings = 1;
6665: }
6666: if (control) {
6667: if (control.showmultpick.length) {
6668: for (var i=0; i<control.showmultpick.length; i++) {
6669: if (control.showmultpick[i].checked) {
6670: if (control.showmultpick[i].value == 1) {
6671: if (context == 'settings') {
6672: dosettings = 0;
6673: } else {
6674: doaction = 0;
6675: }
6676: }
6677: }
6678: }
6679: }
6680: }
6681: if (context == 'settings') {
6682: if (dosettings == 1) {
6683: targetform.changeparms.value=param;
6684: targetform.submit();
6685: }
6686: }
6687: if (context == 'actions') {
6688: if (doaction == 1) {
6689: targetform.cmd.value=param+'_'+index;
6690: targetform.folderpath.value=folderpath;
6691: targetform.markcopy.value=idx+':'+param;
6692: targetform.copyfolder.value=folder+'.'+container;
6693: if (param == 'remove') {
1.484.2.63 raeburn 6694: var doremove = 0;
6695: if (skip_confirm) {
6696: if (confirm_removal) {
6697: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
6698: doremove = 1;
6699: }
6700: } else {
6701: doremove = 1;
6702: }
6703: } else {
6704: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
6705: doremove = 1;
6706: }
6707: }
6708: if (doremove) {
1.484.2.30 raeburn 6709: targetform.markcopy.value='';
6710: targetform.copyfolder.value='';
1.484.2.29 raeburn 6711: targetform.submit();
6712: }
6713: }
1.484.2.30 raeburn 6714: if (param == 'cut') {
1.484.2.61 raeburn 6715: 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 6716: targetform.submit();
6717: return;
6718: }
6719: }
6720: if (param == 'copy') {
6721: targetform.submit();
6722: return;
6723: }
6724: targetform.markcopy.value='';
6725: targetform.copyfolder.value='';
6726: targetform.cmd.value='';
6727: targetform.folderpath.value='';
6728: return;
6729: } else {
6730: if (document.getElementById(param+'_'+idx)) {
6731: item = document.getElementById(param+'_'+idx);
6732: if (item.type == 'checkbox') {
6733: if (item.checked) {
6734: item.checked = false;
6735: } else {
6736: item.checked = true;
6737: singleCheck(item,idx,param);
6738: }
6739: }
6740: }
6741: }
6742: }
6743: return;
6744: }
6745:
6746: function singleCheck(caller,idx,action) {
6747: actions = new Array('cut','copy','remove');
6748: if (caller.checked) {
6749: for (var i=0; i<actions.length; i++) {
6750: if (actions[i] != action) {
6751: if (document.getElementById(actions[i]+'_'+idx)) {
6752: if (document.getElementById(actions[i]+'_'+idx).checked) {
6753: document.getElementById(actions[i]+'_'+idx).checked = false;
6754: }
6755: }
6756: }
1.484.2.29 raeburn 6757: }
6758: }
6759: return;
1.478 raeburn 6760: }
6761:
1.334 muellerd 6762: function unselectInactive(nav) {
1.335 ehlerst 6763: currentNav = document.getElementById(nav);
6764: currentLis = currentNav.getElementsByTagName('LI');
6765: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6766: if (currentLis[i].className == 'goback') {
6767: currentLis[i].className = 'goback';
6768: } else {
6769: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6770: currentLis[i].className = 'right';
1.472 raeburn 6771: } else {
1.374 tempelho 6772: currentLis[i].className = 'i';
1.472 raeburn 6773: }
6774: }
1.335 ehlerst 6775: }
1.332 tempelho 6776: }
6777:
1.334 muellerd 6778: function hideAll(current, nav, data) {
1.335 ehlerst 6779: unselectInactive(nav);
1.484.2.43 raeburn 6780: if (current) {
6781: if (current.className == 'right'){
1.374 tempelho 6782: current.className = 'right active'
1.484.2.43 raeburn 6783: } else {
1.374 tempelho 6784: current.className = 'active';
1.484.2.43 raeburn 6785: }
1.374 tempelho 6786: }
1.335 ehlerst 6787: currentData = document.getElementById(data);
6788: currentDivs = currentData.getElementsByTagName('DIV');
6789: for (i = 0; i < currentDivs.length; i++) {
6790: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6791: currentDivs[i].style.display = 'none';
1.330 tempelho 6792: }
6793: }
1.335 ehlerst 6794: }
1.330 tempelho 6795:
1.374 tempelho 6796: function openTabs(pageId) {
6797: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6798: if(tabnav.length > 2 ){
1.389 tempelho 6799: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6800: currentLis = currentNav.getElementsByTagName('LI');
6801: for(i = 0; i< currentLis.length; i++){
6802: if(currentLis[i].className == 'active') {
1.375 tempelho 6803: funcString = currentLis[i].onclick.toString();
6804: tab = funcString.split('"');
1.420 onken 6805: if(tab.length < 2) {
6806: tab = funcString.split("'");
6807: }
1.375 tempelho 6808: currentData = document.getElementById(tab[1]);
6809: currentData.style.display = 'block';
1.374 tempelho 6810: }
6811: }
6812: }
6813: }
6814:
1.334 muellerd 6815: function showPage(current, pageId, nav, data) {
1.484.2.43 raeburn 6816: currstate = current.className;
1.334 muellerd 6817: hideAll(current, nav, data);
1.375 tempelho 6818: openTabs(pageId);
1.334 muellerd 6819: unselectInactive(nav);
1.484.2.43 raeburn 6820: if ((currstate == 'active') || (currstate == 'right active')) {
6821: if (currstate == 'active') {
6822: current.className = '';
6823: } else {
6824: current.className = 'right';
6825: }
6826: activeTab = '';
6827: toggleUpload();
6828: toggleMap();
6829: resize_scrollbox('contentscroll','1','0');
6830: return;
6831: } else {
6832: current.className = 'active';
6833: }
1.330 tempelho 6834: currentData = document.getElementById(pageId);
6835: currentData.style.display = 'block';
1.458 raeburn 6836: activeTab = pageId;
1.484.2.12 raeburn 6837: toggleUpload();
1.484.2.14 raeburn 6838: toggleMap();
1.433 raeburn 6839: if (nav == 'mainnav') {
6840: var storedpath = "$docs_folderpath";
1.434 raeburn 6841: var storedpage = "$main_container_page";
1.433 raeburn 6842: var reg = new RegExp("^supplemental");
6843: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6844: if (storedpage == 1) {
6845: document.simpleedit.folderpath.value = '';
6846: document.uploaddocument.folderpath.value = '';
6847: } else {
6848: if (reg.test(storedpath)) {
6849: document.simpleedit.folderpath.value = '$toplevelmain';
6850: document.uploaddocument.folderpath.value = '$toplevelmain';
6851: document.newext.folderpath.value = '$toplevelmain';
6852: } else {
6853: document.simpleedit.folderpath.value = storedpath;
6854: document.uploaddocument.folderpath.value = storedpath;
6855: document.newext.folderpath.value = storedpath;
6856: }
1.433 raeburn 6857: }
6858: } else {
1.434 raeburn 6859: if (reg.test(storedpath)) {
6860: document.simpleedit.folderpath.value = storedpath;
6861: document.supuploaddocument.folderpath.value = storedpath;
6862: document.supnewext.folderpath.value = storedpath;
6863: } else {
1.433 raeburn 6864: document.simpleedit.folderpath.value = '$toplevelsupp';
6865: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6866: document.supnewext.folderpath.value = '$toplevelsupp';
6867: }
6868: }
6869: }
1.484.2.3 raeburn 6870: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6871: return false;
6872: }
1.329 droeschl 6873:
1.472 raeburn 6874: function toContents(jumpto) {
6875: var newurl = '$backtourl';
1.484.2.21 raeburn 6876: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6877: newurl = newurl+'?postdata='+jumpto;
6878: }
6879: location.href=newurl;
6880: }
6881:
1.484.2.30 raeburn 6882: function togglePick(caller,value) {
6883: var disp = 'none';
6884: if (document.getElementById('multi'+caller)) {
6885: var curr = document.getElementById('multi'+caller).style.display;
6886: if (value == 1) {
6887: disp='block';
6888: }
6889: if (curr == disp) {
6890: return;
6891: }
6892: document.getElementById('multi'+caller).style.display=disp;
6893: if (value == 1) {
1.484.2.61 raeburn 6894: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6895: } else {
6896: document.getElementById('more'+caller).innerHTML = '';
6897: }
6898: if (caller == 'actions') {
6899: setClass(value);
6900: setBoxes(value);
6901: }
6902: }
6903: var showButton = multiSettings();
6904: if (showButton != 1) {
6905: showButton = multiActions();
6906: }
6907: if (document.getElementById('multisave')) {
6908: if (showButton == 1) {
6909: document.getElementById('multisave').style.display='block';
6910: } else {
6911: document.getElementById('multisave').style.display='none';
6912: }
6913: }
6914: resize_scrollbox('contentscroll','1','1');
6915: return;
6916: }
6917:
6918: function toggleCheckUncheck(caller,more) {
6919: if (more == 1) {
1.484.2.61 raeburn 6920: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.484.2.30 raeburn 6921: document.getElementById('allfields'+caller).style.display='block';
6922: } else {
1.484.2.61 raeburn 6923: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.484.2.30 raeburn 6924: document.getElementById('allfields'+caller).style.display='none';
6925: }
6926: resize_scrollbox('contentscroll','1','1');
6927: }
6928:
6929: function multiSettings() {
6930: var inuse = 0;
6931: var settingsform = document.togglemultsettings;
6932: if (settingsform.showmultpick.length > 1) {
6933: for (var i=0; i<settingsform.showmultpick.length; i++) {
6934: if (settingsform.showmultpick[i].checked) {
6935: if (settingsform.showmultpick[i].value == 1) {
6936: inuse = 1;
6937: }
6938: }
6939: }
6940: }
6941: return inuse;
6942: }
6943:
6944: function multiActions() {
6945: var inuse = 0;
6946: var actionsform = document.togglemultactions;
6947: if (actionsform.showmultpick.length > 1) {
6948: for (var i=0; i<actionsform.showmultpick.length; i++) {
6949: if (actionsform.showmultpick[i].checked) {
6950: if (actionsform.showmultpick[i].value == 1) {
6951: inuse = 1;
6952: }
6953: }
6954: }
6955: }
6956: return inuse;
6957: }
6958:
6959: function checkSubmits() {
6960: var numchanges = 0;
6961: var form = document.saveactions;
6962: var doactions = multiActions();
6963: var cutwarnings = 0;
6964: var remwarnings = 0;
1.484.2.63 raeburn 6965: var removalinfo = 0;
1.484.2.30 raeburn 6966: if (doactions == 1) {
6967: var remidxlist = document.cumulativeactions.allremoveidx.value;
6968: if ((remidxlist != '') && (remidxlist != null)) {
6969: var remidxs = remidxlist.split(',');
6970: for (var i=0; i<remidxs.length; i++) {
6971: if (document.getElementById('remove_'+remidxs[i])) {
6972: if (document.getElementById('remove_'+remidxs[i]).checked) {
6973: form.multiremove.value += remidxs[i]+',';
6974: numchanges ++;
6975: if (document.getElementById('skip_remove_'+remidxs[i])) {
6976: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6977: remwarnings ++;
6978: }
6979: }
1.484.2.63 raeburn 6980: if (document.getElementById('confirm_removal_'+remidxs[i])) {
6981: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
6982: removalinfo ++;
6983: }
6984: }
1.484.2.30 raeburn 6985: }
6986: }
6987: }
6988: }
6989: var cutidxlist = document.cumulativeactions.allcutidx.value;
6990: if ((cutidxlist != '') && (cutidxlist != null)) {
6991: var cutidxs = cutidxlist.split(',');
6992: for (var i=0; i<cutidxs.length; i++) {
6993: if (document.getElementById('cut_'+cutidxs[i])) {
6994: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6995: form.multicut.value += cutidxs[i]+',';
6996: numchanges ++;
6997: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6998: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6999: cutwarnings ++;
7000: }
7001: }
7002: }
7003: }
7004: }
7005: }
7006: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7007: if ((copyidxlist != '') && (copyidxlist != null)) {
7008: var copyidxs = copyidxlist.split(',');
7009: for (var i=0; i<copyidxs.length; i++) {
7010: if (document.getElementById('copy_'+copyidxs[i])) {
7011: if (document.getElementById('copy_'+copyidxs[i]).checked) {
7012: form.multicopy.value += copyidxs[i]+',';
7013: numchanges ++;
7014: }
7015: }
7016: }
7017: }
7018: if (numchanges > 0) {
7019: form.multichange.value = numchanges;
7020: }
7021: }
7022: var dosettings = multiSettings();
7023: var haschanges = 0;
7024: if (dosettings == 1) {
7025: form.allencrypturl.value = '';
7026: form.allhiddenresource.value = '';
7027: form.changeparms.value = 'all';
7028: var patt=new RegExp(",\$");
7029: var allidxlist = document.cumulativesettings.allidx.value;
7030: if ((allidxlist != '') && (allidxlist != null)) {
7031: var allidxs = allidxlist.split(',');
7032: if (allidxs.length > 1) {
7033: for (var i=0; i<allidxs.length; i++) {
7034: if (document.getElementById('hiddenresource_'+allidxs[i])) {
7035: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
7036: form.allhiddenresource.value += allidxs[i]+',';
7037: }
7038: }
7039: if (document.getElementById('encrypturl_'+allidxs[i])) {
7040: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
7041: form.allencrypturl.value += allidxs[i]+',';
7042: }
1.484.2.29 raeburn 7043: }
7044: }
1.484.2.30 raeburn 7045: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
7046: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
7047: }
7048: }
7049: form.allrandompick.value = '';
7050: form.allrandomorder.value = '';
7051: var allmapidxlist = document.cumulativesettings.allmapidx.value;
7052: if ((allmapidxlist != '') && (allmapidxlist != null)) {
7053: var allmapidxs = allmapidxlist.split(',');
7054: for (var i=0; i<allmapidxs.length; i++) {
7055: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
7056: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
7057: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
7058: if ((randompick.checked) && (rpicknum.value != '')) {
7059: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
7060: }
7061: if (randorder.checked) {
7062: form.allrandomorder.value += allmapidxs[i]+',';
7063: }
7064: }
7065: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
7066: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
7067: }
7068: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
7069: haschanges = 1;
7070: }
7071: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
7072: haschanges = 1;
7073: }
7074: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
7075: haschanges = 1;
7076: }
7077: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
7078: haschanges = 1;
7079: }
7080: }
7081: if (doactions == 1) {
7082: if (numchanges > 0) {
1.484.2.63 raeburn 7083: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.484.2.30 raeburn 7084: if (remwarnings > 0) {
1.484.2.61 raeburn 7085: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.484.2.30 raeburn 7086: return false;
7087: }
7088: }
1.484.2.63 raeburn 7089: if (removalinfo > 0) {
7090: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
7091: return false;
7092: }
7093: }
1.484.2.30 raeburn 7094: if (cutwarnings > 0) {
1.484.2.61 raeburn 7095: 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 7096: return false;
1.484.2.29 raeburn 7097: }
7098: }
7099: }
1.484.2.30 raeburn 7100: form.submit();
7101: return true;
7102: }
7103: }
7104: if (dosettings == 1) {
7105: if (haschanges == 1) {
7106: form.submit();
7107: return true;
1.484.2.29 raeburn 7108: }
7109: }
1.484.2.30 raeburn 7110: if ((dosettings == 1) && (doactions == 1)) {
1.484.2.61 raeburn 7111: alert("$js_lt{'noor'}");
1.484.2.30 raeburn 7112: } else {
7113: if (dosettings == 1) {
1.484.2.61 raeburn 7114: alert("$js_lt{'noch'}");
1.484.2.30 raeburn 7115: } else {
1.484.2.61 raeburn 7116: alert("$js_lt{'noac'}");
1.484.2.30 raeburn 7117: }
7118: }
7119: return false;
7120: }
7121:
7122: function setClass(value) {
7123: var cutclass = 'LC_docs_cut';
7124: var copyclass = 'LC_docs_copy';
7125: var removeclass = 'LC_docs_remove';
7126: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
7127: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
7128: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
7129: var links = document.getElementsByTagName('a');
7130: for (var i=0; i<links.length; i++) {
7131: var classes = links[i].className;
7132: if (cutreg.test(classes)) {
7133: links[i].className = cutclass;
7134: if (value == 1) {
7135: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 7136: }
1.484.2.30 raeburn 7137: } else {
7138: if (copyreg.test(classes)) {
7139: links[i].className = copyclass;
7140: if (value == 1) {
7141: links[i].className += " LC_menubuttons_link";
7142: }
7143: } else {
7144: if (removereg.test(classes)) {
7145: links[i].className = removeclass;
7146: if (value == 1) {
7147: links[i].className += " LC_menubuttons_link";
7148: }
7149: }
1.484.2.29 raeburn 7150: }
7151: }
7152: }
1.484.2.30 raeburn 7153: return;
1.484.2.29 raeburn 7154: }
7155:
1.484.2.30 raeburn 7156: function setBoxes(value) {
7157: var remidxlist = document.cumulativeactions.allremoveidx.value;
7158: if ((remidxlist != '') && (remidxlist != null)) {
7159: var remidxs = remidxlist.split(',');
7160: for (var i=0; i<remidxs.length; i++) {
7161: if (document.getElementById('remove_'+remidxs[i])) {
7162: var item = document.getElementById('remove_'+remidxs[i]);
7163: if (value == 1) {
7164: item.className = 'LC_docs_remove';
7165: } else {
7166: item.className = 'LC_hidden';
7167: }
7168: }
1.484.2.29 raeburn 7169: }
7170: }
1.484.2.30 raeburn 7171: var cutidxlist = document.cumulativeactions.allcutidx.value;
7172: if ((cutidxlist != '') && (cutidxlist != null)) {
7173: var cutidxs = cutidxlist.split(',');
7174: for (var i=0; i<cutidxs.length; i++) {
7175: if (document.getElementById('cut_'+cutidxs[i])) {
7176: var item = document.getElementById('cut_'+cutidxs[i]);
7177: if (value == 1) {
7178: item.className = 'LC_docs_cut';
7179: } else {
7180: item.className = 'LC_hidden';
7181: }
7182: }
7183: }
7184: }
7185: var copyidxlist = document.cumulativeactions.allcopyidx.value;
7186: if ((copyidxlist != '') && (copyidxlist != null)) {
7187: var copyidxs = copyidxlist.split(',');
7188: for (var i=0; i<copyidxs.length; i++) {
7189: if (document.getElementById('copy_'+copyidxs[i])) {
7190: var item = document.getElementById('copy_'+copyidxs[i]);
7191: if (value == 1) {
7192: item.className = 'LC_docs_copy';
7193: } else {
7194: item.className = 'LC_hidden';
7195: }
7196: }
1.484.2.29 raeburn 7197: }
7198: }
7199: return;
7200: }
7201:
1.484.2.67 raeburn 7202: ENDSCRIPT
1.329 droeschl 7203: }
1.457 raeburn 7204:
1.483 raeburn 7205: sub history_tab_js {
7206: return <<"ENDHIST";
7207: function toggleHistoryDisp(choice) {
7208: document.docslogform.docslog.value = choice;
7209: document.docslogform.submit();
7210: return;
7211: }
7212:
7213: ENDHIST
7214: }
7215:
1.484 raeburn 7216: sub inject_data_js {
7217: return <<ENDINJECT;
7218:
7219: function injectData(current, hiddenField, name, value) {
7220: currentElement = document.getElementById(hiddenField);
7221: currentElement.name = name;
7222: currentElement.value = value;
7223: current.submit();
7224: }
7225:
7226: ENDINJECT
7227: }
7228:
7229: sub dump_switchserver_js {
7230: my @hosts = @_;
1.484.2.61 raeburn 7231: my %js_lt = &Apache::lonlocal::texthash(
1.484.2.46 raeburn 7232: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 7233: swit => 'Switch server?',
1.484.2.61 raeburn 7234: );
7235: my %html_js_lt = &Apache::lonlocal::texthash(
7236: swit => 'Switch server?',
1.484.2.43 raeburn 7237: duco => 'Copying Content to Authoring Space',
1.484 raeburn 7238: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
7239: chos => 'Choose server',
7240: );
1.484.2.61 raeburn 7241: &js_escape(\%js_lt);
7242: &html_escape(\%html_js_lt);
7243: &js_escape(\%html_js_lt);
1.484 raeburn 7244: my $role = $env{'request.role'};
7245: my $js = <<"ENDSWJS";
7246: <script type="text/javascript">
7247: function write_switchserver() {
7248: var server;
7249: if (document.setserver.posshosts.length > 0) {
7250: for (var i=0; i<document.setserver.posshosts.length; i++) {
7251: if (document.setserver.posshosts[i].checked) {
7252: server = document.setserver.posshosts[i].value;
7253: }
7254: }
7255: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
7256: }
7257: window.close();
7258: }
7259: </script>
7260:
7261: ENDSWJS
7262:
7263: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
7264: {'only_body' => 1,
7265: 'js_ready' => 1,});
7266: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
7267:
7268: my $hostpicker;
7269: my $count = 0;
7270: foreach my $host (sort(@hosts)) {
7271: my $checked;
7272: if ($count == 0) {
7273: $checked = ' checked="checked"';
7274: }
7275: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
7276: $host.'"'.$checked.' />'.$host.'</label> ';
7277: $count++;
7278: }
7279:
7280: return <<"ENDSWITCHJS";
7281:
7282: function dump_needs_switchserver(url) {
7283: if (url!='' && url!= null) {
1.484.2.61 raeburn 7284: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 7285: go(url);
7286: }
7287: }
7288: return;
7289: }
7290:
7291: function choose_switchserver_window() {
7292: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
7293: newWindow.document.open();
7294: newWindow.document.writeln('$startpage');
1.484.2.61 raeburn 7295: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
7296: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
7297: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 7298: '<form name="setserver" method="post" action="" \\/>\\n'+
7299: '$hostpicker\\n'+
7300: '<br \\/><br \\/>\\n'+
1.484.2.61 raeburn 7301: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 7302: 'onclick="write_switchserver();" \\/>\\n'+
7303: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
7304: newWindow.document.writeln('$endpage');
7305: newWindow.document.close();
7306: newWindow.focus();
7307: }
7308:
7309: ENDSWITCHJS
7310: }
7311:
7312: sub makedocslogform {
7313: my ($formelems,$docslog) = @_;
7314: return <<"LOGSFORM";
7315: <form action="/adm/coursedocs" method="post" name="docslogform">
7316: <input type="hidden" name="docslog" value="$docslog" />
7317: $formelems
7318: </form>
7319: LOGSFORM
7320: }
7321:
7322: sub makesimpleeditform {
7323: my ($formelems) = @_;
7324: return <<"SIMPFORM";
7325: <form name="simpleedit" method="post" action="/adm/coursedocs">
7326: <input type="hidden" name="importdetail" value="" />
7327: $formelems
7328: </form>
7329: SIMPFORM
7330: }
7331:
1.329 droeschl 7332: 1;
7333: __END__
7334:
7335:
7336: =head1 NAME
7337:
7338: Apache::londocs.pm
7339:
7340: =head1 SYNOPSIS
7341:
7342: This is part of the LearningOnline Network with CAPA project
7343: described at http://www.lon-capa.org.
7344:
7345: =head1 SUBROUTINES
7346:
7347: =over
7348:
7349: =item %help=()
7350:
7351: Available help topics
7352:
7353: =item mapread()
7354:
1.344 bisitz 7355: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 7356: @order and @resources, determines status
7357: sets @order - pointer to resources in right order
7358: sets @resources - array with the resources with correct idx
7359:
7360: =item authorhosts()
7361:
7362: Return hash with valid author names
7363:
7364: =item clean()
7365:
7366: =item dumpcourse()
7367:
7368: Actually dump course
7369:
7370: =item group_import()
7371:
7372: Imports the given (name, url) resources into the course
7373: coursenum, coursedom, and folder must precede the list
7374:
7375: =item breadcrumbs()
7376:
7377: =item log_docs()
7378:
7379: =item docs_change_log()
7380:
7381: =item update_paste_buffer()
7382:
7383: =item print_paste_buffer()
7384:
7385: =item do_paste_from_buffer()
7386:
1.484.2.30 raeburn 7387: =item do_buffer_empty()
7388:
7389: =item clear_from_buffer()
7390:
1.484.2.7 raeburn 7391: =item get_newmap_url()
7392:
7393: =item dbcopy()
7394:
7395: =item uniqueness_check()
7396:
7397: =item contained_map_check()
7398:
7399: =item url_paste_fixups()
7400:
7401: =item apply_fixups()
7402:
7403: =item copy_dependencies()
7404:
1.329 droeschl 7405: =item update_parameter()
7406:
7407: =item handle_edit_cmd()
7408:
7409: =item editor()
7410:
7411: =item process_file_upload()
7412:
7413: =item process_secondary_uploads()
7414:
7415: =item is_supplemental_title()
7416:
7417: =item entryline()
7418:
7419: =item tiehash()
7420:
7421: =item untiehash()
7422:
7423: =item checkonthis()
7424:
7425: check on this
7426:
7427: =item verifycontent()
7428:
7429: Verify Content
7430:
7431: =item devalidateversioncache() & checkversions()
7432:
7433: Check Versions
7434:
7435: =item mark_hash_old()
7436:
7437: =item is_hash_old()
7438:
7439: =item changewarning()
7440:
7441: =item init_breadcrumbs()
7442:
7443: Breadcrumbs for special functions
7444:
1.484 raeburn 7445: =item create_list_elements()
7446:
7447: =item create_form_ul()
7448:
7449: =item startContentScreen()
7450:
7451: =item endContentScreen()
7452:
7453: =item supplemental_base()
7454:
7455: =item embedded_form_elems()
7456:
7457: =item embedded_destination()
7458:
7459: =item return_to_editor()
7460:
7461: =item decompression_info()
7462:
7463: =item decompression_phase_one()
7464:
7465: =item decompression_phase_two()
7466:
7467: =item remove_archive()
7468:
7469: =item generate_admin_menu()
7470:
7471: =item generate_edit_table()
7472:
7473: =item editing_js()
7474:
7475: =item history_tab_js()
7476:
7477: =item inject_data_js()
7478:
7479: =item dump_switchserver_js()
7480:
1.484.2.3 raeburn 7481: =item resize_scrollbox_js()
1.484 raeburn 7482:
7483: =item makedocslogform()
7484:
1.484.2.3 raeburn 7485: =item makesimpleeditform()
7486:
1.329 droeschl 7487: =back
7488:
7489: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>