Annotation of loncom/interface/londocs.pm, revision 1.643
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.643 ! raeburn 4: # $Id: londocs.pm,v 1.642 2017/11/30 01:52:14 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.510 raeburn 43: use Apache::lonextresedit();
1.567 raeburn 44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
1.606 raeburn 46: use Apache::lonhomework();
47: use Apache::lonpublisher();
1.329 droeschl 48: use HTML::Entities;
1.488 raeburn 49: use HTML::TokeParser;
1.329 droeschl 50: use GDBM_File;
1.578 raeburn 51: use File::MMagic;
1.606 raeburn 52: use File::Copy;
1.329 droeschl 53: use Apache::lonlocal;
54: use Cwd;
1.643 ! raeburn 55: use UUID::Tiny ':std';
1.329 droeschl 56: use LONCAPA qw(:DEFAULT :match);
57:
58: my $iconpath;
59:
60: my %hash;
61:
62: my $hashtied;
63: my %alreadyseen=();
64:
65: my $hadchanges;
1.557 raeburn 66: my $suppchanges;
1.329 droeschl 67:
68:
69: my %help=();
70:
71:
72: sub mapread {
73: my ($coursenum,$coursedom,$map)=@_;
74: return
75: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
76: $map);
77: }
78:
79: sub storemap {
1.492 raeburn 80: my ($coursenum,$coursedom,$map,$contentchg)=@_;
81: my $report;
82: if (($contentchg) && ($map =~ /^default/)) {
83: $report = 1;
84: }
1.329 droeschl 85: my ($outtext,$errtext)=
86: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 87: $map,1,$report);
1.329 droeschl 88: if ($errtext) { return ($errtext,2); }
1.364 bisitz 89:
1.557 raeburn 90: if ($map =~ /^default/) {
91: $hadchanges=1;
92: } else {
93: $suppchanges=1;
94: }
1.329 droeschl 95: return ($errtext,0);
96: }
97:
98:
99:
100: sub authorhosts {
101: my %outhash=();
102: my $home=0;
103: my $other=0;
104: foreach my $key (keys(%env)) {
105: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
106: my $role=$1;
107: my $realm=$2;
108: my ($start,$end)=split(/\./,$env{$key});
109: if (($start) && ($start>time)) { next; }
110: if (($end) && (time>$end)) { next; }
111: my ($ca,$cd);
112: if ($1 eq 'au') {
113: $ca=$env{'user.name'};
114: $cd=$env{'user.domain'};
115: } else {
116: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
117: }
118: my $allowed=0;
119: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
120: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 121: foreach my $id (@ids) {
122: if ($id eq $myhome) {
123: $allowed=1;
124: last;
125: }
126: }
1.329 droeschl 127: if ($allowed) {
128: $home++;
1.484 raeburn 129: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 130: } else {
1.484 raeburn 131: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 132: $other++;
133: }
134: }
135: }
136: return ($home,$other,%outhash);
137: }
138:
139:
140: sub clean {
141: my ($title)=@_;
142: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 143: return $title;
1.329 droeschl 144: }
145:
1.617 raeburn 146: sub default_folderpath {
147: my ($coursenum,$coursedom,$navmapref) = @_;
148: return unless ($coursenum && $coursedom && ref($navmapref));
149: # Check if entire course is hidden and/or encrypted
150: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
151: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
152: unless (ref($$navmapref)) {
153: $$navmapref = Apache::lonnavmaps::navmap->new();
154: }
155: if (ref($$navmapref)) {
156: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
157: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
158: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
159: unless (@resources) {
160: $hiddenmap = 1;
161: unless ($env{'request.role.adv'}) {
162: $hiddentop = 1;
163: if ($env{'form.folder'}) {
164: undef($env{'form.folder'});
165: }
166: }
167: }
168: }
169: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
170: $encryptmap = 1;
171: }
172: }
173: unless ($hiddentop) {
174: $folderpath='default&'.&escape(&mt('Main Content')).
175: '::'.$hiddenmap.':'.$encryptmap.'::';
176: }
177: if (wantarray) {
178: return ($folderpath,$hiddentop);
179: } else {
180: return $folderpath;
181: }
182: }
1.329 droeschl 183:
184: sub dumpcourse {
185: my ($r) = @_;
1.408 raeburn 186: my $crstype = &Apache::loncommon::course_type();
1.567 raeburn 187: my ($starthash,$js);
188: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
189: $js = <<"ENDJS";
190: <script type="text/javascript">
191: // <![CDATA[
192:
193: function hide_searching() {
194: if (document.getElementById('searching')) {
195: document.getElementById('searching').style.display = 'none';
196: }
197: return;
198: }
199:
200: // ]]>
201: </script>
202: ENDJS
203: $starthash = {
204: add_entries => {'onload' => "hide_searching();"},
205: };
206: }
1.568 raeburn 207: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
208: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
1.484 raeburn 209: $r->print(&startContentScreen('tools'));
1.329 droeschl 210: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 211: unless ($home) {
212: $r->print(&endContentScreen());
213: return '';
214: }
1.329 droeschl 215: my $origcrsid=$env{'request.course.id'};
216: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
217: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
218: # Do the dumping
1.484 raeburn 219: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
220: $r->print(&endContentScreen());
221: return '';
222: }
1.531 raeburn 223: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 224: $r->print('<h3>'.&mt('Copying Files').'</h3>');
225: my $title=$env{'form.authorfolder'};
226: $title=&clean($title);
1.567 raeburn 227: my ($navmap,$errormsg) =
228: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
229: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
230: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
231: my (%maps,%resources,%titles);
232: if (!ref($navmap)) {
233: $r->print($errormsg.
234: &endContentScreen());
235: return '';
236: } else {
237: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
238: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 239: }
1.567 raeburn 240: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
241: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
242: %newcontent,%has_simpleprobs);
243: foreach my $item (sort {$a <=> $b} (@todump)) {
244: my $name = $env{'form.namefor_'.$item};
245: if ($resources{$item}) {
246: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
247: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
248: $tocopy{$1} = $name;
249: $display{$item} = $1;
250: $lookup{$1} = $item;
251: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
252: $simpleproblems{$item} = {
253: symb => $resources{$item},
254: name => $name,
255: };
256: $display{$item} = 'simpleproblem_'.$name;
257: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
258: $has_simpleprobs{$1}{$id} = $item;
259: }
260: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
261: my $marker = $1;
262: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
263: $simplepages{$item} = {
264: res => $res,
265: title => $titles{$item},
266: db => $db_name,
267: marker => $marker,
268: symb => $resources{$item},
269: name => $name,
270: };
271: $display{$item} = '/'.$res;
272: }
273: } elsif ($maps{$item}) {
274: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
275: $tocopy{$1} = $name;
276: $display{$item} = $1;
277: $lookup{$1} = $item;
278: }
279: } else {
280: next;
281: }
282: }
1.329 droeschl 283: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
284: $crs=~s/\_/\//g;
1.567 raeburn 285: my $mm = new File::MMagic;
286: my $prefix = "/uploaded/$cdom/$cnum/";
287: %replacehash = %tocopy;
288: foreach my $item (sort(keys(%simpleproblems))) {
289: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
290: $newcontent{$display{$item}} = $content;
291: }
292: my $gateway = Apache::lonhtmlgateway->new('web');
293: foreach my $item (sort(keys(%simplepages))) {
294: if (ref($simplepages{$item}) eq 'HASH') {
295: my $pagetitle = $simplepages{$item}{'title'};
296: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
297: my %contents;
298: foreach my $field (keys(%fields)) {
299: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
300: my $name = $1;
301: my $msg = $fields{$field};
302: if ($name eq 'webreferences') {
303: if ($msg =~ m{^https?://}) {
304: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
305: }
306: } else {
307: $msg = &Encode::decode('utf8',$msg);
308: $msg = $gateway->process_outgoing_html($msg,1);
309: $contents{$name} = $msg;
310: }
311: } elsif ($field eq 'uploaded.photourl') {
312: my $marker = $simplepages{$item}{marker};
313: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
314: my $filepath = $1;
315: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
316: if ($fname ne '') {
317: $fname=~s/\.(\w+)$//;
318: my $ext=$1;
319: $fname = &clean($fname);
320: $fname.='.'.$ext;
321: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
322: $replacehash{$filepath} = $relpath.$fname;
323: $deps{$item}{$filepath} = 1;
324: }
325: }
326: }
327: }
328: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
329: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
330: my $content = '
331: <html>
332: <head>
333: <title>'.$pagetitle.'</title>
334: </head>
335: <body bgcolor="#ffffff">';
336: if ($contents{title}) {
337: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
338: }
339: if ($contents{image}) {
340: $content .= "\n".$contents{image};
341: }
342: if ($contents{content}) {
343: $content .= '
344: <div class="LC_Box">
1.577 bisitz 345: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
1.567 raeburn 346: $contents{content}.'
347: </div>';
348: }
349: if ($contents{webreferences}) {
350: $content .= '
351: <div class="LC_Box">
1.577 bisitz 352: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
1.567 raeburn 353: $contents{webreferences}.'
354: </div>';
355: }
356: $content .= '
357: </body>
358: </html>
359: ';
360: $newcontent{'/'.$simplepages{$item}{res}} = $content;
361: }
362: }
363: foreach my $item (keys(%tocopy)) {
364: unless ($item=~/\.(sequence|page)$/) {
365: my $currurlpath = $prefix.$item;
366: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
367: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
368: }
369: }
370: foreach my $num (sort {$a <=> $b} (@todump)) {
371: my $src = $display{$num};
372: next if ($src eq '');
373: my @needcopy = ();
374: if ($replacehash{$src}) {
375: push(@needcopy,$src);
376: if (ref($deps{$num}) eq 'HASH') {
377: foreach my $dep (sort(keys(%{$deps{$num}}))) {
378: if ($replacehash{$dep}) {
379: push(@needcopy,$dep);
380: }
381: }
382: }
383: } elsif ($src =~ /^simpleproblem_/) {
384: push(@needcopy,$src);
385: }
386: next if (@needcopy == 0);
387: my ($result,$depresult);
388: for (my $i=0; $i<@needcopy; $i++) {
389: my $item = $needcopy[$i];
390: my $newfilename;
391: if ($simpleproblems{$num}) {
392: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
393: } else {
394: $newfilename=$title.'/'.$replacehash{$item};
395: }
396: $newfilename=~s/\.(\w+)$//;
397: my $ext=$1;
398: $newfilename=&clean($newfilename);
399: $newfilename.='.'.$ext;
400: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
401: if ($newrelpath ne $replacehash{$item}) {
402: $replacehash{$item} = $newrelpath;
403: }
404: my @dirs=split(/\//,$newfilename);
405: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
406: my $makepath=$path;
407: my $fail;
408: my $origin;
409: for (my $i=0;$i<$#dirs;$i++) {
410: $makepath.='/'.$dirs[$i];
411: unless (-e $makepath) {
412: unless(mkdir($makepath,0755)) {
413: $fail = &mt('Directory creation failed.');
414: }
415: }
416: }
417: if ($i == 0) {
418: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
419: } else {
420: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
421: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
422: &mt('(dependency)').'</span>: ';
423: }
424: if (-e $path.'/'.$newfilename) {
425: $fail = &mt('Destination already exists -- not overwriting.');
426: } else {
427: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
428: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
429: ($item =~ /^simpleproblem_/)) {
430: print $fh $newcontent{$item};
431: } else {
432: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
433: if (-e $fileloc) {
434: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
435: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
436: (ref($has_simpleprobs{$item}) eq 'HASH')) {
437: my %changes = %{$has_simpleprobs{$item}};
438: my $content = &Apache::lonclonecourse::rewritefile(
439: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
440: (%replacehash,$crs => '')
441: );
442: my $updatedcontent = '';
443: my $parser = HTML::TokeParser->new(\$content);
444: $parser->attr_encoded(1);
445: while (my $token = $parser->get_token) {
446: if ($token->[0] eq 'S') {
447: if (($token->[1] eq 'resource') &&
448: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
449: ($changes{$token->[2]->{'id'}})) {
450: my $id = $token->[2]->{'id'};
451: $updatedcontent .= '<'.$token->[1];
452: foreach my $attrib (@{$token->[3]}) {
453: next unless ($attrib =~ /^(src|type|title|id)$/);
454: if ($attrib eq 'src') {
455: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
456: if ($file) {
457: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
458: } else {
459: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
460: }
461: } else {
462: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
463: }
464: }
465: $updatedcontent .= ' />'."\n";
466: } else {
467: $updatedcontent .= $token->[4]."\n";
468: }
469: } else {
470: $updatedcontent .= $token->[2];
471: }
472: }
473: print $fh $updatedcontent;
474: } else {
475: print $fh &Apache::lonclonecourse::rewritefile(
476: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
477: (%replacehash,$crs => '')
478: );
479: }
480: } else {
481: print $fh
482: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
483: }
484: } else {
485: $fail = &mt('Source does not exist.');
486: }
487: }
488: $fh->close();
489: } else {
490: $fail = &mt('Could not write to destination.');
491: }
492: }
493: my $text;
494: if ($fail) {
495: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
496: } else {
497: $text = '<span class="LC_success">'.&mt('ok').'</span>';
498: }
499: if ($i == 0) {
500: $result .= $text;
501: } else {
502: $depresult .= $text.'</li>';
503: }
504: }
505: $r->print($result);
506: if ($depresult) {
507: $r->print('<ul>'.$depresult.'</ul>');
508: }
509: }
510: } else {
511: my ($navmap,$errormsg) =
512: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
513: if (!ref($navmap)) {
514: $r->print($errormsg);
515: } else {
516: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
517: $r->rflush();
518: my ($preamble,$formname);
519: $formname = 'dumpdoc';
520: unless ($home==1) {
521: $preamble = '<div class="LC_left_float">'.
522: '<fieldset><legend>'.
523: &mt('Select the Authoring Space').
524: '</legend><select name="authorspace">';
1.329 droeschl 525: }
1.567 raeburn 526: my @orderspaces = ();
527: foreach my $key (sort(keys(%outhash))) {
528: if ($key=~/^home_(.+)$/) {
529: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
530: unshift(@orderspaces,$1);
531: } else {
532: push(@orderspaces,$1);
533: }
534: }
535: }
1.569 raeburn 536: if ($home>1) {
537: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
538: }
1.567 raeburn 539: foreach my $user (@orderspaces) {
1.329 droeschl 540: if ($home==1) {
1.567 raeburn 541: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 542: } else {
1.567 raeburn 543: $preamble .= '<option value="'.$user.'">'.$user.' - '.
544: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
545: }
1.329 droeschl 546: }
1.567 raeburn 547: unless ($home==1) {
548: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 549: }
1.567 raeburn 550: my $title=$origcrsdata{'description'};
551: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 552: $title=&clean($title);
1.567 raeburn 553: $preamble .= '<div class="LC_left_float">'.
554: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
555: '<input type="text" size="50" name="authorfolder" value="'.
556: $title.'" />'.
557: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
558: my %uploadedfiles;
559: &tiehash();
560: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
561: my ($ext)=($file=~/\.(\w+)$/);
562: # FIXME Check supplemental here
563: my $title=$hash{'title_'.$hash{
564: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
565: if (!$title) {
566: $title=$file;
567: } else {
568: $title=~s|/|_|g;
569: }
570: $title=~s/\.(\w+)$//;
571: $title=&clean($title);
572: $title.='.'.$ext;
573: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
574: $uploadedfiles{$file} = $title;
575: }
576: &untiehash();
577: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
578: undef,undef,$preamble,$home,\%uploadedfiles));
579: }
1.329 droeschl 580: }
1.484 raeburn 581: $r->print(&endContentScreen());
1.329 droeschl 582: }
583:
1.567 raeburn 584: sub recurse_html {
585: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
586: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
587: my (%allfiles,%codebase);
588: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
589: if (keys(%allfiles)) {
590: foreach my $dependency (keys(%allfiles)) {
591: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
592: my ($depurl,$relfile,$newcontainer);
593: if ($dependency =~ m{^/}) {
594: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
595: $relfile = $1;
596: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
597: $newcontainer = $1;
598: next if ($replacehash->{$newcontainer});
599: }
600: $depurl = $dependency;
601: } else {
602: next;
603: }
604: } else {
605: $relfile = $dependency;
606: $depurl = $currurlpath;
1.630 raeburn 607: $depurl =~ s{[^/]+$}{};
1.567 raeburn 608: $depurl .= $dependency;
1.630 raeburn 609: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
1.567 raeburn 610: }
611: next if ($relfile eq '');
612: my $newname = $replacehash->{$container};
613: $newname =~ s{[^/]+$}{};
614: $replacehash->{$newcontainer} = $newname.$relfile;
615: $deps->{$item}{$newcontainer} = 1;
616: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
617: my $depfile = &Apache::lonnet::filelocation('',$depurl);
618: my $type = $mm->checktype_filename($depfile);
619: if ($type eq 'text/html') {
620: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
621: }
622: }
623: }
624: }
625: return;
626: }
627:
1.329 droeschl 628: sub group_import {
1.598 raeburn 629: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
1.529 raeburn 630: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
631: %removeparam,$importuploaded,$fixuperrors);
632: $allmaps = {};
1.329 droeschl 633: while (@files) {
634: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 635: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 636: && ($caller eq 'londocs')
637: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 638:
1.329 droeschl 639: my $errtext = '';
640: my $fatal = 0;
641: my $newmapstr = '<map>'."\n".
642: '<resource id="1" src="" type="start"></resource>'."\n".
643: '<link from="1" to="2" index="1"></link>'."\n".
644: '<resource id="2" src="" type="finish"></resource>'."\n".
645: '</map>';
646: $env{'form.output'}=$newmapstr;
647: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
648: 'output',$1.$2);
1.534 raeburn 649: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 650: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
651: $fatal = 2;
652: }
653: if ($fatal) {
654: return ($errtext,$fatal);
655: }
656: }
657: if ($url) {
1.626 raeburn 658: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
1.598 raeburn 659: $url = $1;
660: my $marker = $2;
661: my $info = $3;
1.604 raeburn 662: my ($toolid,%toolhash,%toolsettings);
1.642 raeburn 663: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
1.598 raeburn 664: my @toolinfo = split(/:/,$info);
665: if ($residx) {
1.604 raeburn 666: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
1.598 raeburn 667: $toolid = $toolsettings{'id'};
668: } else {
1.604 raeburn 669: $toolid = shift(@toolinfo);
1.598 raeburn 670: }
671: $toolid =~ s/\D//g;
1.604 raeburn 672: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
1.624 raeburn 673: $toolhash{'linktext'},$toolhash{'explanation'},
1.642 raeburn 674: $toolhash{'crslabel'},$toolhash{'crstitle'},$toolhash{'crsappend'}) = @toolinfo;
1.624 raeburn 675: foreach my $item (@extras) {
676: $toolhash{$item} = &unescape($toolhash{$item});
677: }
1.598 raeburn 678: if (ref($ltitoolsref) eq 'HASH') {
679: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
1.643 ! raeburn 680: my @deleted;
1.598 raeburn 681: $toolhash{'id'} = $toolid;
1.628 raeburn 682: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
683: ($toolhash{'target'} eq 'window')) {
1.604 raeburn 684: if ($toolhash{'target'} eq 'window') {
685: foreach my $item ('width','height') {
686: $toolhash{$item} =~ s/^\s+//;
687: $toolhash{$item} =~ s/\s+$//;
1.624 raeburn 688: if ($toolhash{$item} =~ /\D/) {
689: delete($toolhash{$item});
690: if ($residx) {
691: if ($toolsettings{$item}) {
692: push(@deleted,$item);
693: }
694: }
695: }
1.604 raeburn 696: }
697: }
698: } elsif ($residx) {
699: $toolhash{'target'} = $toolsettings{'target'};
700: if ($toolhash{'target'} eq 'window') {
1.630 raeburn 701: foreach my $item ('width','height') {
1.624 raeburn 702: $toolhash{$item} = $toolsettings{$item};
703: }
1.604 raeburn 704: }
705: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
706: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
707: if ($toolhash{'target'} eq 'window') {
708: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
709: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
710: }
711: }
1.598 raeburn 712: if ($toolhash{'target'} eq 'iframe') {
1.624 raeburn 713: foreach my $item ('width','height','linktext','explanation') {
714: delete($toolhash{$item});
715: if ($residx) {
716: if ($toolsettings{$item}) {
717: push(@deleted,$item);
718: }
1.604 raeburn 719: }
720: }
1.628 raeburn 721: } elsif ($toolhash{'target'} eq 'tab') {
722: foreach my $item ('width','height') {
723: delete($toolhash{$item});
724: if ($residx) {
725: if ($toolsettings{$item}) {
726: push(@deleted,$item);
727: }
728: }
729: }
1.604 raeburn 730: }
731: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
1.624 raeburn 732: foreach my $item ('label','title','linktext','explanation') {
733: my $crsitem;
734: if (($item eq 'label') || ($item eq 'title')) {
735: $crsitem = 'crs'.$item;
736: } else {
737: $crsitem = $item;
738: }
1.604 raeburn 739: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
1.624 raeburn 740: $toolhash{$crsitem} =~ s/^\s+//;
741: $toolhash{$crsitem} =~ s/\s+$//;
742: if ($toolhash{$crsitem} eq '') {
743: delete($toolhash{$crsitem});
1.604 raeburn 744: }
745: } else {
1.624 raeburn 746: delete($toolhash{$crsitem});
1.604 raeburn 747: }
1.624 raeburn 748: if (($residx) && (exists($toolsettings{$crsitem}))) {
749: unless (exists($toolhash{$crsitem})) {
750: push(@deleted,$crsitem);
1.604 raeburn 751: }
752: }
1.598 raeburn 753: }
754: }
1.643 ! raeburn 755: if ($toolhash{'passback'}) {
! 756: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
! 757: $toolhash{'gradesecret'} = $gradesecret;
! 758: $toolhash{'gradesecretdate'} = time;
! 759: }
! 760: if ($toolhash{'roster'}) {
! 761: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
! 762: $toolhash{'rostersecret'} = $rostersecret;
! 763: $toolhash{'rostersecretdate'} = time;
! 764: }
1.598 raeburn 765: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
1.604 raeburn 766: if ($putres eq 'ok') {
767: if (@deleted) {
768: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
769: }
770: }
1.598 raeburn 771: }
772: }
773: }
1.529 raeburn 774: if (($caller eq 'londocs') &&
775: ($folder =~ /^default/)) {
1.534 raeburn 776: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 777: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
778: my $cid = $coursedom.'_'.$coursenum;
779: $allmaps =
780: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
781: $chome,$cid);
782: $donechk = 1;
783: }
784: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
1.627 raeburn 785: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
786: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
1.529 raeburn 787: $importuploaded = 1;
788: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
789: next if ($allmaps->{$url});
790: }
791: }
1.344 bisitz 792: if (!$residx
1.329 droeschl 793: || defined($LONCAPA::map::zombies[$residx])) {
794: $residx = &LONCAPA::map::getresidx($url,$residx);
795: push(@LONCAPA::map::order, $residx);
796: }
797: my $ext = 'false';
798: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
799: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 800: if ($name eq '') {
1.538 raeburn 801: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 802: }
803: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
804: my $filepath = $1;
805: my $fname = $name;
806: if ($fname =~ /^\W+$/) {
807: $fname = 'web';
808: } else {
809: $fname =~ s/\W/_/g;
810: }
1.599 damieng 811: if (length($fname) > 15) {
1.534 raeburn 812: $fname = substr($fname,0,14);
813: }
814: my $initialtext = &mt('Replace with your own content.');
815: my $newhtml = <<END;
1.545 raeburn 816: <html>
1.534 raeburn 817: <head>
818: <title>$name</title>
819: </head>
820: <body bgcolor="#ffffff">
821: $initialtext
822: </body>
823: </html>
824: END
825: $env{'form.output'}=$newhtml;
1.630 raeburn 826: my $result =
1.534 raeburn 827: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
828: 'output',
829: "$filepath/$residx/$fname.html");
830: if ($result =~ m{^/uploaded/}) {
831: $url = $result;
832: if ($filepath =~ /^supplemental/) {
833: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
834: $env{'user.domain'}.'___&&&___'.$name;
835: }
836: } else {
837: return (&mt('Failed to save new web page.'),1);
838: }
839: }
1.538 raeburn 840: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 841: $LONCAPA::map::resources[$residx] =
1.329 droeschl 842: join(':', ($name, $url, $ext, 'normal', 'res'));
843: }
844: }
1.529 raeburn 845: if ($importuploaded) {
846: my %import_errors;
847: my %updated = (
848: removefrommap => \%removefrommap,
849: removeparam => \%removeparam,
850: );
1.533 raeburn 851: my ($result,$msgsarray,$lockerror) =
852: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 853: if (keys(%import_errors) > 0) {
1.530 raeburn 854: $fixuperrors =
1.529 raeburn 855: '<p span class="LC_warning">'."\n".
856: &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".
857: '<ul>'."\n";
858: foreach my $key (sort(keys(%import_errors))) {
859: $fixuperrors .= '<li>'.$key.'</li>'."\n";
860: }
861: $fixuperrors .= '</ul></p>'."\n";
862: }
1.533 raeburn 863: if (ref($msgsarray) eq 'ARRAY') {
864: if (@{$msgsarray} > 0) {
865: $fixuperrors .= '<p class="LC_info">'.
866: join('<br />',@{$msgsarray}).
867: '</p>';
868: }
869: }
870: if ($lockerror) {
871: $fixuperrors .= '<p class="LC_error">'.
872: $lockerror.
873: '</p>';
874: }
1.529 raeburn 875: }
876: my ($errtext,$fatal) =
877: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 878: unless ($fatal) {
879: if ($folder =~ /^supplemental/) {
880: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 881: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
882: $folder.'.'.$container);
1.557 raeburn 883: }
884: }
1.529 raeburn 885: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 886: }
887:
888: sub log_docs {
1.494 raeburn 889: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 890: }
891:
892: {
893: my @oldresources=();
894: my @oldorder=();
895: my $parmidx;
896: my %parmaction=();
897: my %parmvalue=();
898: my $changedflag;
899:
900: sub snapshotbefore {
901: @oldresources=@LONCAPA::map::resources;
902: @oldorder=@LONCAPA::map::order;
903: $parmidx=undef;
904: %parmaction=();
905: %parmvalue=();
906: $changedflag=0;
907: }
908:
909: sub remember_parms {
910: my ($idx,$parameter,$action,$value)=@_;
911: $parmidx=$idx;
912: $parmaction{$parameter}=$action;
913: $parmvalue{$parameter}=$value;
914: $changedflag=1;
915: }
916:
917: sub log_differences {
918: my ($plain)=@_;
919: my %storehash=('folder' => $plain,
920: 'currentfolder' => $env{'form.folder'});
921: if ($parmidx) {
922: $storehash{'parameter_res'}=$oldresources[$parmidx];
923: foreach my $parm (keys(%parmaction)) {
924: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
925: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
926: }
927: }
928: my $maxidx=$#oldresources;
929: if ($#LONCAPA::map::resources>$#oldresources) {
930: $maxidx=$#LONCAPA::map::resources;
931: }
932: for (my $idx=0; $idx<=$maxidx; $idx++) {
933: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
934: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
935: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
936: $changedflag=1;
937: }
938: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
939: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
940: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
941: $changedflag=1;
942: }
943: }
944: $storehash{'maxidx'}=$maxidx;
945: if ($changedflag) { &log_docs(\%storehash); }
946: }
947: }
948:
949: sub docs_change_log {
1.611 raeburn 950: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1.486 raeburn 951: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.617 raeburn 952: my $navmap;
1.483 raeburn 953: my $js = '<script type="text/javascript">'."\n".
954: '// <![CDATA['."\n".
955: &Apache::loncommon::display_filter_js('docslog')."\n".
1.606 raeburn 956: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1.622 raeburn 957: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1.483 raeburn 958: &history_tab_js()."\n".
1.484 raeburn 959: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 960: '// ]]>'."\n".
961: '</script>'."\n";
1.484 raeburn 962: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
963: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 964: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 965: my %orderhash;
966: my $container='sequence';
967: my $pathitem;
1.519 raeburn 968: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 969: $container='page';
970: }
1.519 raeburn 971: my $folderpath=$env{'form.folderpath'};
972: if ($folderpath eq '') {
1.617 raeburn 973: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1.519 raeburn 974: }
1.617 raeburn 975: undef($navmap);
1.519 raeburn 976: $pathitem = '<input type="hidden" name="folderpath" value="'.
977: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 978: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
979: my $jumpto = $readfile;
980: $jumpto =~ s{^/}{};
981: my $tid = 1;
1.489 raeburn 982: if ($supplementalflag) {
983: $tid = 2;
984: }
1.630 raeburn 985: my ($breadcrumbtrail) =
1.509 raeburn 986: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 987: $r->print($breadcrumbtrail.
988: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
989: $readfile));
1.329 droeschl 990: my %docslog=&Apache::lonnet::dump('nohist_docslog',
991: $env{'course.'.$env{'request.course.id'}.'.domain'},
992: $env{'course.'.$env{'request.course.id'}.'.num'});
993:
994: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
995:
996: my %saveable_parameters = ('show' => 'scalar',);
997: &Apache::loncommon::store_course_settings('docs_log',
998: \%saveable_parameters);
999: &Apache::loncommon::restore_course_settings('docs_log',
1000: \%saveable_parameters);
1001: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 1002: # FIXME: internationalization seems wrong here
1.329 droeschl 1003: my %lt=('hiddenresource' => 'Resources hidden',
1004: 'encrypturl' => 'URL hidden',
1005: 'randompick' => 'Randomly pick',
1006: 'randomorder' => 'Randomly ordered',
1007: 'set' => 'set to',
1008: 'del' => 'deleted');
1.484 raeburn 1009: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1010: $pathitem."\n".
1011: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1012: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1013: $r->print('<div class="LC_left_float">'.
1014: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1015: &makedocslogform($filter,1).
1016: '</fieldset></div><br clear="all" />');
1.329 droeschl 1017: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1018: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1019: &mt('After').'</th>'.
1020: &Apache::loncommon::end_data_table_header_row());
1021: my $shown=0;
1022: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1023: if ($env{'form.displayfilter'} eq 'currentfolder') {
1024: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1025: }
1026: my @changes=keys(%{$docslog{$id}{'logentry'}});
1027: if ($env{'form.displayfilter'} eq 'containing') {
1028: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1029: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1030: foreach my $key (@changes) {
1031: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1032: }
1.344 bisitz 1033: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1034: }
1035: my $count = 0;
1036: my $time =
1037: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1038: my $plainname =
1039: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1040: $docslog{$id}{'exe_udom'});
1041: my $about_me_link =
1042: &Apache::loncommon::aboutmewrapper($plainname,
1043: $docslog{$id}{'exe_uname'},
1044: $docslog{$id}{'exe_udom'});
1045: my $send_msg_link='';
1046: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1047: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1048: $send_msg_link ='<br />'.
1049: &Apache::loncommon::messagewrapper(&mt('Send message'),
1050: $docslog{$id}{'exe_uname'},
1051: $docslog{$id}{'exe_udom'});
1052: }
1053: $r->print(&Apache::loncommon::start_data_table_row());
1054: $r->print('<td>'.$time.'</td>
1055: <td>'.$about_me_link.
1056: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1057: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1058: $send_msg_link.'</td><td>'.
1059: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 1060: my $is_supp = 0;
1061: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1062: $is_supp = 1;
1063: }
1.329 droeschl 1064: # Before
1065: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1066: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1067: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1068: if ($oldname ne $newname) {
1.488 raeburn 1069: my $shown = &LONCAPA::map::qtescape($oldname);
1070: if ($is_supp) {
1071: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1072: }
1073: $r->print($shown);
1.329 droeschl 1074: }
1075: }
1076: $r->print('<ul>');
1077: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1078: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 1079: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1080: if ($is_supp) {
1081: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1082: }
1083: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1084: }
1085: }
1086: $r->print('</ul>');
1087: # After
1088: $r->print('</td><td>');
1089:
1090: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1091: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1092: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1093: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 1094: my $shown = &LONCAPA::map::qtescape($newname);
1095: if ($is_supp) {
1096: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1097: }
1098: $r->print($shown);
1.329 droeschl 1099: }
1.364 bisitz 1100: }
1.329 droeschl 1101: $r->print('<ul>');
1102: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1103: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 1104: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1105: if ($is_supp) {
1106: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1107: }
1108: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 1109: }
1110: }
1111: $r->print('</ul>');
1112: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1113: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1114: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1115: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 1116: # FIXME: internationalization seems wrong here
1.329 droeschl 1117: $r->print('<li>'.
1118: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1119: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1120: .'</li>');
1121: }
1122: }
1123: $r->print('</ul>');
1124: }
1125: # End
1126: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1127: $shown++;
1128: if (!($env{'form.show'} eq &mt('all')
1129: || $shown<=$env{'form.show'})) { last; }
1130: }
1.484 raeburn 1131: $r->print(&Apache::loncommon::end_data_table()."\n".
1132: &makesimpleeditform($pathitem)."\n".
1133: '</div></div>');
1134: $r->print(&endContentScreen());
1.329 droeschl 1135: }
1136:
1137: sub update_paste_buffer {
1.492 raeburn 1138: my ($coursenum,$coursedom,$folder) = @_;
1.591 raeburn 1139: my (@possibles,%removals,%cuts,$output);
1.538 raeburn 1140: if ($env{'form.multiremove'}) {
1141: $env{'form.multiremove'} =~ s/,$//;
1142: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1143: }
1144: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1145: if ($env{'form.multicut'}) {
1146: $env{'form.multicut'} =~ s/,$//;
1147: foreach my $item (split(/,/,$env{'form.multicut'})) {
1148: unless ($removals{$item}) {
1149: $cuts{$item} = 1;
1150: push(@possibles,$item.':cut');
1151: }
1152: }
1153: }
1154: if ($env{'form.multicopy'}) {
1155: $env{'form.multicopy'} =~ s/,$//;
1156: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1157: unless ($removals{$item} || $cuts{$item}) {
1158: push(@possibles,$item.':copy');
1159: }
1160: }
1161: }
1162: } elsif ($env{'form.markcopy'}) {
1163: @possibles = split(/,/,$env{'form.markcopy'});
1164: }
1.329 droeschl 1165:
1.538 raeburn 1166: return if (@possibles == 0);
1.329 droeschl 1167: return if (!defined($env{'form.copyfolder'}));
1168:
1169: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1170: $env{'form.copyfolder'});
1.538 raeburn 1171: return if ($fatal);
1172:
1173: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1174:
1.538 raeburn 1175: # Retrieve current paste buffer suffixes.
1176: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1177: my (%pasteurls,@newpaste);
1178:
1179: # Construct identifiers for current contents of user's paste buffer
1180: if (@currpaste) {
1181: foreach my $suffix (@currpaste) {
1182: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1183: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.630 raeburn 1184: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1185: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1186: ($url ne '')) {
1.597 raeburn 1187: $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
1.538 raeburn 1188: }
1189: }
1190: }
1191:
1192: # Mark items for copying (skip any items already in user's paste buffer)
1193: my %addtoenv;
1.597 raeburn 1194:
1195: my @pathitems = split(/\&/,$env{'form.folderpath'});
1196: my @folderconf = split(/\:/,$pathitems[-1]);
1197: my $ispage = $folderconf[4];
1198:
1.538 raeburn 1199: foreach my $item (@possibles) {
1200: my ($orderidx,$cmd) = split(/:/,$item);
1201: next if ($orderidx =~ /\D/);
1202: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1.597 raeburn 1203: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1.538 raeburn 1204: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1205: my %denied = &action_restrictions($coursenum,$coursedom,
1206: &LONCAPA::map::qtescape($url),
1207: $env{'form.folderpath'},\%curr_groups);
1208: next if ($denied{'copy'});
1209: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1.597 raeburn 1210: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1.538 raeburn 1211: my ($suffix,$errortxt,$locknotfreed) =
1212: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1.591 raeburn 1213: if ($suffix ne '') {
1214: push(@newpaste,$suffix);
1215: } else {
1216: if ($locknotfreed) {
1217: return $locknotfreed;
1218: }
1.538 raeburn 1219: }
1220: if (&is_supplemental_title($title)) {
1221: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1222: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1223: }
1.329 droeschl 1224:
1.538 raeburn 1225: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1226: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1227: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1228: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1.597 raeburn 1229: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1.538 raeburn 1230: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1231: my $prefix = $1;
1232: my $subdir =$2;
1233: if ($subdir eq '') {
1234: $subdir = $prefix;
1.492 raeburn 1235: }
1.538 raeburn 1236: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1.627 raeburn 1237: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1238: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1.538 raeburn 1239: if (ref($hierarchy{$url}) eq 'HASH') {
1240: my ($nested,$nestednames);
1241: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1242: $nested =~ s/\&$//;
1243: $nestednames =~ s/\Q___&&&___\E$//;
1244: if ($nested ne '') {
1245: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1246: }
1247: if ($nestednames ne '') {
1248: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1249: }
1.492 raeburn 1250: }
1251: }
1.591 raeburn 1252: if ($locknotfreed) {
1253: $output = $locknotfreed;
1254: last;
1255: }
1.492 raeburn 1256: }
1.538 raeburn 1257: if (@newpaste) {
1258: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1259: }
1.492 raeburn 1260: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1261: delete($env{'form.markcopy'});
1.591 raeburn 1262: return $output;
1.329 droeschl 1263: }
1264:
1.492 raeburn 1265: sub recurse_uploaded_maps {
1266: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1267: if (ref($hierarchy->{$url}) eq 'HASH') {
1268: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1269: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1270: my (@uploaded,@names,%shorter);
1271: for (my $i=0; $i<@maps; $i++) {
1272: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1273: if ($inner ne '') {
1274: push(@uploaded,$inner);
1275: push(@names,&escape($titles[$i]));
1276: $shorter{$maps[$i]} = $inner;
1277: }
1278: }
1279: $$nestref .= "$dir:".join(',',@uploaded).'&';
1280: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1281: foreach my $map (@maps) {
1282: if ($shorter{$map} ne '') {
1283: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1284: }
1285: }
1286: }
1287: return;
1288: }
1289:
1.329 droeschl 1290: sub print_paste_buffer {
1.492 raeburn 1291: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1292: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1293:
1.538 raeburn 1294: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1295: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1296: }
1297:
1.538 raeburn 1298: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1299: my ($pasteitems,@pasteable);
1.575 raeburn 1300: my $clipboardcount = 0;
1.488 raeburn 1301:
1.538 raeburn 1302: # Construct identifiers for current contents of user's paste buffer
1303: foreach my $suffix (@currpaste) {
1304: next if ($suffix =~ /\D/);
1305: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1306: my $url = $env{'docs.markedcopy_url_'.$suffix};
1.597 raeburn 1307: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1.538 raeburn 1308: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1309: ($url ne '')) {
1.575 raeburn 1310: $clipboardcount ++;
1.538 raeburn 1311: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1.598 raeburn 1312: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1.538 raeburn 1313: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1314: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1315: $is_external = 1;
1.626 raeburn 1316: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1.598 raeburn 1317: $is_exttool = 1;
1.538 raeburn 1318: }
1319: if ($folder =~ /^supplemental/) {
1320: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1321: unless ($canpaste) {
1322: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1323: }
1324: } else {
1325: $canpaste = 1;
1326: }
1327: if ($canpaste) {
1328: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1329: my $srcdom = $1;
1330: my $srcnum = $2;
1331: my $rem = $3;
1332: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1333: $othercourse = 1;
1334: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.596 raeburn 1335: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1336: } else {
1337: $canpaste = 0;
1338: $nopaste = &mt('Paste from another course unavailable.');
1339: }
1340: }
1341: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1342: my $prefix = $1;
1343: $parent = $2;
1344: if ($folder !~ /^\Q$prefix\E/) {
1345: $areachange = 1;
1346: }
1347: $is_uploaded_map = 1;
1.492 raeburn 1348: }
1.597 raeburn 1349: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.627 raeburn 1350: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1.596 raeburn 1351: if ($cid ne $env{'request.course.id'}) {
1352: my ($srcdom,$srcnum) = split(/_/,$cid);
1353: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.627 raeburn 1354: if (($is_exttool) && ($srcdom ne $coursedom)) {
1355: $canpaste = 0;
1356: $nopaste = &mt('Paste from another domain unavailable.');
1357: } else {
1358: $othercrs = '<br />'.&mt('(from another course)');
1359: }
1.596 raeburn 1360: } else {
1361: $canpaste = 0;
1362: $nopaste = &mt('Paste from another course unavailable.');
1.629 raeburn 1363: }
1.596 raeburn 1364: }
1.492 raeburn 1365: }
1.596 raeburn 1366: if ($canpaste) {
1367: push(@pasteable,$suffix);
1.629 raeburn 1368: }
1.538 raeburn 1369: }
1370: my $buffer;
1.627 raeburn 1371: if ($is_external) {
1.538 raeburn 1372: $buffer = &mt('External Resource').': '.
1373: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1374: &LONCAPA::map::qtescape($url).')';
1.627 raeburn 1375: } elsif ($is_exttool) {
1376: $buffer = &mt('External Tool').': '.
1377: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.538 raeburn 1378: } else {
1379: my $icon = &Apache::loncommon::icon($extension);
1380: if ($extension eq 'sequence' &&
1381: $url =~ m{/default_\d+\.sequence$}x) {
1382: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1383: $icon .= '/navmap.folder.closed.gif';
1384: }
1.589 raeburn 1385: my $title = $env{'docs.markedcopy_title_'.$suffix};
1386: if ($title eq '') {
1387: ($title) = ($url =~ m{/([^/]+)$});
1388: }
1.538 raeburn 1389: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1390: ': '.
1391: &Apache::loncommon::parse_supplemental_title(
1.589 raeburn 1392: &LONCAPA::map::qtescape($title));
1.538 raeburn 1393: }
1394: $pasteitems .= '<div class="LC_left_float">';
1395: my ($options,$onclick);
1396: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1397: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1398: if (($is_uploaded_map) ||
1399: ($url =~ /(bulletinboard|smppg)$/) ||
1400: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1401: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1402: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1403: }
1404: }
1405: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1406: if ($nopaste) {
1407: $pasteitems .= $nopaste;
1408: } else {
1409: if ($othercrs) {
1410: $pasteitems .= $othercrs;
1411: }
1412: if ($options) {
1413: $pasteitems .= $options;
1.492 raeburn 1414: }
1415: }
1.538 raeburn 1416: $pasteitems .= '</div>';
1417: }
1418: }
1419: if ($pasteitems eq '') {
1420: &Apache::lonnet::delenv('docs.markedcopies');
1421: }
1422: my ($pasteform,$form_start,$buttons,$form_end);
1423: if ($pasteitems) {
1424: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1425: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1426: if (@pasteable) {
1.575 raeburn 1427: my $value = &mt('Paste to current folder');
1428: if ($container eq 'page') {
1429: $value = &mt('Paste to current page');
1430: }
1431: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1432: }
1433: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1434: if ($clipboardcount > 1) {
1435: $buttons .=
1436: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1437: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1438: (' 'x2).
1439: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1440: (' 'x2);
1.492 raeburn 1441: }
1.575 raeburn 1442: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1443: '</form>';
1.538 raeburn 1444: } else {
1445: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1446: }
1.538 raeburn 1447: $r->print($form_start
1448: .'<fieldset>'
1449: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1450: .$pasteitems
1451: .'</fieldset>'
1452: .$form_end);
1453: }
1454:
1455: sub paste_options {
1456: my ($suffix,$is_uploaded_map,$parent) = @_;
1457: my ($copytext,$movetext);
1458: if ($is_uploaded_map) {
1459: $copytext = &mt('Copy to new folder');
1460: $movetext = &mt('Move old');
1461: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1462: $copytext = &mt('Copy to new board');
1463: $movetext = &mt('Move (not posts)');
1464: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1465: $copytext = &mt('Copy to new page');
1466: $movetext = &mt('Move');
1.533 raeburn 1467: } else {
1.538 raeburn 1468: $copytext = &mt('Copy to new file');
1469: $movetext = &mt('Move');
1470: }
1471: my $output = '<br />'.
1472: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1473: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1474: '<label>'.
1475: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1476: $copytext.'</label></span>'.(' 'x2).' '.
1477: '<span class="LC_nobreak"><label>'.
1478: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1479: $movetext.'</label></span>';
1480: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1481: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1482: '</legend><table border="0">';
1483: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1484: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1485: my $lastdir = $parent;
1486: my %depths = (
1487: $lastdir => 0,
1488: );
1489: my (%display,%deps);
1490: for (my $i=0; $i<@pastemaps; $i++) {
1491: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1492: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1493: my @subfolders = split(/,/,$subfolderstr);
1494: $deps{$lastdir} = \@subfolders;
1495: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1496: my $depth = $depths{$lastdir} + 1;
1497: my $offset = int($depth * 4);
1498: my $indent = (' ' x $offset);
1499: for (my $j=0; $j<@subfolders; $j++) {
1500: $depths{$subfolders[$j]} = $depth;
1501: $display{$subfolders[$j]} =
1502: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1503: '<td><label>'.
1504: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1505: '<label>'.
1506: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1507: &mt('Move old').'</label>'.
1508: '</td></tr>';
1509: }
1.492 raeburn 1510: }
1.538 raeburn 1511: &recurse_print(\$output,$parent,\%deps,\%display);
1512: $output .= '</table></fieldset>';
1.329 droeschl 1513: }
1.538 raeburn 1514: $output .= '</div>';
1515: return $output;
1.488 raeburn 1516: }
1517:
1.492 raeburn 1518: sub recurse_print {
1.538 raeburn 1519: my ($outputref,$dir,$deps,$display) = @_;
1520: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1521: if (ref($deps->{$dir}) eq 'ARRAY') {
1522: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1523: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1524: }
1525: }
1526: }
1527:
1.488 raeburn 1528: sub supp_pasteable {
1529: my ($url) = @_;
1530: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1531: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1532: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1533: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1.598 raeburn 1534: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.626 raeburn 1535: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.488 raeburn 1536: return 1;
1537: }
1538: return;
1.329 droeschl 1539: }
1540:
1.492 raeburn 1541: sub paste_popup_js {
1.594 damieng 1542: my %html_js_lt = &Apache::lonlocal::texthash(
1.538 raeburn 1543: show => 'Show Options',
1544: hide => 'Hide Options',
1.594 damieng 1545: );
1546: my %js_lt = &Apache::lonlocal::texthash(
1.541 raeburn 1547: none => 'No items selected from clipboard.',
1.492 raeburn 1548: );
1.594 damieng 1549: &html_escape(\%html_js_lt);
1550: &js_escape(\%html_js_lt);
1551: &js_escape(\%js_lt);
1.492 raeburn 1552: return <<"END";
1553:
1.538 raeburn 1554: function showPasteOptions(suffix) {
1555: document.getElementById('pasteoptions_'+suffix).style.display='block';
1.594 damieng 1556: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1.492 raeburn 1557: return;
1558: }
1559:
1.538 raeburn 1560: function hidePasteOptions(suffix) {
1561: document.getElementById('pasteoptions_'+suffix).style.display='none';
1.594 damieng 1562: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1563: return;
1564: }
1565:
1566: function showOptions(caller,suffix) {
1567: if (document.getElementById('pasteoptionstext_'+suffix)) {
1568: if (caller.checked) {
1.594 damieng 1569: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1.538 raeburn 1570: } else {
1571: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1572: }
1573: if (document.getElementById('pasteoptions_'+suffix)) {
1574: document.getElementById('pasteoptions_'+suffix).style.display='none';
1575: }
1576: }
1.492 raeburn 1577: return;
1578: }
1579:
1.541 raeburn 1580: function validateClipboard() {
1581: var numchk = 0;
1582: if (document.pasteform.pasting.length > 1) {
1583: for (var i=0; i<document.pasteform.pasting.length; i++) {
1584: if (document.pasteform.pasting[i].checked) {
1585: numchk ++;
1586: }
1587: }
1588: } else {
1589: if (document.pasteform.pasting.type == 'checkbox') {
1590: if (document.pasteform.pasting.checked) {
1591: numchk ++;
1592: }
1593: }
1594: }
1595: if (numchk > 0) {
1596: return true;
1597: } else {
1.594 damieng 1598: alert("$js_lt{'none'}");
1.541 raeburn 1599: return false;
1600: }
1601: }
1602:
1.575 raeburn 1603: function checkClipboard() {
1604: if (document.pasteform.pasting.length > 1) {
1605: for (var i=0; i<document.pasteform.pasting.length; i++) {
1606: document.pasteform.pasting[i].checked = true;
1607: }
1608: }
1609: return;
1610: }
1611:
1612: function uncheckClipboard() {
1613: if (document.pasteform.pasting.length >1) {
1614: for (var i=0; i<document.pasteform.pasting.length; i++) {
1615: document.pasteform.pasting[i].checked = false;
1616: }
1617: }
1618: return;
1619: }
1620:
1.492 raeburn 1621: END
1622:
1623: }
1624:
1.329 droeschl 1625: sub do_paste_from_buffer {
1.492 raeburn 1626: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1627:
1.538 raeburn 1628: # Array of items in paste buffer
1629: my (@currpaste,%pastebuffer,%allerrors);
1630: @currpaste = split(/,/,$env{'docs.markedcopies'});
1631:
1.492 raeburn 1632: # Early out if paste buffer is empty
1.538 raeburn 1633: if (@currpaste == 0) {
1.492 raeburn 1634: return ();
1.538 raeburn 1635: }
1636: map { $pastebuffer{$_} = 1; } @currpaste;
1637:
1638: # Array of items selected items to paste
1639: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1640:
1641: # Early out if nothing selected to paste
1642: if (@reqpaste == 0) {
1643: return();
1644: }
1645: my @topaste;
1646: foreach my $suffix (@reqpaste) {
1647: next if ($suffix =~ /\D/);
1648: next unless (exists($pastebuffer{$suffix}));
1649: push(@topaste,$suffix);
1650: }
1651:
1652: # Early out if nothing available to paste
1653: if (@topaste == 0) {
1654: return();
1.329 droeschl 1655: }
1656:
1.627 raeburn 1657: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1.597 raeburn 1658: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1659:
1660: foreach my $suffix (@topaste) {
1661: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.596 raeburn 1662: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.597 raeburn 1663: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1.492 raeburn 1664: # Supplemental content may only include certain types of content
1665: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1666: if ($folder =~ /^supplemental/) {
1667: unless (&supp_pasteable($url)) {
1668: $notinsupp{$suffix} = 1;
1669: next;
1670: }
1.492 raeburn 1671: }
1.538 raeburn 1672: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1673: my $srcd = $1;
1674: my $srcn = $2;
1.492 raeburn 1675: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1676: # check for mdc privilege in the course from which the resource was pasted
1677: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1678: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1679: $notincrs{$suffix} = 1;
1680: next;
1681: }
1.491 raeburn 1682: }
1.538 raeburn 1683: $srcdom{$suffix} = $srcd;
1684: $srcnum{$suffix} = $srcn;
1.597 raeburn 1685: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1.632 raeburn 1686: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1687: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1.596 raeburn 1688: my ($srcd,$srcn) = split(/_/,$cid);
1689: # When paste buffer was populated using an active role in a different course
1690: # check for mdc privilege in the course from which the resource was pasted
1691: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1692: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1693: $notincrs{$suffix} = 1;
1694: next;
1695: }
1696: }
1.632 raeburn 1697: # When buffer was populated using an active role in a different course
1698: # disallow pasting of External Tool if course is in a different domain.
1699: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1.627 raeburn 1700: $notindom{$suffix} = 1;
1701: next;
1702: }
1.596 raeburn 1703: $srcdom{$suffix} = $srcd;
1704: $srcnum{$suffix} = $srcn;
1.491 raeburn 1705: }
1.597 raeburn 1706: $srcmapidx{$suffix} = $mapidx;
1.538 raeburn 1707: push(@dopaste,$suffix);
1708: if ($url=~/\.(page|sequence)$/) {
1709: $is_map{$suffix} = 1;
1710: }
1711: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1712: my $oldprefix = $1;
1.492 raeburn 1713: # When pasting content from Main Content to Supplemental Content and vice versa
1714: # URLs will contain different paths (which depend on whether pasted item is
1.597 raeburn 1715: # a folder/page or a document).
1.538 raeburn 1716: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1717: $prefixchg{$suffix} = 'docstosupp';
1718: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1719: $prefixchg{$suffix} = 'supptodocs';
1720: }
1.491 raeburn 1721:
1.492 raeburn 1722: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1723: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1724: my @nested;
1725: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1726: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1727: my @deps = map { /\d+:([\d,]+$)/ } @items;
1728: foreach my $dep (@deps) {
1729: if ($dep =~ /,/) {
1730: push(@nested,split(/,/,$dep));
1731: } else {
1732: push(@nested,$dep);
1733: }
1.492 raeburn 1734: }
1.538 raeburn 1735: foreach my $item (@nested) {
1736: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1737: push(@{$marktomove{$suffix}},$type.'_'.$item);
1738: }
1.492 raeburn 1739: }
1740: }
1.488 raeburn 1741: }
1742: }
1743:
1.538 raeburn 1744: # Early out if nothing available to paste
1745: if (@dopaste == 0) {
1746: return ();
1747: }
1748:
1749: # Populate message hash and hashes used for main content <=> supplemental content
1750: # changes
1751:
1752: %msgs = &Apache::lonlocal::texthash (
1753: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1754: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1.627 raeburn 1755: notindom => 'Paste failed: Item is an external tool from a course in a different donain.',
1.538 raeburn 1756: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1757: );
1758:
1759: %before = (
1760: docstosupp => {
1761: map => 'default',
1762: doc => 'docs',
1763: },
1764: supptodocs => {
1765: map => 'supplemental',
1766: doc => 'supplemental',
1767: },
1768: );
1769:
1770: %after = (
1771: docstosupp => {
1772: map => 'supplemental',
1773: doc => 'supplemental'
1774: },
1775: supptodocs => {
1776: map => 'default',
1777: doc => 'docs',
1778: },
1779: );
1780:
1781: # Retrieve information about all course maps in main content area
1782:
1783: my $allmaps = {};
1784: if ($folder =~ /^default/) {
1785: $allmaps =
1786: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1787: $env{"course.$env{'request.course.id'}.home"},
1788: $env{'request.course.id'});
1789: }
1790:
1791: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1792:
1793: # Loop over the items to paste
1794: foreach my $suffix (@dopaste) {
1.329 droeschl 1795: # Maps need to be copied first
1.538 raeburn 1796: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1797: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1.597 raeburn 1798: %newurls,%tomove,%resdatacopy);
1.538 raeburn 1799: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1800: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1801: }
1802: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1803: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1.596 raeburn 1804: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1.538 raeburn 1805: my $oldurl = $url;
1806: if ($is_map{$suffix}) {
1.491 raeburn 1807: # If pasting a map, check if map contains other maps
1.538 raeburn 1808: my (%hierarchy,%titles);
1.627 raeburn 1809: &contained_map_check($url,$folder,$coursenum,$coursedom,
1810: \%removefrommap,\%removeparam,\%addedmaps,
1811: \%hierarchy,\%titles,$allmaps);
1.538 raeburn 1812: if ($url=~ m{^/uploaded/}) {
1813: my $newurl;
1814: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1815: ($newurl,my $error) =
1816: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1817: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1818: \$title,$allmaps,\%newurls);
1819: if ($error) {
1820: $allerrors{$suffix} = $error;
1821: next;
1822: }
1823: if ($newurl ne '') {
1824: if ($newurl ne $url) {
1825: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1826: $newsubdir{$url} = $1;
1827: }
1828: $mapchanges{$url} = 1;
1.492 raeburn 1829: }
1.538 raeburn 1830: }
1831: }
1832: if (($srcdom{$suffix} ne $coursedom) ||
1833: ($srcnum{$suffix} ne $coursenum) ||
1834: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1835: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1836: $coursedom,$coursenum,$srcdom{$suffix},
1837: $srcnum{$suffix},$allmaps,\%rewrites,
1838: \%retitles,\%copies,\%dbcopies,
1839: \%zombies,\%params,\%mapmoves,
1840: \%mapchanges,\%tomove,\%newsubdir,
1.597 raeburn 1841: \%newurls,\%resdatacopy)) {
1.538 raeburn 1842: $mapmoves{$url} = 1;
1843: }
1844: $url = $newurl;
1845: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1846: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1847: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1848: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1849: \%zombies,\%params,\%mapmoves,\%mapchanges,
1.597 raeburn 1850: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1.538 raeburn 1851: }
1852: } elsif ($url=~m {^/res/}) {
1.597 raeburn 1853: # published map can only exist once, so remove from paste buffer when done
1.538 raeburn 1854: push(@toclear,$suffix);
1855: # if pasting published map (main content area only) check map not already in course
1856: if ($folder =~ /^default/) {
1857: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1858: $duplicate{$suffix} = 1;
1859: next;
1.492 raeburn 1860: }
1.491 raeburn 1861: }
1862: }
1.538 raeburn 1863: }
1.627 raeburn 1864: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1.538 raeburn 1865: my $prefix = $1;
1.596 raeburn 1866: my $fromothercrs;
1.538 raeburn 1867: #need to copy the db contents to a new one, unless this is a move.
1868: my %info = (
1869: src => $url,
1870: cdom => $coursedom,
1871: cnum => $coursenum,
1.596 raeburn 1872: );
1873: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1874: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1875: $fromothercrs = 1;
1876: $info{'cdom'} = $srcdom{$suffix};
1877: $info{'cnum'} = $srcnum{$suffix};
1878: }
1879: }
1880: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1.630 raeburn 1881: my (%lockerr,$msg);
1.538 raeburn 1882: my ($newurl,$result,$errtext) =
1883: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1884: if ($result eq 'ok') {
1885: $url = $newurl;
1886: $title=&mt('Copy of').' '.$title;
1887: } else {
1888: if ($prefix eq 'smppg') {
1889: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1890: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1891: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.627 raeburn 1892: } elsif ($prefix eq 'ext.tool') {
1893: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1.538 raeburn 1894: }
1895: $results{$suffix} = $result;
1896: $msgerrs{$suffix} = $msg;
1897: $lockerrs{$suffix} = $lockerr{$prefix};
1898: next;
1899: }
1900: if ($lockerr{$prefix}) {
1901: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1902: }
1.489 raeburn 1903: }
1904: }
1.538 raeburn 1905: $title = &LONCAPA::map::qtunescape($title);
1906: my $ext='false';
1907: if ($url=~m{^http(|s)://}) { $ext='true'; }
1908: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1909: if ($folder !~ /^supplemental/) {
1910: (undef,undef,$title) =
1911: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1912: }
1913: } else {
1914: if ($folder=~/^supplemental/) {
1915: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1916: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1917: }
1.533 raeburn 1918: }
1.491 raeburn 1919:
1920: # For uploaded files (excluding pages/sequences) path in copied file is changed
1921: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1922: # courses.
1923:
1.538 raeburn 1924: unless ($is_map{$suffix}) {
1925: my $newidx;
1.492 raeburn 1926: # Now insert the URL at the bottom
1.538 raeburn 1927: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1928: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1929: my $relpath = $1;
1930: if ($relpath ne '') {
1931: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1932: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1933: my $newprefix = $newloc;
1934: if ($newloc eq 'default') {
1935: $newprefix = 'docs';
1936: }
1937: if ($newdocsdir eq '') {
1938: $newdocsdir = 'default';
1939: }
1.630 raeburn 1940: if (($prefixchg{$suffix}) ||
1941: ($srcdom{$suffix} ne $coursedom) ||
1.538 raeburn 1942: ($srcnum{$suffix} ne $coursenum) ||
1943: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1944: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1945: $url =
1946: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1947: &Apache::lonnet::getfile($oldurl));
1948: if ($url eq '/adm/notfound.html') {
1949: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1950: next;
1951: } else {
1952: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1953: $newsubpath =~ s{/+$}{/};
1954: $docmoves{$oldurl} = $newsubpath;
1955: }
1.491 raeburn 1956: }
1957: }
1.597 raeburn 1958: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
1959: my $template = $1;
1960: if ($newidx) {
1961: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
1962: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
1963: }
1.491 raeburn 1964: }
1.538 raeburn 1965: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1966: ':'.$ext.':normal:res';
1967: push(@LONCAPA::map::order,$newidx);
1968: # Store the result
1969: my ($errtext,$fatal) =
1970: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1971: if ($fatal) {
1972: $save_err .= $errtext;
1973: $allresult = 'fail';
1974: }
1.488 raeburn 1975: }
1.538 raeburn 1976:
1.597 raeburn 1977: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
1978: # resourcedata for simpleproblems copied from another course
1.538 raeburn 1979: unless ($allresult eq 'fail') {
1980: my %updated = (
1981: rewrites => \%rewrites,
1982: zombies => \%zombies,
1983: removefrommap => \%removefrommap,
1984: removeparam => \%removeparam,
1985: dbcopies => \%dbcopies,
1.597 raeburn 1986: resdatacopy => \%resdatacopy,
1.538 raeburn 1987: retitles => \%retitles,
1988: );
1989: my %info = (
1990: newsubdir => \%newsubdir,
1991: params => \%params,
1992: );
1993: if ($prefixchg{$suffix}) {
1994: $info{'before'} = $before{$prefixchg{$suffix}};
1995: $info{'after'} = $after{$prefixchg{$suffix}};
1996: }
1997: my %moves = (
1998: copies => \%copies,
1999: docmoves => \%docmoves,
2000: mapmoves => \%mapmoves,
2001: );
2002: (my $result,$msgs{$suffix},my $lockerror) =
2003: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2004: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2005: $url,'paste');
2006: $lockerrors .= $lockerror;
2007: if ($result eq 'ok') {
2008: if ($is_map{$suffix}) {
2009: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2010: $folder.'.'.$container);
2011: if ($fatal) {
2012: $allresult = 'failread';
2013: } else {
2014: if ($#LONCAPA::map::order<1) {
2015: my $idx=&LONCAPA::map::getresidx();
2016: if ($idx<=0) { $idx=1; }
2017: $LONCAPA::map::order[0]=$idx;
2018: $LONCAPA::map::resources[$idx]='';
2019: }
2020: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2021: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2022: ':'.$ext.':normal:res';
2023: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 2024:
2025: # Store the result
1.538 raeburn 2026: my ($errtext,$fatal) =
2027: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2028: if ($fatal) {
2029: $save_err .= $errtext;
2030: $allresult = 'failstore';
2031: }
2032: }
2033: }
2034: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2035: push(@toclear,$suffix);
2036: }
2037: }
1.492 raeburn 2038: }
2039: }
1.538 raeburn 2040: &clear_from_buffer(\@toclear,\@currpaste);
2041: my $msgsarray;
2042: foreach my $suffix (keys(%msgs)) {
2043: if (ref($msgs{$suffix}) eq 'ARRAY') {
2044: $msgsarray .= join(',',@{$msgs{$suffix}});
2045: }
2046: }
2047: return ($allresult,$save_err,$msgsarray,$lockerrors);
2048: }
1.533 raeburn 2049:
1.538 raeburn 2050: sub do_buffer_empty {
2051: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2052: if (@currpaste == 0) {
2053: return &mt('Clipboard is already empty');
2054: }
2055: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2056: if (@toclear == 0) {
2057: return &mt('Nothing selected to clear from clipboard');
2058: }
2059: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2060: if ($numdel) {
2061: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2062: } else {
2063: return &mt('Clipboard unchanged');
1.492 raeburn 2064: }
1.538 raeburn 2065: return;
2066: }
2067:
2068: sub clear_from_buffer {
2069: my ($toclear,$currpaste) = @_;
2070: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2071: my %pastebuffer;
2072: map { $pastebuffer{$_} = 1; } @{$currpaste};
2073: my $numdel = 0;
2074: foreach my $suffix (@{$toclear}) {
2075: next if ($suffix =~ /\D/);
2076: next unless (exists($pastebuffer{$suffix}));
2077: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2078: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2079: delete($pastebuffer{$suffix});
2080: $numdel ++;
2081: }
2082: }
2083: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2084: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2085: return $numdel;
1.492 raeburn 2086: }
2087:
2088: sub get_newmap_url {
2089: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2090: $titleref,$allmaps,$newurls) = @_;
2091: my $newurl;
2092: if ($url=~ m{^/uploaded/}) {
2093: $$titleref=&mt('Copy of').' '.$$titleref;
2094: }
2095: my $now = time;
2096: my $suffix=$$.int(rand(100)).$now;
2097: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2098: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2099: my $path = $1;
2100: my $prefix = $2;
2101: my $ancestor = $3;
2102: if (length($ancestor) > 10) {
2103: $ancestor = substr($ancestor,-10,10);
2104: }
2105: my $newid;
2106: if ($prefixchg) {
2107: if ($folder =~ /^supplemental/) {
2108: $prefix =~ s/^default/supplemental/;
2109: } else {
2110: $prefix =~ s/^supplemental/default/;
2111: }
2112: }
2113: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2114: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2115: } else {
2116: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2117: }
2118: my $counter = 0;
2119: my $is_unique = &uniqueness_check($newurl);
2120: if ($folder =~ /^default/) {
2121: if ($allmaps->{$newurl}) {
2122: $is_unique = 0;
2123: }
2124: }
2125: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2126: $counter ++;
2127: $suffix ++;
2128: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2129: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2130: } else {
2131: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2132: }
2133: $is_unique = &uniqueness_check($newurl);
2134: }
2135: if ($is_unique) {
2136: $newurls->{$newurl} = 1;
2137: } else {
2138: if ($url=~/\.page$/) {
2139: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2140: } else {
2141: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2142: }
2143: }
1.329 droeschl 2144: }
1.492 raeburn 2145: return ($newurl);
1.329 droeschl 2146: }
2147:
1.488 raeburn 2148: sub dbcopy {
1.533 raeburn 2149: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2150: my ($url,$result,$errtext);
2151: if (ref($dbref) eq 'HASH') {
1.596 raeburn 2152: $url = $dbref->{'src'};
1.627 raeburn 2153: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
1.533 raeburn 2154: my $prefix = $1;
1.627 raeburn 2155: if ($prefix eq 'ext.tool') {
2156: $prefix = 'exttool';
2157: }
1.533 raeburn 2158: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2159: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2160: my $db_name;
2161: my $marker = (split(m{/},$url))[4];
2162: $marker=~s/\D//g;
2163: if ($dbref->{'src'} =~ m{/smppg$}) {
2164: $db_name =
2165: &Apache::lonsimplepage::get_db_name($url,$marker,
2166: $dbref->{'cdom'},
2167: $dbref->{'cnum'});
1.627 raeburn 2168: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2169: $db_name = 'exttool_'.$marker;
1.533 raeburn 2170: } else {
2171: $db_name = 'bulletinpage_'.$marker;
2172: }
2173: my ($suffix,$freedlock,$error) =
2174: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2175: $coursedom,$coursenum,
2176: 'concat');
2177: if (!$suffix) {
2178: if ($prefix eq 'smppg') {
2179: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1.631 raeburn 2180: } elsif ($prefix eq 'exttool') {
2181: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
1.533 raeburn 2182: } else {
1.565 bisitz 2183: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 2184: }
2185: if ($error) {
2186: $errtext .= '<br />'.$error;
2187: }
2188: } else {
2189: #need to copy the db contents to a new one.
2190: my %contents=&Apache::lonnet::dump($db_name,
2191: $dbref->{'cdom'},
2192: $dbref->{'cnum'});
2193: if (exists($contents{'uploaded.photourl'})) {
2194: my $photo = $contents{'uploaded.photourl'};
2195: my ($subdir,$fname) =
2196: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1.596 raeburn 2197: my $newphoto;
1.533 raeburn 2198: if ($fname ne '') {
2199: my $content = &Apache::lonnet::getfile($photo);
2200: unless ($content eq '-1') {
2201: $env{'form.'.$suffix.'.photourl'} = $content;
2202: $newphoto =
2203: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2204: delete($env{'form.'.$suffix.'.photourl'});
2205: }
2206: }
2207: if ($newphoto =~ m{^/uploaded/}) {
2208: $contents{'uploaded.photourl'} = $newphoto;
2209: }
2210: }
2211: $db_name =~ s{_\d*$ }{_$suffix}x;
2212: $result=&Apache::lonnet::put($db_name,\%contents,
2213: $coursedom,$coursenum);
2214: if ($result eq 'ok') {
1.627 raeburn 2215: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
1.533 raeburn 2216: }
2217: }
2218: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 2219: $lockerrorsref->{$prefix} =
1.533 raeburn 2220: '<div class="LC_error">'.
2221: &mt('There was a problem removing a lockfile.');
2222: if ($prefix eq 'smppg') {
1.560 raeburn 2223: $lockerrorsref->{$prefix} .=
1.559 raeburn 2224: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.627 raeburn 2225: } elsif ($prefix eq 'exttool') {
2226: $lockerrorsref->{$prefix} .=
2227: ' '.&mt('This will prevent addition of more external tools to this course.');
1.533 raeburn 2228: } else {
1.565 bisitz 2229: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 2230: }
1.560 raeburn 2231: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2232: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2233: '</div>';
1.533 raeburn 2234: }
2235: }
2236: } elsif ($url =~ m{/syllabus$}) {
2237: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2238: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2239: if (($dbref->{'cdom'} ne $coursedom) ||
2240: ($dbref->{'cnum'} ne $coursenum)) {
2241: my %contents=&Apache::lonnet::dump('syllabus',
2242: $dbref->{'cdom'},
2243: $dbref->{'cnum'});
2244: $result=&Apache::lonnet::put('syllabus',\%contents,
2245: $coursedom,$coursenum);
2246: }
2247: }
1.488 raeburn 2248: }
2249: }
1.533 raeburn 2250: return ($url,$result,$errtext);
1.488 raeburn 2251: }
2252:
1.597 raeburn 2253: sub copy_templated_files {
2254: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2255: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2256: my $srccontainer = 'sequence';
2257: if ($srcwaspage) {
2258: $srccontainer = 'page';
2259: }
2260: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2261: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2262: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2263: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2264: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2265: $template.'.problem';
2266: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2267: if ($template eq 'simpleproblem') {
2268: $srcprefix .= '.0.';
2269: my $weightprefix = $newprefix;
2270: $newprefix .= '.0.';
2271: my @simpleprobqtypes = qw(radio option string essay numerical);
2272: my $qtype=$srcparms{$srcprefix.'questiontype'};
2273: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2274: my %newdata;
2275: foreach my $type (@simpleprobqtypes) {
2276: if ($type eq $qtype) {
2277: $newdata{"$weightprefix.$type.weight"}=1;
2278: } else {
2279: $newdata{"$weightprefix.$type.weight"}=0;
2280: }
2281: }
2282: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2283: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2284: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2285: if ($qtype eq 'numerical') {
2286: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2287: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2288: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2289: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2290: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2291: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2292: unless (defined($maxfoils)) { $maxfoils=10; }
2293: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2294: if ($maxfoils<=0) { $maxfoils=10; }
2295: my $randomize=$srcparms{$srcprefix.'randomize'};
2296: unless (defined($randomize)) { $randomize='yes'; }
2297: unless ($randomize eq 'no') { $randomize='yes'; }
2298: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2299: $newdata{$newprefix.'randomize'} = $randomize;
2300: if ($qtype eq 'option') {
2301: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2302: }
2303: for (my $i=1; $i<=10; $i++) {
2304: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2305: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2306: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2307: }
2308:
2309: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2310: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2311: unless (defined($maxfoils)) { $maxfoils=10; }
2312: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2313: if ($maxfoils<=0) { $maxfoils=10; }
2314: my $randomize=$srcparms{$srcprefix.'randomize'};
2315: unless (defined($randomize)) { $randomize='yes'; }
2316: unless ($randomize eq 'no') { $randomize='yes'; }
2317: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2318: $newdata{$newprefix.'randomize'} = $randomize;
2319: if ($qtype eq 'option') {
2320: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2321: }
2322: for (my $i=1; $i<=10; $i++) {
2323: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2324: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2325: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2326: }
2327: } elsif ($qtype eq 'string') {
2328: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2329: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2330: }
2331: if (keys(%newdata)) {
2332: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2333: $coursenum);
2334: if ($putres eq 'ok') {
2335: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2336: }
2337: }
2338: }
2339: }
2340: }
2341:
1.329 droeschl 2342: sub uniqueness_check {
2343: my ($newurl) = @_;
2344: my $unique = 1;
2345: foreach my $res (@LONCAPA::map::order) {
2346: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2347: $url=&LONCAPA::map::qtescape($url);
2348: if ($newurl eq $url) {
2349: $unique = 0;
1.344 bisitz 2350: last;
1.329 droeschl 2351: }
2352: }
2353: return $unique;
2354: }
2355:
1.488 raeburn 2356: sub contained_map_check {
1.627 raeburn 2357: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2358: $hierarchy,$titles,$allmaps) = @_;
1.488 raeburn 2359: my $content = &Apache::lonnet::getfile($url);
2360: unless ($content eq '-1') {
2361: my $parser = HTML::TokeParser->new(\$content);
2362: $parser->attr_encoded(1);
2363: while (my $token = $parser->get_token) {
2364: next if ($token->[0] ne 'S');
2365: if ($token->[1] eq 'resource') {
2366: next if ($token->[2]->{'type'} eq 'zombie');
2367: my $ressrc = $token->[2]->{'src'};
1.627 raeburn 2368: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2369: my $srcdom = $1;
2370: unless ($srcdom eq $coursedom) {
2371: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2372: next;
2373: }
2374: } elsif ($folder =~ /^supplemental/) {
1.488 raeburn 2375: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 2376: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 2377: next;
2378: }
2379: }
1.492 raeburn 2380: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2381: if ($1 eq 'uploaded') {
2382: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2383: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 2384: } else {
1.492 raeburn 2385: if ($allmaps->{$ressrc}) {
1.529 raeburn 2386: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2387: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2388: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2389: } else {
2390: $addedmaps->{$ressrc} = [$url];
2391: }
1.488 raeburn 2392: }
1.627 raeburn 2393: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2394: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2395: }
1.492 raeburn 2396: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2397: if ($folder =~ /^supplemental/) {
1.492 raeburn 2398: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2399: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2400: } else {
2401: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2402: }
1.488 raeburn 2403: }
2404: }
2405: }
2406: }
2407: return;
2408: }
2409:
2410: sub url_paste_fixups {
1.533 raeburn 2411: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2412: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1.597 raeburn 2413: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
1.491 raeburn 2414: my $checktitle;
2415: if (($prefixchg) &&
1.492 raeburn 2416: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2417: $checktitle = 1;
2418: }
1.492 raeburn 2419: my $skip;
2420: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2421: my $mapid = $1.$2;
2422: if ($tomove->{$mapid}) {
2423: $skip = 1;
2424: }
2425: }
1.491 raeburn 2426: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2427: return if ($file eq '-1');
2428: my $parser = HTML::TokeParser->new(\$file);
2429: $parser->attr_encoded(1);
1.491 raeburn 2430: my $changed = 0;
1.488 raeburn 2431: while (my $token = $parser->get_token) {
2432: next if ($token->[0] ne 'S');
2433: if ($token->[1] eq 'resource') {
2434: my $ressrc = $token->[2]->{'src'};
2435: next if ($ressrc eq '');
1.491 raeburn 2436: my $id = $token->[2]->{'id'};
1.492 raeburn 2437: my $title = $token->[2]->{'title'};
1.491 raeburn 2438: if ($checktitle) {
2439: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2440: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2441: }
2442: }
1.488 raeburn 2443: next if ($token->[2]->{'type'} eq 'external');
2444: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2445: next if ($skip);
1.532 raeburn 2446: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2447: $changed = 1;
2448: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2449: my $srcdom = $1;
2450: my $srcnum = $2;
1.488 raeburn 2451: my $rem = $3;
1.492 raeburn 2452: my $newurl;
2453: my $mapname;
2454: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2455: my $prefix = $1;
2456: $mapname = $prefix.$2;
2457: if ($tomove->{$mapname}) {
1.533 raeburn 2458: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2459: $srcdom,$srcnum,$allmaps,$rewrites,
2460: $retitles,$copies,$dbcopies,$zombies,
2461: $params,$mapmoves,$mapchanges,$tomove,
1.597 raeburn 2462: $newsubdir,$newurls,$resdatacopy);
1.492 raeburn 2463: next;
2464: } else {
2465: ($newurl,my $error) =
2466: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2467: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2468: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2469: $newsubdir->{$ressrc} = $1;
2470: }
2471: if ($error) {
2472: next;
2473: }
2474: }
2475: }
2476: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2477: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2478:
1.488 raeburn 2479: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2480: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2481: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2482: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2483: $cnum,$srcdom,$srcnum,$allmaps,
2484: $rewrites,$retitles,$copies,$dbcopies,
2485: $zombies,$params,$mapmoves,$mapchanges,
1.597 raeburn 2486: $tomove,$newsubdir,$newurls,$resdatacopy)) {
1.491 raeburn 2487: $mapmoves->{$ressrc} = 1;
2488: }
2489: $changed = 1;
1.488 raeburn 2490: } else {
1.532 raeburn 2491: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2492: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2493: $changed = 1;
1.488 raeburn 2494: }
2495: }
1.533 raeburn 2496: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2497: next if ($skip);
1.492 raeburn 2498: my $srcdom = $1;
2499: my $srcnum = $2;
2500: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2501: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2502: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2503: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2504: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2505: $changed = 1;
2506: }
2507: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2508: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2509: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2510: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2511: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2512: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2513: $changed = 1;
1.488 raeburn 2514: }
1.597 raeburn 2515: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2516: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2517: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2518: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2519: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2520: }
1.488 raeburn 2521: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2522: next if ($skip);
2523: my $srcdom = $1;
2524: my $srcnum = $2;
2525: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2526: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2527: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2528: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2529: $changed = 1;
1.488 raeburn 2530: }
2531: }
2532: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2533: next if ($skip);
1.488 raeburn 2534: my $to = $token->[2]->{'to'};
2535: if ($to ne '') {
2536: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2537: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2538: } else {
2539: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2540: }
2541: }
2542: }
2543: }
1.491 raeburn 2544: return $changed;
1.488 raeburn 2545: }
2546:
2547: sub apply_fixups {
1.529 raeburn 2548: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2549: $oldurl,$url,$caller) = @_;
2550: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2551: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1.597 raeburn 2552: %resdatacopy,%lockerrors,$lockmsg);
1.529 raeburn 2553: if (ref($updated) eq 'HASH') {
2554: if (ref($updated->{'rewrites'}) eq 'HASH') {
2555: %rewrites = %{$updated->{'rewrites'}};
2556: }
2557: if (ref($updated->{'zombies'}) eq 'HASH') {
2558: %zombies = %{$updated->{'zombies'}};
2559: }
2560: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2561: %removefrommap = %{$updated->{'removefrommap'}};
2562: }
2563: if (ref($updated->{'removeparam'}) eq 'HASH') {
2564: %removeparam = %{$updated->{'removeparam'}};
2565: }
2566: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2567: %dbcopies = %{$updated->{'dbcopies'}};
2568: }
2569: if (ref($updated->{'retitles'}) eq 'HASH') {
2570: %retitles = %{$updated->{'retitles'}};
2571: }
1.597 raeburn 2572: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2573: %resdatacopy = %{$updated->{'resdatacopy'}};
2574: }
1.529 raeburn 2575: }
2576: if (ref($info) eq 'HASH') {
2577: if (ref($info->{'newsubdir'}) eq 'HASH') {
2578: %newsubdir = %{$info->{'newsubdir'}};
2579: }
2580: if (ref($info->{'params'}) eq 'HASH') {
2581: %params = %{$info->{'params'}};
2582: }
2583: if (ref($info->{'before'}) eq 'HASH') {
2584: %before = %{$info->{'before'}};
2585: }
2586: if (ref($info->{'after'}) eq 'HASH') {
2587: %after = %{$info->{'after'}};
2588: }
2589: }
2590: if (ref($moves) eq 'HASH') {
2591: if (ref($moves->{'copies'}) eq 'HASH') {
2592: %copies = %{$moves->{'copies'}};
2593: }
2594: if (ref($moves->{'docmoves'}) eq 'HASH') {
2595: %docmoves = %{$moves->{'docmoves'}};
2596: }
2597: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2598: %mapmoves = %{$moves->{'mapmoves'}};
2599: }
2600: }
2601: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2602: my @allcopies;
1.529 raeburn 2603: if (exists($copies{$key})) {
2604: if (ref($copies{$key}) eq 'HASH') {
2605: my %added;
2606: foreach my $innerkey (keys(%{$copies{$key}})) {
2607: if (($innerkey ne '') && (!$added{$innerkey})) {
2608: push(@allcopies,$innerkey);
2609: $added{$innerkey} = 1;
2610: }
1.491 raeburn 2611: }
1.529 raeburn 2612: undef(%added);
1.491 raeburn 2613: }
2614: }
2615: if ($key eq $oldurl) {
1.529 raeburn 2616: if ((exists($docmoves{$key}))) {
1.532 raeburn 2617: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2618: push(@allcopies,$oldurl);
2619: }
2620: }
2621: }
2622: if (@allcopies > 0) {
2623: foreach my $item (@allcopies) {
1.492 raeburn 2624: my ($relpath,$oldsubdir,$fname) =
2625: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2626: if ($fname ne '') {
2627: my $content = &Apache::lonnet::getfile($item);
2628: unless ($content eq '-1') {
2629: my $storefn;
1.529 raeburn 2630: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2631: $storefn = $docmoves{$key};
1.491 raeburn 2632: } else {
2633: $storefn = $relpath;
2634: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2635: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2636: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2637: }
1.529 raeburn 2638: if ($newsubdir{$key}) {
1.532 raeburn 2639: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2640: }
2641: }
2642: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2643: my $copyurl =
2644: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2645: $storefn.$fname,$content);
2646: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2647: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2648: return &mt('Paste failed: an error occurred copying the file.');
2649: } elsif (ref($errors) eq 'HASH') {
2650: $errors->{$item} = 1;
1.489 raeburn 2651: }
2652: }
1.488 raeburn 2653: }
2654: }
1.491 raeburn 2655: }
2656: }
2657: }
1.529 raeburn 2658: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2659: my $storefn=$key;
2660: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2661: if ($prefixchg && $before{'map'} && $after{'map'}) {
2662: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2663: }
1.529 raeburn 2664: if ($newsubdir{$key}) {
2665: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2666: }
1.491 raeburn 2667: my $mapcontent = &Apache::lonnet::getfile($key);
2668: if ($mapcontent eq '-1') {
2669: if (ref($errors) eq 'HASH') {
2670: $errors->{$key} = 1;
2671: }
2672: } else {
2673: my $newmap =
2674: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2675: $mapcontent);
2676: if ($newmap eq '/adm/notfound.html') {
2677: if (ref($errors) eq 'HASH') {
2678: $errors->{$key} = 1;
1.489 raeburn 2679: }
1.488 raeburn 2680: }
2681: }
2682: }
1.491 raeburn 2683: my %updates;
2684: if ($is_map) {
1.529 raeburn 2685: if (ref($updated) eq 'HASH') {
2686: foreach my $type (keys(%{$updated})) {
2687: if (ref($updated->{$type}) eq 'HASH') {
2688: foreach my $key (keys(%{$updated->{$type}})) {
2689: $updates{$key} = 1;
2690: }
2691: }
2692: }
1.491 raeburn 2693: }
2694: foreach my $key (keys(%updates)) {
1.492 raeburn 2695: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2696: if (ref($rewrites{$key}) eq 'HASH') {
2697: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2698: }
1.529 raeburn 2699: if (ref($retitles{$key}) eq 'HASH') {
2700: %toretitle = %{$retitles{$key}};
1.491 raeburn 2701: }
1.529 raeburn 2702: if (ref($removefrommap{$key}) eq 'HASH') {
2703: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2704: }
1.529 raeburn 2705: if (ref($removeparam{$key}) eq 'HASH') {
2706: %remparam = %{$removeparam{$key}};
1.492 raeburn 2707: }
1.529 raeburn 2708: if (ref($zombies{$key}) eq 'HASH') {
2709: %zombie = %{$zombies{$key}};
1.491 raeburn 2710: }
1.529 raeburn 2711: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2712: foreach my $idx (keys(%{$dbcopies{$key}})) {
2713: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2714: my ($newurl,$result,$errtext) =
2715: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2716: if ($result eq 'ok') {
2717: $newdb{$idx} = $newurl;
2718: } elsif (ref($errors) eq 'HASH') {
2719: $errors->{$key} = 1;
2720: }
2721: push(@msgs,$errtext);
2722: }
1.491 raeburn 2723: }
2724: }
1.597 raeburn 2725: if (ref($resdatacopy{$key}) eq 'HASH') {
2726: if ($newsubdir{$key}) {
2727:
2728: }
2729: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2730: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2731: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2732: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2733: my $template = $1;
2734: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2735: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2736: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2737: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2738: my ($newmapname) = ($key =~ m{/([^/]+)$});
2739: my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2740: my $srcmapinfo = $srcfolder.':'.$idx;
2741: if ($srccontainer eq 'page') {
2742: $srcmapinfo .= ':1';
2743: }
2744: if ($newsubdir{$key}) {
2745: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2746: }
2747: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2748: $cnum,$template,$idx,$newmapname);
2749: }
2750: }
2751: }
2752: }
2753: }
1.529 raeburn 2754: if (ref($params{$key}) eq 'HASH') {
2755: %currparam = %{$params{$key}};
1.492 raeburn 2756: }
2757: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2758: if ($fatal) {
1.533 raeburn 2759: return ($errtext);
1.492 raeburn 2760: }
2761: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2762: if (defined($LONCAPA::map::zombies[$i])) {
2763: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2764: if ($zombie{$i} eq $src) {
1.492 raeburn 2765: undef($LONCAPA::map::zombies[$i]);
2766: }
2767: }
2768: }
1.529 raeburn 2769: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2770: my $idx = $LONCAPA::map::order[$i];
2771: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2772: my $changed;
1.529 raeburn 2773: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2774: if ((exists($toremove{$idx})) &&
2775: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2776: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2777: if (ref($currparam{$idx}) eq 'ARRAY') {
2778: foreach my $name (@{$currparam{$idx}}) {
2779: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2780: }
2781: }
2782: next;
2783: }
2784: my $origsrc = $src;
1.532 raeburn 2785: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2786: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2787: $changed = 1;
1.491 raeburn 2788: }
1.492 raeburn 2789: }
1.532 raeburn 2790: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2791: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2792: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2793: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2794: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2795: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2796: } else {
1.529 raeburn 2797: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2798: }
1.491 raeburn 2799: }
1.532 raeburn 2800: if ($origsrc =~ /\.(page|sequence)$/) {
2801: if ($newsubdir{$origsrc}) {
1.529 raeburn 2802: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2803: }
1.532 raeburn 2804: } elsif ($newsubdir{$key}) {
2805: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2806: }
2807: }
1.492 raeburn 2808: $changed = 1;
1.533 raeburn 2809: } elsif ($newdb{$idx} ne '') {
2810: $src = $newdb{$idx};
1.492 raeburn 2811: $changed = 1;
2812: }
2813: if ($changed) {
1.538 raeburn 2814: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2815: }
2816: }
2817: }
2818: foreach my $idx (keys(%remparam)) {
2819: if (ref($remparam{$idx}) eq 'ARRAY') {
2820: foreach my $name (@{$remparam{$idx}}) {
2821: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2822: }
2823: }
2824: }
1.533 raeburn 2825: if (values(%lockerrors) > 0) {
2826: $lockmsg = join('<br />',values(%lockerrors));
2827: }
1.491 raeburn 2828: my $storefn;
2829: if ($key eq $oldurl) {
2830: $storefn = $url;
2831: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2832: } else {
2833: $storefn = $key;
2834: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2835: if ($prefixchg && $before{'map'} && $after{'map'}) {
2836: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2837: }
1.529 raeburn 2838: if ($newsubdir{$key}) {
2839: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2840: }
1.491 raeburn 2841: }
1.492 raeburn 2842: my $report;
2843: if ($folder !~ /^supplemental/) {
2844: $report = 1;
2845: }
1.527 raeburn 2846: (my $outtext,$errtext) =
1.492 raeburn 2847: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2848: if ($errtext) {
1.529 raeburn 2849: if ($caller eq 'paste') {
1.533 raeburn 2850: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2851: }
1.491 raeburn 2852: }
2853: }
2854: }
1.533 raeburn 2855: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2856: }
2857:
2858: sub copy_dependencies {
2859: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2860: my $content;
2861: if (ref($contentref)) {
2862: $content = $$contentref;
2863: } else {
2864: $content = &Apache::lonnet::getfile($item);
2865: }
2866: unless ($content eq '-1') {
2867: my $mm = new File::MMagic;
2868: my $mimetype = $mm->checktype_contents($content);
2869: if ($mimetype eq 'text/html') {
2870: my (%allfiles,%codebase,$state);
2871: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2872: if ($res eq 'ok') {
2873: my ($numexisting,$numpathchanges,$existing);
2874: (undef,$numexisting,$numpathchanges,$existing) =
2875: &Apache::loncommon::ask_for_embedded_content(
2876: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2877: {'error_on_invalid_names' => 1,
2878: 'ignore_remote_references' => 1,
2879: 'docs_url' => $item,
2880: 'context' => 'paste'});
2881: if ($numexisting > 0) {
2882: if (ref($existing) eq 'HASH') {
2883: foreach my $dep (keys(%{$existing})) {
2884: my $depfile = $dep;
2885: unless ($depfile =~ m{^\Q$relpath\E}) {
2886: $depfile = $relpath.$dep;
2887: }
2888: my $depcontent = &Apache::lonnet::getfile($depfile);
2889: unless ($depcontent eq '-1') {
2890: my $storedep = $dep;
2891: $storedep =~ s{^\Q$relpath\E}{};
2892: my $dep_url =
2893: &Apache::lonclonecourse::writefile(
2894: $env{'request.course.id'},
2895: $storefn.$storedep,$depcontent);
2896: if ($dep_url eq '/adm/notfound.html') {
2897: if (ref($errors) eq 'HASH') {
2898: $errors->{$depfile} = 1;
2899: }
2900: } else {
2901: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2902: }
2903: }
2904: }
1.488 raeburn 2905: }
2906: }
2907: }
2908: }
2909: }
2910: return;
2911: }
2912:
1.329 droeschl 2913: my %parameter_type = ( 'randompick' => 'int_pos',
2914: 'hiddenresource' => 'string_yesno',
2915: 'encrypturl' => 'string_yesno',
2916: 'randomorder' => 'string_yesno',);
2917: my $valid_parameters_re = join('|',keys(%parameter_type));
2918: # set parameters
2919: sub update_parameter {
1.537 raeburn 2920: if ($env{'form.changeparms'} eq 'all') {
2921: my (@allidx,@allmapidx,%allchecked,%currchecked);
2922: %allchecked = (
2923: 'hiddenresource' => {},
2924: 'encrypturl' => {},
2925: 'randompick' => {},
2926: 'randomorder' => {},
2927: );
2928: foreach my $which (keys(%allchecked)) {
1.630 raeburn 2929: $env{'form.all'.$which} =~ s/,$//;
1.537 raeburn 2930: if ($which eq 'randompick') {
2931: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2932: my ($res,$value) = split(/:/,$item);
2933: if ($value =~ /^\d+$/) {
2934: $allchecked{$which}{$res} = $value;
2935: }
2936: }
2937: } else {
1.539 raeburn 2938: if ($env{'form.all'.$which}) {
2939: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2940: }
1.537 raeburn 2941: }
2942: }
2943: my $haschanges = 0;
2944: foreach my $res (@LONCAPA::map::order) {
2945: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2946: $name=&LONCAPA::map::qtescape($name);
2947: $url=&LONCAPA::map::qtescape($url);
2948: next unless ($name && $url);
2949: my $is_map;
2950: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2951: $is_map = 1;
2952: }
2953: foreach my $which (keys(%allchecked)) {
2954: if (($which eq 'randompick' || $which eq 'randomorder')) {
2955: next if (!$is_map);
2956: }
2957: my $oldvalue = 0;
2958: my $newvalue = 0;
2959: if ($allchecked{$which}{$res}) {
2960: $newvalue = $allchecked{$which}{$res};
2961: }
2962: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2963: if ($which eq 'randompick') {
2964: if ($current =~ /^(\d+)$/) {
2965: $oldvalue = $1;
2966: }
2967: } else {
2968: if ($current =~ /^yes$/i) {
2969: $oldvalue = 1;
2970: }
2971: }
2972: if ($oldvalue ne $newvalue) {
2973: $haschanges = 1;
2974: if ($newvalue) {
2975: my $storeval = 'yes';
2976: if ($which eq 'randompick') {
2977: $storeval = $newvalue;
2978: }
2979: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2980: $storeval,
2981: $parameter_type{$which});
2982: &remember_parms($res,$which,'set',$storeval);
2983: } elsif ($oldvalue) {
2984: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2985: &remember_parms($res,$which,'del');
2986: }
2987: }
2988: }
2989: }
2990: return $haschanges;
2991: } else {
1.588 raeburn 2992: my $haschanges = 0;
2993: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2994:
1.537 raeburn 2995: my $which = $env{'form.changeparms'};
2996: my $idx = $env{'form.setparms'};
1.588 raeburn 2997: my $oldvalue = 0;
2998: my $newvalue = 0;
2999: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3000: if ($which eq 'randompick') {
3001: if ($current =~ /^(\d+)$/) {
3002: $oldvalue = $1;
3003: }
3004: } elsif ($current =~ /^yes$/i) {
3005: $oldvalue = 1;
3006: }
1.537 raeburn 3007: if ($env{'form.'.$which.'_'.$idx}) {
1.588 raeburn 3008: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3009: : 1;
3010: }
3011: if ($oldvalue ne $newvalue) {
3012: $haschanges = 1;
3013: if ($newvalue) {
3014: my $storeval = 'yes';
3015: if ($which eq 'randompick') {
3016: $storeval = $newvalue;
3017: }
3018: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3019: $parameter_type{$which});
3020: &remember_parms($idx,$which,'set',$storeval);
3021: } else {
3022: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3023: &remember_parms($idx,$which,'del');
3024: }
1.537 raeburn 3025: }
1.588 raeburn 3026: return $haschanges;
1.329 droeschl 3027: }
3028: }
3029:
3030: sub handle_edit_cmd {
3031: my ($coursenum,$coursedom) =@_;
1.633 raeburn 3032: my $haschanges = 0;
1.543 raeburn 3033: if ($env{'form.cmd'} eq '') {
1.633 raeburn 3034: return $haschanges;
1.543 raeburn 3035: }
1.329 droeschl 3036: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3037:
3038: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3039: my ($title, $url, @rrest) = split(':', $ratstr);
3040:
1.538 raeburn 3041: if ($cmd eq 'remove') {
1.329 droeschl 3042: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 3043: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 3044: &Apache::lonnet::removeuploadedurl($url);
3045: } else {
3046: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3047: }
3048: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3049: $haschanges = 1;
1.329 droeschl 3050: } elsif ($cmd eq 'cut') {
3051: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3052: splice(@LONCAPA::map::order, $idx, 1);
1.633 raeburn 3053: $haschanges = 1;
1.344 bisitz 3054: } elsif ($cmd eq 'up'
1.329 droeschl 3055: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3056: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1.633 raeburn 3057: $haschanges = 1;
1.329 droeschl 3058: } elsif ($cmd eq 'down'
3059: && defined($LONCAPA::map::order[$idx+1])) {
3060: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1.633 raeburn 3061: $haschanges = 1;
1.329 droeschl 3062: } elsif ($cmd eq 'rename') {
3063: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3064: if ($comment=~/\S/) {
3065: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3066: $comment.':'.join(':', $url, @rrest);
3067: }
3068: # Devalidate title cache
3069: my $renamed_url=&LONCAPA::map::qtescape($url);
3070: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.633 raeburn 3071: $haschanges = 1;
3072: } elsif ($cmd eq 'setalias') {
3073: my $newvalue = $env{'form.alias'};
3074: if ($newvalue ne '') {
3075: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3076: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3077: 'string');
3078: &remember_parms($idx,'mapalias','set',$newvalue);
3079: $haschanges = 1;
3080: }
3081: }
3082: } elsif ($cmd eq 'delalias') {
3083: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3084: if ($current ne '') {
3085: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3086: &remember_parms($idx,'mapalias','del');
3087: $haschanges = 1;
3088: }
1.329 droeschl 3089: }
1.633 raeburn 3090: return $haschanges;
1.329 droeschl 3091: }
3092:
3093: sub editor {
1.458 raeburn 3094: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.615 raeburn 3095: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
1.622 raeburn 3096: $canedit,$hostname,$navmapref,$hiddentop)=@_;
1.519 raeburn 3097: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 3098: if ($allowed) {
1.519 raeburn 3099: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3100: $is_random_order,$container) =
1.510 raeburn 3101: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3102: $r->print($breadcrumbtrail);
1.519 raeburn 3103: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3104: $container = 'page';
3105: } else {
3106: $container = 'sequence';
1.510 raeburn 3107: }
1.484 raeburn 3108:
1.525 raeburn 3109: my $jumpto;
3110:
3111: unless ($supplementalflag) {
1.546 raeburn 3112: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 3113: }
1.484 raeburn 3114:
3115: unless ($allowed) {
3116: $randompick = -1;
3117: }
3118:
1.615 raeburn 3119: my ($errtext,$fatal);
3120: if (($folder eq '') && (!$supplementalflag)) {
3121: if (@LONCAPA::map::order) {
3122: undef(@LONCAPA::map::order);
3123: undef(@LONCAPA::map::resources);
3124: undef(@LONCAPA::map::resparms);
3125: undef(@LONCAPA::map::zombies);
3126: }
3127: $folder = 'default';
3128: $container = 'sequence';
3129: } else {
3130: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3131: $folder.'.'.$container);
3132: return $errtext if ($fatal);
3133: }
1.329 droeschl 3134:
3135: if ($#LONCAPA::map::order<1) {
3136: my $idx=&LONCAPA::map::getresidx();
3137: if ($idx<=0) { $idx=1; }
3138: $LONCAPA::map::order[0]=$idx;
3139: $LONCAPA::map::resources[$idx]='';
3140: }
1.364 bisitz 3141:
1.329 droeschl 3142: # ------------------------------------------------------------ Process commands
3143:
3144: # ---------------- if they are for this folder and user allowed to make changes
1.611 raeburn 3145: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
1.329 droeschl 3146: # set parameters and change order
3147: &snapshotbefore();
3148:
3149: if (&update_parameter()) {
1.588 raeburn 3150: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1.329 droeschl 3151: return $errtext if ($fatal);
3152: }
3153:
3154: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3155: # change order
3156: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3157: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3158:
3159: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3160: return $errtext if ($fatal);
3161: }
1.364 bisitz 3162:
1.329 droeschl 3163: if ($env{'form.pastemarked'}) {
1.491 raeburn 3164: my %paste_errors;
1.533 raeburn 3165: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 3166: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3167: \%paste_errors);
1.541 raeburn 3168: if (ref($pastemsgarray) eq 'ARRAY') {
3169: if (@{$pastemsgarray} > 0) {
3170: $r->print('<p class="LC_info">'.
3171: join('<br />',@{$pastemsgarray}).
1.533 raeburn 3172: '</p>');
3173: }
1.541 raeburn 3174: }
3175: if ($lockerror) {
3176: $r->print('<p class="LC_error">'.
3177: $lockerror.
3178: '</p>');
3179: }
3180: if ($save_error ne '') {
3181: return $save_error;
3182: }
3183: if ($paste_res) {
3184: my %errortext = &Apache::lonlocal::texthash (
3185: fail => 'Storage of folder contents failed',
3186: failread => 'Reading folder contents failed',
3187: failstore => 'Storage of folder contents failed',
3188: );
3189: if ($errortext{$paste_res}) {
3190: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 3191: }
1.329 droeschl 3192: }
1.491 raeburn 3193: if (keys(%paste_errors) > 0) {
1.538 raeburn 3194: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 3195: &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".
3196: '<ul>'."\n");
3197: foreach my $key (sort(keys(%paste_errors))) {
3198: $r->print('<li>'.$key.'</li>'."\n");
3199: }
3200: $r->print('</ul></p>'."\n");
3201: }
1.538 raeburn 3202: } elsif ($env{'form.clearmarked'}) {
3203: my $output = &do_buffer_empty();
3204: if ($output) {
3205: $r->print('<p class="LC_info">'.$output.'</p>');
3206: }
3207: }
1.329 droeschl 3208:
3209: $r->print($upload_output);
3210:
1.538 raeburn 3211: # Rename, cut, copy or remove a single resource
1.602 raeburn 3212: if (&handle_edit_cmd($coursenum,$coursedom)) {
1.492 raeburn 3213: my $contentchg;
1.633 raeburn 3214: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
1.492 raeburn 3215: $contentchg = 1;
3216: }
3217: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 3218: return $errtext if ($fatal);
3219: }
1.538 raeburn 3220:
3221: # Cut, copy and/or remove multiple resources
3222: if ($env{'form.multichange'}) {
3223: my %allchecked = (
3224: cut => {},
3225: remove => {},
3226: );
3227: my $needsupdate;
3228: foreach my $which (keys(%allchecked)) {
3229: $env{'form.multi'.$which} =~ s/,$//;
3230: if ($env{'form.multi'.$which}) {
3231: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3232: if (ref($allchecked{$which}) eq 'HASH') {
3233: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3234: }
3235: }
3236: }
3237: if ($needsupdate) {
3238: my $haschanges = 0;
3239: my %curr_groups = &Apache::longroup::coursegroups();
3240: my $total = scalar(@LONCAPA::map::order) - 1;
3241: for (my $i=$total; $i>=0; $i--) {
3242: my $res = $LONCAPA::map::order[$i];
3243: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3244: $name=&LONCAPA::map::qtescape($name);
3245: $url=&LONCAPA::map::qtescape($url);
1.586 droeschl 3246: next unless $url;
1.538 raeburn 3247: my %denied =
3248: &action_restrictions($coursenum,$coursedom,$url,
3249: $env{'form.folderpath'},\%curr_groups);
3250: foreach my $which (keys(%allchecked)) {
3251: next if ($denied{$which});
3252: next unless ($allchecked{$which}{$res});
3253: if ($which eq 'remove') {
3254: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3255: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3256: &Apache::lonnet::removeuploadedurl($url);
3257: } else {
3258: &LONCAPA::map::makezombie($res);
3259: }
3260: splice(@LONCAPA::map::order,$i,1);
3261: $haschanges ++;
3262: } elsif ($which eq 'cut') {
3263: &LONCAPA::map::makezombie($res);
3264: splice(@LONCAPA::map::order,$i,1);
3265: $haschanges ++;
3266: }
3267: }
3268: }
3269: if ($haschanges) {
3270: ($errtext,$fatal) =
3271: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3272: return $errtext if ($fatal);
3273: }
3274: }
3275: }
3276:
1.329 droeschl 3277: # Group import/search
3278: if ($env{'form.importdetail'}) {
3279: my @imports;
3280: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3281: if (defined($item)) {
3282: my ($name,$url,$residx)=
1.533 raeburn 3283: map { &unescape($_); } split(/\=/,$item);
3284: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3285: my ($suffix,$errortxt,$locknotfreed) =
3286: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 3287: if ($locknotfreed) {
3288: $r->print($locknotfreed);
3289: }
3290: if ($suffix) {
3291: $url =~ s/_new\./_$suffix./;
3292: } else {
3293: return $errortxt;
3294: }
1.533 raeburn 3295: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3296: my $type = $1;
3297: my ($suffix,$errortxt,$locknotfreed) =
3298: &new_timebased_suffix($coursedom,$coursenum,$type);
3299: if ($locknotfreed) {
3300: $r->print($locknotfreed);
3301: }
3302: if ($suffix) {
3303: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3304: } else {
3305: return $errortxt;
3306: }
1.626 raeburn 3307: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
1.598 raeburn 3308: my ($suffix,$errortxt,$locknotfreed) =
3309: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3310: if ($locknotfreed) {
3311: $r->print($locknotfreed);
3312: }
3313: if ($suffix) {
3314: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3315: } else {
3316: return $errortxt;
3317: }
1.534 raeburn 3318: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3319: if ($supplementalflag) {
3320: next unless ($1 eq 'supplemental');
3321: if ($folder eq 'supplemental') {
3322: next unless ($2 eq 'default');
3323: } else {
3324: next unless ($folder eq 'supplemental_'.$2);
3325: }
3326: } else {
3327: next unless ($1 eq 'docs');
3328: if ($folder eq 'default') {
3329: next unless ($2 eq 'default');
3330: } else {
3331: next unless ($folder eq 'default_'.$2);
3332: }
3333: }
1.504 raeburn 3334: }
1.329 droeschl 3335: push(@imports, [$name, $url, $residx]);
3336: }
3337: }
1.530 raeburn 3338: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 3339: &group_import($coursenum, $coursedom, $folder,$container,
1.598 raeburn 3340: 'londocs',$ltitoolsref,@imports);
1.329 droeschl 3341: return $errtext if ($fatal);
1.529 raeburn 3342: if ($fixuperrors) {
3343: $r->print($fixuperrors);
3344: }
1.329 droeschl 3345: }
3346: # Loading a complete map
3347: if ($env{'form.loadmap'}) {
3348: if ($env{'form.importmap'}=~/\w/) {
3349: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3350: my ($title,$url,$ext,$type)=split(/\:/,$res);
3351: my $idx=&LONCAPA::map::getresidx($url);
3352: $LONCAPA::map::resources[$idx]=$res;
3353: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3354: }
3355: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3356: $folder.'.'.$container,1);
1.329 droeschl 3357: return $errtext if ($fatal);
3358: } else {
3359: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 3360:
1.329 droeschl 3361: }
3362: }
3363: &log_differences($plain);
3364: }
3365: # ---------------------------------------------------------------- End commands
3366: # ---------------------------------------------------------------- Print screen
3367: my $idx=0;
3368: my $shown=0;
3369: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 3370: $r->print('<div class="LC_Box">'.
1.432 raeburn 3371: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3372: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3373: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3374: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3375: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 3376: '</ol>');
1.381 bisitz 3377: if ($randompick>=0) {
3378: $r->print('<p class="LC_warning">'
3379: .&mt('Caution: this folder is set to randomly pick a subset'
3380: .' of resources. Adding or removing resources from this'
3381: .' folder will change the set of resources that the'
3382: .' students see, resulting in spurious or missing credit'
3383: .' for completed problems, not limited to ones you'
3384: .' modify. Do not modify the contents of this folder if'
3385: .' it is in active student use.')
3386: .'</p>'
3387: );
3388: }
3389: if ($is_random_order) {
3390: $r->print('<p class="LC_warning">'
3391: .&mt('Caution: this folder is set to randomly order its'
3392: .' contents. Adding or removing resources from this folder'
3393: .' will change the order of resources shown.')
3394: .'</p>'
3395: );
3396: }
3397: $r->print('</div>');
1.364 bisitz 3398: }
1.381 bisitz 3399:
1.538 raeburn 3400: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3401: %filters = (
1.543 raeburn 3402: canremove => [],
3403: cancut => [],
3404: cancopy => [],
3405: hiddenresource => [],
3406: encrypturl => [],
3407: randomorder => [],
3408: randompick => [],
1.538 raeburn 3409: );
3410: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 3411: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 3412: foreach my $res (@LONCAPA::map::order) {
3413: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3414: $name=&LONCAPA::map::qtescape($name);
3415: $url=&LONCAPA::map::qtescape($url);
3416: unless ($name) { $name=(split(/\//,$url))[-1]; }
3417: unless ($name) { $idx++; next; }
1.537 raeburn 3418: push(@allidx,$res);
3419: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3420: push(@allmapidx,$res);
3421: }
1.617 raeburn 3422:
1.381 bisitz 3423: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 3424: $coursenum,$coursedom,$crstype,
1.538 raeburn 3425: $pathitem,$supplementalflag,$container,
1.620 raeburn 3426: \%filters,\%curr_groups,$ltitoolsref,$canedit,
1.622 raeburn 3427: $isencrypted,$navmapref,$hostname);
1.381 bisitz 3428: $idx++;
3429: $shown++;
1.329 droeschl 3430: }
1.424 onken 3431: &Apache::loncommon::end_data_table_count();
1.510 raeburn 3432:
1.538 raeburn 3433: my $need_save;
1.611 raeburn 3434: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 3435: my $toolslink;
1.611 raeburn 3436: if ($allowed) {
1.544 raeburn 3437: $toolslink = '<table><tr><td>'
1.520 raeburn 3438: .&Apache::loncommon::help_open_menu('Navigation Screen',
3439: 'Navigation_Screen',undef,'RAT')
3440: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3441: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 3442: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 3443: .'id="LC_content_toolbar_edittoplevel" '
3444: .'class="LC_toolbarItem" '
3445: .'title="'.&mt('Supplemental Content Editor').'">'
3446: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 3447: }
1.510 raeburn 3448: if ($shown) {
3449: if ($allowed) {
3450: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3451: .&Apache::loncommon::start_data_table(undef,'contentlist')
3452: .&Apache::loncommon::start_data_table_header_row()
3453: .'<th colspan="2">'.&mt('Move').'</th>'
1.633 raeburn 3454: .'<th colspan="3">'.&mt('Actions').'</th>'
1.538 raeburn 3455: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 3456: if ($folder !~ /^supplemental/) {
1.633 raeburn 3457: $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
1.510 raeburn 3458: }
1.537 raeburn 3459: $to_show .= &Apache::loncommon::end_data_table_header_row();
3460: if ($folder !~ /^supplemental/) {
1.538 raeburn 3461: $lists{'canhide'} = join(',',@allidx);
3462: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 3463: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3464: 'randomorder','randompick');
3465: foreach my $item (@possfilters) {
1.538 raeburn 3466: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 3467: if (@{$filters{$item}} > 0) {
3468: $lists{$item} = join(',',@{$filters{$item}});
3469: }
1.538 raeburn 3470: }
3471: }
1.537 raeburn 3472: if (@allidx > 0) {
3473: my $path;
3474: if ($env{'form.folderpath'}) {
1.630 raeburn 3475: $path =
1.537 raeburn 3476: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3477: }
1.538 raeburn 3478: if (@allidx > 1) {
1.630 raeburn 3479: $to_show .=
1.538 raeburn 3480: &Apache::loncommon::continue_data_table_row().
3481: '<td colspan="2"> </td>'.
3482: '<td>'.
1.611 raeburn 3483: &multiple_check_form('actions',\%lists,$canedit).
1.538 raeburn 3484: '</td>'.
1.633 raeburn 3485: '<td colspan="3"> </td>'.
3486: '<td colspan="2">'.
1.611 raeburn 3487: &multiple_check_form('settings',\%lists,$canedit).
1.538 raeburn 3488: '</td>'.
3489: &Apache::loncommon::end_data_table_row();
3490: $need_save = 1;
3491: }
1.537 raeburn 3492: }
3493: }
3494: $to_show .= $output.' '
1.510 raeburn 3495: .&Apache::loncommon::end_data_table()
3496: .'<br style="line-height:2px;" />'
3497: .&Apache::loncommon::end_scrollbox();
3498: } else {
1.520 raeburn 3499: $to_show .= $toolslink
1.510 raeburn 3500: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3501: .$output.' '
3502: .&Apache::loncommon::end_data_table();
1.393 raeburn 3503: }
1.510 raeburn 3504: } else {
1.520 raeburn 3505: if (!$allowed) {
3506: $to_show .= $toolslink;
3507: }
1.615 raeburn 3508: my $noresmsg;
3509: if ($allowed && $hiddentop && !$supplementalflag) {
3510: $noresmsg = &mt('Main Content Hidden');
3511: } else {
3512: $noresmsg = &mt('Currently empty');
3513: }
1.510 raeburn 3514: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3515: .'<div class="LC_info" id="contentlist">'
1.615 raeburn 3516: .$noresmsg
1.510 raeburn 3517: .'</div>'
3518: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3519: }
3520: } else {
1.510 raeburn 3521: if ($shown) {
3522: $to_show = '<div>'
3523: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3524: .$output
3525: .&Apache::loncommon::end_data_table()
3526: .'</div>';
3527: } else {
3528: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3529: .&mt('Currently empty')
1.510 raeburn 3530: .'</div>'
3531: }
1.458 raeburn 3532: }
3533: my $tid = 1;
3534: if ($supplementalflag) {
3535: $tid = 2;
1.329 droeschl 3536: }
3537: if ($allowed) {
1.484 raeburn 3538: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3539: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
1.611 raeburn 3540: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3541: if ($canedit) {
3542: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3543: }
1.460 raeburn 3544: } else {
3545: $r->print($to_show);
1.329 droeschl 3546: }
3547: return;
3548: }
3549:
1.538 raeburn 3550: sub multiple_check_form {
1.611 raeburn 3551: my ($caller,$listsref,$canedit) = @_;
1.538 raeburn 3552: return unless (ref($listsref) eq 'HASH');
1.611 raeburn 3553: my $disabled;
3554: unless ($canedit) {
3555: $disabled = 'disabled="disabled"';
3556: }
1.538 raeburn 3557: my $output =
3558: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3559: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3560: '<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>'.
3561: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3562: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3563: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3564: if ($caller eq 'settings') {
3565: $output .=
3566: '<table><tr>'.
3567: '<td class="LC_docs_entry_parameter">'.
3568: '<span class="LC_nobreak"><label>'.
1.611 raeburn 3569: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
1.538 raeburn 3570: '</label></span></td>'.
3571: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3572: '<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.538 raeburn 3573: '</span></td>'.
3574: '</tr>'."\n".
3575: '<tr>'.
3576: '<td class="LC_docs_entry_parameter">'.
1.611 raeburn 3577: '<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.538 raeburn 3578: '</label></span>'.
3579: '</td></tr></table>'."\n";
3580: } else {
3581: $output .=
3582: '<table><tr>'.
3583: '<td class="LC_docs_entry_parameter">'.
3584: '<span class="LC_nobreak LC_docs_remove">'.
1.611 raeburn 3585: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
1.538 raeburn 3586: '</label></span></td>'.
3587: '<td class="LC_docs_entry_parameter">'.
3588: '<span class="LC_nobreak LC_docs_cut">'.
1.611 raeburn 3589: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
1.538 raeburn 3590: '</label></span></td>'."\n".
3591: '<td class="LC_docs_entry_parameter">'.
3592: '<span class="LC_nobreak LC_docs_copy">'.
1.611 raeburn 3593: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
1.538 raeburn 3594: '</label></span></td>'.
3595: '</tr></table>'."\n";
3596: }
3597: $output .=
3598: '</fieldset>'.
3599: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3600: if ($caller eq 'settings') {
3601: $output .=
1.543 raeburn 3602: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3603: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3604: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3605: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3606: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3607: } elsif ($caller eq 'actions') {
3608: $output .=
3609: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3610: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3611: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3612: }
3613: $output .=
3614: '</form>'.
3615: '</div>';
3616: return $output;
3617: }
3618:
1.329 droeschl 3619: sub process_file_upload {
1.552 raeburn 3620: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3621: # upload a file, if present
1.552 raeburn 3622: my $filesize = length($env{'form.uploaddoc'});
3623: if (!$filesize) {
3624: $$upload_output = '<div class="LC_error">'.
3625: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3626: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3627: $filesize).'<br />'.
3628: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3629: '</div>';
3630: return;
3631: }
3632: my $quotatype = 'unofficial';
3633: if ($crstype eq 'Community') {
1.601 raeburn 3634: $quotatype = 'community';
3635: } elsif ($crstype eq 'Placement') {
3636: $quotatype = 'placement';
1.580 raeburn 3637: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
1.552 raeburn 3638: $quotatype = 'official';
1.573 raeburn 3639: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3640: $quotatype = 'textbook';
1.552 raeburn 3641: }
3642: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3643: $filesize = int($filesize/1000); #expressed in kb
3644: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
1.579 raeburn 3645: $env{'form.uploaddoc.filename'},$filesize,
3646: 'upload',$quotatype);
1.552 raeburn 3647: return if ($$upload_output);
3648: }
1.440 raeburn 3649: my ($parseaction,$showupload,$nextphase,$mimetype);
3650: if ($env{'form.parserflag'}) {
1.329 droeschl 3651: $parseaction = 'parse';
3652: }
3653: my $folder=$env{'form.folder'};
3654: if ($folder eq '') {
3655: $folder='default';
3656: }
3657: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3658: my $errtext='';
3659: my $fatal=0;
3660: my $container='sequence';
1.519 raeburn 3661: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3662: $container='page';
3663: }
3664: ($errtext,$fatal)=
1.534 raeburn 3665: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3666: if ($#LONCAPA::map::order<1) {
3667: $LONCAPA::map::order[0]=1;
3668: $LONCAPA::map::resources[1]='';
3669: }
3670: my $destination = 'docs/';
3671: if ($folder =~ /^supplemental/) {
3672: $destination = 'supplemental/';
3673: }
3674: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3675: $destination .= 'default/';
3676: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3677: $destination .= $2.'/';
3678: }
1.534 raeburn 3679: if ($fatal) {
3680: $$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>';
3681: return;
3682: }
1.440 raeburn 3683: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3684: my $newidx=&LONCAPA::map::getresidx();
3685: $destination .= $newidx;
1.439 raeburn 3686: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3687: $parseaction,$allfiles,
1.440 raeburn 3688: $codebase,undef,undef,undef,undef,
3689: undef,undef,\$mimetype);
3690: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3691: my $stored = $1;
3692: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3693: $stored.'</span>').'</p>';
3694: } else {
3695: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3696:
1.457 raeburn 3697: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3698: return;
3699: }
1.329 droeschl 3700: my $ext='false';
3701: if ($url=~m{^http://}) { $ext='true'; }
3702: $url = &LONCAPA::map::qtunescape($url);
3703: my $comment=$env{'form.comment'};
3704: $comment = &LONCAPA::map::qtunescape($comment);
3705: if ($folder=~/^supplemental/) {
3706: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3707: $env{'user.domain'}.'___&&&___'.$comment;
3708: }
3709:
3710: $LONCAPA::map::resources[$newidx]=
3711: $comment.':'.$url.':'.$ext.':normal:res';
3712: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3713: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3714: $folder.'.'.$container,1);
1.329 droeschl 3715: if ($fatal) {
1.457 raeburn 3716: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3717: return;
1.329 droeschl 3718: } else {
1.440 raeburn 3719: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3720: $$upload_output = $showupload;
1.384 raeburn 3721: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3722: if ($total_embedded > 0) {
1.440 raeburn 3723: my $uploadphase = 'upload_embedded';
3724: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3725: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1.630 raeburn 3726: my ($embedded,$num) =
1.440 raeburn 3727: &Apache::loncommon::ask_for_embedded_content(
3728: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3729: if ($embedded) {
3730: if ($num) {
3731: $$upload_output .=
3732: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3733: $nextphase = $uploadphase;
3734: } else {
3735: $$upload_output .= $embedded;
3736: }
3737: } else {
3738: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3739: }
1.329 droeschl 3740: } else {
1.440 raeburn 3741: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3742: }
1.457 raeburn 3743: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.578 raeburn 3744: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3745: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
1.476 raeburn 3746: $nextphase = 'decompress_uploaded';
3747: my $position = scalar(@LONCAPA::map::order)-1;
3748: my $noextract = &return_to_editor();
3749: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3750: my %archiveitems = (
3751: folderpath => $env{'form.folderpath'},
3752: cmd => $nextphase,
3753: newidx => $newidx,
3754: position => $position,
3755: phase => $nextphase,
1.477 raeburn 3756: comment => $comment,
1.480 raeburn 3757: );
3758: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3759: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3760: $$upload_output = $showupload.
3761: &Apache::loncommon::decompress_form($mimetype,
3762: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3763: \%archiveitems,\@current);
1.329 droeschl 3764: }
3765: }
3766: }
1.440 raeburn 3767: return $nextphase;
1.329 droeschl 3768: }
3769:
1.480 raeburn 3770: sub get_dir_list {
3771: my ($url,$coursenum,$coursedom,$newidx) = @_;
3772: my ($destination,$dir_root) = &embedded_destination();
3773: my ($dirlistref,$listerror) =
3774: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3775: my @dir_lines;
3776: my $dirptr=16384;
3777: if (ref($dirlistref) eq 'ARRAY') {
3778: foreach my $dir_line (sort
3779: {
3780: my ($afile)=split('&',$a,2);
3781: my ($bfile)=split('&',$b,2);
3782: return (lc($afile) cmp lc($bfile));
3783: } (@{$dirlistref})) {
3784: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3785: $filename =~ s/\s+$//;
3786: next if ($filename =~ /^\.\.?$/);
3787: my $isdir = 0;
3788: if ($dirptr&$testdir) {
3789: $isdir = 1;
3790: }
3791: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3792: }
3793: }
3794: return @dir_lines;
3795: }
3796:
1.329 droeschl 3797: sub is_supplemental_title {
3798: my ($title) = @_;
3799: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3800: }
3801:
3802: # --------------------------------------------------------------- An entry line
3803:
3804: sub entryline {
1.501 raeburn 3805: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.598 raeburn 3806: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
1.622 raeburn 3807: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname)=@_;
1.581 raeburn 3808: my ($foldertitle,$renametitle,$oldtitle);
1.329 droeschl 3809: if (&is_supplemental_title($title)) {
1.488 raeburn 3810: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3811: } else {
3812: $title=&HTML::Entities::encode($title,'"<>&\'');
3813: $renametitle=$title;
3814: $foldertitle=$title;
3815: }
3816:
1.611 raeburn 3817: my ($disabled,$readonly,$js_lt);
3818: unless ($canedit) {
3819: $disabled = 'disabled="disabled"';
3820: $readonly = 1;
3821: }
3822:
1.329 droeschl 3823: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3824:
1.329 droeschl 3825: $renametitle=~s/\\/\\\\/g;
3826: $renametitle=~s/\"\;/\\\"/g;
1.585 raeburn 3827: $renametitle=~s/"/%22/g;
1.581 raeburn 3828: $renametitle=~s/ /%20/g;
3829: $oldtitle = $renametitle;
1.576 raeburn 3830: $renametitle=~s/\'/\\\'/g;
1.379 bisitz 3831: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3832: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3833: # Edit commands
1.633 raeburn 3834: my ($esc_path, $path, $symb, $curralias);
1.329 droeschl 3835: if ($env{'form.folderpath'}) {
3836: $esc_path=&escape($env{'form.folderpath'});
3837: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3838: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3839: }
1.505 raeburn 3840: my $isexternal;
1.510 raeburn 3841: if ($residx) {
1.501 raeburn 3842: my $currurl = $url;
3843: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3844: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3845: $isexternal = 1;
3846: }
1.510 raeburn 3847: if (!$supplementalflag) {
3848: my $path = 'uploaded/'.
3849: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3850: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3851: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3852: $residx,
3853: &Apache::lonnet::declutter($currurl));
3854: }
1.501 raeburn 3855: }
1.538 raeburn 3856: my ($renamelink,%lt,$ishash);
3857: if (ref($filtersref) eq 'HASH') {
3858: $ishash = 1;
3859: }
3860:
1.329 droeschl 3861: if ($allowed) {
1.538 raeburn 3862: $form_start = '
3863: <form action="/adm/coursedocs" method="post">
3864: ';
3865: $form_common=(<<END);
3866: <input type="hidden" name="folderpath" value="$path" />
3867: <input type="hidden" name="symb" value="$symb" />
3868: END
3869: $form_param=(<<END);
3870: <input type="hidden" name="setparms" value="$orderidx" />
3871: <input type="hidden" name="changeparms" value="0" />
3872: END
3873: $form_end = '</form>';
3874:
1.329 droeschl 3875: my $incindex=$index+1;
3876: my $selectbox='';
1.471 raeburn 3877: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3878: ((split(/\:/,
1.344 bisitz 3879: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3880: ne '') &&
1.329 droeschl 3881: ((split(/\:/,
1.344 bisitz 3882: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3883: ne '')) {
3884: $selectbox=
3885: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.611 raeburn 3886: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
1.329 droeschl 3887: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3888: if ($i==$incindex) {
1.358 bisitz 3889: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3890: } else {
3891: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3892: }
3893: }
3894: $selectbox.='</select>';
3895: }
1.501 raeburn 3896: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3897: 'up' => 'Move Up',
3898: 'dw' => 'Move Down',
3899: 'rm' => 'Remove',
3900: 'ct' => 'Cut',
3901: 'rn' => 'Rename',
1.501 raeburn 3902: 'cp' => 'Copy',
1.633 raeburn 3903: 'da' => 'Unset alias',
3904: 'sa' => 'Set alias',
1.501 raeburn 3905: 'ex' => 'External Resource',
1.598 raeburn 3906: 'et' => 'External Tool',
1.501 raeburn 3907: 'ed' => 'Edit',
3908: 'pr' => 'Preview',
3909: 'sv' => 'Save',
3910: 'ul' => 'URL',
1.611 raeburn 3911: 'ti' => 'Title',
1.618 raeburn 3912: 'er' => 'Editing rights unavailable for your current role.',
1.501 raeburn 3913: );
1.538 raeburn 3914: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3915: $env{'form.folderpath'},
3916: $currgroups);
1.517 raeburn 3917: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3918: my $skip_confirm = 0;
1.603 raeburn 3919: my $confirm_removal = 0;
1.329 droeschl 3920: if ( $folder =~ /^supplemental/
3921: || ($url =~ m{( /smppg$
3922: |/syllabus$
3923: |/aboutme$
3924: |/navmaps$
3925: |/bulletinboard$
1.626 raeburn 3926: |/ext\.tool$
1.505 raeburn 3927: |\.html$)}x)
3928: || $isexternal) {
1.329 droeschl 3929: $skip_confirm = 1;
3930: }
1.603 raeburn 3931: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3932: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3933: $confirm_removal = 1;
3934: }
1.633 raeburn 3935: if ($url =~ /$LONCAPA::assess_re/) {
3936: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
3937: }
1.329 droeschl 3938:
1.538 raeburn 3939: if ($denied{'copy'}) {
1.543 raeburn 3940: $copylink=(<<ENDCOPY)
1.507 raeburn 3941: <span style="visibility: hidden;">$lt{'cp'}</span>
3942: ENDCOPY
3943: } else {
1.538 raeburn 3944: my $formname = 'edit_copy_'.$orderidx;
3945: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3946: $copylink=(<<ENDCOPY);
1.538 raeburn 3947: <form name="$formname" method="post" action="/adm/coursedocs">
3948: $form_common
1.611 raeburn 3949: <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.538 raeburn 3950: $form_end
1.329 droeschl 3951: ENDCOPY
1.538 raeburn 3952: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3953: push(@{$filtersref->{'cancopy'}},$orderidx);
3954: }
1.329 droeschl 3955: }
1.538 raeburn 3956: if ($denied{'cut'}) {
1.507 raeburn 3957: $cutlink=(<<ENDCUT);
3958: <span style="visibility: hidden;">$lt{'ct'}</span>
3959: ENDCUT
3960: } else {
1.538 raeburn 3961: my $formname = 'edit_cut_'.$orderidx;
3962: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3963: $cutlink=(<<ENDCUT);
1.538 raeburn 3964: <form name="$formname" method="post" action="/adm/coursedocs">
3965: $form_common
1.542 raeburn 3966: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.611 raeburn 3967: <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.538 raeburn 3968: $form_end
1.329 droeschl 3969: ENDCUT
1.538 raeburn 3970: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3971: push(@{$filtersref->{'cancut'}},$orderidx);
3972: }
1.329 droeschl 3973: }
1.538 raeburn 3974: if ($denied{'remove'}) {
1.507 raeburn 3975: $removelink=(<<ENDREM);
3976: <span style="visibility: hidden;">$lt{'rm'}</a>
3977: ENDREM
3978: } else {
1.538 raeburn 3979: my $formname = 'edit_remove_'.$orderidx;
1.603 raeburn 3980: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
1.497 raeburn 3981: $removelink=(<<ENDREM);
1.538 raeburn 3982: <form name="$formname" method="post" action="/adm/coursedocs">
3983: $form_common
1.542 raeburn 3984: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.603 raeburn 3985: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
1.611 raeburn 3986: <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.538 raeburn 3987: $form_end
1.497 raeburn 3988: ENDREM
1.538 raeburn 3989: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3990: push(@{$filtersref->{'canremove'}},$orderidx);
3991: }
1.497 raeburn 3992: }
1.551 raeburn 3993: $renamelink=(<<ENDREN);
1.581 raeburn 3994: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3995: ENDREN
1.611 raeburn 3996: my ($uplink,$downlink);
3997: if ($canedit) {
3998: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
3999: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4000: } else {
4001: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4002: $downlink = $uplink;
4003: }
1.329 droeschl 4004: $line.=(<<END);
4005: <td>
1.379 bisitz 4006: <div class="LC_docs_entry_move">
1.611 raeburn 4007: <a href="$uplink">
1.501 raeburn 4008: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 4009: </a>
4010: </div>
4011: <div class="LC_docs_entry_move">
1.611 raeburn 4012: <a href="$downlink">
1.501 raeburn 4013: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 4014: </a>
4015: </div>
1.329 droeschl 4016: </td>
4017: <td>
4018: $form_start
1.538 raeburn 4019: $form_param
1.478 raeburn 4020: $form_common
1.329 droeschl 4021: $selectbox
4022: $form_end
4023: </td>
1.540 raeburn 4024: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 4025: $removelink
1.329 droeschl 4026: $cutlink
4027: $copylink
4028: </td>
4029: END
4030: }
4031: # Figure out what kind of a resource this is
4032: my ($extension)=($url=~/\.(\w+)$/);
4033: my $uploaded=($url=~/^\/*uploaded\//);
4034: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 4035: my $isfolder;
4036: my $ispage;
4037: my $containerarg;
1.615 raeburn 4038: my $folderurl;
1.329 droeschl 4039: if ($uploaded) {
1.472 raeburn 4040: if (($extension eq 'sequence') || ($extension eq 'page')) {
4041: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 4042: $containerarg = $1;
1.472 raeburn 4043: if ($extension eq 'sequence') {
4044: $icon=$iconpath.'navmap.folder.closed.gif';
4045: $isfolder=1;
4046: } else {
4047: $icon=$iconpath.'page.gif';
4048: $ispage=1;
4049: }
1.615 raeburn 4050: $folderurl = &Apache::lonnet::declutter($url);
1.472 raeburn 4051: if ($allowed) {
4052: $url='/adm/coursedocs?';
4053: } else {
4054: $url='/adm/supplemental?';
4055: }
1.329 droeschl 4056: } else {
4057: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4058: }
4059: }
1.364 bisitz 4060:
1.621 raeburn 4061: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
1.329 droeschl 4062: my $orig_url = $url;
1.340 raeburn 4063: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 4064: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 4065: if (!$supplementalflag && $residx && $symb) {
4066: if ((!$isfolder) && (!$ispage)) {
4067: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4068: $url=&Apache::lonnet::clutter($url);
4069: if ($url=~/^\/*uploaded\//) {
4070: $url=~/\.(\w+)$/;
4071: my $embstyle=&Apache::loncommon::fileembstyle($1);
4072: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4073: $url='/adm/wrapper'.$url;
4074: } elsif ($embstyle eq 'ssi') {
4075: #do nothing with these
4076: } elsif ($url!~/\.(sequence|page)$/) {
4077: $url='/adm/coursedocs/showdoc'.$url;
4078: }
1.623 raeburn 4079: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4080: my $wrapped = $1;
4081: my $exturl = $2;
4082: if ($wrapped eq '') {
4083: $url='/adm/wrapper'.$url;
4084: }
4085: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4086: $nomodal = 1;
4087: }
1.626 raeburn 4088: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4089: $url='/adm/wrapper'.$url;
1.621 raeburn 4090: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4091: if (($ENV{'SERVER_PORT'} == 443) &&
4092: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4093: $url .= '?usehttp=1';
4094: $nomodal = 1;
4095: }
1.598 raeburn 4096: }
1.501 raeburn 4097: if (&Apache::lonnet::symbverify($symb,$url)) {
1.609 raeburn 4098: my $shownsymb = $symb;
4099: if ($isexternal) {
4100: if ($url =~ /^([^#]+)#([^#]+)$/) {
4101: $url = $1;
4102: $anchor = $2;
4103: if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {
4104: $shownsymb = $1.&escape('#').$anchor;
4105: }
4106: }
4107: }
1.617 raeburn 4108: unless ($env{'request.role.adv'}) {
4109: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4110: $url = '';
4111: }
4112: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4113: $url = '';
4114: $hiddenres = 1;
4115: }
4116: }
4117: if ($url ne '') {
1.641 raeburn 4118: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.617 raeburn 4119: }
1.615 raeburn 4120: } elsif (!$env{'request.role.adv'}) {
4121: my $checkencrypt;
4122: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4123: $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4124: $checkencrypt = 1;
1.620 raeburn 4125: } elsif (ref($navmapref)) {
1.615 raeburn 4126: unless (ref($$navmapref)) {
4127: $$navmapref = Apache::lonnavmaps::navmap->new();
4128: }
4129: if (ref($$navmapref)) {
4130: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4131: $checkencrypt = 1;
4132: }
4133: }
4134: }
4135: if ($checkencrypt) {
4136: my $shownsymb = &Apache::lonenc::encrypted($symb);
4137: my $shownurl = &Apache::lonenc::encrypted($url);
4138: if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
1.641 raeburn 4139: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
1.615 raeburn 4140: if ($env{'request.enc'} ne '') {
4141: delete($env{'request.enc'});
4142: }
4143: } else {
4144: $url='';
1.613 raeburn 4145: }
1.612 raeburn 4146: } else {
4147: $url='';
4148: }
1.501 raeburn 4149: } else {
4150: $url='';
4151: }
1.329 droeschl 4152: }
1.621 raeburn 4153: } elsif ($supplementalflag) {
1.610 raeburn 4154: if ($isexternal) {
4155: if ($url =~ /^([^#]+)#([^#]+)$/) {
4156: $url = $1;
4157: $anchor = $2;
1.623 raeburn 4158: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4159: if ($hostname ne '') {
4160: $url = 'http://'.$hostname.$url;
4161: }
4162: $nomodal = 1;
4163: }
1.610 raeburn 4164: }
1.621 raeburn 4165: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4166: if (($ENV{'SERVER_PORT'} == 443) &&
4167: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.622 raeburn 4168: if ($hostname ne '') {
4169: $url = 'http://'.$hostname.$url;
4170: }
1.621 raeburn 4171: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4172: $nomodal = 1;
4173: }
1.610 raeburn 4174: }
1.329 droeschl 4175: }
1.615 raeburn 4176: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
1.617 raeburn 4177: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.519 raeburn 4178: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 4179: my $foldername=&escape($foldertitle);
4180: my $folderpath=$env{'form.folderpath'};
4181: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 4182: if (!$allowed && $supplementalflag) {
1.519 raeburn 4183: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 4184: $url.='folderpath='.&escape($folderpath);
4185: } else {
1.617 raeburn 4186: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4187: 'parameter_randompick'))[0];
4188: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4189: 'parameter_randomorder'))[0]=~/^yes$/i);
4190: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4191: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4192: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4193: 'parameter_encrypturl'))[0]=~/^yes$/i);
4194: unless ($hiddenmap) {
1.620 raeburn 4195: if (ref($navmapref)) {
4196: unless (ref($$navmapref)) {
4197: $$navmapref = Apache::lonnavmaps::navmap->new();
4198: }
4199: if (ref($$navmapref)) {
4200: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4201: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4202: unless (@resources) {
4203: $hiddenmap = 1;
4204: unless ($env{'request.role.adv'}) {
4205: $url = '';
4206: $hiddenfolder = 1;
4207: }
1.617 raeburn 4208: }
1.615 raeburn 4209: }
4210: }
4211: }
4212: }
1.617 raeburn 4213: unless ($encryptmap) {
1.620 raeburn 4214: if ((ref($navmapref)) && (ref($$navmapref))) {
4215: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4216: $encryptmap = 1;
4217: }
1.617 raeburn 4218: }
4219: }
1.630 raeburn 4220:
1.617 raeburn 4221: # Append randompick number, hidden, and encrypted with ":" to foldername,
4222: # so it gets transferred between levels
4223: $folderpath.=$containerarg.'&'.$foldername.
4224: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
1.615 raeburn 4225: unless ($url eq '') {
1.612 raeburn 4226: $url.='folderpath='.&escape($folderpath);
4227: }
1.510 raeburn 4228: my $rpckchk;
4229: if ($rpicknum) {
4230: $rpckchk = ' checked="checked"';
1.543 raeburn 4231: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4232: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4233: }
1.510 raeburn 4234: }
1.537 raeburn 4235: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 4236: $rand_pick_text =
1.478 raeburn 4237: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4238: $form_param."\n".
1.478 raeburn 4239: $form_common."\n".
1.611 raeburn 4240: '<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.510 raeburn 4241: if ($rpicknum ne '') {
4242: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4243: }
1.537 raeburn 4244: $rand_pick_text .= '</span></span>'.
4245: $form_end;
1.543 raeburn 4246: my $ro_set;
1.617 raeburn 4247: if ($randorder) {
1.543 raeburn 4248: $ro_set = 'checked="checked"';
4249: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4250: push(@{$filtersref->{'randomorder'}},$orderidx);
4251: }
4252: }
1.564 raeburn 4253: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 4254: $rand_order_text =
1.537 raeburn 4255: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 4256: $form_param."\n".
1.537 raeburn 4257: $form_common."\n".
1.611 raeburn 4258: '<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.537 raeburn 4259: $form_end;
1.510 raeburn 4260: }
1.509 raeburn 4261: } elsif ($supplementalflag && !$allowed) {
1.598 raeburn 4262: my $isexttool;
1.626 raeburn 4263: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4264: $url='/adm/wrapper'.$url;
4265: $isexttool = 1;
4266: }
1.510 raeburn 4267: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 4268: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 4269: if ($title) {
4270: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4271: }
1.598 raeburn 4272: if ((($isexternal) || ($isexttool)) && $orderidx) {
1.510 raeburn 4273: $url .= '&idx='.$orderidx;
4274: }
1.610 raeburn 4275: if ($anchor ne '') {
4276: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4277: }
1.329 droeschl 4278: }
1.519 raeburn 4279: my ($tdalign,$tdwidth);
1.501 raeburn 4280: if ($allowed) {
1.630 raeburn 4281: my $fileloc =
1.501 raeburn 4282: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 4283: if ($isexternal) {
1.630 raeburn 4284: ($editlink,$extresform) =
1.611 raeburn 4285: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4286: undef,undef,undef,undef,undef,undef,
4287: undef,$disabled);
1.626 raeburn 4288: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
1.598 raeburn 4289: ($editlink,$extresform) =
4290: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4291: undef,undef,undef,'tool',$coursedom,
1.611 raeburn 4292: $coursenum,$ltitoolsref,$disabled);
1.511 raeburn 4293: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 4294: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4295: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 4296: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.610 raeburn 4297: my $suppanchor;
4298: if ($supplementalflag) {
4299: $suppanchor = $anchor;
4300: }
1.630 raeburn 4301: my $jscall =
1.501 raeburn 4302: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4303: $switchserver,
1.503 raeburn 4304: $forceedit,
1.511 raeburn 4305: undef,$symb,
4306: &escape($env{'form.folderpath'}),
1.622 raeburn 4307: $renametitle,$hostname,
4308: '','',1,$suppanchor);
1.501 raeburn 4309: if ($jscall) {
1.518 raeburn 4310: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4311: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 4312: }
4313: }
4314: }
1.519 raeburn 4315: $tdalign = ' align="right" valign="top"';
4316: $tdwidth = ' width="80%"';
1.329 droeschl 4317: }
1.408 raeburn 4318: my $reinit;
4319: if ($crstype eq 'Community') {
4320: $reinit = &mt('(re-initialize community to access)');
4321: } else {
4322: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 4323: }
4324: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.633 raeburn 4325: if ($url =~ /$LONCAPA::assess_re/) {
4326: $line.= '<br />';
4327: if ($curralias ne '') {
4328: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4329: $lt{'da'}.'</a></span>';
4330: } else {
4331: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4332: $lt{'sa'}.'</a></span>';
4333: }
4334: }
4335: $line.='</td><td>';
1.621 raeburn 4336: my $link;
1.472 raeburn 4337: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4338: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4339: } elsif ($url) {
1.610 raeburn 4340: if ($anchor ne '') {
4341: if ($supplementalflag) {
4342: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4343: } else {
4344: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4345: }
4346: }
1.622 raeburn 4347: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4348: $link = 'http://'.$hostname.$url;
4349: } else {
4350: $link = $url;
4351: }
4352: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
1.621 raeburn 4353: (($anchor ne '')?$anchor:''));
4354: if ($nomodal) {
4355: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4356: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4357: } else {
4358: $line.=&Apache::loncommon::modal_link($link,
4359: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4360: }
1.469 www 4361: } else {
4362: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4363: }
1.519 raeburn 4364: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 4365: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 4366: $line.='<a href="'.$url.'">'.$title.'</a>';
4367: } elsif ($url) {
1.621 raeburn 4368: if ($nomodal) {
4369: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4370: $title.'</a>';
4371: } else {
4372: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4373: }
1.617 raeburn 4374: } elsif (($hiddenfolder) || ($hiddenres)) {
1.632 raeburn 4375: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
1.469 www 4376: } else {
4377: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4378: }
1.633 raeburn 4379: if (($allowed) && ($curralias ne '')) {
4380: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4381: } else {
4382: $line .= $extresform;
4383: }
4384: $line .= '</td>';
1.478 raeburn 4385: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4386: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 4387: if (($allowed) && ($folder!~/^supplemental/)) {
4388: my %lt=&Apache::lonlocal::texthash(
4389: 'hd' => 'Hidden',
4390: 'ec' => 'URL hidden');
1.543 raeburn 4391: my ($enctext,$hidtext);
4392: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4393: $enctext = ' checked="checked"';
4394: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4395: push(@{$filtersref->{'encrypturl'}},$orderidx);
4396: }
4397: }
4398: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4399: $hidtext = ' checked="checked"';
4400: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4401: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4402: }
4403: }
1.537 raeburn 4404: my $formhidden = 'edit_hiddenresource_'.$orderidx;
4405: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 4406: $line.=(<<ENDPARMS);
4407: <td class="LC_docs_entry_parameter">
1.537 raeburn 4408: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 4409: $form_param
1.478 raeburn 4410: $form_common
1.611 raeburn 4411: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
1.329 droeschl 4412: $form_end
1.458 raeburn 4413: <br />
1.537 raeburn 4414: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 4415: $form_param
1.478 raeburn 4416: $form_common
1.611 raeburn 4417: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
1.329 droeschl 4418: $form_end
4419: </td>
1.478 raeburn 4420: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4421: $rand_order_text</td>
1.329 droeschl 4422: ENDPARMS
4423: }
1.379 bisitz 4424: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 4425: return $line;
4426: }
4427:
1.538 raeburn 4428: sub action_restrictions {
4429: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4430: my %denied = (
4431: cut => 0,
4432: copy => 0,
4433: remove => 0,
4434: );
4435: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4436: # no copy for published maps
4437: $denied{'copy'} = 1;
1.597 raeburn 4438: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4439: unless ($1 eq 'simpleproblem') {
4440: $denied{'copy'} = 1;
4441: }
4442: $denied{'cut'} = 1;
1.538 raeburn 4443: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4444: if ($folderpath =~ /^default&[^\&]+$/) {
4445: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4446: $denied{'remove'} = 1;
4447: }
4448: $denied{'cut'} = 1;
4449: $denied{'copy'} = 1;
4450: }
4451: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4452: my $group = $1;
4453: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4454: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4455: $denied{'remove'} = 1;
4456: }
4457: }
4458: $denied{'cut'} = 1;
4459: $denied{'copy'} = 1;
4460: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4461: my $group = $1;
4462: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4463: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4464: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4465: if (keys(%groupsettings) > 0) {
4466: $denied{'remove'} = 1;
4467: }
4468: $denied{'cut'} = 1;
4469: $denied{'copy'} = 1;
4470: }
4471: }
4472: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4473: my $group = $1;
4474: if ($url =~ /group_boards_\Q$group\E/) {
4475: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4476: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4477: if (keys(%groupsettings) > 0) {
4478: if (ref($groupsettings{'functions'}) eq 'HASH') {
4479: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4480: $denied{'remove'} = 1;
4481: }
4482: }
4483: }
4484: $denied{'cut'} = 1;
4485: $denied{'copy'} = 1;
4486: }
4487: }
4488: }
4489: return %denied;
4490: }
4491:
1.533 raeburn 4492: sub new_timebased_suffix {
1.538 raeburn 4493: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 4494: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 4495: if ($type eq 'paste') {
4496: $prefix = $type;
4497: $namespace = 'courseeditor';
1.587 raeburn 4498: $idtype = 'addcode';
1.538 raeburn 4499: } elsif ($type eq 'map') {
1.533 raeburn 4500: $prefix = 'docs';
4501: if ($area eq 'supplemental') {
4502: $prefix = 'supp';
4503: }
4504: $prefix .= $container;
4505: $namespace = 'uploadedmaps';
4506: } else {
4507: $prefix = $type;
4508: $namespace = 'templated';
1.504 raeburn 4509: }
4510: my ($suffix,$freedlock,$error) =
1.587 raeburn 4511: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
1.504 raeburn 4512: if (!$suffix) {
1.538 raeburn 4513: if ($type eq 'paste') {
4514: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4515: } elsif ($type eq 'map') {
1.533 raeburn 4516: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4517: } elsif ($type eq 'smppg') {
4518: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
1.626 raeburn 4519: } elsif ($type eq 'exttool') {
4520: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
1.533 raeburn 4521: } else {
1.565 bisitz 4522: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 4523: }
1.504 raeburn 4524: if ($error) {
4525: $errtext .= '<br />'.$error;
4526: }
4527: }
4528: if ($freedlock ne 'ok') {
1.630 raeburn 4529: $locknotfreed =
1.533 raeburn 4530: '<div class="LC_error">'.
4531: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 4532: if ($type eq 'paste') {
1.591 raeburn 4533: if ($freedlock eq 'nolock') {
4534: $locknotfreed =
4535: '<div class="LC_error">'.
4536: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4537:
1.593 droeschl 4538: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
1.591 raeburn 4539: } else {
4540: $locknotfreed .=
4541: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4542: }
1.538 raeburn 4543: } elsif ($type eq 'map') {
1.591 raeburn 4544: $locknotfreed .=
4545: &mt('This will prevent creation of additional folders or composite pages in this course.');
1.533 raeburn 4546: } elsif ($type eq 'smppg') {
4547: $locknotfreed .=
4548: &mt('This will prevent creation of additional simple pages in this course.');
1.626 raeburn 4549: } elsif ($type eq 'exttool') {
4550: $locknotfreed .=
4551: &mt('This will prevent creation of additional external tools in this course.');
1.533 raeburn 4552: } else {
4553: $locknotfreed .=
1.565 bisitz 4554: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 4555: }
1.538 raeburn 4556: unless ($type eq 'paste') {
4557: $locknotfreed .=
1.560 raeburn 4558: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4559: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 4560: }
4561: $locknotfreed .= '</div>';
1.504 raeburn 4562: }
4563: return ($suffix,$errtext,$locknotfreed);
4564: }
4565:
1.329 droeschl 4566: =pod
4567:
4568: =item tiehash()
4569:
4570: tie the hash
4571:
4572: =cut
4573:
4574: sub tiehash {
4575: my ($mode)=@_;
4576: $hashtied=0;
4577: if ($env{'request.course.fn'}) {
4578: if ($mode eq 'write') {
4579: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4580: &GDBM_WRCREAT(),0640)) {
4581: $hashtied=2;
4582: }
4583: } else {
4584: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4585: &GDBM_READER(),0640)) {
4586: $hashtied=1;
4587: }
4588: }
1.364 bisitz 4589: }
1.329 droeschl 4590: }
4591:
4592: sub untiehash {
4593: if ($hashtied) { untie %hash; }
4594: $hashtied=0;
4595: return OK;
4596: }
4597:
4598:
4599:
4600:
4601: sub checkonthis {
1.637 raeburn 4602: my ($r,$url,$level,$title,$checkstale)=@_;
1.329 droeschl 4603: $url=&unescape($url);
4604: $alreadyseen{$url}=1;
4605: $r->rflush();
4606: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4607: $r->print("\n<br />");
4608: if ($level==0) {
4609: $r->print("<br />");
4610: }
4611: for (my $i=0;$i<=$level*5;$i++) {
4612: $r->print(' ');
4613: }
4614: $r->print('<a href="'.$url.'" target="cat">'.
4615: ($title?$title:$url).'</a> ');
4616: if ($url=~/^\/res\//) {
1.637 raeburn 4617: my $updated;
4618: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4619: ($url !~ /\.\d+\.\w+$/)) {
4620: $updated = &Apache::lonnet::remove_stale_resfile($url);
4621: }
1.329 droeschl 4622: my $result=&Apache::lonnet::repcopy(
4623: &Apache::lonnet::filelocation('',$url));
4624: if ($result eq 'ok') {
4625: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1.637 raeburn 4626: if ($updated) {
4627: $r->print('<br />');
4628: for (my $i=0;$i<=$level*5;$i++) {
4629: $r->print(' ');
4630: }
4631: $r->print('- '.&mt('Outdated copy removed'));
4632: }
1.329 droeschl 4633: $r->rflush();
4634: &Apache::lonnet::countacc($url);
4635: $url=~/\.(\w+)$/;
4636: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4637: $r->print('<br />');
4638: $r->rflush();
4639: for (my $i=0;$i<=$level*5;$i++) {
4640: $r->print(' ');
4641: }
4642: $r->print('- '.&mt('Rendering:').' ');
4643: my ($errorcount,$warningcount)=split(/:/,
4644: &Apache::lonnet::ssi_body($url,
4645: ('grade_target'=>'web',
4646: 'return_only_error_and_warning_counts' => 1)));
4647: if (($errorcount) ||
4648: ($warningcount)) {
4649: if ($errorcount) {
1.369 bisitz 4650: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 4651: &mt('[quant,_1,error]',$errorcount).'</span>');
4652: }
4653: if ($warningcount) {
4654: $r->print('<span class="LC_warning">'.
4655: &mt('[quant,_1,warning]',$warningcount).'</span>');
4656: }
4657: } else {
4658: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4659: }
4660: $r->rflush();
4661: }
4662: my $dependencies=
4663: &Apache::lonnet::metadata($url,'dependencies');
4664: foreach my $dep (split(/\,/,$dependencies)) {
4665: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1.637 raeburn 4666: &checkonthis($r,$dep,$level+1,'',$checkstale);
1.329 droeschl 4667: }
4668: }
4669: } elsif ($result eq 'unavailable') {
4670: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4671: } elsif ($result eq 'not_found') {
4672: unless ($url=~/\$/) {
1.521 bisitz 4673: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 4674: } else {
1.366 bisitz 4675: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 4676: }
4677: } else {
4678: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4679: }
1.637 raeburn 4680: if (($updated) && ($result ne 'ok')) {
4681: $r->print('<br />'.&mt('Outdated copy removed'));
4682: }
1.329 droeschl 4683: }
4684: }
4685: }
4686:
4687:
4688:
4689: =pod
4690:
4691: =item list_symbs()
4692:
1.485 raeburn 4693: List Content Identifiers
1.329 droeschl 4694:
4695: =cut
4696:
4697: sub list_symbs {
4698: my ($r) = @_;
4699:
1.408 raeburn 4700: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4701: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4702: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4703: $r->print(&startContentScreen('tools'));
1.329 droeschl 4704: my $navmap = Apache::lonnavmaps::navmap->new();
4705: if (!defined($navmap)) {
4706: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4707: '<div class="LC_error">'.
4708: &mt('Unable to retrieve information about course contents').
4709: '</div>');
1.408 raeburn 4710: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 4711: } else {
1.484 raeburn 4712: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4713: &Apache::loncommon::start_data_table().
4714: &Apache::loncommon::start_data_table_header_row().
4715: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4716: &Apache::loncommon::end_data_table_header_row()."\n");
4717: my $count;
1.329 droeschl 4718: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 4719: $r->print(&Apache::loncommon::start_data_table_row().
4720: '<td>'.$res->compTitle().'</td>'.
4721: '<td>'.$res->symb().'</td>'.
1.521 bisitz 4722: &Apache::loncommon::end_data_table_row());
1.484 raeburn 4723: $count ++;
4724: }
4725: if (!$count) {
4726: $r->print(&Apache::loncommon::start_data_table_row().
4727: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4728: &Apache::loncommon::end_data_table_row());
1.329 droeschl 4729: }
1.484 raeburn 4730: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 4731: }
1.521 bisitz 4732: $r->print(&endContentScreen());
1.329 droeschl 4733: }
4734:
1.637 raeburn 4735: sub contentverifyform {
4736: my ($r) = @_;
4737: my $crstype = &Apache::loncommon::course_type();
4738: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4739: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4740: $r->print(&startContentScreen('tools'));
4741: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4742: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4743: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4744: ' <span class="LC_nobreak">'.
4745: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4746: &mt('No').'</label>'.(' 'x2).
4747: '<label><input type="radio" name="checkstale" value="1" />'.
4748: &mt('Yes').'</label></span></p><p>'.
4749: '<input type="submit" value="'.&mt('Verify content').' "/>'.
4750: '<input type="hidden" value="1" name="tools" />'.
4751: '<input type="hidden" value="1" name="verify" /></p></form>');
4752: $r->print(&endContentScreen());
4753: return;
4754: }
1.329 droeschl 4755:
4756: sub verifycontent {
1.637 raeburn 4757: my ($r,$checkstale) = @_;
1.408 raeburn 4758: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 4759: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4760: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 4761: $r->print(&startContentScreen('tools'));
4762: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4763: $hashtied=0;
4764: undef %alreadyseen;
4765: %alreadyseen=();
4766: &tiehash();
1.484 raeburn 4767:
1.329 droeschl 4768: foreach my $key (keys(%hash)) {
4769: if ($hash{$key}=~/\.(page|sequence)$/) {
4770: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4771: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4772: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4773: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4774: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4775: }
4776: }
4777: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1.637 raeburn 4778: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
1.329 droeschl 4779: }
4780: }
4781: &untiehash();
1.442 www 4782: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4783: $r->print(&endContentScreen());
1.329 droeschl 4784: }
4785:
4786: sub devalidateversioncache {
4787: my $src=shift;
4788: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4789: &Apache::lonnet::clutter($src));
4790: }
4791:
4792: sub checkversions {
1.611 raeburn 4793: my ($r,$canedit) = @_;
1.408 raeburn 4794: my $crstype = &Apache::loncommon::course_type();
1.571 raeburn 4795: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
4796: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
1.484 raeburn 4797: $r->print(&startContentScreen('tools'));
1.442 www 4798:
1.329 droeschl 4799: my $header='';
4800: my $startsel='';
4801: my $monthsel='';
4802: my $weeksel='';
4803: my $daysel='';
4804: my $allsel='';
4805: my %changes=();
4806: my $starttime=0;
4807: my $haschanged=0;
4808: my %setversions=&Apache::lonnet::dump('resourceversions',
4809: $env{'course.'.$env{'request.course.id'}.'.domain'},
4810: $env{'course.'.$env{'request.course.id'}.'.num'});
4811:
4812: $hashtied=0;
4813: &tiehash();
1.611 raeburn 4814: if ($canedit) {
4815: my %newsetversions=();
4816: if ($env{'form.setmostrecent'}) {
4817: $haschanged=1;
4818: foreach my $key (keys(%hash)) {
4819: if ($key=~/^ids\_(\/res\/.+)$/) {
4820: $newsetversions{$1}='mostrecent';
4821: &devalidateversioncache($1);
4822: }
4823: }
4824: } elsif ($env{'form.setcurrent'}) {
4825: $haschanged=1;
4826: foreach my $key (keys(%hash)) {
4827: if ($key=~/^ids\_(\/res\/.+)$/) {
4828: my $getvers=&Apache::lonnet::getversion($1);
4829: if ($getvers>0) {
4830: $newsetversions{$1}=$getvers;
4831: &devalidateversioncache($1);
4832: }
4833: }
1.329 droeschl 4834: }
1.611 raeburn 4835: } elsif ($env{'form.setversions'}) {
4836: $haschanged=1;
4837: foreach my $key (keys(%env)) {
4838: if ($key=~/^form\.set_version_(.+)$/) {
4839: my $src=$1;
4840: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4841: $newsetversions{$src}=$env{$key};
4842: &devalidateversioncache($src);
4843: }
4844: }
1.329 droeschl 4845: }
1.611 raeburn 4846: }
4847: if ($haschanged) {
4848: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4849: $env{'course.'.$env{'request.course.id'}.'.domain'},
4850: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
4851: $r->print(&Apache::loncommon::confirmwrapper(
4852: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
4853: } else {
4854: $r->print(&Apache::loncommon::confirmwrapper(
4855: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4856: }
1.611 raeburn 4857: &mark_hash_old();
4858: }
4859: &changewarning($r,'');
1.329 droeschl 4860: }
4861: if ($env{'form.timerange'} eq 'all') {
4862: # show all documents
1.549 raeburn 4863: $header=&mt('All content in '.$crstype);
1.521 bisitz 4864: $allsel=' selected="selected"';
1.329 droeschl 4865: foreach my $key (keys(%hash)) {
4866: if ($key=~/^ids\_(\/res\/.+)$/) {
4867: my $src=$1;
4868: $changes{$src}=1;
4869: }
4870: }
4871: } else {
4872: # show documents which changed
4873: %changes=&Apache::lonnet::dump
4874: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4875: $env{'course.'.$env{'request.course.id'}.'.num'});
4876: my $firstkey=(keys(%changes))[0];
4877: unless ($firstkey=~/^error\:/) {
4878: unless ($env{'form.timerange'}) {
4879: $env{'form.timerange'}=604800;
4880: }
4881: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4882: .&mt('seconds');
4883: if ($env{'form.timerange'}==-1) {
4884: $seltext='since start of course';
1.521 bisitz 4885: $startsel=' selected="selected"';
1.329 droeschl 4886: $env{'form.timerange'}=time;
4887: }
4888: $starttime=time-$env{'form.timerange'};
4889: if ($env{'form.timerange'}==2592000) {
4890: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4891: $monthsel=' selected="selected"';
1.329 droeschl 4892: } elsif ($env{'form.timerange'}==604800) {
4893: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4894: $weeksel=' selected="selected"';
1.329 droeschl 4895: } elsif ($env{'form.timerange'}==86400) {
4896: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4897: $daysel=' selected="selected"';
1.329 droeschl 4898: }
4899: $header=&mt('Content changed').' '.$seltext;
4900: } else {
4901: $header=&mt('No content modifications yet.');
4902: }
4903: }
4904: %setversions=&Apache::lonnet::dump('resourceversions',
4905: $env{'course.'.$env{'request.course.id'}.'.domain'},
4906: $env{'course.'.$env{'request.course.id'}.'.num'});
4907: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4908: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4909: 'lm' => 'Version changes since last Month',
4910: 'lw' => 'Version changes since last Week',
4911: 'sy' => 'Version changes since Yesterday',
4912: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4913: 'cd' => 'Change display',
1.329 droeschl 4914: 'sd' => 'Display',
4915: 'fi' => 'File',
4916: 'md' => 'Modification Date',
4917: 'mr' => 'Most recently published Version',
1.408 raeburn 4918: 've' => 'Version used in '.$crstype,
4919: 'vu' => 'Set Version to be used in '.$crstype,
4920: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4921: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4922: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4923: 'di' => 'Differences',
1.484 raeburn 4924: 'save' => 'Save changes',
4925: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4926: 'act' => 'Actions');
1.611 raeburn 4927: my ($disabled,$readonly);
4928: unless ($canedit) {
4929: $disabled = 'disabled="disabled"';
4930: $readonly = 1;
4931: }
1.329 droeschl 4932: $r->print(<<ENDHEADERS);
1.484 raeburn 4933: <h4 class="LC_info">$header</h4>
1.329 droeschl 4934: <form action="/adm/coursedocs" method="post">
4935: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4936: <div class="LC_left_float">
1.479 golterma 4937: <fieldset>
1.484 raeburn 4938: <legend>$lt{'cd'}</legend>
1.329 droeschl 4939: <select name="timerange">
1.521 bisitz 4940: <option value='all'$allsel>$lt{'al'}</option>
4941: <option value="-1"$startsel>$lt{'st'}</option>
4942: <option value="2592000"$monthsel>$lt{'lm'}</option>
4943: <option value="604800"$weeksel>$lt{'lw'}</option>
4944: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4945: </select>
4946: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4947: </fieldset>
4948: </div>
4949: <div class="LC_left_float">
4950: <fieldset>
4951: <legend>$lt{'act'}</legend>
1.611 raeburn 4952: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
4953: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
1.484 raeburn 4954: </fieldset>
4955: </div>
4956: <br clear="all" />
4957: <hr />
4958: <h4>$lt{'vers'}</h4>
1.329 droeschl 4959: ENDHEADERS
1.479 golterma 4960: #number of columns for version history
1.571 raeburn 4961: my %changedbytime;
4962: foreach my $key (keys(%changes)) {
4963: #excludes not versionable problems from resource version history:
4964: next if ($key =~ /^\/res\/lib\/templates/);
4965: my $chg;
4966: if ($env{'form.timerange'} eq 'all') {
4967: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4968: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
4969: } else {
4970: $chg = $changes{$key};
4971: next if ($chg < $starttime);
4972: }
4973: push(@{$changedbytime{$chg}},$key);
4974: }
4975: if (keys(%changedbytime) == 0) {
4976: &untiehash();
4977: $r->print(&mt('No content changes in imported content in specified time frame').
4978: &endContentScreen());
4979: return;
4980: }
1.479 golterma 4981: $r->print(
1.611 raeburn 4982: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 4983: &Apache::loncommon::start_data_table().
4984: &Apache::loncommon::start_data_table_header_row().
4985: '<th>'.&mt('Resources').'</th>'.
4986: "<th>$lt{'mr'}</th>".
4987: "<th>$lt{'ve'}</th>".
4988: "<th>$lt{'vu'}</th>".
4989: '<th>'.&mt('History').'</th>'.
4990: &Apache::loncommon::end_data_table_header_row()
4991: );
1.571 raeburn 4992: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
4993: foreach my $key (sort(@{$changedbytime{$chg}})) {
4994: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4995: my $currentversion=&Apache::lonnet::getversion($key);
4996: if ($currentversion<0) {
4997: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4998: }
4999: my $linkurl=&Apache::lonnet::clutter($key);
5000: $r->print(
5001: &Apache::loncommon::start_data_table_row().
5002: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5003: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5004: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5005: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5006: '<td align="right">'
5007: );
5008: # Used in course
5009: my $usedversion=$hash{'version_'.$linkurl};
5010: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.521 bisitz 5011: if ($usedversion != $currentversion) {
1.479 golterma 5012: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 5013: } else {
1.479 golterma 5014: $r->print($usedversion);
5015: }
1.329 droeschl 5016: } else {
1.521 bisitz 5017: $r->print($currentversion);
1.329 droeschl 5018: }
1.571 raeburn 5019: $r->print('</td><td title="'.$lt{'vu'}.'">');
5020: # Set version
5021: $r->print(&Apache::loncommon::select_form(
5022: $setversions{$linkurl},
5023: 'set_version_'.$linkurl,
5024: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5025: '' => '',
5026: 'mostrecent' => &mt('most recent'),
1.611 raeburn 5027: map {$_,$_} (1..$currentversion)},'',$readonly));
1.571 raeburn 5028: my $lastold=1;
5029: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5030: my $url=$root.'.'.$prevvers.'.'.$extension;
5031: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5032: $lastold=$prevvers;
5033: }
5034: }
5035: $r->print('</td>');
5036: # List all available versions
5037: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5038: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5039: my $url=$root.'.'.$prevvers.'.'.$extension;
5040: $r->print(
5041: '<span class="LC_nobreak">'
5042: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5043: .&mt('Version [_1]',$prevvers).'</a>'
5044: .' ('.&Apache::lonlocal::locallocaltime(
1.521 bisitz 5045: &Apache::lonnet::metadata($url,'lastrevisiondate'))
1.571 raeburn 5046: .')');
5047: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5048: $r->print(
5049: ' <a href="/adm/diff?filename='.
5050: &Apache::lonnet::clutter($root.'.'.$extension).
5051: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5052: '" target="diffs">'.&mt('Diffs').'</a>');
5053: }
5054: $r->print('</span><br />');
1.329 droeschl 5055: }
1.571 raeburn 5056: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.521 bisitz 5057: }
1.329 droeschl 5058: }
1.521 bisitz 5059: $r->print(
5060: &Apache::loncommon::end_data_table().
1.611 raeburn 5061: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
1.521 bisitz 5062: '</form>'
5063: );
1.329 droeschl 5064:
5065: &untiehash();
1.521 bisitz 5066: $r->print(&endContentScreen());
1.571 raeburn 5067: return;
1.329 droeschl 5068: }
5069:
5070: sub mark_hash_old {
5071: my $retie_hash=0;
5072: if ($hashtied) {
5073: $retie_hash=1;
5074: &untiehash();
5075: }
5076: &tiehash('write');
5077: $hash{'old'}=1;
5078: &untiehash();
5079: if ($retie_hash) { &tiehash(); }
5080: }
5081:
5082: sub is_hash_old {
5083: my $untie_hash=0;
5084: if (!$hashtied) {
5085: $untie_hash=1;
5086: &tiehash();
5087: }
5088: my $return=$hash{'old'};
5089: if ($untie_hash) { &untiehash(); }
5090: return $return;
5091: }
5092:
5093: sub changewarning {
5094: my ($r,$postexec,$message,$url)=@_;
5095: if (!&is_hash_old()) { return; }
5096: my $pathvar='folderpath';
5097: my $path=&escape($env{'form.folderpath'});
5098: if (!defined($url)) {
5099: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5100: }
5101: my $course_type = &Apache::loncommon::course_type();
5102: if (!defined($message)) {
5103: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5104: }
5105: $r->print("\n\n".
1.372 bisitz 5106: '<script type="text/javascript">'."\n".
5107: '// <![CDATA['."\n".
5108: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5109: '// ]]>'."\n".
1.369 bisitz 5110: '</script>'."\n".
1.375 tempelho 5111: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 5112: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 5113: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 5114: &mt($message,' <input type="hidden" name="'.
5115: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 5116: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 5117: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 5118: }
5119:
5120:
5121: sub init_breadcrumbs {
1.571 raeburn 5122: my ($form,$text,$help)=@_;
1.329 droeschl 5123: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 5124: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 5125: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 5126: faq=>273,
5127: bug=>'Instructor Interface',
1.571 raeburn 5128: help => $help});
1.329 droeschl 5129: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5130: text=>$text,
5131: faq=>273,
5132: bug=>'Instructor Interface'});
5133: }
5134:
1.441 www 5135: # subroutine to list form elements
5136: sub create_list_elements {
5137: my @formarr = @_;
5138: my $list = '';
1.501 raeburn 5139: foreach my $button (@formarr){
5140: foreach my $picture (keys(%{$button})) {
5141: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 5142: }
5143: }
5144: return $list;
5145: }
1.329 droeschl 5146:
1.441 www 5147: # subroutine to create ul from list elements
5148: sub create_form_ul {
5149: my $list = shift;
5150: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5151: return $ul;
5152: }
1.329 droeschl 5153:
1.442 www 5154: #
5155: # Start tabs
5156: #
5157:
5158: sub startContentScreen {
1.484 raeburn 5159: my ($mode) = @_;
5160: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 5161: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 5162: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5163: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5164: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5165: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5166: } else {
1.549 raeburn 5167: $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 5168: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5169: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5170: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5171: }
5172: $output .= "\n".'</ul>'."\n";
5173: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5174: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5175: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5176: return $output;
1.442 www 5177: }
5178:
5179: #
5180: # End tabs
5181: #
5182:
5183: sub endContentScreen {
1.484 raeburn 5184: return '</div></div></div>';
1.442 www 5185: }
1.329 droeschl 5186:
1.446 www 5187: sub supplemental_base {
1.548 raeburn 5188: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 5189: }
5190:
1.329 droeschl 5191: sub handler {
5192: my $r = shift;
5193: &Apache::loncommon::content_type($r,'text/html');
5194: $r->send_http_header;
5195: return OK if $r->header_only;
1.484 raeburn 5196:
5197: # get course data
1.408 raeburn 5198: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 5199: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5200: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5201:
1.606 raeburn 5202: # get docroot
5203: my $londocroot = $r->dir_config('lonDocRoot');
5204:
1.484 raeburn 5205: # graphics settings
5206: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 5207:
1.443 www 5208: #
1.329 droeschl 5209: # --------------------------------------------- Initialize help topics for this
5210: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
1.627 raeburn 5211: 'Adding_External_Resource','Adding_External_Tool',
5212: 'Navigate_Content','Adding_Folders','Docs_Overview',
5213: 'Load_Map','Supplemental','Score_Upload_Form',
5214: 'Adding_Pages','Importing_LON-CAPA_Resource',
5215: 'Importing_IMS_Course','Uploading_From_Harddrive',
5216: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
1.329 droeschl 5217: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5218: }
5219: # Composite help files
5220: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5221: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5222: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5223: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5224: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5225: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 5226: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 5227: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 5228: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 5229: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 5230:
1.611 raeburn 5231: my ($allowed,$canedit,$canview,$noendpage,$disabled);
1.472 raeburn 5232: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5233: unless ($r->uri eq '/adm/supplemental') {
5234: # does this user have privileges to modify content.
1.611 raeburn 5235: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5236: $allowed = 1;
5237: $canedit = 1;
5238: $canview = 1;
5239: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5240: $allowed = 1;
5241: $canview = 1;
5242: }
5243: }
5244: unless ($canedit) {
5245: $disabled = ' disabled="disabled"';
1.472 raeburn 5246: }
1.582 raeburn 5247: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
1.635 raeburn 5248: if ($env{'form.inhibitmenu'}) {
5249: unless ($env{'form.inhibitmenu'} eq 'yes') {
5250: delete($env{'form.inhibitmenu'});
5251: }
5252: }
5253:
1.582 raeburn 5254: if ($allowed && $env{'form.verify'}) {
1.571 raeburn 5255: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
1.637 raeburn 5256: if (!$canedit) {
5257: &verifycontent($r);
5258: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5259: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5260: text=>'Results',
5261: faq=>273,
5262: bug=>'Instructor Interface'});
5263: &verifycontent($r,$env{'form.checkstale'});
5264: } else {
5265: &contentverifyform($r);
5266: }
1.329 droeschl 5267: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 5268: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 5269: &list_symbs($r);
5270: } elsif ($allowed && $env{'form.docslog'}) {
5271: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 5272: my $folder = $env{'form.folder'};
5273: if ($folder eq '') {
5274: $folder='default';
5275: }
1.611 raeburn 5276: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
1.329 droeschl 5277: } elsif ($allowed && $env{'form.versions'}) {
1.571 raeburn 5278: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
1.611 raeburn 5279: &checkversions($r,$canedit);
5280: } elsif ($canedit && $env{'form.dumpcourse'}) {
1.568 raeburn 5281: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 5282: &dumpcourse($r);
1.611 raeburn 5283: } elsif ($canedit && $env{'form.exportcourse'}) {
1.377 bisitz 5284: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 5285: &Apache::imsexport::exportcourse($r);
1.329 droeschl 5286: } else {
1.611 raeburn 5287: if ($canedit && $env{'form.authorrole'}) {
1.606 raeburn 5288: $noendpage = 1;
5289: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5290: if ($redirect) {
5291: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5292: my $container = 'sequence';
5293: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5294: $is_random_order,$container) =
5295: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5296: my (@folders)=split('&',$env{'form.folderpath'});
5297: $env{'form.foldername'}=&unescape(pop(@folders));
5298: my $folder=pop(@folders);
5299: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5300: $folder.'.'.$container);
5301: my $warning;
5302: if ($fatal) {
5303: if ($container eq 'page') {
5304: $warning = &mt('An error occurred retrieving the contents of the current page.');
5305: } else {
5306: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5307: }
5308: } else {
5309: my $url = $redirect;
5310: my $srcfile = $londocroot.$url;
5311: $url =~ s{^/priv/}{/res/};
5312: my $targetfile = $londocroot.$url;
5313: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5314: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5315: $env{'form.folder'} = $folder;
5316: &snapshotbefore();
5317: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5318: my $ext = 'false';
5319: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5320: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5321: ':'.$ext.':normal:res';
5322: push(@LONCAPA::map::order,$newidx);
5323: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5324: 'string_yesno');
5325: &remember_parms($newidx,'hiddenresource','set','yes');
5326: ($errtext,$fatal) =
5327: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5328: &log_differences($plain);
5329: &mark_hash_old();
5330: $r->internal_redirect($redirect);
5331: return OK;
5332: }
5333: }
5334: }
5335: }
1.445 www 5336: #
5337: # Done catching special calls
1.484 raeburn 5338: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 5339: # Get the parameters that may be needed
5340: #
5341: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 5342: ['folderpath',
5343: 'forcesupplement','forcestandard',
1.510 raeburn 5344: 'tools','symb','command','supppath']);
1.445 www 5345:
1.635 raeburn 5346: foreach my $item ('forcesupplement','forcestandard','tools') {
5347: next if ($env{'form.'.$item} eq '');
5348: unless ($env{'form.'.$item} eq '1') {
5349: delete($env{'form.'.$item});
5350: }
5351: }
5352:
5353: if ($env{'form.command'}) {
5354: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5355: delete($env{'form.command'});
5356: }
5357: }
5358:
5359: if ($env{'form.symb'}) {
5360: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5361: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5362: delete($env{'form.symb'});
5363: }
5364: }
5365:
1.445 www 5366: # standard=1: this is a "new-style" course with an uploaded map as top level
5367: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 5368:
5369: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 5370:
1.484 raeburn 5371: # Decide whether this should display supplemental or main content or utilities
1.445 www 5372: # supplementalflag=1: show supplemental documents
5373: # supplementalflag=0: show standard documents
1.484 raeburn 5374: # toolsflag=1: show utilities
1.445 www 5375:
1.561 raeburn 5376: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5377: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5378: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 5379: $supplementalflag=0;
5380: }
5381: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5382: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5383: unless ($allowed) { $supplementalflag=1; }
5384: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 5385: my $toolsflag=0;
5386: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 5387:
1.635 raeburn 5388: if ($env{'form.folderpath'} ne '') {
5389: my @items = split(/\&/,$env{'form.folderpath'});
5390: my $badpath;
5391: for (my $i=0; $i<@items; $i++) {
5392: my $odd = $i%2;
5393: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
5394: $badpath = 1;
5395: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
5396: $badpath = 1;
5397: }
5398: last if ($badpath);
5399: }
5400: if ($badpath) {
5401: delete($env{'form.folderpath'});
5402: }
5403: }
5404:
5405: if ($env{'form.supppath'} ne '') {
5406: my @items = split(/\&/,$env{'form.supppath'});
5407: my $badpath;
5408: for (my $i=0; $i<@items; $i++) {
5409: my $odd = $i%2;
5410: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
5411: $badpath = 1;
5412: }
5413: last if ($badpath);
5414: }
5415: if ($badpath) {
5416: delete($env{'form.supppath'});
5417: }
5418: }
5419:
1.329 droeschl 5420: my $script='';
5421: my $showdoc=0;
1.457 raeburn 5422: my $addentries = {};
1.475 raeburn 5423: my $container;
1.329 droeschl 5424: my $containertag;
1.508 raeburn 5425: my $pathitem;
1.598 raeburn 5426: my %ltitools;
1.617 raeburn 5427: my $hiddentop;
1.615 raeburn 5428: my $navmap;
1.617 raeburn 5429: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
1.329 droeschl 5430:
1.464 www 5431: # Do we directly jump somewhere?
1.525 raeburn 5432: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 5433: if ($env{'form.symb'} ne '') {
1.522 raeburn 5434: $env{'form.folderpath'}=
1.617 raeburn 5435: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
1.530 raeburn 5436: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5437: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 5438: } elsif ($env{'form.supppath'} ne '') {
5439: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 5440: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 5441: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 5442: }
1.472 raeburn 5443: } elsif ($env{'form.command'} eq 'editdocs') {
1.617 raeburn 5444: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
1.525 raeburn 5445: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 5446: } elsif ($env{'form.command'} eq 'editsupp') {
1.617 raeburn 5447: $env{'form.folderpath'} = &supplemental_base();
1.525 raeburn 5448: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5449: } elsif ($env{'form.command'} eq 'contents') {
5450: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5451: } elsif ($env{'form.command'} eq 'home') {
5452: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 5453: }
5454:
1.525 raeburn 5455:
1.445 www 5456: # Where do we store these for when we come back?
5457: my $stored_folderpath='docs_folderpath';
5458: if ($supplementalflag) {
5459: $stored_folderpath='docs_sup_folderpath';
5460: }
1.464 www 5461:
1.519 raeburn 5462: # No folderpath, and in edit mode, see if we have something stored
5463: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 5464: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 5465: {'folderpath' => 'scalar'});
1.615 raeburn 5466:
5467: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5468: if ($supplementalflag) {
5469: undef($env{'form.folderpath'}) if ($1 eq 'default');
5470: } else {
5471: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5472: }
5473: } else {
1.523 raeburn 5474: undef($env{'form.folderpath'});
5475: }
1.329 droeschl 5476: }
1.446 www 5477:
5478: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 5479: if (!$allowed) {
1.446 www 5480: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5481: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 5482: }
5483: }
1.446 www 5484: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 5485: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 5486: $env{'form.folderpath'} = &supplemental_base()
5487: .'&'.
1.329 droeschl 5488: $env{'form.folderpath'};
5489: }
1.615 raeburn 5490: # If allowed and user's role is not advanced check folderpath is not hidden
5491: if (($allowed) && (!$env{'request.role.adv'}) &&
5492: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5493: my $folderurl;
5494: my @pathitems = split(/\&/,$env{'form.folderpath'});
1.617 raeburn 5495: my $folder = $pathitems[-2];
5496: if ($folder eq '') {
5497: undef($env{'form.folderpath'});
5498: } else {
5499: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
1.615 raeburn 5500: if ((split(/\:/,$pathitems[-1]))[4]) {
5501: $folderurl .= '.page';
5502: } else {
5503: $folderurl .= '.sequence';
5504: }
1.617 raeburn 5505: unless (ref($navmap)) {
5506: $navmap = Apache::lonnavmaps::navmap->new();
5507: }
1.615 raeburn 5508: if (ref($navmap)) {
5509: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
1.617 raeburn 5510: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5511: unless (@resources) {
5512: undef($env{'form.folderpath'});
5513: }
1.615 raeburn 5514: }
5515: }
5516: }
5517: }
5518:
5519:
1.446 www 5520: # If after all of this, we still don't have any paths, make them
1.519 raeburn 5521: unless ($env{'form.folderpath'}) {
1.446 www 5522: if ($supplementalflag) {
5523: $env{'form.folderpath'}=&supplemental_base();
1.617 raeburn 5524: } elsif ($allowed) {
5525: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
1.446 www 5526: }
1.472 raeburn 5527: }
1.446 www 5528:
1.445 www 5529: # Store this
1.484 raeburn 5530: unless ($toolsflag) {
1.615 raeburn 5531: if (($allowed) && ($env{'form.folderpath'} ne '')) {
1.510 raeburn 5532: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 5533: {'folderpath' => 'scalar'});
1.510 raeburn 5534: }
1.519 raeburn 5535: my $folderpath;
1.484 raeburn 5536: if ($env{'form.folderpath'}) {
1.519 raeburn 5537: $folderpath = $env{'form.folderpath'};
5538: my (@folders)=split('&',$env{'form.folderpath'});
5539: $env{'form.foldername'}=&unescape(pop(@folders));
5540: if ($env{'form.foldername'} =~ /\:1$/) {
5541: $container = 'page';
5542: } else {
5543: $container = 'sequence';
5544: }
5545: $env{'form.folder'}=pop(@folders);
1.484 raeburn 5546: } else {
1.519 raeburn 5547: if ($env{'form.folder'} eq '' ||
5548: $env{'form.folder'} eq 'supplemental') {
1.617 raeburn 5549: if ($env{'form.folder'} eq 'supplemental') {
5550: $folderpath=&supplemental_base();
5551: } elsif (!$hiddentop) {
5552: $folderpath='default&'.
5553: &escape(&mt('Main Content').':::::');
5554: }
1.484 raeburn 5555: }
5556: }
1.519 raeburn 5557: $containertag = '<input type="hidden" name="folderpath" value="" />';
5558: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 5559: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5560: $showdoc='/'.$1;
5561: }
5562: if ($showdoc) { # got called in sequence from course
5563: $allowed=0;
5564: } else {
1.611 raeburn 5565: if ($canedit) {
1.484 raeburn 5566: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5567: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 5568: }
5569: }
1.329 droeschl 5570: }
5571:
1.344 bisitz 5572: # get personal data
1.329 droeschl 5573: my $uname=$env{'user.name'};
5574: my $udom=$env{'user.domain'};
5575: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5576:
5577: if ($allowed) {
1.484 raeburn 5578: if ($toolsflag) {
5579: $script .= &inject_data_js();
5580: my ($home,$other,%outhash)=&authorhosts();
5581: if (!$home && $other) {
5582: my @hosts;
5583: foreach my $aurole (keys(%outhash)) {
5584: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5585: push(@hosts,$outhash{$aurole});
5586: }
5587: }
5588: $script .= &dump_switchserver_js(@hosts);
5589: }
1.458 raeburn 5590: } else {
1.570 raeburn 5591: my $tid = 1;
1.484 raeburn 5592: my @tabids;
5593: if ($supplementalflag) {
5594: @tabids = ('002','ee2','ff2');
1.570 raeburn 5595: $tid = 2;
1.484 raeburn 5596: } else {
5597: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 5598: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 5599: unshift(@tabids,'001');
5600: push(@tabids,('dd1','ee1'));
5601: }
1.458 raeburn 5602: }
1.484 raeburn 5603: my $tabidstr = join("','",@tabids);
1.598 raeburn 5604: %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);
1.600 raeburn 5605: my $posslti = keys(%ltitools);
1.622 raeburn 5606: my $hostname = $r->hostname();
1.606 raeburn 5607: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
1.622 raeburn 5608: $londocroot,$canedit,$hostname,\$navmap).
1.484 raeburn 5609: &history_tab_js().
5610: &inject_data_js().
1.570 raeburn 5611: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
1.598 raeburn 5612: &Apache::lonextresedit::extedit_javascript(\%ltitools);
1.484 raeburn 5613: $addentries = {
1.485 raeburn 5614: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 5615: };
1.458 raeburn 5616: }
1.538 raeburn 5617: $script .= &paste_popup_js();
1.501 raeburn 5618: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5619: &mt('Switch server?');
5620:
5621:
1.329 droeschl 5622: }
5623: # -------------------------------------------------------------------- Body tag
1.369 bisitz 5624: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 5625: .'// <![CDATA['."\n"
5626: .$script."\n"
5627: .'// ]]>'."\n"
1.595 musolffc 5628: .'</script>'."\n"
5629: .'<script type="text/javascript"
5630: src="/res/adm/includes/file_upload.js"></script>'."\n";
1.385 bisitz 5631:
5632: # Breadcrumbs
5633: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 5634:
5635: if ($showdoc) {
5636: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
5637: {'force_register' => $showdoc,}));
1.571 raeburn 5638: } elsif ($toolsflag) {
1.611 raeburn 5639: my ($breadtext,$breadtitle);
1.617 raeburn 5640: $breadtext = "$crstype Editor";
1.611 raeburn 5641: if ($canedit) {
5642: $breadtitle = 'Editing '.$crstype.' Contents';
5643: } else {
5644: $breadtext .= ' (View-only mode)';
5645: $breadtitle = 'Viewing '.$crstype.' Contents';
5646: }
1.571 raeburn 5647: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5648: href=>"/adm/coursedocs",text=>$breadtext});
1.571 raeburn 5649: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5650: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5651: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5652: $breadtitle)
1.571 raeburn 5653: );
1.510 raeburn 5654: } elsif ($r->uri eq '/adm/supplemental') {
5655: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5656: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5657: {'bread_crumbs' => $brcrum,}));
5658: } else {
1.611 raeburn 5659: my ($breadtext,$breadtitle,$helpitem);
1.617 raeburn 5660: $breadtext = "$crstype Editor";
1.611 raeburn 5661: if ($canedit) {
5662: $breadtitle = 'Editing '.$crstype.' Contents';
5663: $helpitem = 'Docs_Adding_Course_Doc';
5664: } else {
5665: $breadtext .= ' (View-only mode)';
5666: $breadtitle = 'Viewing '.$crstype.' Contents';
5667: $helpitem = 'Docs_Viewing_Course_Doc';
5668: }
1.392 raeburn 5669: &Apache::lonhtmlcommon::add_breadcrumb({
1.611 raeburn 5670: href=>"/adm/coursedocs",text=>$breadtext});
1.446 www 5671: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 5672: {'add_entries' => $addentries}
5673: )
1.392 raeburn 5674: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5675: .&Apache::lonhtmlcommon::breadcrumbs(
1.611 raeburn 5676: $breadtitle,
5677: $helpitem)
1.392 raeburn 5678: );
5679: }
1.364 bisitz 5680:
1.329 droeschl 5681: my %allfiles = ();
5682: my %codebase = ();
1.440 raeburn 5683: my ($upload_result,$upload_output,$uploadphase);
1.611 raeburn 5684: if ($canedit) {
1.329 droeschl 5685: if (($env{'form.uploaddoc.filename'}) &&
5686: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 5687: my $context = $1;
5688: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 5689: undef($hadchanges);
1.440 raeburn 5690: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 5691: \%allfiles,\%codebase,$context,$crstype);
1.638 raeburn 5692: undef($navmap);
1.329 droeschl 5693: if ($hadchanges) {
5694: &mark_hash_old();
5695: }
1.440 raeburn 5696: $r->print($upload_output);
5697: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5698: # Process file upload - phase two - upload embedded objects
5699: $uploadphase = 'check_embedded';
5700: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5701: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5702: $env{'form.newidx'});
5703: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5704: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5705: my ($destination,$dir_root) = &embedded_destination();
5706: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5707: my $actionurl = '/adm/coursedocs';
1.630 raeburn 5708: my ($result,$flag) =
1.440 raeburn 5709: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5710: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5711: $actionurl);
5712: $r->print($result.&return_to_editor());
5713: } elsif ($env{'form.phase'} eq 'check_embedded') {
5714: # Process file upload - phase three - modify references in HTML file
5715: $uploadphase = 'modified_orightml';
5716: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5717: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5718: my ($destination,$dir_root) = &embedded_destination();
1.630 raeburn 5719: my $result =
1.482 raeburn 5720: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5721: $docuname,$docudom,undef,
5722: $dir_root);
1.630 raeburn 5723: $r->print($result.&return_to_editor());
1.476 raeburn 5724: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5725: $uploadphase = 'decompress_phase_one';
5726: $r->print(&decompression_phase_one().
5727: &return_to_editor());
5728: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5729: $uploadphase = 'decompress_phase_two';
5730: $r->print(&decompression_phase_two().
5731: &return_to_editor());
1.329 droeschl 5732: }
5733: }
5734:
1.484 raeburn 5735: if ($allowed && $toolsflag) {
5736: $r->print(&startContentScreen('tools'));
1.611 raeburn 5737: $r->print(&generate_admin_menu($crstype,$canedit));
1.484 raeburn 5738: $r->print(&endContentScreen());
5739: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 5740: # -----------------------------------------------------------------------------
5741: my %lt=&Apache::lonlocal::texthash(
5742: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 5743: 'upfi' => 'Upload File',
1.553 raeburn 5744: 'upld' => 'Upload Content',
1.329 droeschl 5745: 'srch' => 'Search',
5746: 'impo' => 'Import',
1.487 raeburn 5747: 'lnks' => 'Import from Stored Links',
1.502 raeburn 5748: 'impm' => 'Import from Assembled Map',
1.630 raeburn 5749: 'imcr' => 'Import from Course Resources',
1.598 raeburn 5750: 'extr' => 'External Resource',
5751: 'extt' => 'External Tool',
1.329 droeschl 5752: 'selm' => 'Select Map',
5753: 'load' => 'Load Map',
5754: 'newf' => 'New Folder',
5755: 'newp' => 'New Composite Page',
5756: 'syll' => 'Syllabus',
1.425 raeburn 5757: 'navc' => 'Table of Contents',
1.343 biermanm 5758: 'sipa' => 'Simple Course Page',
1.329 droeschl 5759: 'sipr' => 'Simple Problem',
1.630 raeburn 5760: 'webp' => 'Blank Web Page (editable)',
1.606 raeburn 5761: 'stpr' => 'Standard Problem',
5762: 'news' => 'New sub-directory',
5763: 'crpr' => 'Create Problem',
1.329 droeschl 5764: 'drbx' => 'Drop Box',
1.451 www 5765: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 5766: 'bull' => 'Discussion Board',
1.347 weissno 5767: 'mypi' => 'My Personal Information Page',
1.353 weissno 5768: 'grpo' => 'Group Portfolio',
1.329 droeschl 5769: 'rost' => 'Course Roster',
1.528 raeburn 5770: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 5771: 'imsf' => 'IMS Upload',
5772: 'imsl' => 'Upload IMS package',
1.501 raeburn 5773: 'cms' => 'Origin of IMS package',
5774: 'se' => 'Select',
1.329 droeschl 5775: 'file' => 'File',
5776: 'title' => 'Title',
1.606 raeburn 5777: 'addp' => 'Add Placeholder to course?',
5778: 'uste' => 'Use Template?',
5779: 'fnam' => 'File Name:',
5780: 'loca' => 'Location:',
5781: 'dire' => 'Directory:',
5782: 'cate' => 'Category:',
5783: 'tmpl' => 'Template:',
1.329 droeschl 5784: 'comment' => 'Comment',
1.403 raeburn 5785: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.577 bisitz 5786: 'bb5' => 'Blackboard 5',
5787: 'bb6' => 'Blackboard 6',
5788: 'angel5' => 'ANGEL 5.5',
5789: 'webctce4' => 'WebCT 4 Campus Edition',
1.606 raeburn 5790: 'yes' => 'Yes',
5791: 'no' => 'No',
1.618 raeburn 5792: 'er' => 'Editing rights unavailable for your current role.',
1.577 bisitz 5793: );
1.329 droeschl 5794: # -----------------------------------------------------------------------------
1.595 musolffc 5795:
5796: # Calculate free quota space for a user or course. A javascript function checks
5797: # file size to determine if upload should be allowed.
5798: my $quotatype = 'unofficial';
5799: if ($crstype eq 'Community') {
1.601 raeburn 5800: $quotatype = 'community';
5801: } elsif ($crstype eq 'Placement') {
5802: $quotatype = 'placement';
1.595 musolffc 5803: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
5804: $quotatype = 'official';
5805: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
5806: $quotatype = 'textbook';
5807: }
5808: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
5809: 'course',$quotatype); # expressed in MB
5810: my $current_disk_usage = 0;
5811: foreach my $subdir ('docs','supplemental') {
5812: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
5813: "userfiles/$subdir",1); # expressed in kB
5814: }
5815: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
1.605 raeburn 5816: my $usage = $current_disk_usage/1024; # in MB
5817: my $quota = $disk_quota;
5818: my $percent;
5819: if ($disk_quota == 0) {
5820: $percent = 100.0;
5821: } else {
1.619 raeburn 5822: $percent = 100*($usage/$disk_quota);
1.605 raeburn 5823: }
5824: $usage = sprintf("%.2f",$usage);
5825: $quota = sprintf("%.2f",$quota);
5826: $percent = sprintf("%.0f",$percent);
5827: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
5828: $percent.'%',$quota.' MB').'</p>';
1.595 musolffc 5829:
1.329 droeschl 5830: my $fileupload=(<<FIUP);
1.605 raeburn 5831: $quotainfo
1.329 droeschl 5832: $lt{'file'}:<br />
1.611 raeburn 5833: <input type="file" name="uploaddoc" class="flUpload" size="40" $disabled />
1.606 raeburn 5834: <input type="hidden" id="free_space" value="$free_space" />
1.329 droeschl 5835: FIUP
5836:
5837: my $checkbox=(<<CHBO);
5838: <!-- <label>$lt{'parse'}?
5839: <input type="checkbox" name="parserflag" />
5840: </label> -->
5841: <label>
1.611 raeburn 5842: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
1.329 droeschl 5843: </label>
5844: CHBO
1.501 raeburn 5845: my $imsfolder = $env{'form.folder'};
5846: if ($imsfolder eq '') {
5847: $imsfolder = 'default';
5848: }
5849: my $imspform=(<<IMSFORM);
5850: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
5851: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
5852: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 5853: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 5854: <legend>$lt{'imsf'}</legend>
5855: $fileupload
5856: <br />
5857: <p>
5858: $lt{'cms'}:
1.611 raeburn 5859: <select name="source" $disabled>
1.501 raeburn 5860: <option value="-1" selected="selected">$lt{'se'}</option>
1.577 bisitz 5861: <option value="bb5">$lt{'bb5'}</option>
5862: <option value="bb6">$lt{'bb6'}</option>
5863: <option value="angel5">$lt{'angel5'}</option>
5864: <option value="webctce4">$lt{'webctce4'}</option>
1.501 raeburn 5865: </select>
5866: <input type="hidden" name="folder" value="$imsfolder" />
5867: </p>
5868: <input type="hidden" name="phase" value="one" />
1.611 raeburn 5869: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
1.501 raeburn 5870: </fieldset>
5871: </form>
5872: IMSFORM
1.329 droeschl 5873:
5874: my $fileuploadform=(<<FUFORM);
1.501 raeburn 5875: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
5876: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
5877: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 5878: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 5879: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5880: <input type="hidden" name="active" value="aa" />
1.595 musolffc 5881: $fileupload
1.329 droeschl 5882: <br />
5883: $lt{'title'}:<br />
1.611 raeburn 5884: <input type="text" size="60" name="comment" $disabled />
1.508 raeburn 5885: $pathitem
1.329 droeschl 5886: <input type="hidden" name="cmd" value="upload_default" />
5887: <br />
1.458 raeburn 5888: <span class="LC_nobreak" style="float:left">
1.329 droeschl 5889: $checkbox
5890: </span>
1.501 raeburn 5891: <br clear="all" />
1.611 raeburn 5892: <input type="submit" value="$lt{'upld'}" $disabled />
1.501 raeburn 5893: </fieldset>
5894: </form>
1.383 tempelho 5895: FUFORM
1.329 droeschl 5896:
1.611 raeburn 5897: my $mapimportjs;
5898: if ($canedit) {
5899: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
5900: } else {
5901: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
5902: }
1.502 raeburn 5903: my $importpubform=(<<SEDFFORM);
1.514 raeburn 5904: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 5905: $lt{'impm'}</a>$help{'Load_Map'}
5906: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 5907: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 5908: <legend>$lt{'impm'}</legend>
1.371 tempelho 5909: <input type="hidden" name="active" value="bb" />
1.502 raeburn 5910: $lt{'copm'}<br />
5911: <span class="LC_nobreak">
5912: <input type="text" name="importmap" size="40" value=""
1.611 raeburn 5913: onfocus="this.blur();$mapimportjs" $disabled />
5914: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
5915: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
1.502 raeburn 5916: </fieldset>
5917: </form>
5918:
1.383 tempelho 5919: SEDFFORM
1.606 raeburn 5920: my $importcrsresform;
1.608 raeburn 5921: my ($numdirs,$pickfile) =
5922: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
5923: "resize_scrollbox('contentscroll','1','0');",
5924: undef,'res');
1.606 raeburn 5925: if ($pickfile) {
5926: $importcrsresform=(<<CRSFORM);
5927: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
5928: $lt{'imcr'}</a>$help{'Course_Resources'}
5929: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
5930: <fieldset id="importcrsresform" style="display: none;">
5931: <legend>$lt{'imcr'}</legend>
5932: <input type="hidden" name="active" value="bb" />
5933: $pickfile
5934: <p>
1.611 raeburn 5935: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
1.606 raeburn 5936: </p>
5937: <input type="hidden" name="importdetail" value="" />
1.611 raeburn 5938: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
1.606 raeburn 5939: </fieldset>
5940: </form>
5941: CRSFORM
5942: }
5943:
1.611 raeburn 5944: my $fromstoredjs;
5945: if ($canedit) {
5946: $fromstoredjs = 'open_StoredLinks_Import()';
5947: } else {
5948: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
5949: }
5950:
1.502 raeburn 5951: my @importpubforma = (
1.508 raeburn 5952: { '<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 5953: { '<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.611 raeburn 5954: { '<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.606 raeburn 5955: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
5956: );
5957: if ($pickfile) {
5958: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
5959: }
1.502 raeburn 5960: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 5961: my $extresourcesform =
5962: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
1.611 raeburn 5963: $help{'Adding_External_Resource'},
5964: undef,undef,undef,undef,undef,undef,$disabled);
1.598 raeburn 5965: my $exttoolform =
5966: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
5967: $help{'Adding_External_Tool'},undef,
5968: undef,'tool',$coursedom,$coursenum,
1.611 raeburn 5969: \%ltitools,$disabled);
1.329 droeschl 5970: if ($allowed) {
1.492 raeburn 5971: my $folder = $env{'form.folder'};
5972: if ($folder eq '') {
5973: $folder='default';
5974: }
1.615 raeburn 5975: if ($canedit) {
5976: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
5977: if ($output) {
5978: $r->print($output);
5979: }
1.538 raeburn 5980: }
1.337 ehlerst 5981: $r->print(<<HIDDENFORM);
5982: <form name="renameform" method="post" action="/adm/coursedocs">
5983: <input type="hidden" name="title" />
5984: <input type="hidden" name="cmd" />
5985: <input type="hidden" name="markcopy" />
5986: <input type="hidden" name="copyfolder" />
5987: $containertag
5988: </form>
1.633 raeburn 5989: <form name="aliasform" method="post" action="/adm/coursedocs">
5990: <input type="hidden" name="alias" />
5991: <input type="hidden" name="cmd" />
5992: $containertag
5993: </form>
1.484 raeburn 5994:
1.337 ehlerst 5995: HIDDENFORM
1.508 raeburn 5996: $r->print(&makesimpleeditform($pathitem)."\n".
5997: &makedocslogform($pathitem."\n".
1.484 raeburn 5998: '<input type="hidden" name="folder" value="'.
5999: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 6000: }
1.442 www 6001:
6002: # Generate the tabs
1.510 raeburn 6003: my ($mode,$needs_end);
1.472 raeburn 6004: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 6005: my @folders = split('&',$env{'form.folderpath'});
6006: unless (@folders > 2) {
6007: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6008: $needs_end = 1;
6009: }
1.472 raeburn 6010: } else {
1.484 raeburn 6011: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 6012: $needs_end = 1;
1.472 raeburn 6013: }
1.443 www 6014:
1.442 www 6015: #
1.622 raeburn 6016: my $hostname = $r->hostname();
1.442 www 6017: my $savefolderpath;
6018:
1.395 raeburn 6019: if ($allowed) {
1.329 droeschl 6020: my $folder=$env{'form.folder'};
1.615 raeburn 6021: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
1.329 droeschl 6022: $folder='default';
1.356 tempelho 6023: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 6024: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 6025: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 6026: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6027: }
6028: my $postexec='';
6029: if ($folder eq 'default') {
1.372 bisitz 6030: $r->print('<script type="text/javascript">'."\n"
6031: .'// <![CDATA['."\n"
6032: .'this.window.name="loncapaclient";'."\n"
6033: .'// ]]>'."\n"
6034: .'</script>'."\n"
1.369 bisitz 6035: );
1.329 droeschl 6036: } else {
6037: #$postexec='self.close();';
6038: }
1.504 raeburn 6039: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6040: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 6041: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6042:
6043: my $newnavform=(<<NNFORM);
6044: <form action="/adm/coursedocs" method="post" name="newnav">
1.570 raeburn 6045: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6046: $pathitem
1.329 droeschl 6047: <input type="hidden" name="importdetail"
6048: value="$lt{'navc'}=/adm/navmaps" />
1.611 raeburn 6049: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
1.329 droeschl 6050: $help{'Navigate_Content'}
6051: </form>
6052: NNFORM
6053: my $newsmppageform=(<<NSPFORM);
6054: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.570 raeburn 6055: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6056: $pathitem
1.329 droeschl 6057: <input type="hidden" name="importdetail" value="" />
1.423 onken 6058: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 6059: $help{'Simple Page'}
1.329 droeschl 6060: </form>
6061: NSPFORM
6062:
6063: my $newsmpproblemform=(<<NSPROBFORM);
6064: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 6065: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6066: $pathitem
1.329 droeschl 6067: <input type="hidden" name="importdetail" value="" />
1.423 onken 6068: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.572 raeburn 6069: $help{'Simple_Problem'}
1.329 droeschl 6070: </form>
6071:
6072: NSPROBFORM
6073:
6074: my $newdropboxform=(<<NDBFORM);
6075: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 6076: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6077: $pathitem
1.329 droeschl 6078: <input type="hidden" name="importdetail" value="" />
1.423 onken 6079: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 6080: $help{'Dropbox'}
1.344 bisitz 6081: </form>
1.329 droeschl 6082: NDBFORM
6083:
6084: my $newexuploadform=(<<NEXUFORM);
6085: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 6086: <input type="hidden" name="active" value="cc" />
1.508 raeburn 6087: $pathitem
1.329 droeschl 6088: <input type="hidden" name="importdetail" value="" />
1.423 onken 6089: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 6090: $help{'Score_Upload_Form'}
6091: </form>
6092: NEXUFORM
6093:
6094: my $newbulform=(<<NBFORM);
6095: <form action="/adm/coursedocs" method="post" name="newbul">
1.570 raeburn 6096: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6097: $pathitem
1.329 droeschl 6098: <input type="hidden" name="importdetail" value="" />
1.423 onken 6099: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 6100: $help{'Bulletin Board'}
6101: </form>
6102: NBFORM
6103:
6104: my $newaboutmeform=(<<NAMFORM);
6105: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.570 raeburn 6106: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6107: $pathitem
1.329 droeschl 6108: <input type="hidden" name="importdetail"
6109: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6110: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
1.347 weissno 6111: $help{'My Personal Information Page'}
1.329 droeschl 6112: </form>
6113: NAMFORM
6114:
6115: my $newaboutsomeoneform=(<<NASOFORM);
6116: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.570 raeburn 6117: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6118: $pathitem
1.329 droeschl 6119: <input type="hidden" name="importdetail" value="" />
1.423 onken 6120: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 6121: </form>
6122: NASOFORM
6123:
6124: my $newrosterform=(<<NROSTFORM);
6125: <form action="/adm/coursedocs" method="post" name="newroster">
1.570 raeburn 6126: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6127: $pathitem
1.329 droeschl 6128: <input type="hidden" name="importdetail"
6129: value="$lt{'rost'}=/adm/viewclasslist" />
1.611 raeburn 6130: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
1.556 raeburn 6131: $help{'Course_Roster'}
1.329 droeschl 6132: </form>
6133: NROSTFORM
6134:
1.534 raeburn 6135: my $newwebpage;
6136: if ($folder =~ /^default_?(\d*)$/) {
6137: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6138: if ($1) {
6139: $newwebpage .= $1;
6140: } else {
6141: $newwebpage .= 'default';
6142: }
6143: $newwebpage .= '/new.html';
6144: }
6145: my $newwebpageform =(<<NWEBFORM);
6146: <form action="/adm/coursedocs" method="post" name="newwebpage">
1.570 raeburn 6147: <input type="hidden" name="active" value="ee" />
1.534 raeburn 6148: $pathitem
6149: <input type="hidden" name="importdetail" value="$newwebpage" />
6150: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 6151: $help{'Web_Page'}
1.534 raeburn 6152: </form>
6153: NWEBFORM
1.604 raeburn 6154:
1.606 raeburn 6155: my @ids=&Apache::lonnet::current_machine_ids();
6156: my %select_menus;
6157: my $numauthor = 0;
6158: my $numcrsdirs = 0;
6159: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6160: if ($env{'user.author'}) {
6161: $numauthor ++;
6162: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6163: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6164: my $is_home = 1;
6165: my %subdirs;
1.608 raeburn 6166: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6167: $select_menus{'author'}->{'default'} = '/';
6168: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6169: my @ordered = ('/');
6170: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6171: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6172: push(@ordered,$relpath);
6173: }
6174: $select_menus{'author'}->{'order'} = \@ordered;
6175: } else {
6176: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6177: $select_menus{'author'}->{'default'} = 'switch';
6178: $select_menus{'author'}->{'order'} = ['switch'];
6179: }
6180: }
6181: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6182: ['active'],['ca','aa']);
6183: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6184: my %by_roletype;
6185: if (keys(%roleshash)) {
6186: foreach my $entry (keys(%roleshash)) {
6187: my ($auname,$audom,$roletype) = split(/:/,$entry);
6188: my $key = $entry;
6189: $key =~ s/:/___/g;
6190: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6191: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6192: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6193: if (grep(/^\Q$rolehome\E$/,@ids)) {
6194: my $is_home = 1;
6195: my (%subdirs,@ordered);
6196: my $toppath="/priv/$audom/$auname";
1.608 raeburn 6197: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6198: $select_menus{$key}->{'default'} = '/';
6199: $select_menus{$key}->{'select2'}->{'/'} = '/';
6200: my @ordered = ('/');
6201: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6202: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6203: push(@ordered,$relpath);
6204: }
6205: $select_menus{$key}->{'order'} = \@ordered;
6206: } else {
6207: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6208: $select_menus{$key}->{'default'} = 'switch';
6209: $select_menus{$key}->{'order'} = ['switch'];
6210: }
6211: $numauthor ++;
6212: }
6213: }
1.631 raeburn 6214: my ($pickdir,$showtitle);
1.606 raeburn 6215: if ($numauthor) {
6216: my @order;
6217: my $defrole;
6218: if ($env{'user.author'}) {
6219: push(@order,'author');
6220: $defrole = 'author';
6221: }
6222: if (keys(%by_roletype)) {
6223: foreach my $possrole ('ca','aa') {
6224: if (ref($by_roletype{$possrole}) eq 'HASH') {
6225: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6226: unless ($defrole) {
6227: $defrole = $author;
6228: }
6229: push(@order,$author.'___'.$possrole);
6230: }
6231: }
6232: }
6233: }
6234: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6235: if (grep(/^\Q$crshome\E$/,@ids)) {
6236: my $is_home = 1;
6237: my %subdirs;
6238: my $toppath="/priv/$coursedom/$coursenum";
1.608 raeburn 6239: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6240: $numcrsdirs = keys(%subdirs);
6241: $select_menus{'course'}->{'default'} = '/';
6242: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6243: my @ordered = ('/');
6244: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6245: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6246: push(@ordered,$relpath);
6247: }
6248: $select_menus{'course'}->{'order'} = \@ordered;
6249: } else {
6250: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6251: $select_menus{'course'}->{'default'} = 'switch';
6252: $select_menus{'course'}->{'order'} = ['switch'];
6253: }
6254: push(@order,'course');
6255: $pickdir = $lt{'loca'}.
6256: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6257: $defrole,'authorrole','authorpath',
6258: \%select_menus,\@order,'toggleCrsResTitle();',
6259: '','priv').'<br />';
6260: $showtitle = 'none';
6261: } else {
6262: my $is_home;
6263: $showtitle = 'inline';
6264: if (grep(/^\Q$crshome\E$/,@ids)) {
6265: $is_home = 1;
6266: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6267: my $toppath="/priv/$coursedom/$coursenum'}";
6268: my %subdirs;
1.608 raeburn 6269: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
1.606 raeburn 6270: $numcrsdirs = keys(%subdirs);
6271: if ($numcrsdirs) {
6272: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6273: '<option value="/">/</option>'."\n";
6274: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
1.608 raeburn 6275: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
1.606 raeburn 6276: }
6277: $pickdir .= '</select>';
6278: } else {
6279: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6280: }
6281: }
6282: }
6283:
6284: my %seltemplate_menus;
6285: my @files = &Apache::lonhomework::get_template_list('problem');
6286: my @noexamplelink = ('blank.problem','blank.library','script.library');
6287: my $currentcategory = '';
6288: my @ordered = ('');
6289: my %templatehelp;
6290: my $defcategory = '';
6291: my @catorder = ($defcategory);
6292: $seltemplate_menus{$defcategory}->{'order'} = [''];
6293: $seltemplate_menus{$defcategory}->{'text'} = '';
6294: foreach my $file (@files) {
6295: if (ref($file) eq 'ARRAY') {
6296: my ($path,$title,$category,$help) = @{$file};
6297: next if ($title !~ /\S/);
6298: if (&js_escape($category) ne $currentcategory) {
6299: $currentcategory = &js_escape($category);
6300: push(@catorder,&js_escape($currentcategory));
6301: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6302: $seltemplate_menus{$currentcategory}->{'default'} = '';
6303: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6304: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6305: }
6306: if ($path) {
6307: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6308: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6309: if ($help) {
6310: $templatehelp{$path} = $help;
6311: }
6312: }
6313: }
6314: }
6315:
6316: my $templates = $lt{'cate'}.' '.
6317: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6318: $defcategory,'tempcategory','template',
6319: \%seltemplate_menus,\@catorder,
6320: "resize_scrollbox('contentscroll','1','0');",
6321: "toggleExampleText();",'template').'<br />';
6322: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6323: '<span id="newresexample">'.&mt('Example').'<span></a>';
6324: my $crsresform=(<<RESFORM);
6325: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6326: $lt{'stpr'}</a>$help{'Course_Resource'}
6327: <form action="/adm/coursedocs" method="post" name="courseresform">
6328: <fieldset id="crsresform" style="display:none;">
6329: <legend>$lt{'stpr'}</legend>
6330: <input type="hidden" name="active" value="ee" />
6331: <p>
6332: $pickdir
6333: <span class="LC_nobreak">$lt{'news'}?
1.611 raeburn 6334: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
1.606 raeburn 6335:
1.611 raeburn 6336: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
1.606 raeburn 6337: </span><span id="newsubdir"></span>
6338: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6339: </p>
6340: $lt{'fnam'}
1.611 raeburn 6341: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
1.606 raeburn 6342: <p>
6343: <div id="newresource" style="display:$showtitle">
6344: $lt{'addp'}
1.611 raeburn 6345: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6346: $lt{'no'}</label>
1.611 raeburn 6347: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
1.606 raeburn 6348: $lt{'yes'}</label>
6349: <span id="newrestitle"></span>
1.611 raeburn 6350: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
1.606 raeburn 6351: </div>
6352: </p>
6353: <p>
6354: $lt{'uste'}
1.611 raeburn 6355: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6356: $lt{'no'}</label>
1.611 raeburn 6357: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
1.606 raeburn 6358: $lt{'yes'}</label>
6359: <div id="newrestemplate" style="display:none">
6360: $templates
6361: $templatepreview
6362: </div>
6363: </p>
6364: <span class="LC_nobreak">
6365: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.611 raeburn 6366: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
1.606 raeburn 6367: </span>
6368: </fieldset>
6369: </form>
6370:
6371: RESFORM
1.534 raeburn 6372:
1.342 ehlerst 6373: my $specialdocumentsform;
1.383 tempelho 6374: my @specialdocumentsforma;
1.451 www 6375: my $gradingform;
6376: my @gradingforma;
6377: my $communityform;
6378: my @communityforma;
1.351 ehlerst 6379: my $newfolderform;
1.390 tempelho 6380: my $newfolderb;
1.342 ehlerst 6381:
1.451 www 6382: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 6383:
1.329 droeschl 6384: my $newpageform=(<<NPFORM);
6385: <form action="/adm/coursedocs" method="post" name="newpage">
6386: <input type="hidden" name="folderpath" value="$path" />
6387: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6388: <input type="hidden" name="active" value="ee" />
1.423 onken 6389: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 6390: $help{'Adding_Pages'}
1.329 droeschl 6391: </form>
6392: NPFORM
1.390 tempelho 6393:
6394:
1.351 ehlerst 6395: $newfolderform=(<<NFFORM);
1.329 droeschl 6396: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 6397: $pathitem
1.329 droeschl 6398: <input type="hidden" name="importdetail" value="" />
1.570 raeburn 6399: <input type="hidden" name="active" value="" />
1.422 onken 6400: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 6401: </form>
6402: NFFORM
6403:
6404: my $newsylform=(<<NSYLFORM);
6405: <form action="/adm/coursedocs" method="post" name="newsyl">
1.570 raeburn 6406: <input type="hidden" name="active" value="ee" />
1.508 raeburn 6407: $pathitem
1.329 droeschl 6408: <input type="hidden" name="importdetail"
6409: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6410: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
1.329 droeschl 6411: $help{'Syllabus'}
1.383 tempelho 6412:
1.329 droeschl 6413: </form>
6414: NSYLFORM
1.364 bisitz 6415:
1.329 droeschl 6416: my $newgroupfileform=(<<NGFFORM);
6417: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.570 raeburn 6418: <input type="hidden" name="active" value="dd" />
1.508 raeburn 6419: $pathitem
1.329 droeschl 6420: <input type="hidden" name="importdetail"
6421: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.611 raeburn 6422: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
1.353 weissno 6423: $help{'Group Portfolio'}
1.329 droeschl 6424: </form>
6425: NGFFORM
1.383 tempelho 6426: @specialdocumentsforma=(
1.421 onken 6427: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.618 raeburn 6428: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
1.611 raeburn 6429: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
1.451 www 6430: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 6431: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 6432: );
6433: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6434:
1.434 raeburn 6435:
6436: my @importdoc = (
1.519 raeburn 6437: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
6438: );
1.598 raeburn 6439: if (keys(%ltitools)) {
6440: push(@importdoc,
1.627 raeburn 6441: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},
1.598 raeburn 6442: );
6443: }
1.519 raeburn 6444: unless ($container eq 'page') {
6445: push(@importdoc,
6446: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6447: );
6448: }
6449: push(@importdoc,
1.558 raeburn 6450: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 6451: );
1.501 raeburn 6452: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 6453:
1.451 www 6454: @gradingforma=(
6455: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6456: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6457: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
1.606 raeburn 6458: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
1.451 www 6459: );
6460: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6461:
6462: @communityforma=(
6463: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6464: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6465: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
1.611 raeburn 6466: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6467: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
1.451 www 6468: );
6469: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 6470:
1.330 tempelho 6471: my %orderhash = (
1.553 raeburn 6472: 'aa' => ['Upload',$fileuploadform],
6473: 'bb' => ['Import',$importpubform],
6474: 'cc' => ['Grading',$gradingform],
1.330 tempelho 6475: );
1.519 raeburn 6476: unless ($container eq 'page') {
1.434 raeburn 6477: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 6478: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 6479: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 6480: }
6481:
1.341 ehlerst 6482: $hadchanges=0;
1.484 raeburn 6483: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 6484: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6485: $supplementalflag,\%orderhash,$iconpath,$pathitem,
1.622 raeburn 6486: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
1.617 raeburn 6487: undef($navmap);
1.443 www 6488: if ($error) {
6489: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6490: }
1.639 raeburn 6491: if ($hadchanges) {
6492: unless (&is_hash_old()) {
1.638 raeburn 6493: &mark_hash_old();
6494: }
6495: }
1.341 ehlerst 6496:
1.443 www 6497: &changewarning($r,'');
6498: }
1.458 raeburn 6499: }
1.442 www 6500:
1.443 www 6501: # Supplemental documents start here
6502:
1.329 droeschl 6503: my $folder=$env{'form.folder'};
1.443 www 6504: unless ($supplementalflag) {
1.329 droeschl 6505: $folder='supplemental';
6506: }
6507: if ($folder =~ /^supplemental$/ &&
6508: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 6509: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 6510: } elsif ($allowed) {
1.356 tempelho 6511: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 6512: }
1.508 raeburn 6513: $pathitem = '<input type="hidden" name="folderpath" value="'.
6514: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 6515: if ($allowed) {
6516: my $folderseq=
1.504 raeburn 6517: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 6518:
6519: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 6520: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6521: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 6522: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 6523: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 6524: <legend>$lt{'upfi'}</legend>
1.630 raeburn 6525: <input type="hidden" name="active" value="ee" />
1.329 droeschl 6526: $fileupload
6527: <br />
6528: <br />
6529: <span class="LC_nobreak">
6530: $checkbox
6531: </span>
6532: <br /><br />
6533: $lt{'comment'}:<br />
1.383 tempelho 6534: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 6535: <br />
1.508 raeburn 6536: $pathitem
1.329 droeschl 6537: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 6538: <input type='submit' value="$lt{'upld'}" />
6539: </form>
1.329 droeschl 6540: SUPDOCFORM
6541:
6542: my $supnewfolderform=(<<SNFFORM);
6543: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.570 raeburn 6544: <input type="hidden" name="active" value="" />
1.508 raeburn 6545: $pathitem
1.329 droeschl 6546: <input type="hidden" name="importdetail" value="" />
1.423 onken 6547: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 6548: $help{'Adding_Folders'}
1.329 droeschl 6549: </form>
6550: SNFFORM
1.383 tempelho 6551:
1.510 raeburn 6552: my $supextform =
6553: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
1.611 raeburn 6554: $help{'Adding_External_Resource'},
6555: undef,undef,undef,undef,undef,undef,
6556: $disabled);
1.329 droeschl 6557:
1.598 raeburn 6558: my $supexttoolform =
6559: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6560: $help{'Adding_External_Tool'},
6561: undef,undef,'tool',$coursedom,
1.611 raeburn 6562: $coursenum,\%ltitools,$disabled);
1.598 raeburn 6563:
1.329 droeschl 6564: my $supnewsylform=(<<SNSFORM);
6565: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 6566: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6567: $pathitem
1.329 droeschl 6568: <input type="hidden" name="importdetail"
6569: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.611 raeburn 6570: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
1.329 droeschl 6571: $help{'Syllabus'}
6572: </form>
6573: SNSFORM
6574:
6575: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 6576: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 6577: <input type="hidden" name="active" value="ff" />
1.508 raeburn 6578: $pathitem
1.329 droeschl 6579: <input type="hidden" name="importdetail"
6580: value="$plainname=/adm/$udom/$uname/aboutme" />
1.611 raeburn 6581: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
1.347 weissno 6582: $help{'My Personal Information Page'}
1.329 droeschl 6583: </form>
6584: SNAMFORM
6585:
1.534 raeburn 6586: my $supwebpage;
6587: if ($folder =~ /^supplemental_?(\d*)$/) {
6588: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6589: if ($1) {
6590: $supwebpage .= $1;
6591: } else {
6592: $supwebpage .= 'default';
6593: }
6594: $supwebpage .= '/new.html';
6595: }
6596: my $supwebpageform =(<<SWEBFORM);
6597: <form action="/adm/coursedocs" method="post" name="supwebpage">
6598: <input type="hidden" name="active" value="cc" />
6599: $pathitem
6600: <input type="hidden" name="importdetail" value="$supwebpage" />
6601: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 6602: $help{'Web_Page'}
1.534 raeburn 6603: </form>
6604: SWEBFORM
6605:
1.333 muellerd 6606:
1.383 tempelho 6607: my @specialdocs = (
1.618 raeburn 6608: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
1.417 droeschl 6609: =>$supnewsylform},
1.611 raeburn 6610: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
1.417 droeschl 6611: =>$supnewaboutmeform},
1.534 raeburn 6612: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6613:
1.383 tempelho 6614: );
1.417 droeschl 6615: my @supimportdoc = (
1.515 raeburn 6616: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.598 raeburn 6617: =>$supextform});
6618: if (keys(%ltitools)) {
6619: push(@supimportdoc,
1.627 raeburn 6620: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'
1.598 raeburn 6621: =>$supexttoolform});
6622: }
6623: push(@supimportdoc,
6624: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
1.501 raeburn 6625: =>$supupdocform},
1.598 raeburn 6626: );
1.501 raeburn 6627:
6628: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 6629: my %suporderhash = (
1.390 tempelho 6630: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 6631: 'ee' => ['Upload',$supupdocform],
6632: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 6633: );
1.443 www 6634: if ($supplementalflag) {
1.458 raeburn 6635: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.615 raeburn 6636: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
1.622 raeburn 6637: \%ltitools,$canedit,$hostname);
1.443 www 6638: if ($error) {
6639: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 6640: } else {
6641: if ($suppchanges) {
6642: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6643: my @ids=&Apache::lonnet::current_machine_ids();
6644: foreach my $server (keys(%servers)) {
6645: next if (grep(/^\Q$server\E$/,@ids));
6646: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 6647: my $cachekey = &escape('suppcount').':'.&escape($hashid);
6648: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 6649: }
6650: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
6651: undef($suppchanges);
1.630 raeburn 6652: }
6653: }
1.393 raeburn 6654: }
1.443 www 6655: } elsif ($supplementalflag) {
1.458 raeburn 6656: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.622 raeburn 6657: $supplementalflag,'',$iconpath,$pathitem,'','',$hostname);
1.393 raeburn 6658: if ($error) {
6659: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 6660: }
1.393 raeburn 6661: }
1.389 tempelho 6662:
1.510 raeburn 6663: if ($needs_end) {
6664: $r->print(&endContentScreen());
6665: }
1.383 tempelho 6666:
1.329 droeschl 6667: if ($allowed) {
6668: $r->print('
6669: <form method="post" name="extimport" action="/adm/coursedocs">
6670: <input type="hidden" name="title" />
6671: <input type="hidden" name="url" />
6672: <input type="hidden" name="useform" />
6673: <input type="hidden" name="residx" />
6674: </form>');
6675: }
1.484 raeburn 6676: } elsif ($showdoc) {
1.329 droeschl 6677: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 6678: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 6679: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 6680: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 6681: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 6682: }
6683: }
1.630 raeburn 6684: unless ($noendpage) {
1.606 raeburn 6685: $r->print(&Apache::loncommon::end_page());
6686: }
1.329 droeschl 6687: return OK;
1.364 bisitz 6688: }
1.329 droeschl 6689:
1.440 raeburn 6690: sub embedded_form_elems {
6691: my ($phase,$primaryurl,$newidx) = @_;
6692: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.634 raeburn 6693: $newidx =~s /\D+//g;
1.440 raeburn 6694: return <<STATE;
6695: <input type="hidden" name="folderpath" value="$folderpath" />
6696: <input type="hidden" name="cmd" value="upload_embedded" />
6697: <input type="hidden" name="newidx" value="$newidx" />
6698: <input type="hidden" name="phase" value="$phase" />
6699: <input type="hidden" name="primaryurl" value="$primaryurl" />
6700: STATE
6701: }
6702:
6703: sub embedded_destination {
6704: my $folder=$env{'form.folder'};
6705: my $destination = 'docs/';
6706: if ($folder =~ /^supplemental/) {
6707: $destination = 'supplemental/';
6708: }
6709: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6710: $destination .= 'default/';
6711: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6712: $destination .= $2.'/';
6713: }
1.634 raeburn 6714: my $newidx = $env{'form.newidx'};
6715: $newidx =~s /\D+//g;
6716: if ($newidx) {
6717: $destination .= $newidx;
6718: }
1.440 raeburn 6719: my $dir_root = '/userfiles';
6720: return ($destination,$dir_root);
6721: }
6722:
6723: sub return_to_editor {
6724: my $actionurl = '/adm/coursedocs';
6725: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
6726: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
6727: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
6728: '</a></p>';
6729: }
6730:
1.476 raeburn 6731: sub decompression_info {
6732: my ($destination,$dir_root) = &embedded_destination();
6733: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
6734: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
6735: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
6736: my $container='sequence';
1.480 raeburn 6737: my ($pathitem,$hiddenelem);
1.583 raeburn 6738: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
1.519 raeburn 6739: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 6740: $container='page';
6741: }
1.480 raeburn 6742: unshift(@hiddens,$pathitem);
6743: foreach my $item (@hiddens) {
1.634 raeburn 6744: if ($item eq 'newidx') {
6745: next if ($env{'form.'.$item} =~ /\D/);
6746: }
1.480 raeburn 6747: if ($env{'form.'.$item}) {
6748: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
1.583 raeburn 6749: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
1.480 raeburn 6750: }
1.477 raeburn 6751: }
1.476 raeburn 6752: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
6753: $hiddenelem);
6754: }
6755:
6756: sub decompression_phase_one {
6757: my ($dir,$file,$warning,$error,$output);
6758: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6759: &decompression_info();
1.490 raeburn 6760: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 6761: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
6762: } else {
6763: my $file = $1;
1.630 raeburn 6764: $output =
1.481 raeburn 6765: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
6766: $destination,$dir_root,
6767: $hiddenelem);
6768: if ($env{'form.autoextract_camtasia'}) {
6769: $output .= &remove_archive($docudom,$docuname,$container);
6770: }
1.476 raeburn 6771: }
6772: if ($error) {
6773: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
6774: $error.'</p>'."\n";
6775: }
6776: if ($warning) {
6777: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
6778: }
6779: return $output;
6780: }
6781:
6782: sub decompression_phase_two {
6783: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
6784: &decompression_info();
1.481 raeburn 6785: my $output;
1.480 raeburn 6786: if ($env{'form.archivedelete'}) {
1.481 raeburn 6787: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 6788: }
6789: $output .=
1.481 raeburn 6790: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 6791: $destination,$dir_root,$hiddenelem);
6792: return $output;
6793: }
6794:
1.480 raeburn 6795: sub remove_archive {
6796: my ($docudom,$docuname,$container) = @_;
6797: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 6798: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 6799: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
6800: if ($fatal) {
6801: if ($container eq 'page') {
6802: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
6803: } else {
6804: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
6805: }
1.583 raeburn 6806: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6807: } else {
6808: my $currcmd = $env{'form.cmd'};
6809: my $position = $env{'form.position'};
1.583 raeburn 6810: my $archiveidx = $position;
1.563 raeburn 6811: if ($position > 0) {
1.583 raeburn 6812: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
6813: $archiveidx = $position-1;
6814: }
6815: $env{'form.cmd'} = 'remove_'.$archiveidx;
1.584 raeburn 6816: my ($title,$url,@rrest) =
1.583 raeburn 6817: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
6818: if ($url eq $env{'form.archiveurl'}) {
6819: if (&handle_edit_cmd($docuname,$docudom)) {
6820: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
6821: if ($fatal) {
6822: if ($container eq 'page') {
6823: $delwarning = &mt('An error occurred updating the contents of the current page.');
6824: } else {
6825: $delwarning = &mt('An error occurred updating the contents of the current folder.');
6826: }
1.480 raeburn 6827: } else {
1.583 raeburn 6828: $delresult = &mt('Archive file removed.');
1.480 raeburn 6829: }
6830: }
1.583 raeburn 6831: } else {
6832: $delwarning .= &mt('Archive file had unexpected item number in folder.').
6833: ' '.&mt('As a result the archive file has not been removed.');
1.480 raeburn 6834: }
6835: }
6836: $env{'form.cmd'} = $currcmd;
6837: }
6838: if ($delwarning) {
6839: $output = '<p class="LC_warning">'.
6840: $delwarning.
6841: '</p>';
6842: }
6843: if ($delresult) {
6844: $output .= '<p class="LC_info">'.
6845: $delresult.
6846: '</p>';
6847: }
1.481 raeburn 6848: return $output;
1.480 raeburn 6849: }
6850:
1.484 raeburn 6851: sub generate_admin_menu {
1.611 raeburn 6852: my ($crstype,$canedit) = @_;
1.484 raeburn 6853: my $lc_crstype = lc($crstype);
6854: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 6855: my %lt= ( # do not translate here
1.484 raeburn 6856: 'vc' => 'Verify Content',
6857: 'cv' => 'Check/Set Resource Versions',
6858: 'ls' => 'List Resource Identifiers',
6859: 'imse' => 'Export contents to IMS Archive',
1.568 raeburn 6860: 'dcd' => "Copy $crstype Content to Authoring Space",
1.562 bisitz 6861: );
1.484 raeburn 6862: my ($candump,$dumpurl);
6863: if ($home + $other > 0) {
6864: $candump = 'F';
6865: if ($home) {
6866: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
6867: } else {
6868: my @hosts;
6869: foreach my $aurole (keys(%outhash)) {
6870: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
6871: push(@hosts,$outhash{$aurole});
1.538 raeburn 6872: }
1.484 raeburn 6873: }
6874: if (@hosts == 1) {
6875: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
6876: '&role='.
6877: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
6878: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
6879: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
6880: } else {
6881: $dumpurl = "javascript:choose_switchserver_window()";
6882: }
6883: }
6884: }
6885: my @menu=
6886: ({ categorytitle=>'Administration',
6887: items =>[
6888: { linktext => $lt{'vc'},
6889: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
6890: permission => 'F',
1.571 raeburn 6891: help => 'Docs_Verify_Content',
1.484 raeburn 6892: icon => 'verify.png',
6893: linktitle => 'Verify contents can be retrieved/rendered',
6894: },
6895: { linktext => $lt{'cv'},
6896: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
6897: permission => 'F',
1.571 raeburn 6898: help => 'Docs_Check_Resource_Versions',
1.484 raeburn 6899: icon => 'resversion.png',
6900: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
6901: },
6902: { linktext => $lt{'ls'},
6903: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
6904: permission => 'F',
6905: #help => '',
6906: icon => 'symbs.png',
6907: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
6908: },
6909: ]
1.611 raeburn 6910: });
6911: if ($canedit) {
6912: push(@menu,
1.484 raeburn 6913: { categorytitle=>'Export',
6914: items =>[
6915: { linktext => $lt{'imse'},
6916: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
6917: permission => 'F',
6918: help => 'Docs_Export_Course_Docs',
6919: icon => 'imsexport.png',
6920: linktitle => $lt{'imse'},
6921: },
6922: { linktext => $lt{'dcd'},
6923: url => $dumpurl,
6924: permission => $candump,
1.571 raeburn 6925: help => 'Docs_Dump_Course_Docs',
1.484 raeburn 6926: icon => 'dump.png',
6927: linktitle => $lt{'dcd'},
6928: },
6929: ]
6930: });
1.611 raeburn 6931: }
1.484 raeburn 6932: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
6933: '<input type="hidden" id="dummy" />'."\n".
6934: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
6935: '</form>';
1.329 droeschl 6936: }
6937:
6938: sub generate_edit_table {
1.538 raeburn 6939: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
1.611 raeburn 6940: $need_save,$copyfolder,$canedit) = @_;
1.406 raeburn 6941: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 6942: my %orderhash = %{$orderhash_ref};
1.611 raeburn 6943: my ($form, $activetab, $active, $disabled);
1.570 raeburn 6944: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
1.371 tempelho 6945: $activetab = $env{'form.active'};
6946: }
1.611 raeburn 6947: unless ($canedit) {
6948: $disabled = ' disabled="disabled"';
6949: }
1.472 raeburn 6950: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 6951: my $backtext = &mt('Exit Editor');
1.458 raeburn 6952: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 6953: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
6954: '<li class="goback">'.
1.546 raeburn 6955: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 6956: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
6957: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
6958: '<li>'.
6959: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
6960: &mt('Undo Delete').'</a></li>'."\n";
6961: if ($env{'form.docslog'}) {
6962: $form .= '<li class="active">';
6963: } else {
6964: $form .= '<li>';
6965: }
6966: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
6967: &mt('History').'</a></li>'."\n";
6968: if ($env{'form.docslog'}) {
6969: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
6970: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 6971: }
1.458 raeburn 6972: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 6973: if($name ne '00'){
1.371 tempelho 6974: if($activetab eq '' || $activetab ne $name){
6975: $active = '';
6976: }elsif($activetab eq $name){
6977: $active = 'class="active"';
6978: }
1.458 raeburn 6979: $form .= '<li style="float:right" '.$active
1.484 raeburn 6980: .' 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 6981: } else {
1.570 raeburn 6982: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 6983:
6984: }
1.329 droeschl 6985: }
1.484 raeburn 6986: $form .= '</ul>'."\n";
6987: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 6988:
6989: if ($to_show ne '') {
1.538 raeburn 6990: my $saveform;
6991: if ($need_save) {
6992: my $button = &mt('Make changes');
6993: my $path;
6994: if ($env{'form.folderpath'}) {
6995: $path =
6996: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6997: }
6998: $saveform = <<"END";
6999: <div id="multisave" style="display:none; clear:both;" >
7000: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7001: <input type="hidden" name="folderpath" value="$path" />
7002: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7003: <input type="hidden" name="allhiddenresource" value="" />
7004: <input type="hidden" name="allencrypturl" value="" />
7005: <input type="hidden" name="allrandompick" value="" />
7006: <input type="hidden" name="allrandomorder" value="" />
7007: <input type="hidden" name="changeparms" value="" />
7008: <input type="hidden" name="multiremove" value="" />
7009: <input type="hidden" name="multicut" value="" />
7010: <input type="hidden" name="multicopy" value="" />
7011: <input type="hidden" name="multichange" value="" />
7012: <input type="hidden" name="copyfolder" value="$copyfolder" />
1.611 raeburn 7013: <input type="submit" name="savemultiples" value="$button" $disabled />
1.538 raeburn 7014: </form>
7015: </div>
7016: END
7017: }
7018: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 7019: }
1.363 ehlerst 7020: foreach my $field (keys(%orderhash)){
1.390 tempelho 7021: if($field ne '00'){
1.422 onken 7022: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 7023: $active = 'style="display: none;float:left"';
1.422 onken 7024: }elsif($activetab eq $field){
1.458 raeburn 7025: $active = 'style="display:block;float:left"';
1.422 onken 7026: }
7027: $form .= '<div id="'.$field.$tid.'"'
7028: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 7029: .'</div>'."\n";
1.363 ehlerst 7030: }
7031: }
1.484 raeburn 7032: unless ($env{'form.docslog'}) {
7033: $form .= '</div></div>'."\n";
7034: }
1.329 droeschl 7035: return $form;
7036: }
7037:
7038: sub editing_js {
1.622 raeburn 7039: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7040: $londocroot,$canedit,$hostname,$navmapref) = @_;
1.594 damieng 7041: my %js_lt = &Apache::lonlocal::texthash(
1.329 droeschl 7042: p_mnf => 'Name of New Folder',
7043: t_mnf => 'New Folder',
7044: p_mnp => 'Name of New Page',
7045: t_mnp => 'New Page',
1.451 www 7046: p_mxu => 'Title for the External Score',
1.349 biermanm 7047: p_msp => 'Name of Simple Course Page',
1.329 droeschl 7048: p_msb => 'Title for the Problem',
7049: p_mdb => 'Title for the Drop Box',
1.336 schafran 7050: p_mbb => 'Title for the Discussion Board',
1.604 raeburn 7051: p_mwp => 'Title for Web Page',
1.606 raeburn 7052: p_mnr => 'Title for the Resource',
1.348 weissno 7053: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 7054: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 7055: p_mab_alrt1 => 'Not a valid user:domain',
7056: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7057: p_chn => 'New Title',
7058: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
1.603 raeburn 7059: p_rmr2a => 'Remove',
7060: p_rmr2b => '?',
7061: p_rmr3a => 'Remove those',
7062: p_rmr3b => 'items?',
7063: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7064: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
1.329 droeschl 7065: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7066: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
1.603 raeburn 7067: p_ctr2a => 'Cut',
7068: p_ctr2b => '?',
7069: p_ctr3a => 'Cut those',
7070: p_ctr3b => 'items?',
1.633 raeburn 7071: setal => 'Enter a (unique) alias',
7072: delal => 'Are you sure you want to eliminate the alias?',
1.478 raeburn 7073: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 7074: imsfile => 'You must choose an IMS package for import',
7075: imscms => 'You must select which Course Management System was the source of the IMS package',
7076: invurl => 'Invalid URL',
7077: titbl => 'Title is blank',
1.538 raeburn 7078: more => '(More ...)',
7079: less => '(Less ...)',
1.543 raeburn 7080: noor => 'No actions selected or changes to settings specified.',
7081: noch => 'No changes to settings specified.',
7082: noac => 'No actions selected.',
1.606 raeburn 7083: nofi => 'No file selected',
7084: tinc => 'Title in course',
7085: sunm => 'Sub-directory name',
1.618 raeburn 7086: edri => 'Editing rights unavailable for your current role.',
1.329 droeschl 7087: );
1.594 damieng 7088: &js_escape(\%js_lt);
1.433 raeburn 7089: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 7090: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7091: my $main_container_page;
1.519 raeburn 7092: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7093: $main_container_page = 1;
1.434 raeburn 7094: }
1.617 raeburn 7095: my $backtourl;
7096: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
1.446 www 7097: my $toplevelsupp = &supplemental_base();
1.433 raeburn 7098:
1.530 raeburn 7099: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7100: my $caller = $1;
1.525 raeburn 7101: if ($caller =~ /^supplemental/) {
7102: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7103: } else {
7104: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7105: $res = &Apache::lonnet::clutter($res);
7106: if (&Apache::lonnet::is_on_map($res)) {
1.609 raeburn 7107: my ($url,$anchor);
7108: if ($res =~ /^([^#]+)#([^#]+)$/) {
7109: $url = $1;
7110: $anchor = $2;
7111: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7112: $caller = $1.&escape('#').$anchor;
7113: }
1.614 raeburn 7114: } else {
7115: $url = $res;
1.609 raeburn 7116: }
1.640 raeburn 7117: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7118: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7119: $backtourl .= '?navmap=1';
7120: } else {
7121: $backtourl .= '?symb='.
7122: &HTML::Entities::encode($caller,'<>&"');
7123: }
1.622 raeburn 7124: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7125: if (($ENV{'SERVER_PORT'} == 443) &&
7126: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7127: if ($hostname ne '') {
7128: $backtourl = 'http://'.$hostname.$backtourl;
7129: }
1.627 raeburn 7130: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
1.622 raeburn 7131: }
1.623 raeburn 7132: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7133: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7134: $backtourl = 'http://'.$hostname.$backtourl;
7135: }
1.622 raeburn 7136: }
1.609 raeburn 7137: if ($anchor ne '') {
7138: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7139: }
1.590 raeburn 7140: $backtourl = &Apache::loncommon::escape_single($backtourl);
1.544 raeburn 7141: } else {
7142: $backtourl = '/adm/navmaps';
1.525 raeburn 7143: }
7144: }
7145: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7146: $backtourl = '/adm/menu';
7147: } elsif ($supplementalflag) {
1.472 raeburn 7148: $backtourl = '/adm/supplemental';
1.525 raeburn 7149: } else {
7150: $backtourl = '/adm/navmaps';
1.472 raeburn 7151: }
7152:
1.600 raeburn 7153: my $fieldsets = "'ext','doc'";
7154: if ($posslti) {
7155: $fieldsets .= ",'tool'";
7156: }
1.519 raeburn 7157: unless ($main_container_page) {
7158: $fieldsets .=",'ims'";
7159: }
1.501 raeburn 7160: if ($supplementalflag) {
1.600 raeburn 7161: $fieldsets = "'suppext','suppdoc'";
7162: if ($posslti) {
7163: $fieldsets .= ",'supptool'";
7164: }
1.501 raeburn 7165: }
1.611 raeburn 7166:
7167: my $jsmakefunctions;
7168: if ($canedit) {
7169: $jsmakefunctions = <<ENDNEWSCRIPT;
1.329 droeschl 7170: function makenewfolder(targetform,folderseq) {
1.594 damieng 7171: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
1.329 droeschl 7172: if (foldername) {
7173: targetform.importdetail.value=escape(foldername)+"="+folderseq;
7174: targetform.submit();
7175: }
7176: }
7177:
7178: function makenewpage(targetform,folderseq) {
1.594 damieng 7179: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
1.329 droeschl 7180: if (pagename) {
7181: targetform.importdetail.value=escape(pagename)+"="+folderseq;
7182: targetform.submit();
7183: }
7184: }
7185:
7186: function makeexamupload() {
1.594 damieng 7187: var title=prompt('$js_lt{"p_mxu"}');
1.344 bisitz 7188: if (title) {
1.329 droeschl 7189: this.document.forms.newexamupload.importdetail.value=
7190: escape(title)+'=/res/lib/templates/examupload.problem';
7191: this.document.forms.newexamupload.submit();
7192: }
7193: }
7194:
7195: function makesmppage() {
1.594 damieng 7196: var title=prompt('$js_lt{"p_msp"}');
1.344 bisitz 7197: if (title) {
1.329 droeschl 7198: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 7199: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 7200: this.document.forms.newsmppg.submit();
7201: }
7202: }
7203:
1.534 raeburn 7204: function makewebpage(type) {
1.594 damieng 7205: var title=prompt('$js_lt{"p_mwp"}');
1.534 raeburn 7206: var formname;
7207: if (type == 'supp') {
7208: formname = this.document.forms.supwebpage;
7209: } else {
7210: formname = this.document.forms.newwebpage;
7211: }
7212: if (title) {
7213: var webpage = formname.importdetail.value;
7214: formname.importdetail.value = escape(title)+'='+webpage;
7215: formname.submit();
7216: }
7217: }
7218:
1.329 droeschl 7219: function makesmpproblem() {
1.594 damieng 7220: var title=prompt('$js_lt{"p_msb"}');
1.344 bisitz 7221: if (title) {
1.329 droeschl 7222: this.document.forms.newsmpproblem.importdetail.value=
7223: escape(title)+'=/res/lib/templates/simpleproblem.problem';
7224: this.document.forms.newsmpproblem.submit();
7225: }
7226: }
7227:
7228: function makedropbox() {
1.594 damieng 7229: var title=prompt('$js_lt{"p_mdb"}');
1.344 bisitz 7230: if (title) {
1.329 droeschl 7231: this.document.forms.newdropbox.importdetail.value=
7232: escape(title)+'=/res/lib/templates/DropBox.problem';
7233: this.document.forms.newdropbox.submit();
7234: }
7235: }
7236:
7237: function makebulboard() {
1.594 damieng 7238: var title=prompt('$js_lt{"p_mbb"}');
1.329 droeschl 7239: if (title) {
7240: this.document.forms.newbul.importdetail.value=
1.533 raeburn 7241: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 7242: this.document.forms.newbul.submit();
7243: }
7244: }
7245:
7246: function makeabout() {
1.594 damieng 7247: var user=prompt("$js_lt{'p_mab'}");
1.329 droeschl 7248: if (user) {
7249: var comp=new Array();
7250: comp=user.split(':');
7251: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7252: if ((comp[0]) && (comp[1])) {
7253: this.document.forms.newaboutsomeone.importdetail.value=
1.594 damieng 7254: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.611 raeburn 7255: this.document.forms.newaboutsomeone.submit();
7256: } else {
7257: alert("$js_lt{'p_mab_alrt1'}");
7258: }
7259: } else {
7260: alert("$js_lt{'p_mab_alrt2'}");
7261: }
7262: }
7263: }
7264:
7265: function makenew(targetform) {
7266: targetform.submit();
7267: }
7268:
7269: function changename(folderpath,index,oldtitle) {
7270: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7271: if (title) {
7272: this.document.forms.renameform.markcopy.value='';
7273: this.document.forms.renameform.title.value=title;
7274: this.document.forms.renameform.cmd.value='rename_'+index;
7275: this.document.forms.renameform.folderpath.value=folderpath;
7276: this.document.forms.renameform.submit();
7277: }
7278: }
7279:
1.633 raeburn 7280: function setalias(folderpath,index) {
7281: var alias = prompt('$js_lt{"setal"}');
7282: if ((alias != null) && (alias != '')) {
7283: this.document.forms.aliasform.alias.value=alias;
7284: this.document.forms.aliasform.cmd.value='setalias_'+index;
7285: this.document.forms.aliasform.folderpath.value=folderpath;
7286: this.document.forms.aliasform.submit();
7287: }
7288: }
7289:
7290: function delalias(folderpath,index) {
7291: if (confirm('$js_lt{"delal"}')) {
7292: this.document.forms.aliasform.cmd.value='delalias_'+index;
7293: this.document.forms.aliasform.folderpath.value=folderpath;
7294: this.document.forms.aliasform.submit();
7295: }
7296: }
7297:
1.611 raeburn 7298: ENDNEWSCRIPT
7299: } else {
7300: $jsmakefunctions = <<ENDNEWSCRIPT;
7301:
7302: function makenewfolder() {
7303: alert("$js_lt{'edri'}");
7304: }
7305:
7306: function makenewpage() {
7307: alert("$js_lt{'edri'}");
7308: }
7309:
7310: function makeexamupload() {
7311: alert("$js_lt{'edri'}");
7312: }
7313:
7314: function makesmppage() {
7315: alert("$js_lt{'edri'}");
7316: }
7317:
7318: function makewebpage(type) {
7319: alert("$js_lt{'edri'}");
7320: }
7321:
7322: function makesmpproblem() {
7323: alert("$js_lt{'edri'}");
7324: }
7325:
7326: function makedropbox() {
7327: alert("$js_lt{'edri'}");
7328: }
7329:
7330: function makebulboard() {
7331: alert("$js_lt{'edri'}");
7332: }
7333:
7334: function makeabout() {
7335: alert("$js_lt{'edri'}");
7336: }
7337:
7338: function changename() {
7339: alert("$js_lt{'edri'}");
7340: }
7341:
1.633 raeburn 7342: function setalias() {
7343: alert("$js_lt{'edri'}");
7344: }
7345:
7346: function delalias() {
7347: alert("$js_lt{'edri'}");
7348: }
7349:
1.611 raeburn 7350: function makenew() {
7351: alert("$js_lt{'edri'}");
7352: }
7353:
7354: function groupimport() {
7355: alert("$js_lt{'edri'}");
1.335 ehlerst 7356: }
1.611 raeburn 7357:
7358: function groupsearch() {
7359: alert("$js_lt{'edri'}");
1.335 ehlerst 7360: }
1.611 raeburn 7361:
7362: function groupopen(url,recover) {
7363: var options="scrollbars=1,resizable=1,menubar=0";
7364: idxflag=1;
7365: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7366: idx.focus();
1.329 droeschl 7367: }
7368:
1.611 raeburn 7369: ENDNEWSCRIPT
7370:
7371: }
7372: return <<ENDSCRIPT;
7373:
7374: $jsmakefunctions
7375:
1.501 raeburn 7376: function toggleUpload(caller) {
7377: var blocks = Array($fieldsets);
7378: for (var i=0; i<blocks.length; i++) {
7379: var disp = 'none';
7380: if (caller == blocks[i]) {
7381: var curr = document.getElementById('upload'+caller+'form').style.display;
7382: if (curr == 'none') {
7383: disp='block';
7384: }
7385: }
7386: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
1.598 raeburn 7387: if ((caller == 'tool') || (caller == 'supptool')) {
7388: if (disp == 'block') {
7389: if (document.getElementById('LC_exttoolid')) {
7390: var toolselector = document.getElementById('LC_exttoolid');
7391: var suppflag = 0;
7392: if (caller == 'supptool') {
7393: suppflag = 1;
7394: }
7395: currForm = document.getElementById('new'+caller);
7396: updateExttool(toolselector,currForm,suppflag);
7397: }
7398: }
7399: }
1.501 raeburn 7400: }
1.502 raeburn 7401: resize_scrollbox('contentscroll','1','1');
7402: return;
7403: }
7404:
1.514 raeburn 7405: function toggleMap(caller) {
1.502 raeburn 7406: var disp = 'none';
1.510 raeburn 7407: if (document.getElementById('importmapform')) {
1.514 raeburn 7408: if (caller == 'map') {
7409: var curr = document.getElementById('importmapform').style.display;
7410: if (curr == 'none') {
7411: disp='block';
7412: }
1.510 raeburn 7413: }
7414: document.getElementById('importmapform').style.display=disp;
7415: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 7416: }
1.501 raeburn 7417: return;
1.329 droeschl 7418: }
7419:
1.606 raeburn 7420: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7421: var disp = 'none';
7422: if (document.getElementById('crsresform')) {
7423: if (caller == 'res') {
7424: var curr = document.getElementById('crsresform').style.display;
7425: if (curr == 'none') {
7426: disp='block';
7427: numauthor = parseInt(numauthorrole);
7428: if (numauthor > 0) {
7429: document.courseresform.authorrole.selectedIndex = 0;
7430: select1priv_changed();
7431: document.courseresform.authorpath.selectedIndex = 0;
7432: document.courseresform.newresourceadd.selectedIndex = 0;
7433: toggleNewInCourse(document.courseresform);
7434: if (document.getElementById('newresource')) {
7435: document.getElementById('newresource').style.display = 'none';
7436: }
7437: } else {
7438: if (numcrsdirs) {
7439: document.courseresform.authorpath.selectedIndex = 0;
7440: }
7441: }
7442: if (document.courseresform.newresusetemp.length) {
7443: document.courseresform.newresusetemp[0].checked = true;
7444: toggleWithTemplate(document.courseresform);
7445: }
7446: document.courseresform.newresourcename.value = '';
7447: }
7448: }
7449: if (document.courseresform.newsubdir.length) {
7450: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7451: if (document.courseresform.newsubdir[j].value == 0) {
7452: document.courseresform.newsubdir[j].checked = true;
7453: }
7454: break;
7455: }
7456: if (document.getElementById('newsubdirname')) {
7457: document.getElementById('newsubdirname').type = "hidden";
7458: document.getElementById('newsubdirname').value = "";
7459: }
7460: if (document.getElementById('newsubdir')) {
7461: document.getElementById('newsubdir').innerHTML = "";
7462: }
7463: }
7464: document.getElementById('crsresform').style.display=disp;
7465: resize_scrollbox('contentscroll','1','0');
7466: }
7467: return;
7468: }
7469:
7470: function toggleNewsubdir(form) {
7471: if (form.newsubdir.length) {
7472: for (var j=0; j<form.newsubdir.length; j++) {
7473: if (form.newsubdir[j].checked) {
7474: if (document.getElementById('newsubdirname')) {
7475: if (form.newsubdir[j].value == '1') {
7476: document.getElementById('newsubdirname').type = "text";
7477: if (document.getElementById('newsubdir')) {
7478: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7479: }
7480: } else {
7481: document.getElementById('newsubdirname').type = "hidden";
7482: document.getElementById('newsubdirname').value = "";
7483: document.getElementById('newsubdir').innerHTML = "";
7484: }
7485: }
7486: break;
7487: }
7488: }
7489: }
7490: }
7491:
7492: function toggleCrsResTitle() {
7493: if (document.getElementById('newresource')) {
7494: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7495: document.getElementById('newresource').style.display = 'inline';
7496: document.courseresform.newresourceadd[0].checked = true;
7497: toggleNewInCourse(document.courseresform);
7498: } else {
7499: document.getElementById('newresource').style.display = 'none';
7500: }
7501: }
7502: }
7503:
7504: function toggleNewInCourse(form) {
7505: if (form.newresourceadd.length) {
7506: for (var i=0; i<form.newresourceadd.length; i++) {
7507: if (form.newresourceadd[i].checked) {
7508: if (document.getElementById('newresourcetitle')) {
7509: if (form.newresourceadd[i].value == '1') {
7510: document.getElementById('newresourcetitle').type = 'text';
7511: if (document.getElementById('newrestitle')) {
7512: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7513: }
7514: } else {
7515: document.getElementById('newresourcetitle').type = 'hidden';
7516: document.getElementById('newresourcetitle').value = '';
7517: if (document.getElementById('newrestitle')) {
7518: document.getElementById('newrestitle').innerHTML = '';
7519: }
7520: }
7521: }
7522: break;
7523: }
7524: }
7525: }
7526: }
7527:
7528: function toggleWithTemplate(form) {
7529: if (form.newresusetemp.length) {
7530: for (var i=0; i<form.newresusetemp.length; i++) {
7531: if (form.newresusetemp[i].checked) {
7532: if (document.getElementById('newrestemplate')) {
7533: if (form.newresusetemp[i].value == '1') {
7534: document.getElementById('newrestemplate').style.display = 'inline';
7535: toggleExampleText();
7536: } else {
7537: form.tempcategory.selectedIndex = 0;
7538: select1template_changed();
7539: document.getElementById('newrestemplate').style.display = 'none';
7540: }
7541: }
7542: }
7543: }
7544: }
7545: }
7546:
7547: function toggleExampleText() {
7548: if (document.getElementById('newresexample')) {
7549: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7550: if (url == '') {
7551: document.getElementById('newresexample').style.fontWeight = 'normal';
7552: } else {
7553: document.getElementById('newresexample').style.fontWeight = 'bold';
7554: }
7555: }
7556: }
7557:
7558: function getExample(width,height,scrolling,transparency) {
7559: var url;
7560: if (document.courseresform.newresusetemp.length) {
7561: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7562: if (document.courseresform.newresusetemp[i].checked) {
7563: if (document.courseresform.newresusetemp[i].value == '1') {
7564: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7565: if (url == '') {
7566: alert('Pick a category and template');
7567: } else {
7568: url = url.replace("$londocroot","");
7569: url += '?inhibitmenu=yes';
7570: }
7571: }
7572: break;
7573: }
7574: }
7575: }
7576: if (url != '') {
7577: openMyModal(url,width,height,scrolling,transparency,'');
7578: }
7579: }
7580:
7581: function toggleImportCrsres(caller,dircount) {
7582: var disp = 'none';
7583: if (document.getElementById('importcrsresform')) {
7584: if (caller == 'res') {
7585: var numdirs = parseInt(dircount);
7586: var curr = document.getElementById('importcrsresform').style.display;
7587: if (curr == 'none') {
7588: disp='block';
7589: if (numdirs > 1) {
7590: select1res_changed();
7591: }
7592: }
7593: }
7594: document.getElementById('importcrsresform').style.display=disp;
7595: resize_scrollbox('contentscroll','1','0');
7596: }
7597: return;
7598: }
7599:
1.501 raeburn 7600: function makeims(imsform) {
7601: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
1.594 damieng 7602: alert("$js_lt{'imsfile'}");
1.501 raeburn 7603: return;
7604: }
7605: if (imsform.source.selectedIndex == 0) {
1.594 damieng 7606: alert("$js_lt{'imscms'}");
1.501 raeburn 7607: return;
7608: }
7609: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7610: imsform.submit();
7611: }
7612:
1.478 raeburn 7613: function updatePick(targetform,index,caller) {
1.537 raeburn 7614: var pickitem;
7615: var picknumitem;
7616: var picknumtext;
7617: if (index == 'all') {
7618: pickitem = document.getElementById('randompickall');
7619: picknumitem = document.getElementById('rpicknumall');
7620: picknumtext = document.getElementById('rpicktextall');
7621: } else {
7622: pickitem = document.getElementById('randompick_'+index);
7623: picknumitem = document.getElementById('rpicknum_'+index);
7624: picknumtext = document.getElementById('randompicknum_'+index);
7625: }
1.478 raeburn 7626: if (pickitem.checked) {
1.594 damieng 7627: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
1.478 raeburn 7628: if (picknum == '' || picknum == null) {
7629: if (caller == 'check') {
7630: pickitem.checked=false;
1.537 raeburn 7631: if (index == 'all') {
7632: picknumtext.innerHTML = '';
7633: if (caller == 'link') {
7634: propagateState(targetform,'rpicknum');
7635: }
7636: } else {
1.538 raeburn 7637: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7638: }
1.478 raeburn 7639: }
7640: } else {
7641: picknum.toString();
7642: var regexdigit=/^\\d+\$/;
7643: if (regexdigit.test(picknum)) {
7644: picknumitem.value = picknum;
1.537 raeburn 7645: if (index == 'all') {
1.538 raeburn 7646: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 7647: if (caller == 'link') {
7648: propagateState(targetform,'rpicknum');
7649: }
7650: } else {
7651: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 7652: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7653: }
1.478 raeburn 7654: } else {
7655: if (caller == 'check') {
1.537 raeburn 7656: if (index == 'all') {
7657: picknumtext.innerHTML = '';
7658: if (caller == 'link') {
7659: propagateState(targetform,'rpicknum');
7660: }
7661: } else {
7662: pickitem.checked=false;
1.538 raeburn 7663: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7664: }
1.478 raeburn 7665: }
7666: return;
7667: }
7668: }
7669: } else {
1.537 raeburn 7670: picknumitem.value = '';
7671: picknumtext.innerHTML = '';
7672: if (index == 'all') {
7673: if (caller == 'link') {
7674: propagateState(targetform,'rpicknum');
7675: }
7676: } else {
1.538 raeburn 7677: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 7678: }
7679: }
7680: }
7681:
7682: function propagateState(form,param) {
7683: if (document.getElementById(param+'all')) {
7684: var setcheck = 0;
7685: var rpick = 0;
7686: if (param == 'rpicknum') {
7687: if (document.getElementById('randompickall')) {
7688: if (document.getElementById('randompickall').checked) {
7689: if (document.getElementById('rpicknumall')) {
7690: rpick = document.getElementById('rpicknumall').value;
7691: }
7692: }
7693: }
7694: } else {
7695: if (document.getElementById(param+'all').checked) {
7696: setcheck = 1;
7697: }
7698: }
1.538 raeburn 7699: var allidxlist;
7700: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7701: if (document.getElementById('all'+param+'idx')) {
7702: allidxlist = document.getElementById('all'+param+'idx').value;
7703: }
7704: var actions = new Array ('remove','cut','copy');
7705: for (var i=0; i<actions.length; i++) {
7706: if (actions[i] != param) {
7707: if (document.getElementById(actions[i]+'all')) {
7708: document.getElementById(actions[i]+'all').checked = false;
7709: }
7710: }
7711: }
7712: }
1.537 raeburn 7713: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 7714: allidxlist = form.allidx.value;
7715: }
7716: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
7717: allidxlist = form.allmapidx.value;
7718: }
7719: if ((allidxlist != '') && (allidxlist != null)) {
7720: var allidxs = allidxlist.split(',');
7721: if (allidxs.length > 1) {
7722: for (var i=0; i<allidxs.length; i++) {
7723: if (document.getElementById(param+'_'+allidxs[i])) {
7724: if (param == 'rpicknum') {
7725: if (document.getElementById('randompick_'+allidxs[i])) {
7726: if (document.getElementById('randompick_'+allidxs[i]).checked) {
7727: document.getElementById(param+'_'+allidxs[i]).value = rpick;
7728: if (rpick > 0) {
7729: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
7730: } else {
7731: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7732: }
7733: }
7734: }
7735: } else {
1.537 raeburn 7736: if (setcheck == 1) {
7737: document.getElementById(param+'_'+allidxs[i]).checked = true;
7738: } else {
7739: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 7740: if (param == 'randompick') {
7741: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
7742: }
1.537 raeburn 7743: }
7744: }
7745: }
7746: }
1.538 raeburn 7747: if (setcheck == 1) {
7748: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
7749: var actions = new Array('copy','cut','remove');
7750: for (var i=0; i<actions.length; i++) {
7751: var otheractions;
7752: var otheridxs;
7753: if (actions[i] === param) {
7754: continue;
7755: } else {
7756: if (document.getElementById('all'+actions[i]+'idx')) {
7757: otheractions = document.getElementById('all'+actions[i]+'idx').value;
7758: otheridxs = otheractions.split(',');
7759: if (otheridxs.length > 1) {
7760: for (var j=0; j<otheridxs.length; j++) {
7761: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
7762: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
7763: }
1.537 raeburn 7764: }
7765: }
7766: }
1.538 raeburn 7767: }
7768: }
7769: }
7770: }
7771: }
7772: }
7773: }
7774: return;
7775: }
7776:
1.603 raeburn 7777: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
1.611 raeburn 7778: var canedit = '$canedit';
7779: if (canedit == '') {
7780: alert("$js_lt{'edri'}");
7781: return;
7782: }
1.539 raeburn 7783: var dosettings;
7784: var doaction;
1.538 raeburn 7785: var control = document.togglemultsettings;
7786: if (context == 'actions') {
7787: control = document.togglemultactions;
1.539 raeburn 7788: doaction = 1;
7789: } else {
7790: dosettings = 1;
1.538 raeburn 7791: }
1.539 raeburn 7792: if (control) {
7793: if (control.showmultpick.length) {
7794: for (var i=0; i<control.showmultpick.length; i++) {
7795: if (control.showmultpick[i].checked) {
7796: if (control.showmultpick[i].value == 1) {
7797: if (context == 'settings') {
7798: dosettings = 0;
7799: } else {
7800: doaction = 0;
1.538 raeburn 7801: }
7802: }
7803: }
1.537 raeburn 7804: }
7805: }
1.539 raeburn 7806: }
7807: if (context == 'settings') {
7808: if (dosettings == 1) {
1.538 raeburn 7809: targetform.changeparms.value=param;
7810: targetform.submit();
7811: }
1.537 raeburn 7812: }
1.539 raeburn 7813: if (context == 'actions') {
7814: if (doaction == 1) {
7815: targetform.cmd.value=param+'_'+index;
7816: targetform.folderpath.value=folderpath;
7817: targetform.markcopy.value=idx+':'+param;
7818: targetform.copyfolder.value=folder+'.'+container;
7819: if (param == 'remove') {
1.603 raeburn 7820: var doremove = 0;
7821: if (skip_confirm) {
7822: if (confirm_removal) {
7823: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
7824: doremove = 1;
7825: }
7826: } else {
7827: doremove = 1;
7828: }
7829: } else {
7830: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
7831: doremove = 1;
7832: }
7833: }
7834: if (doremove) {
1.539 raeburn 7835: targetform.markcopy.value='';
7836: targetform.copyfolder.value='';
7837: targetform.submit();
7838: }
7839: }
7840: if (param == 'cut') {
1.594 damieng 7841: 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.539 raeburn 7842: targetform.submit();
7843: return;
7844: }
7845: }
7846: if (param == 'copy') {
7847: targetform.submit();
7848: return;
7849: }
7850: targetform.markcopy.value='';
7851: targetform.copyfolder.value='';
7852: targetform.cmd.value='';
7853: targetform.folderpath.value='';
7854: return;
7855: } else {
7856: if (document.getElementById(param+'_'+idx)) {
7857: item = document.getElementById(param+'_'+idx);
7858: if (item.type == 'checkbox') {
7859: if (item.checked) {
7860: item.checked = false;
7861: } else {
7862: item.checked = true;
7863: singleCheck(item,idx,param);
7864: }
7865: }
7866: }
7867: }
7868: }
1.537 raeburn 7869: return;
7870: }
7871:
1.538 raeburn 7872: function singleCheck(caller,idx,action) {
7873: actions = new Array('cut','copy','remove');
7874: if (caller.checked) {
7875: for (var i=0; i<actions.length; i++) {
7876: if (actions[i] != action) {
7877: if (document.getElementById(actions[i]+'_'+idx)) {
7878: if (document.getElementById(actions[i]+'_'+idx).checked) {
7879: document.getElementById(actions[i]+'_'+idx).checked = false;
7880: }
1.537 raeburn 7881: }
7882: }
7883: }
1.478 raeburn 7884: }
1.537 raeburn 7885: return;
1.478 raeburn 7886: }
7887:
1.334 muellerd 7888: function unselectInactive(nav) {
1.335 ehlerst 7889: currentNav = document.getElementById(nav);
7890: currentLis = currentNav.getElementsByTagName('LI');
7891: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 7892: if (currentLis[i].className == 'goback') {
7893: currentLis[i].className = 'goback';
7894: } else {
7895: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 7896: currentLis[i].className = 'right';
1.472 raeburn 7897: } else {
1.374 tempelho 7898: currentLis[i].className = 'i';
1.472 raeburn 7899: }
7900: }
1.335 ehlerst 7901: }
1.332 tempelho 7902: }
7903:
1.334 muellerd 7904: function hideAll(current, nav, data) {
1.335 ehlerst 7905: unselectInactive(nav);
1.570 raeburn 7906: if (current) {
7907: if (current.className == 'right'){
7908: current.className = 'right active'
7909: } else {
7910: current.className = 'active';
7911: }
1.374 tempelho 7912: }
1.335 ehlerst 7913: currentData = document.getElementById(data);
7914: currentDivs = currentData.getElementsByTagName('DIV');
7915: for (i = 0; i < currentDivs.length; i++) {
7916: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 7917: currentDivs[i].style.display = 'none';
1.330 tempelho 7918: }
7919: }
1.335 ehlerst 7920: }
1.330 tempelho 7921:
1.374 tempelho 7922: function openTabs(pageId) {
7923: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 7924: if(tabnav.length > 2 ){
1.389 tempelho 7925: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 7926: currentLis = currentNav.getElementsByTagName('LI');
7927: for(i = 0; i< currentLis.length; i++){
7928: if(currentLis[i].className == 'active') {
1.375 tempelho 7929: funcString = currentLis[i].onclick.toString();
7930: tab = funcString.split('"');
1.420 onken 7931: if(tab.length < 2) {
7932: tab = funcString.split("'");
7933: }
1.375 tempelho 7934: currentData = document.getElementById(tab[1]);
7935: currentData.style.display = 'block';
1.374 tempelho 7936: }
7937: }
7938: }
7939: }
7940:
1.334 muellerd 7941: function showPage(current, pageId, nav, data) {
1.570 raeburn 7942: currstate = current.className;
1.334 muellerd 7943: hideAll(current, nav, data);
1.375 tempelho 7944: openTabs(pageId);
1.334 muellerd 7945: unselectInactive(nav);
1.570 raeburn 7946: if ((currstate == 'active') || (currstate == 'right active')) {
7947: if (currstate == 'active') {
7948: current.className = '';
7949: } else {
7950: current.className = 'right';
7951: }
7952: activeTab = '';
7953: toggleUpload();
7954: toggleMap();
1.606 raeburn 7955: toggleCrsRes();
7956: toggleImportCrsres();
1.570 raeburn 7957: resize_scrollbox('contentscroll','1','0');
7958: return;
7959: } else {
7960: current.className = 'active';
7961: }
1.330 tempelho 7962: currentData = document.getElementById(pageId);
7963: currentData.style.display = 'block';
1.458 raeburn 7964: activeTab = pageId;
1.501 raeburn 7965: toggleUpload();
1.503 raeburn 7966: toggleMap();
1.606 raeburn 7967: toggleCrsRes();
7968: toggleImportCrsres();
1.433 raeburn 7969: if (nav == 'mainnav') {
7970: var storedpath = "$docs_folderpath";
1.434 raeburn 7971: var storedpage = "$main_container_page";
1.433 raeburn 7972: var reg = new RegExp("^supplemental");
7973: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 7974: if (storedpage == 1) {
7975: document.simpleedit.folderpath.value = '';
7976: document.uploaddocument.folderpath.value = '';
7977: } else {
7978: if (reg.test(storedpath)) {
7979: document.simpleedit.folderpath.value = '$toplevelmain';
7980: document.uploaddocument.folderpath.value = '$toplevelmain';
7981: document.newext.folderpath.value = '$toplevelmain';
7982: } else {
7983: document.simpleedit.folderpath.value = storedpath;
7984: document.uploaddocument.folderpath.value = storedpath;
7985: document.newext.folderpath.value = storedpath;
7986: }
1.433 raeburn 7987: }
7988: } else {
1.434 raeburn 7989: if (reg.test(storedpath)) {
7990: document.simpleedit.folderpath.value = storedpath;
7991: document.supuploaddocument.folderpath.value = storedpath;
7992: document.supnewext.folderpath.value = storedpath;
7993: } else {
1.433 raeburn 7994: document.simpleedit.folderpath.value = '$toplevelsupp';
7995: document.supuploaddocument.folderpath.value = '$toplevelsupp';
7996: document.supnewext.folderpath.value = '$toplevelsupp';
7997: }
7998: }
7999: }
1.485 raeburn 8000: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 8001: return false;
8002: }
1.329 droeschl 8003:
1.472 raeburn 8004: function toContents(jumpto) {
8005: var newurl = '$backtourl';
1.525 raeburn 8006: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 8007: newurl = newurl+'?postdata='+jumpto;
8008: }
8009: location.href=newurl;
8010: }
8011:
1.538 raeburn 8012: function togglePick(caller,value) {
8013: var disp = 'none';
8014: if (document.getElementById('multi'+caller)) {
8015: var curr = document.getElementById('multi'+caller).style.display;
8016: if (value == 1) {
8017: disp='block';
8018: }
8019: if (curr == disp) {
8020: return;
8021: }
8022: document.getElementById('multi'+caller).style.display=disp;
8023: if (value == 1) {
1.594 damieng 8024: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8025: } else {
8026: document.getElementById('more'+caller).innerHTML = '';
8027: }
8028: if (caller == 'actions') {
8029: setClass(value);
8030: setBoxes(value);
8031: }
8032: }
8033: var showButton = multiSettings();
8034: if (showButton != 1) {
8035: showButton = multiActions();
8036: }
8037: if (document.getElementById('multisave')) {
8038: if (showButton == 1) {
8039: document.getElementById('multisave').style.display='block';
8040: } else {
8041: document.getElementById('multisave').style.display='none';
8042: }
8043: }
8044: resize_scrollbox('contentscroll','1','1');
8045: return;
8046: }
8047:
8048: function toggleCheckUncheck(caller,more) {
8049: if (more == 1) {
1.594 damieng 8050: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
1.538 raeburn 8051: document.getElementById('allfields'+caller).style.display='block';
8052: } else {
1.594 damieng 8053: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
1.538 raeburn 8054: document.getElementById('allfields'+caller).style.display='none';
8055: }
8056: resize_scrollbox('contentscroll','1','1');
8057: }
8058:
8059: function multiSettings() {
8060: var inuse = 0;
8061: var settingsform = document.togglemultsettings;
8062: if (settingsform.showmultpick.length > 1) {
8063: for (var i=0; i<settingsform.showmultpick.length; i++) {
8064: if (settingsform.showmultpick[i].checked) {
8065: if (settingsform.showmultpick[i].value == 1) {
8066: inuse = 1;
8067: }
8068: }
8069: }
8070: }
8071: return inuse;
8072: }
8073:
8074: function multiActions() {
8075: var inuse = 0;
8076: var actionsform = document.togglemultactions;
8077: if (actionsform.showmultpick.length > 1) {
8078: for (var i=0; i<actionsform.showmultpick.length; i++) {
8079: if (actionsform.showmultpick[i].checked) {
8080: if (actionsform.showmultpick[i].value == 1) {
8081: inuse = 1;
8082: }
8083: }
8084: }
8085: }
8086: return inuse;
8087: }
8088:
8089: function checkSubmits() {
8090: var numchanges = 0;
8091: var form = document.saveactions;
8092: var doactions = multiActions();
1.542 raeburn 8093: var cutwarnings = 0;
8094: var remwarnings = 0;
1.603 raeburn 8095: var removalinfo = 0;
1.538 raeburn 8096: if (doactions == 1) {
8097: var remidxlist = document.cumulativeactions.allremoveidx.value;
8098: if ((remidxlist != '') && (remidxlist != null)) {
8099: var remidxs = remidxlist.split(',');
8100: for (var i=0; i<remidxs.length; i++) {
8101: if (document.getElementById('remove_'+remidxs[i])) {
8102: if (document.getElementById('remove_'+remidxs[i]).checked) {
8103: form.multiremove.value += remidxs[i]+',';
8104: numchanges ++;
1.542 raeburn 8105: if (document.getElementById('skip_remove_'+remidxs[i])) {
8106: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8107: remwarnings ++;
8108: }
8109: }
1.603 raeburn 8110: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8111: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8112: removalinfo ++;
8113: }
8114: }
1.537 raeburn 8115: }
8116: }
1.538 raeburn 8117: }
8118: }
8119: var cutidxlist = document.cumulativeactions.allcutidx.value;
8120: if ((cutidxlist != '') && (cutidxlist != null)) {
8121: var cutidxs = cutidxlist.split(',');
8122: for (var i=0; i<cutidxs.length; i++) {
8123: if (document.getElementById('cut_'+cutidxs[i])) {
8124: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8125: form.multicut.value += cutidxs[i]+',';
8126: numchanges ++;
1.542 raeburn 8127: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8128: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8129: cutwarnings ++;
8130: }
8131: }
1.537 raeburn 8132: }
8133: }
8134: }
8135: }
1.538 raeburn 8136: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8137: if ((copyidxlist != '') && (copyidxlist != null)) {
8138: var copyidxs = copyidxlist.split(',');
8139: for (var i=0; i<copyidxs.length; i++) {
8140: if (document.getElementById('copy_'+copyidxs[i])) {
8141: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8142: form.multicopy.value += copyidxs[i]+',';
8143: numchanges ++;
8144: }
8145: }
8146: }
8147: }
8148: if (numchanges > 0) {
8149: form.multichange.value = numchanges;
8150: }
1.537 raeburn 8151: }
1.538 raeburn 8152: var dosettings = multiSettings();
1.543 raeburn 8153: var haschanges = 0;
1.538 raeburn 8154: if (dosettings == 1) {
8155: form.allencrypturl.value = '';
8156: form.allhiddenresource.value = '';
1.543 raeburn 8157: form.changeparms.value = 'all';
8158: var patt=new RegExp(",\$");
1.538 raeburn 8159: var allidxlist = document.cumulativesettings.allidx.value;
8160: if ((allidxlist != '') && (allidxlist != null)) {
8161: var allidxs = allidxlist.split(',');
8162: if (allidxs.length > 1) {
8163: for (var i=0; i<allidxs.length; i++) {
8164: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8165: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8166: form.allhiddenresource.value += allidxs[i]+',';
8167: }
8168: }
8169: if (document.getElementById('encrypturl_'+allidxs[i])) {
8170: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8171: form.allencrypturl.value += allidxs[i]+',';
8172: }
8173: }
8174: }
1.543 raeburn 8175: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8176: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 8177: }
1.538 raeburn 8178: }
8179: form.allrandompick.value = '';
8180: form.allrandomorder.value = '';
8181: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8182: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8183: var allmapidxs = allmapidxlist.split(',');
8184: for (var i=0; i<allmapidxs.length; i++) {
8185: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8186: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8187: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8188: if ((randompick.checked) && (rpicknum.value != '')) {
8189: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8190: }
8191: if (randorder.checked) {
8192: form.allrandomorder.value += allmapidxs[i]+',';
8193: }
1.537 raeburn 8194: }
1.543 raeburn 8195: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8196: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8197: }
8198: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8199: haschanges = 1;
8200: }
8201: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8202: haschanges = 1;
8203: }
8204: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8205: haschanges = 1;
8206: }
8207: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8208: haschanges = 1;
1.537 raeburn 8209: }
8210: }
1.543 raeburn 8211: if (doactions == 1) {
1.542 raeburn 8212: if (numchanges > 0) {
1.603 raeburn 8213: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
1.542 raeburn 8214: if (remwarnings > 0) {
1.594 damieng 8215: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
1.542 raeburn 8216: return false;
8217: }
8218: }
1.603 raeburn 8219: if (removalinfo > 0) {
8220: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8221: return false;
8222: }
8223: }
1.542 raeburn 8224: if (cutwarnings > 0) {
1.594 damieng 8225: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
1.542 raeburn 8226: return false;
8227: }
8228: }
8229: }
8230: form.submit();
8231: return true;
1.543 raeburn 8232: }
8233: }
8234: if (dosettings == 1) {
8235: if (haschanges == 1) {
1.542 raeburn 8236: form.submit();
8237: return true;
8238: }
1.543 raeburn 8239: }
8240: if ((dosettings == 1) && (doactions == 1)) {
1.594 damieng 8241: alert("$js_lt{'noor'}");
1.543 raeburn 8242: } else {
8243: if (dosettings == 1) {
1.594 damieng 8244: alert("$js_lt{'noch'}");
1.543 raeburn 8245: } else {
1.594 damieng 8246: alert("$js_lt{'noac'}");
1.543 raeburn 8247: }
8248: }
1.538 raeburn 8249: return false;
8250: }
8251:
8252: function setClass(value) {
8253: var cutclass = 'LC_docs_cut';
8254: var copyclass = 'LC_docs_copy';
8255: var removeclass = 'LC_docs_remove';
8256: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8257: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8258: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8259: var links = document.getElementsByTagName('a');
8260: for (var i=0; i<links.length; i++) {
8261: var classes = links[i].className;
8262: if (cutreg.test(classes)) {
8263: links[i].className = cutclass;
8264: if (value == 1) {
8265: links[i].className += " LC_menubuttons_link";
8266: }
8267: } else {
8268: if (copyreg.test(classes)) {
8269: links[i].className = copyclass;
8270: if (value == 1) {
8271: links[i].className += " LC_menubuttons_link";
8272: }
8273: } else {
8274: if (removereg.test(classes)) {
8275: links[i].className = removeclass;
8276: if (value == 1) {
8277: links[i].className += " LC_menubuttons_link";
8278: }
8279: }
8280: }
8281: }
8282: }
8283: return;
1.537 raeburn 8284: }
8285:
1.538 raeburn 8286: function setBoxes(value) {
8287: var remidxlist = document.cumulativeactions.allremoveidx.value;
8288: if ((remidxlist != '') && (remidxlist != null)) {
8289: var remidxs = remidxlist.split(',');
8290: for (var i=0; i<remidxs.length; i++) {
8291: if (document.getElementById('remove_'+remidxs[i])) {
8292: var item = document.getElementById('remove_'+remidxs[i]);
8293: if (value == 1) {
8294: item.className = 'LC_docs_remove';
8295: } else {
8296: item.className = 'LC_hidden';
8297: }
8298: }
8299: }
8300: }
8301: var cutidxlist = document.cumulativeactions.allcutidx.value;
8302: if ((cutidxlist != '') && (cutidxlist != null)) {
8303: var cutidxs = cutidxlist.split(',');
8304: for (var i=0; i<cutidxs.length; i++) {
8305: if (document.getElementById('cut_'+cutidxs[i])) {
8306: var item = document.getElementById('cut_'+cutidxs[i]);
8307: if (value == 1) {
8308: item.className = 'LC_docs_cut';
8309: } else {
8310: item.className = 'LC_hidden';
8311: }
8312: }
1.537 raeburn 8313: }
8314: }
1.538 raeburn 8315: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8316: if ((copyidxlist != '') && (copyidxlist != null)) {
8317: var copyidxs = copyidxlist.split(',');
8318: for (var i=0; i<copyidxs.length; i++) {
8319: if (document.getElementById('copy_'+copyidxs[i])) {
8320: var item = document.getElementById('copy_'+copyidxs[i]);
8321: if (value == 1) {
8322: item.className = 'LC_docs_copy';
8323: } else {
8324: item.className = 'LC_hidden';
8325: }
8326: }
1.537 raeburn 8327: }
8328: }
8329: return;
8330: }
8331:
1.606 raeburn 8332: function validImportCrsRes() {
8333: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8334: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8335: if ((fname == '') || (fname == null)) {
8336: alert("$js_lt{'nofi'}");
8337: return false;
8338: }
8339: var url = '/res/$coursedom/$coursenum/';
8340: if (path && path != '/') {
8341: url += path+'/';
8342: }
8343: if (fname != '') {
8344: url += fname;
8345: }
8346: var title = document.crsresimportform.crsrestitle.value;
8347: document.crsresimportform.importdetail.value=escape(title)+'='+escape(url);
8348: return true;
8349: }
8350:
8351: function validateNewRes(caller) {
8352: if (caller == 'single') {
8353: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8354: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8355: var resname = document.courseresform.newresourcename.value;
8356: }
8357: }
8358:
1.611 raeburn 8359: ENDSCRIPT
1.329 droeschl 8360: }
1.457 raeburn 8361:
1.483 raeburn 8362: sub history_tab_js {
8363: return <<"ENDHIST";
8364: function toggleHistoryDisp(choice) {
8365: document.docslogform.docslog.value = choice;
8366: document.docslogform.submit();
8367: return;
8368: }
8369:
8370: ENDHIST
8371: }
8372:
1.484 raeburn 8373: sub inject_data_js {
8374: return <<ENDINJECT;
8375:
8376: function injectData(current, hiddenField, name, value) {
8377: currentElement = document.getElementById(hiddenField);
8378: currentElement.name = name;
8379: currentElement.value = value;
8380: current.submit();
8381: }
8382:
8383: ENDINJECT
8384: }
8385:
8386: sub dump_switchserver_js {
8387: my @hosts = @_;
1.594 damieng 8388: my %js_lt = &Apache::lonlocal::texthash(
1.574 raeburn 8389: dump => 'Copying content to Authoring Space requires switching server.',
1.484 raeburn 8390: swit => 'Switch server?',
1.594 damieng 8391: );
8392: my %html_js_lt = &Apache::lonlocal::texthash(
8393: swit => 'Switch server?',
1.568 raeburn 8394: duco => 'Copying Content to Authoring Space',
1.484 raeburn 8395: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8396: chos => 'Choose server',
8397: );
1.594 damieng 8398: &js_escape(\%js_lt);
8399: &html_escape(\%html_js_lt);
8400: &js_escape(\%html_js_lt);
1.484 raeburn 8401: my $role = $env{'request.role'};
8402: my $js = <<"ENDSWJS";
8403: <script type="text/javascript">
8404: function write_switchserver() {
8405: var server;
8406: if (document.setserver.posshosts.length > 0) {
8407: for (var i=0; i<document.setserver.posshosts.length; i++) {
8408: if (document.setserver.posshosts[i].checked) {
8409: server = document.setserver.posshosts[i].value;
8410: }
8411: }
8412: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8413: }
8414: window.close();
8415: }
8416: </script>
8417:
8418: ENDSWJS
8419:
8420: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8421: {'only_body' => 1,
8422: 'js_ready' => 1,});
8423: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8424:
8425: my $hostpicker;
8426: my $count = 0;
8427: foreach my $host (sort(@hosts)) {
8428: my $checked;
8429: if ($count == 0) {
8430: $checked = ' checked="checked"';
8431: }
8432: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8433: $host.'"'.$checked.' />'.$host.'</label> ';
8434: $count++;
8435: }
8436:
8437: return <<"ENDSWITCHJS";
8438:
8439: function dump_needs_switchserver(url) {
8440: if (url!='' && url!= null) {
1.594 damieng 8441: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
1.484 raeburn 8442: go(url);
8443: }
8444: }
8445: return;
8446: }
8447:
8448: function choose_switchserver_window() {
8449: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8450: newWindow.document.open();
8451: newWindow.document.writeln('$startpage');
1.594 damieng 8452: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8453: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8454: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
1.484 raeburn 8455: '<form name="setserver" method="post" action="" \\/>\\n'+
8456: '$hostpicker\\n'+
8457: '<br \\/><br \\/>\\n'+
1.594 damieng 8458: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
1.484 raeburn 8459: 'onclick="write_switchserver();" \\/>\\n'+
8460: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8461: newWindow.document.writeln('$endpage');
8462: newWindow.document.close();
8463: newWindow.focus();
8464: }
8465:
8466: ENDSWITCHJS
8467: }
8468:
8469: sub makedocslogform {
8470: my ($formelems,$docslog) = @_;
8471: return <<"LOGSFORM";
8472: <form action="/adm/coursedocs" method="post" name="docslogform">
8473: <input type="hidden" name="docslog" value="$docslog" />
8474: $formelems
8475: </form>
8476: LOGSFORM
8477: }
8478:
8479: sub makesimpleeditform {
8480: my ($formelems) = @_;
8481: return <<"SIMPFORM";
8482: <form name="simpleedit" method="post" action="/adm/coursedocs">
8483: <input type="hidden" name="importdetail" value="" />
8484: $formelems
8485: </form>
8486: SIMPFORM
8487: }
8488:
1.606 raeburn 8489: sub makenewproblem {
8490: my ($r,$coursedom,$coursenum) = @_;
8491: # Creating a new problem
8492: my ($redirect,$error);
8493: if ($env{'form.authorrole'}) {
8494: my ($newsubdir,$filename);
8495: if ($env{'form.newsubdir'}) {
8496: if ($env{'form.newsubdirname'} ne '') {
8497: $newsubdir = $env{'form.newsubdirname'};
8498: }
8499: }
8500: if ($env{'form.newresourcename'}) {
8501: $filename = $env{'form.newresourcename'};
8502: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8503: $filename =~ s/`//g;
8504: $filename =~ s{/\.\./}{_}g;
8505: $filename =~ s/\.+/./g;
8506: $filename =~ s{/+}{_}g;
8507: if ($filename ne '') {
8508: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8509: if (($ext) && ($ext ne '.problem')) {
8510: $filename = $name.'.problem';
8511: } elsif ($ext eq '') {
8512: $filename .= '.problem';
8513: }
8514: my $docroot = $r->dir_config('lonDocRoot');
8515: my @ids=&Apache::lonnet::current_machine_ids();
8516: if ($env{'form.authorrole'} eq 'author') {
8517: if ($env{'user.author'}) {
8518: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8519: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8520: my $path = $docroot.$url;
8521: my $subdir = $env{'form.authorpath'};
8522: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8523: }
8524: }
8525: } elsif ($env{'form.authorrole'} eq 'course') {
8526: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8527: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8528: my $url = "/priv/$coursedom/$coursenum";
8529: my $path=$docroot.$url;
8530: my $subdir = $env{'form.authorpath'};
8531: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8532: if ($redirect) {
8533: my $rightsfile = 'default.rights';
8534: my $sourcerights = "$path/$rightsfile";
8535: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8536: my $now = time;
8537: if (!-e $sourcerights) {
8538: my $cid = $coursedom.'_'.$coursenum;
8539: if (open(my $fh,">$sourcerights")) {
8540: print $fh <<END;
8541: <accessrule effect="deny" realm="" type="course" role="" />
8542: <accessrule effect="allow" realm="$cid" type="course" role="" />
8543: END
8544: close($fh);
8545: }
8546: }
8547: if (!-e "$sourcerights.meta") {
8548: if (open(my $fh,">$sourcerights.meta")) {
8549: my $author=$env{'environment.firstname'}.' '.
8550: $env{'environment.middlename'}.' '.
8551: $env{'environment.lastname'}.' '.
8552: $env{'environment.generation'};
8553: $author =~ s/\s+$//;
8554: print $fh <<"END";
8555:
8556: <abstract></abstract>
8557: <author>$author</author>
8558: <authorspace>$coursenum:$coursedom</authorspace>
8559: <copyright>private</copyright>
8560: <creationdate>$now</creationdate>
8561: <customdistributionfile></customdistributionfile>
8562: <dependencies></dependencies>
8563: <domain>$coursedom</domain>
8564: <highestgradelevel>0</highestgradelevel>
8565: <keywords></keywords>
8566: <language>notset </language>
8567: <lastrevisiondate>$now</lastrevisiondate>
8568: <lowestgradelevel>0</lowestgradelevel>
8569: <mime>rights</mime>
8570: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8571: <notes></notes>
8572: <obsolete></obsolete>
8573: <obsoletereplacement></obsoletereplacement>
8574: <owner>$coursenum:$coursedom</owner>
8575: <rule>deny:::course,allow:$cid::course</rule>
8576: <sourceavail></sourceavail>
8577: <standards></standards>
8578: <subject></subject>
8579: <title></title>
8580: END
8581: close($fh);
8582: }
8583: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8584: if (!-e "$docroot/res/$coursedom") {
8585: mkdir("$docroot/res/$coursedom",0755);
8586: }
8587: if (!-e "$docroot/res/$coursedom/$coursenum") {
8588: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8589: }
8590: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8591: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8592: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8593: }
8594: }
8595: }
8596: if ($env{'form.newresourceadd'}) {
8597: my $template = $env{'form.template'};
8598: my $source = $docroot.$redirect;
8599: my $target = $redirect;
8600: $target =~ s{^/priv/}{/res/};
8601: $target = $docroot.$target;
8602: if (!-e $source) {
8603: my $copyfrom;
8604: if ($template) {
8605: my %templates;
8606: my @files = &Apache::lonhomework::get_template_list('problem');
8607: foreach my $poss (@files) {
8608: if (ref($poss) eq 'ARRAY') {
8609: if ($template eq $poss->[0]) {
8610: $templates{$template} = 1;
8611: last;
8612: }
8613: }
8614: }
8615: if ($templates{$template}) {
8616: $copyfrom = $template;
8617: }
8618: }
8619: unless ($copyfrom) {
8620: $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';
8621: }
8622: &File::Copy::copy($copyfrom,$source);
8623: }
8624: if (!-e "$source.meta") {
8625: my $cid = $coursedom.'_'.$coursenum;
8626: my $now = time;
8627: if (open(my $fh,">$source.meta")) {
8628: my $author=$env{'environment.firstname'}.' '.
8629: $env{'environment.middlename'}.' '.
8630: $env{'environment.lastname'}.' '.
8631: $env{'environment.generation'};
8632: $author =~ s/\s+$//;
8633: my $title = $env{'form.newresourcetitle'};
8634: $title =~ s/^\s+|\s+$//g;
8635: print $fh <<END;
8636:
8637: <abstract></abstract>
8638: <author>$author</author>
8639: <authorspace>$coursenum:$coursedom</authorspace>
8640: <copyright>custom</copyright>
8641: <creationdate>$now</creationdate>
8642: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8643: <dependencies></dependencies>
8644: <domain>$coursedom</domain>
8645: <highestgradelevel>0</highestgradelevel>
8646: <keywords></keywords>
8647: <language>notset </language>
8648: <lastrevisiondate>$now</lastrevisiondate>
8649: <lowestgradelevel>0</lowestgradelevel>
8650: <mime>problem</mime>
8651: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8652: <notes></notes>
8653: <obsolete></obsolete>
8654: <obsoletereplacement></obsoletereplacement>
8655: <owner>$coursenum:$coursedom</owner>
8656: <sourceavail></sourceavail>
8657: <standards></standards>
8658: <subject></subject>
8659: <title>$title</title>
8660: END
8661: close($fh);
8662: }
8663: }
8664: }
8665: }
8666: }
8667: } else {
8668: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8669: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8670: if (grep(/^\Q$rolehome\E$/,@ids)) {
8671: my $now = time;
8672: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8673: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8674: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8675: my $url = "/priv/$audom/$auname";
8676: my $path = $r->dir_config('lonDocRoot').$url;
8677: my $subdir = $env{'form.authorpath'};
8678: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8679: }
8680: }
8681: }
8682: }
8683: }
8684: }
8685: }
8686: return ($redirect,$error);
8687: }
8688:
8689: sub finishnewprob {
8690: my ($url,$path,$subdir,$newsubdir,$filename) = @_;
1.607 raeburn 8691: unless (-d $path) {
8692: unless (mkdir($path,02770)) {
8693: return;
8694: }
8695: }
1.606 raeburn 8696: my $redirect;
8697: if ($subdir ne '/') {
8698: $subdir = &cleandir($subdir);
8699: if (($subdir ne '') && (-d "$path/$subdir")) {
8700: $path .= "/$subdir";
8701: $url .= "/$subdir";
8702: }
8703: }
8704: my $dest;
8705: if ($newsubdir ne '') {
8706: $newsubdir = &cleandir($newsubdir);
8707: }
8708: if ($newsubdir ne '') {
8709: if (-d "$path/$newsubdir") {
8710: $dest = "$path/$newsubdir/$filename";
8711: } else {
8712: my $dirok;
8713: unless (-e "$path/$newsubdir") {
8714: if (mkdir("$path/$newsubdir",02770)) {
8715: if (chmod(02770,"$path/$newsubdir")) {
8716: $dirok = 1;
8717: }
8718: }
8719: }
8720: if ($dirok) {
8721: $dest = "$path/$newsubdir/$filename";
8722: }
8723: }
8724: if (($dest ne '') && (!-e $dest)) {
8725: $redirect = "$url/$newsubdir/$filename";
8726: }
8727: } else {
8728: $dest = "$path/$filename";
8729: if (($dest ne '') && (!-e $dest)) {
8730: $redirect = "$url/$filename";
8731: }
8732: }
8733: return $redirect;
8734: }
8735:
8736: sub cleandir {
8737: my ($dir) = @_;
8738: $dir =~ s/^\s+//;
8739: $dir =~ s/\s+$//;
8740: $dir =~ s/\.+//g;
8741: $dir =~ s/[\#\?&%\":]//g;
8742: return $dir;
8743: }
8744:
1.329 droeschl 8745: 1;
8746: __END__
8747:
8748:
8749: =head1 NAME
8750:
8751: Apache::londocs.pm
8752:
8753: =head1 SYNOPSIS
8754:
8755: This is part of the LearningOnline Network with CAPA project
8756: described at http://www.lon-capa.org.
8757:
8758: =head1 SUBROUTINES
8759:
8760: =over
8761:
8762: =item %help=()
8763:
8764: Available help topics
8765:
8766: =item mapread()
8767:
1.344 bisitz 8768: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 8769: @order and @resources, determines status
8770: sets @order - pointer to resources in right order
8771: sets @resources - array with the resources with correct idx
8772:
8773: =item authorhosts()
8774:
8775: Return hash with valid author names
8776:
8777: =item clean()
8778:
8779: =item dumpcourse()
8780:
8781: Actually dump course
8782:
8783: =item group_import()
8784:
8785: Imports the given (name, url) resources into the course
8786: coursenum, coursedom, and folder must precede the list
8787:
8788: =item breadcrumbs()
8789:
8790: =item log_docs()
8791:
8792: =item docs_change_log()
8793:
8794: =item update_paste_buffer()
8795:
8796: =item print_paste_buffer()
8797:
8798: =item do_paste_from_buffer()
8799:
1.538 raeburn 8800: =item do_buffer_empty()
8801:
8802: =item clear_from_buffer()
8803:
1.492 raeburn 8804: =item get_newmap_url()
8805:
8806: =item dbcopy()
8807:
8808: =item uniqueness_check()
8809:
8810: =item contained_map_check()
8811:
8812: =item url_paste_fixups()
8813:
8814: =item apply_fixups()
8815:
8816: =item copy_dependencies()
8817:
1.329 droeschl 8818: =item update_parameter()
8819:
8820: =item handle_edit_cmd()
8821:
8822: =item editor()
8823:
8824: =item process_file_upload()
8825:
8826: =item process_secondary_uploads()
8827:
8828: =item is_supplemental_title()
8829:
8830: =item entryline()
8831:
8832: =item tiehash()
8833:
8834: =item untiehash()
8835:
8836: =item checkonthis()
8837:
8838: check on this
8839:
8840: =item verifycontent()
8841:
8842: Verify Content
8843:
1.636 raeburn 8844: =item devalidateversioncache()
8845:
8846: =item checkversions()
1.329 droeschl 8847:
8848: Check Versions
8849:
8850: =item mark_hash_old()
8851:
8852: =item is_hash_old()
8853:
8854: =item changewarning()
8855:
8856: =item init_breadcrumbs()
8857:
8858: Breadcrumbs for special functions
8859:
1.484 raeburn 8860: =item create_list_elements()
8861:
8862: =item create_form_ul()
8863:
8864: =item startContentScreen()
8865:
8866: =item endContentScreen()
8867:
8868: =item supplemental_base()
8869:
8870: =item embedded_form_elems()
8871:
8872: =item embedded_destination()
8873:
8874: =item return_to_editor()
8875:
8876: =item decompression_info()
8877:
8878: =item decompression_phase_one()
8879:
8880: =item decompression_phase_two()
8881:
8882: =item remove_archive()
8883:
8884: =item generate_admin_menu()
8885:
8886: =item generate_edit_table()
8887:
8888: =item editing_js()
8889:
8890: =item history_tab_js()
8891:
8892: =item inject_data_js()
8893:
8894: =item dump_switchserver_js()
8895:
1.485 raeburn 8896: =item resize_scrollbox_js()
1.484 raeburn 8897:
8898: =item makedocslogform()
8899:
1.485 raeburn 8900: =item makesimpleeditform()
8901:
1.329 droeschl 8902: =back
8903:
8904: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>