Annotation of loncom/interface/londocs.pm, revision 1.162
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.162 ! raeburn 4: # $Id: londocs.pm,v 1.161 2004/12/23 17:50:42 albertel Exp $
1.1 www 5: #
1.3 www 6: # Copyright Michigan State University Board of Trustees
1.1 www 7: #
1.3 www 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1 www 9: #
1.3 www 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.
1.1 www 14: #
1.3 www 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:
1.2 www 29: package Apache::londocs;
1.1 www 30:
31: use strict;
1.28 www 32: use Apache::Constants qw(:common :http);
1.158 raeburn 33: use Apache::imsexport;
1.4 www 34: use Apache::lonnet;
35: use Apache::loncommon;
1.7 www 36: use Apache::lonratedt;
37: use Apache::lonratsrv;
1.15 www 38: use Apache::lonxml;
1.74 www 39: use Apache::loncreatecourse;
1.138 raeburn 40: use Apache::lonnavmaps;
1.38 www 41: use HTML::Entities;
1.27 www 42: use GDBM_File;
1.81 www 43: use Apache::lonlocal;
1.143 raeburn 44: use Cwd;
1.7 www 45:
1.8 www 46: my $iconpath;
1.7 www 47:
1.27 www 48: my %hash;
49:
50: my $hashtied;
1.29 www 51: my %alreadyseen=();
1.27 www 52:
1.40 www 53: my $hadchanges;
54:
1.47 www 55: # Available help topics
56:
57: my %help=();
58:
1.7 www 59: # Mapread read maps into lonratedt::global arrays
1.10 www 60: # @order and @resources, determines status
1.7 www 61: # sets @order - pointer to resources in right order
62: # sets @resources - array with the resources with correct idx
63: #
64:
65: sub mapread {
66: my ($coursenum,$coursedom,$map)=@_;
67: return
68: &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
69: $map);
70: }
71:
72: sub storemap {
73: my ($coursenum,$coursedom,$map)=@_;
1.104 albertel 74: my ($outtext,$errtext)=
1.7 www 75: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15 www 76: $map,1);
1.104 albertel 77: if ($errtext) { return ($errtext,2); }
78:
79: $hadchanges=1;
80: return ($errtext,0);
1.7 www 81: }
82:
1.74 www 83: # ----------------------------------------- Return hash with valid author names
84:
85: sub authorhosts {
86: my %outhash=();
87: my $home=0;
88: my $other=0;
89: foreach (keys %ENV) {
90: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
91: my $role=$1;
92: my $realm=$2;
93: my ($start,$end)=split(/\./,$ENV{$_});
94: if (($start) && ($start>time)) { next; }
95: if (($end) && (time>$end)) { next; }
96: my $ca; my $cd;
97: if ($1 eq 'au') {
98: $ca=$ENV{'user.name'};
99: $cd=$ENV{'user.domain'};
100: } else {
101: ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
102: }
1.107 albertel 103: my $allowed=0;
104: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
105: my @ids=&Apache::lonnet::current_machine_ids();
106: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
107: if ($allowed) {
1.74 www 108: $home++;
109: $outhash{'home_'.$ca.'@'.$cd}=1;
110: } else {
1.107 albertel 111: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74 www 112: $other++;
113: }
114: }
115: }
116: return ($home,$other,%outhash);
117: }
118: # ------------------------------------------------------ Generate "dump" button
119:
120: sub dumpbutton {
121: my ($home,$other,%outhash)=&authorhosts();
122: if ($home+$other==0) { return ''; }
123: my $output='</td><td bgcolor="#DDDDCC">';
124: if ($home) {
125: return '</td><td bgcolor="#DDDDCC">'.
1.81 www 126: '<input type="submit" name="dumpcourse" value="'.
1.130 www 127: &mt('Dump Course DOCS to Construction Space').'" />'.
128: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
1.74 www 129: } else {
130: return'</td><td bgcolor="#DDDDCC">'.
1.81 www 131: &mt('Dump Course DOCS to Construction Space: available on other servers');
1.74 www 132: }
133: }
134:
135: # -------------------------------------------------------- Actually dump course
136:
137: sub dumpcourse {
1.75 www 138: my $r=shift;
139: $r->print('<html><head><title>Dump DOCS</title></head>'.
1.76 www 140: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
141: '<form name="dumpdoc" method="post">');
1.74 www 142: my ($home,$other,%outhash)=&authorhosts();
1.75 www 143: unless ($home) { return ''; }
1.76 www 144: my $origcrsid=$ENV{'request.course.id'};
145: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
146: if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
147: # Do the dumping
1.75 www 148: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
149: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
1.87 www 150: $r->print('<h3>'.&mt('Copying Files').'</h3>');
1.76 www 151: my $title=$ENV{'form.authorfolder'};
1.79 www 152: $title=~s/[^\w\/]+/\_/g;
153: my %replacehash=();
154: foreach (keys %ENV) {
155: if ($_=~/^form\.namefor\_(.+)/) {
156: $replacehash{$1}=$ENV{$_};
157: }
158: }
159: my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
160: $crs=~s/\_/\//g;
161: foreach (keys %replacehash) {
162: my $newfilename=$title.'/'.$replacehash{$_};
1.132 www 163: $newfilename=~s/[^\w\/\.\/]+/\_/g;
1.79 www 164: my @dirs=split(/\//,$newfilename);
165: my $path='/home/'.$ca.'/public_html';
166: my $makepath=$path;
167: my $fail=0;
168: for (my $i=0;$i<$#dirs;$i++) {
169: $makepath.='/'.$dirs[$i];
170: unless (-e $makepath) {
171: unless(mkdir($makepath,0777)) { $fail=1; }
172: }
173: }
174: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
175: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
176: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
177: print $fh &Apache::loncreatecourse::rewritefile(
178: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
179: (%replacehash,$crs => '')
180: );
181: } else {
182: print $fh
183: &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
184: }
185: $fh->close();
186: } else {
187: $fail=1;
188: }
189: if ($fail) {
190: $r->print('<font color="red">fail</font>');
191: } else {
192: $r->print('<font color="green">ok</font>');
193: }
194: }
1.76 www 195: } else {
196: # Input form
197: unless ($home==1) {
198: $r->print(
1.81 www 199: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76 www 200: }
201: foreach (sort keys %outhash) {
202: if ($_=~/^home_(.+)$/) {
203: if ($home==1) {
204: $r->print(
205: '<input type="hidden" name="authorspace" value="'.$1.'" />');
206: } else {
1.133 www 207: $r->print('<option value="'.$1.'">'.$1.' - '.
208: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76 www 209: }
210: }
211: }
212: unless ($home==1) {
213: $r->print('</select>');
214: }
215: my $title=$origcrsdata{'description'};
216: $title=~s/\s+/\_/gs;
217: $title=~s/\W//gs;
1.81 www 218: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76 www 219: &tiehash();
1.81 www 220: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
1.76 www 221: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
1.78 www 222: $r->print('<tr><td>'.$_.'</td>');
223: my ($ext)=($_=~/\.(\w+)$/);
224: my $title=$hash{'title_'.$hash{
225: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
226: $r->print('<td>'.($title?$title:' ').'</td>');
227: unless ($title) {
228: $title=$_;
229: }
230: $title=~s/\.(\w+)$//;
1.132 www 231: $title=~s/[^\w\/]+/\_/gs;
1.78 www 232: $title.='.'.$ext;
1.79 www 233: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
1.76 www 234: }
1.78 www 235: $r->print("</table>\n");
1.76 www 236: &untiehash();
237: $r->print(
1.81 www 238: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
1.75 www 239: }
1.74 www 240: }
1.76 www 241:
1.138 raeburn 242: # ------------------------------------------------------ Generate "export" button
243:
244: sub exportbutton {
1.161 albertel 245: return '';
1.138 raeburn 246: return '</td><td bgcolor="#DDDDCC">'.
247: '<input type="submit" name="exportcourse" value="'.
248: &mt('Export Course to IMS').'" />'.
249: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
250: }
251:
252: sub exportcourse {
253: my $r=shift;
254: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
255: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
256: my $numdisc = keys %discussiontime;
257: my $navmap = Apache::lonnavmaps::navmap->new();
258: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
259: my $curRes;
1.143 raeburn 260: my $outcome;
1.138 raeburn 261:
262: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
263: ['finishexport']);
264: if ($ENV{'form.finishexport'}) {
265: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
266: ['archive','discussion']);
267:
268: my @exportitems = ();
269: if (defined($ENV{'form.archive'})) {
270: if (ref($ENV{'form.archive'}) eq 'ARRAY') {
271: @exportitems = @{$ENV{'form.archive'}};
272: } else {
273: $exportitems[0] = $ENV{'form.archive'};
274: }
275: }
276: my @discussions = ();
277: if (defined($ENV{'form.discussion'})) {
278: if (ref($ENV{'form.discussion'}) eq 'ARRAY') {
279: @discussions = $ENV{'form.discussion'};
280: } else {
281: $discussions[0] = $ENV{'form.discussion'};
282: }
283: }
1.143 raeburn 284: if (@exportitems == 0 && @discussions == 0) {
285: $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created. Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
286: } else {
287: my $now = time;
288: my %symbs;
289: my $manifestok = 0;
290: my $imsresources;
291: my $tempexport;
292: my $copyresult;
293: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
294: if ($manifestok) {
1.157 raeburn 295: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
1.143 raeburn 296: close($ims_manifest);
297:
298: #Create zip file in prtspool
299: my $imszipfile = '/prtspool/'.
300: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
301: time.'_'.rand(1000000000).'.zip';
302: # zip can cause an sh launch which can pass along all of %ENV
303: # which can be too large for /bin/sh to handle
304: my %oldENV=%ENV;
305: undef(%ENV);
306: my $cwd = &Cwd::getcwd();
307: my $imszip = '/home/httpd/'.$imszipfile;
308: chdir $tempexport;
309: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
310: close(OUTPUT);
311: chdir $cwd;
312: %ENV=%oldENV;
313: undef(%oldENV);
314: $outcome .= 'Download the zip file from <a href="'.$imszipfile.'">IMS course archive</a><br />';
315: if ($copyresult) {
316: $outcome .= 'The following errors occurred during export - '.$copyresult;
1.138 raeburn 317: }
1.143 raeburn 318: } else {
319: $outcome = '<br />Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.<br />';
1.138 raeburn 320: }
321: }
322:
323: $r->print('<html><head><title>Export Course</title></head>'.
1.158 raeburn 324: &Apache::loncommon::bodytag('Export course to IMS content package'));
1.143 raeburn 325: $r->print($outcome);
1.138 raeburn 326: $r->print('</body></html>');
327: } else {
328: my $display;
329: $display = '<form name="exportdoc" method="post">'."\n";
330: $display .= 'Choose which items you wish to export from your course.<br /><br />';
331: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
332: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
333: '<input type="button" value="check all" '.
334: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
335: ' <input type="button" value="uncheck all"'.
336: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
337: '<td> </td><td> </td>'.
338: '<td align="right"><fieldset><legend> <b>Discussion posts'.
339: '</b></legend><input type="button" value="check all"'.
340: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
341: ' <input type="button" value="uncheck all"'.
342: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
343: '</tr></table>';
344: my $curRes;
345: my $depth = 0;
346: my $count = 0;
347: my $boards = 0;
348: my $startcount = 5;
349: my %parent = ();
350: my %children = ();
351: my $lastcontainer = $startcount;
352: my @bgcolors = ('#F6F6F6','#FFFFFF');
353: $display .= '<table cellspacing="0"><tr>'.
354: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
355: if ($numdisc > 0) {
356: $display.='<b>Export discussion posts?</b>'."\n";
357: }
358: $display.=' </td></tr>';
359: while ($curRes = $it->next()) {
360: if (ref($curRes)) {
361: $count ++;
362: }
363: if ($curRes == $it->BEGIN_MAP()) {
364: $depth++;
365: $parent{$depth} = $lastcontainer;
366: }
367: if ($curRes == $it->END_MAP()) {
368: $depth--;
369: $lastcontainer = $parent{$depth};
370: }
371: if (ref($curRes)) {
372: my $symb = $curRes->symb();
1.158 raeburn 373: my $ressymb = $symb;
374: if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
375: unless ($ressymb =~ m|adm/wrapper/adm|) {
376: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
377: }
378: }
1.138 raeburn 379: my $color = $count%2;
380: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
381: '<input type="checkbox" name="archive" value="'.$count.'" ';
382: if (($curRes->is_sequence()) || ($curRes->is_page())) {
383: my $checkitem = $count + $boards + $startcount;
384: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
385: }
386: $display .= ' />'."\n";
387: for (my $i=0; $i<$depth; $i++) {
388: $display .= '<img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" /><img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" />'."\n";
389: }
390: if ($curRes->is_sequence()) {
391: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
392: $lastcontainer = $count + $startcount + $boards;
393: } elsif ($curRes->is_page()) {
394: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
395: $lastcontainer = $count + $startcount + $boards;
396: }
397: my $currelem = $count+$boards+$startcount;
398: $children{$parent{$depth}} .= $currelem.':';
399: $display .= ' '.$curRes->title().'</td>';
1.158 raeburn 400: if ($discussiontime{$ressymb} > 0) {
1.138 raeburn 401: $boards ++;
402: $currelem = $count+$boards+$startcount;
403: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
404: } else {
405: $display .= '<td colspan="2"> </td>'."\n";
406: }
407: }
408: }
409: my $scripttag = qq|
410: <script>
411:
412: function checkAll(field) {
1.158 raeburn 413: if (field.length > 0) {
414: for (i = 0; i < field.length; i++) {
415: field[i].checked = true ;
416: }
417: } else {
418: field.checked = true
419: }
1.138 raeburn 420: }
1.158 raeburn 421:
1.138 raeburn 422: function uncheckAll(field) {
1.158 raeburn 423: if (field.length > 0) {
424: for (i = 0; i < field.length; i++) {
425: field[i].checked = false ;
426: }
427: } else {
428: field.checked = false ;
429: }
1.138 raeburn 430: }
431:
432: function propagateCheck(item) {
433: if (document.exportdoc.elements[item].checked == true) {
434: containerCheck(item)
435: }
436: }
437:
438: function containerCheck(item) {
439: document.exportdoc.elements[item].checked = true
440: var numitems = $count + $boards + $startcount
441: var parents = new Array(numitems)
442: for (var i=$startcount; i<numitems; i++) {
443: parents[i] = new Array
444: }
445: |;
446:
447: foreach my $container (sort { $a <=> $b } keys %children) {
448: my @contents = split/:/,$children{$container};
449: for (my $i=0; $i<@contents; $i ++) {
450: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
451: }
452: }
453:
454: $scripttag .= qq|
455: if (parents[item].length > 0) {
456: for (var j=0; j<parents[item].length; j++) {
457: containerCheck(parents[item][j])
458: }
459: }
460: }
461:
462: </script>
463: |;
464: $r->print('<html><head><title>Export Course</title>'.$scripttag.'</head>'.
1.158 raeburn 465: &Apache::loncommon::bodytag('Export course to IMS content package'
1.138 raeburn 466: ));
467:
468: $r->print($display.'</table>'.
469: '<p><input type="hidden" name="finishexport" value="1">'.
470: '<input type="submit" name="exportcourse" value="'.
471: &mt('Export Course DOCS').'" /></p></form></body></html>');
472: }
473: }
474:
1.143 raeburn 475: sub create_ims_store {
476: my ($now,$manifestok,$outcome,$tempexport) = @_;
477: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
478: my $ims_manifest;
479: if (!-e $$tempexport) {
480: mkdir($$tempexport,0700);
481: }
482: $$tempexport .= '/'.$now;
483: if (!-e $$tempexport) {
484: mkdir($$tempexport,0700);
485: }
486: $$tempexport .= '/'.$ENV{'user.domain'}.'_'.$ENV{'user.name'};
487: if (!-e $$tempexport) {
488: mkdir($$tempexport,0700);
489: }
1.159 raeburn 490: if (!-e "$$tempexport/resources") {
491: mkdir("$$tempexport/resources",0700);
492: }
1.143 raeburn 493: # open manifest file
494: my $manifest = '/imsmanifest.xml';
495: my $manifestfilename = $$tempexport.$manifest;
496: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
497: $$manifestok=1;
498: print $ims_manifest
499: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
500: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
501: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
502: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
503: ' identifier="MANIFEST-'.$ENV{'request.course.id'}.'-'.$now.'"'.
504: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
505: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
1.158 raeburn 506: ' <organizations default="ORG-'.$ENV{'request.course.id'}.'-'.$now.'">'."\n".
1.143 raeburn 507: ' <organization identifier="ORG-'.$ENV{'request.course.id'}.'-'.$now.'"'.
508: ' structure="hierarchical">'."\n".
509: ' <title>'.$ENV{'request.'.$ENV{'request.course.id'}.'.description'}.'</title>'
510: } else {
511: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
512: ;
513: }
514: return $ims_manifest;
515: }
516:
517: sub build_package {
518: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
519: # first iterator to look for dependencies
520: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
521: my $curRes;
522: my $count = 0;
523: my $depth = 0;
524: my $lastcontainer = 0;
525: my %parent = ();
526: my @dependencies = ();
1.157 raeburn 527: my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
528: my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1.143 raeburn 529: while ($curRes = $it->next()) {
530: if (ref($curRes)) {
531: $count ++;
532: }
533: if ($curRes == $it->BEGIN_MAP()) {
534: $depth++;
535: $parent{$depth} = $lastcontainer;
536: }
537: if ($curRes == $it->END_MAP()) {
538: $depth--;
539: $lastcontainer = $parent{$depth};
540: }
541: if (ref($curRes)) {
542: if ($curRes->is_sequence() || $curRes->is_page()) {
543: $lastcontainer = $count;
544: }
545: if (grep/^$count$/,@$exportitems) {
546: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
547: }
548: }
549: }
550: # second iterator to build manifest and store resources
551: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
552: $depth = 0;
553: my $prevdepth;
554: $count = 0;
555: my $imsresources;
556: my $pkgdepth;
1.157 raeburn 557: my $included = 0;
558: while ($curRes = $it->next()) {
559: if ($curRes == $it->BEGIN_MAP()) {
560: $prevdepth = $depth;
561: $depth++;
562: }
563: if ($curRes == $it->END_MAP()) {
1.143 raeburn 564: $prevdepth = $depth;
1.157 raeburn 565: $depth--;
566: }
567:
568: if (ref($curRes)) {
569: $count ++;
570: if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
571: my $symb = $curRes->symb();
572: my $isvisible = 'true';
573: my $resourceref;
574: if ($curRes->randomout()) {
575: $isvisible = 'false';
576: }
577: unless ($curRes->is_sequence()) {
578: $resourceref = 'identifierref="RES-'.$ENV{'request.course.id'}.'-'.$count.'"';
579: }
580: if (($depth <= $prevdepth) && ($count > 1) && ($included)) {
581: print $ims_manifest "\n".' </item>'."\n";
582: }
583: $included = 1;
584: $prevdepth = $depth;
1.143 raeburn 585:
1.157 raeburn 586: my $itementry =
1.143 raeburn 587: '<item identifier="ITEM-'.$ENV{'request.course.id'}.'-'.$count.
588: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
589: '<title>'.$curRes->title().'</title>';
1.157 raeburn 590: print $ims_manifest "\n".$itementry;
1.143 raeburn 591:
1.157 raeburn 592: unless ($curRes->is_sequence()) {
593: my $content_file;
594: my @hrefs = ();
595: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
596: if ($content_file) {
597: $imsresources .= "\n".
1.143 raeburn 598: ' <resource identifier="RES-'.$ENV{'request.course.id'}.'-'.$count.
599: '" type="webcontent" href="'.$content_file.'">'."\n".
600: ' <file href="'.$content_file.'" />'."\n";
1.157 raeburn 601: foreach (@hrefs) {
602: $imsresources .=
1.143 raeburn 603: ' <file href="'.$_.'" />'."\n";
1.157 raeburn 604: }
1.158 raeburn 605: if (grep/^$count$/,@$discussions) {
606: my $ressymb = $symb;
607: my $mode;
608: if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
609: unless ($ressymb =~ m|adm/wrapper/adm|) {
610: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
611: }
612: $mode = 'board';
613: }
614: my %extras = (
615: caller => 'imsexport',
1.159 raeburn 616: tempexport => $tempexport.'/resources',
1.158 raeburn 617: count => $count
618: );
619: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
620: }
1.157 raeburn 621: $imsresources .= ' </resource>'."\n";
1.143 raeburn 622: }
623: }
1.157 raeburn 624: $pkgdepth = $depth;
625: } else {
626: $included = 0;
1.143 raeburn 627: }
628: }
629: }
1.157 raeburn 630: while ($pkgdepth > 0) {
1.143 raeburn 631: print $ims_manifest " </item>\n";
632: $pkgdepth --;
633: }
634: my $resource_text = qq|
635: </organization>
636: </organizations>
637: <resources>
638: $imsresources
639: </resources>
640: </manifest>
641: |;
642: print $ims_manifest $resource_text;
643: }
644:
645: sub get_dependencies {
646: my ($exportitems,$parent,$depth,$dependencies) = @_;
647: if ($depth > 1) {
1.157 raeburn 648: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
1.143 raeburn 649: push @$dependencies, $$parent{$depth};
650: if ($depth > 2) {
651: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
652: }
653: }
654: }
655: }
656:
657: sub process_content {
658: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
659: my $content_type;
660: my $message;
661: # find where user is author or co-author
1.158 raeburn 662: my @uploads = ();
1.157 raeburn 663: if ($curRes->is_sequence()) {
664: $content_type = 'sequence';
665: } elsif ($curRes->is_page()) {
666: $content_type = 'page'; # need to handle individual items in pages.
1.143 raeburn 667: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
668: $content_type = 'syllabus';
1.158 raeburn 669: my $contents = &Apache::imsexport::templatedpage($content_type);
670: if ($contents) {
671: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
672: }
1.157 raeburn 673: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
1.143 raeburn 674: $content_type = 'external';
1.158 raeburn 675: my $title = $curRes->title;
676: my $contents = &Apache::imsexport::external($symb,$title);
677: if ($contents) {
678: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
679: }
1.143 raeburn 680: } elsif ($symb =~ m-adm/navmaps$-) {
681: $content_type = 'navmap';
1.158 raeburn 682: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
1.143 raeburn 683: $content_type = 'simplepage';
1.158 raeburn 684: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
685: if ($contents) {
686: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
687: }
688: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
1.143 raeburn 689: $content_type = 'simpleproblem';
1.158 raeburn 690: my $contents = &Apache::imsexport::simpleproblem($symb);
691: if ($contents) {
692: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
693: }
694: } elsif ($symb =~ m-lib/templates/examupload\.problem-m) {
695: $content_type = 'examupload';
696: } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
1.143 raeburn 697: $content_type = 'bulletinboard';
1.158 raeburn 698: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
699: if ($contents) {
700: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
701: }
702: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
1.143 raeburn 703: $content_type = 'aboutme';
1.158 raeburn 704: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
705: if ($contents) {
706: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
707: }
1.157 raeburn 708: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
709: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.162 ! raeburn 710: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
1.143 raeburn 711: my $canedit = 0;
1.157 raeburn 712: if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'}) {
1.143 raeburn 713: $canedit= 1;
714: }
715: if ($canedit) {
1.157 raeburn 716: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
1.143 raeburn 717: } else {
1.157 raeburn 718: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
1.143 raeburn 719: }
1.162 ! raeburn 720: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
! 721: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.143 raeburn 722: }
1.158 raeburn 723: if (@uploads > 0) {
724: foreach my $item (@uploads) {
725: my $uploadmsg = '';
1.159 raeburn 726: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
1.158 raeburn 727: if ($uploadmsg) {
728: $$copyresult .= $uploadmsg."\n";
729: }
730: }
731: }
1.157 raeburn 732: if ($message) {
733: $$copyresult .= $message."\n";
734: }
1.143 raeburn 735: }
736:
737: sub replicate_content {
1.157 raeburn 738: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
1.159 raeburn 739: my ($map,$ind,$url);
740: if ($caller eq 'templateupload') {
741: $url = $symb;
742: $url =~ s#//#/#g;
743: } else {
744: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
745: }
1.143 raeburn 746: my $content;
747: my $filename;
748: my $repstatus;
1.157 raeburn 749: my $content_name;
750: if ($url =~ m-/([^/]+)$-) {
1.143 raeburn 751: $filename = $1;
752: if (!-e $tempexport.'/resources') {
753: mkdir($tempexport.'/resources',0700);
754: }
1.157 raeburn 755: if (!-e $tempexport.'/resources/'.$count) {
1.143 raeburn 756: mkdir($tempexport.'/resources/'.$count,0700);
757: }
1.157 raeburn 758: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
1.143 raeburn 759: my $copiedfile;
760: if ($copiedfile = Apache::File->new('>'.$destination)) {
761: my $content;
1.157 raeburn 762: if ($caller eq 'resource') {
1.162 ! raeburn 763: $content = &Apache::lonnet::getfile('/home/httpd/html/res/'.$url);
1.143 raeburn 764: if ($content eq -1) {
765: $$message = 'Could not copy file '.$filename;
766: } else {
1.157 raeburn 767: &extract_media($content,$count,$tempexport,$href,'resource');
1.143 raeburn 768: $repstatus = 'ok';
769: }
1.162 ! raeburn 770: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
1.143 raeburn 771: my $rtncode;
1.157 raeburn 772: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
773: if ($repstatus eq 'ok') {
774: if ($url =~ /\.html?$/i) {
775: &extract_media(\$content,$count,$tempexport,$href,'uploaded');
776: }
777: } else {
1.143 raeburn 778: $$message = 'Could not render '.$url.' server message - '.$rtncode;
779: }
1.162 ! raeburn 780: } elsif ($caller eq 'noedit') {
! 781: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
! 782: $repstatus = 'ok';
! 783: $content = 'Not the owner of this resource';
1.143 raeburn 784: }
785: if ($repstatus eq 'ok') {
786: print $copiedfile $content;
787: }
788: close($copiedfile);
789: } else {
790: $$message = 'Could not open destination file for '.$filename."\n";
791: }
792: } else {
1.159 raeburn 793: $$message = 'Could not determine name of file for '.$symb."\n";
1.143 raeburn 794: }
1.157 raeburn 795: if ($repstatus eq 'ok') {
796: $content_name = $count.'/'.$filename;
797: }
798: return $content_name;
799: }
800:
801: sub extract_media {
802: my ($content,$count,$tempexport,$href,$caller) = @_;
803: # @$href will contain path to any embedded resources in the content.
804: # For LON-CAPA problems this would be images. applets etc.
805: # For uploaded HTML files this would be images etc.
806: # paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths.
807: return;
1.143 raeburn 808: }
1.74 www 809:
1.158 raeburn 810: sub store_template {
811: my ($contents,$tempexport,$count,$content_type) = @_;
812: if ($contents) {
1.159 raeburn 813: if ($tempexport) {
814: if (!-e $tempexport.'/resources') {
815: mkdir($tempexport.'/resources',0700);
816: }
817: if (!-e $tempexport.'/resources/'.$count) {
818: mkdir($tempexport.'/resources/'.$count,0700);
819: }
820: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
821: my $storetemplate;
822: if ($storetemplate = Apache::File->new('>'.$destination)) {
823: print $storetemplate $contents;
824: close($storetemplate);
825: }
826: if ($content_type eq 'external') {
827: return $count.'/'.$content_type.'.html';
828: } else {
829: return $count.'/'.$content_type.'.xml';
830: }
1.158 raeburn 831: }
832: }
833: }
834:
1.73 bowersj2 835: # Imports the given (name, url) resources into the course
836: # coursenum, coursedom, and folder must precede the list
837: sub group_import {
838: my $coursenum = shift;
839: my $coursedom = shift;
840: my $folder = shift;
1.142 raeburn 841: my $container = shift;
842: my $caller = shift;
1.73 bowersj2 843: while (@_) {
844: my $name = shift;
845: my $url = shift;
1.142 raeburn 846: if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
847: my $errtext = '';
848: my $fatal = 0;
849: my $newmapstr = '<map>'."\n".
850: '<resource id="1" src="" type="start"></resource>'."\n".
851: '<link from="1" to="2" index="1"></link>'."\n".
852: '<resource id="2" src="" type="finish"></resource>'."\n".
853: '</map>';
854: $ENV{'form.output'}=$newmapstr;
855: my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
856: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
857: 'output',$1.$2);
858: if ($result != m|^/uploaded/|) {
859: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
860: $fatal = 2;
861: }
862: if ($fatal) {
863: return ($errtext,$fatal);
864: }
865: }
1.73 bowersj2 866: if ($url) {
867: my $idx = $#Apache::lonratedt::resources + 1;
868: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
869: my $ext = 'false';
870: if ($url=~/^http:\/\//) { $ext = 'true'; }
871: $url =~ s/:/\:/g;
872: $name =~ s/:/\:/g;
873: $Apache::lonratedt::resources[$idx] =
874: join ':', ($name, $url, $ext, 'normal', 'res');
875: }
876: }
1.142 raeburn 877: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73 bowersj2 878: }
879:
1.114 albertel 880: sub breadcrumbs {
881: my ($where)=@_;
882: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142 raeburn 883: my (@folders);
884: if ($ENV{'form.pagepath'}) {
885: @folders = split('&',$ENV{'form.pagepath'});
886: } else {
887: @folders=split('&',$ENV{'form.folderpath'});
888: }
1.116 albertel 889: my $folderpath;
890: while (@folders) {
891: my $folder=shift(@folders);
892: my $foldername=shift(@folders);
893: if ($folderpath) {$folderpath.='&';}
894: $folderpath.=$folder.'&'.$foldername;
895: my $url='/adm/coursedocs?folderpath='.
896: &Apache::lonnet::escape($folderpath);
1.114 albertel 897: &Apache::lonhtmlcommon::add_breadcrumb(
898: {'href'=>$url,
899: 'title'=>&Apache::lonnet::unescape($foldername),
1.117 albertel 900: 'text'=>'<font size="+1">'.
901: &Apache::lonnet::unescape($foldername).'</font>'
902: });
1.114 albertel 903:
904:
905: }
1.137 albertel 906: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
907: 0,'nohelp');
1.114 albertel 908: }
909:
1.7 www 910: sub editor {
911: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.114 albertel 912:
913: $r->print(&breadcrumbs($folder));
1.10 www 914: my $errtext='';
915: my $fatal=0;
1.142 raeburn 916: my $container='sequence';
917: if ($ENV{'form.pagepath'}) {
918: $container='page';
919: }
1.10 www 920: ($errtext,$fatal)=
1.142 raeburn 921: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17 www 922: if ($#Apache::lonratedt::order<1) {
923: $Apache::lonratedt::order[0]=1;
924: $Apache::lonratedt::resources[1]='';
925: }
1.7 www 926: if ($fatal) {
927: $r->print('<p><font color="red">'.$errtext.'</font></p>');
928: } else {
929: # ------------------------------------------------------------ Process commands
1.121 www 930:
1.16 www 931: # ---------------- if they are for this folder and user allowed to make changes
932: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.123 www 933: # set parameters and change order
1.121 www 934: if (defined($ENV{'form.setparms'})) {
935: my $idx=$ENV{'form.setparms'};
1.123 www 936: # set parameters
1.121 www 937: if ($ENV{'form.randpick_'.$idx}) {
1.122 www 938: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
1.121 www 939: } else {
1.122 www 940: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121 www 941: }
942: if ($ENV{'form.hidprs_'.$idx}) {
1.122 www 943: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121 www 944: } else {
1.122 www 945: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121 www 946: }
947: if ($ENV{'form.encprs_'.$idx}) {
1.122 www 948: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121 www 949: } else {
1.122 www 950: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121 www 951: }
952:
1.123 www 953: if ($ENV{'form.newpos'}) {
954: # change order
955:
956: my $newpos=$ENV{'form.newpos'}-1;
1.124 www 957: my $currentpos=$ENV{'form.currentpos'}-1;
1.125 www 958: my $i;
959: my @neworder=();
960: if ($newpos>$currentpos) {
961: # moving stuff up
962: for ($i=0;$i<$currentpos;$i++) {
963: $neworder[$i]=$Apache::lonratedt::order[$i];
964: }
965: for ($i=$currentpos;$i<$newpos;$i++) {
966: $neworder[$i]=$Apache::lonratedt::order[$i+1];
967: }
968: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
969: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
970: $neworder[$i]=$Apache::lonratedt::order[$i];
971: }
972: } else {
973: # moving stuff down
974: for ($i=0;$i<$newpos;$i++) {
975: $neworder[$i]=$Apache::lonratedt::order[$i];
976: }
977: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
978: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
979: $neworder[$i]=$Apache::lonratedt::order[$i-1];
980: }
981: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
982: $neworder[$i]=$Apache::lonratedt::order[$i];
983: }
984: }
985: @Apache::lonratedt::order=@neworder;
1.124 www 986: }
987: # store the changed version
1.123 www 988:
1.142 raeburn 989: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124 www 990: if ($fatal) {
991: $r->print('<p><font color="red">'.$errtext.'</font></p>');
992: return;
1.123 www 993: }
1.124 www 994:
995: }
1.123 www 996:
1.10 www 997: # upload a file, if present
998: if (($ENV{'form.uploaddoc.filename'}) &&
999: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
1.112 raeburn 1000: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
1.10 www 1001: # this is for a course, not a user, so set coursedoc flag
1002: # probably the only place in the system where this should be "1"
1.126 albertel 1003: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
1.10 www 1004: my $ext='false';
1005: if ($url=~/^http\:\/\//) { $ext='true'; }
1006: $url=~s/\:/\:/g;
1007: my $comment=$ENV{'form.comment'};
1008: $comment=~s/\</\<\;/g;
1009: $comment=~s/\>/\>\;/g;
1010: $comment=~s/\:/\:/g;
1.17 www 1011: if ($folder=~/^supplemental/) {
1012: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
1013: $ENV{'user.domain'}.'___&&&___'.$comment;
1014: }
1.10 www 1015: my $newidx=$#Apache::lonratedt::resources+1;
1016: $Apache::lonratedt::resources[$newidx]=
1017: $comment.':'.$url.':'.$ext.':normal:res';
1018: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
1019: $newidx;
1.104 albertel 1020:
1.142 raeburn 1021: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.104 albertel 1022: if ($fatal) {
1023: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1024: return;
1025: }
1.10 www 1026: }
1027: }
1.8 www 1028: if ($ENV{'form.cmd'}) {
1.10 www 1029: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
1030: if ($cmd eq 'del') {
1.128 albertel 1031: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1032: if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
1033: &Apache::lonnet::removeuploadedurl($url);
1034: }
1.10 www 1035: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
1036: $Apache::lonratedt::order[$i]=
1037: $Apache::lonratedt::order[$i+1];
1038: }
1039: $#Apache::lonratedt::order--;
1040: } elsif ($cmd eq 'up') {
1.38 www 1041: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10 www 1042: my $i=$Apache::lonratedt::order[$idx-1];
1043: $Apache::lonratedt::order[$idx-1]=
1044: $Apache::lonratedt::order[$idx];
1045: $Apache::lonratedt::order[$idx]=$i;
1.38 www 1046: }
1.10 www 1047: } elsif ($cmd eq 'down') {
1.38 www 1048: if (defined($Apache::lonratedt::order[$idx+1])) {
1.10 www 1049: my $i=$Apache::lonratedt::order[$idx+1];
1050: $Apache::lonratedt::order[$idx+1]=
1051: $Apache::lonratedt::order[$idx];
1052: $Apache::lonratedt::order[$idx]=$i;
1.38 www 1053: }
1.36 www 1054: } elsif ($cmd eq 'rename') {
1.142 raeburn 1055: my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36 www 1056: my ($rtitle,@rrest)=split(/\:/,
1057: $Apache::lonratedt::resources[
1058: $Apache::lonratedt::order[$idx]]);
1.38 www 1059: my $comment=
1060: &HTML::Entities::decode($ENV{'form.title'});
1.36 www 1061: $comment=~s/\</\<\;/g;
1062: $comment=~s/\>/\>\;/g;
1063: $comment=~s/\:/\:/g;
1.144 albertel 1064: if ($comment=~/\S/) {
1065: $Apache::lonratedt::resources[
1.36 www 1066: $Apache::lonratedt::order[$idx]]=
1.144 albertel 1067: $comment.':'.join(':',@rrest);
1068: }
1.10 www 1069: }
1070: # Store the changed version
1.104 albertel 1071: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1072: $folder.'.'.$container);
1.104 albertel 1073: if ($fatal) {
1074: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1075: return;
1076: }
1.8 www 1077: }
1.11 www 1078: # Group import/search
1079: if ($ENV{'form.importdetail'}) {
1.73 bowersj2 1080: my @imports;
1081: foreach (split(/\&/,$ENV{'form.importdetail'})) {
1082: if (defined($_)) {
1083: my ($name,$url)=split(/\=/,$_);
1084: $name=&Apache::lonnet::unescape($name);
1085: $url=&Apache::lonnet::unescape($url);
1086: push @imports, $name, $url;
1087: }
1088: }
1.11 www 1089: # Store the changed version
1.104 albertel 1090: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142 raeburn 1091: $container,'londocs',@imports);
1.104 albertel 1092: if ($fatal) {
1093: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1094: return;
1095: }
1.11 www 1096: }
1.53 www 1097: # Loading a complete map
1098: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1.104 albertel 1099: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.53 www 1100: my $idx=$#Apache::lonratedt::resources;
1101: $idx++;
1102: $Apache::lonratedt::resources[$idx]=$_;
1103: $Apache::lonratedt::order
1.104 albertel 1104: [$#Apache::lonratedt::order+1]=$idx;
1105: }
1.53 www 1106:
1107: # Store the changed version
1.104 albertel 1108: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1109: $folder.'.'.$container);
1.104 albertel 1110: if ($fatal) {
1111: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1112: return;
1113: }
1.53 www 1114: }
1.16 www 1115: }
1116: # ---------------------------------------------------------------- End commands
1.7 www 1117: # ---------------------------------------------------------------- Print screen
1.10 www 1118: my $idx=0;
1.148 www 1119: my $shown=0;
1.10 www 1120: $r->print('<table>');
1121: foreach (@Apache::lonratedt::order) {
1122: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1123: unless ($name) { $name=(split(/\//,$url))[-1]; }
1.148 www 1124: unless ($name) { $idx++; next; }
1.112 raeburn 1125: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10 www 1126: $idx++;
1.148 www 1127: $shown++;
1.10 www 1128: }
1.148 www 1129: unless ($shown) {
1.131 www 1130: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1131: }
1.10 www 1132: $r->print('</table>');
1.7 www 1133: }
1134: }
1.1 www 1135:
1.8 www 1136: # --------------------------------------------------------------- An entry line
1137:
1138: sub entryline {
1.112 raeburn 1139: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38 www 1140: $title=~s/\&colon\;/\:/g;
1141: $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109 albertel 1142: &Apache::lonnet::unescape($title)),'"<>&\'');
1.38 www 1143: my $renametitle=$title;
1144: my $foldertitle=$title;
1.142 raeburn 1145: my $pagetitle=$title;
1.122 www 1146: my $orderidx=$Apache::lonratedt::order[$index];
1.109 albertel 1147: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
1148: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1149: $renametitle=$4;
1150: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
1151: &Apache::loncommon::plainname($2,$3).': <br />'.
1152: $foldertitle;
1153: }
1.38 www 1154: $renametitle=~s/\"\;/\\\"/g;
1.8 www 1155: my $line='<tr>';
1156: # Edit commands
1.142 raeburn 1157: my $container;
1.120 www 1158: my $folderpath;
1159: if ($ENV{'form.folderpath'}) {
1.142 raeburn 1160: $container = 'sequence';
1.120 www 1161: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
1162: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
1163: }
1.156 albertel 1164: my ($pagepath,$pagesymb);
1.142 raeburn 1165: if ($ENV{'form.pagepath'}) {
1166: $container = 'page';
1167: $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
1.156 albertel 1168: $pagesymb=&Apache::lonnet::escape($ENV{'form.pagesymb'});
1.142 raeburn 1169: }
1.109 albertel 1170: if ($allowed) {
1.123 www 1171: my $incindex=$index+1;
1172: my $selectbox='';
1173: if ($folder!~/^supplemental/) {
1174: $selectbox=
1.124 www 1175: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123 www 1176: '<select name="newpos" onChange="this.form.submit()">';
1177: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
1178: if ($i==$incindex) {
1179: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1180: } else {
1181: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1182: }
1183: }
1184: $selectbox.='</select>';
1185: }
1.119 www 1186: my %lt=&Apache::lonlocal::texthash(
1187: 'up' => 'Move Up',
1.109 albertel 1188: 'dw' => 'Move Down',
1189: 'rm' => 'Remove',
1190: 'rn' => 'Rename');
1.142 raeburn 1191: if ($ENV{'form.pagepath'}) {
1192: $line.=(<<END);
1193: <form name="entry_$index" action="/adm/coursedocs" method="post">
1194: <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
1.156 albertel 1195: <input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
1.142 raeburn 1196: <input type="hidden" name="setparms" value="$orderidx" />
1197: <td><table border='0' cellspacing='2' cellpadding='0'>
1198: <tr><td bgcolor="#DDDDDD">
1.156 albertel 1199: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1.142 raeburn 1200: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1201: <tr><td bgcolor="#DDDDDD">
1.156 albertel 1202: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1.142 raeburn 1203: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1204: </table></td>
1205: <td>$selectbox
1206: </td><td bgcolor="#DDDDDD">
1.156 albertel 1207: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142 raeburn 1208: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.156 albertel 1209: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142 raeburn 1210: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1211: END
1212: } else {
1213: $line.=(<<END);
1.121 www 1214: <form name="entry_$index" action="/adm/coursedocs" method="post">
1215: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.122 www 1216: <input type="hidden" name="setparms" value="$orderidx" />
1.54 www 1217: <td><table border='0' cellspacing='2' cellpadding='0'>
1218: <tr><td bgcolor="#DDDDDD">
1.115 albertel 1219: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1.90 www 1220: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54 www 1221: <tr><td bgcolor="#DDDDDD">
1.115 albertel 1222: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1.90 www 1223: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123 www 1224: </table></td>
1225: <td>$selectbox
1226: </td><td bgcolor="#DDDDDD">
1.142 raeburn 1227: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90 www 1228: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.142 raeburn 1229: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.90 www 1230: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1.8 www 1231: END
1.142 raeburn 1232: }
1.8 www 1233: }
1.16 www 1234: # Figure out what kind of a resource this is
1235: my ($extension)=($url=~/\.(\w+)$/);
1236: my $uploaded=($url=~/^\/*uploaded\//);
1.97 albertel 1237: my $icon=&Apache::loncommon::icon($url);
1.17 www 1238: my $isfolder=0;
1.142 raeburn 1239: my $ispage=0;
1.114 albertel 1240: my $folderarg;
1.142 raeburn 1241: my $pagearg;
1242: my $pagefile;
1.16 www 1243: if ($uploaded) {
1.135 albertel 1244: if ($extension eq 'sequence') {
1245: $icon=$iconpath.'/folder_closed.gif';
1246: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
1247: $url='/adm/coursedocs?';
1248: $folderarg=$1;
1249: $isfolder=1;
1.142 raeburn 1250: } elsif ($extension eq 'page') {
1251: $icon=$iconpath.'/page.gif';
1252: $url=~/$coursenum\/([\/\w]+)\.page$/;
1253: $pagearg=$1;
1254: $url='/adm/coursedocs?';
1255: $ispage=1;
1.135 albertel 1256: } else {
1257: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1258: }
1.16 www 1259: }
1.18 www 1260: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.142 raeburn 1261: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113 albertel 1262: my $symb=&Apache::lonnet::symbclean(
1.50 www 1263: &Apache::lonnet::declutter('uploaded/'.
1264: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1265: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
1266: '.sequence').
1267: '___'.$residx.'___'.
1.113 albertel 1268: &Apache::lonnet::declutter($url));
1269: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1270: $url=&Apache::lonnet::clutter($url);
1.127 albertel 1271: if ($url=~/^\/*uploaded\//) {
1272: $url=~/\.(\w+)$/;
1273: my $embstyle=&Apache::loncommon::fileembstyle($1);
1274: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1275: $url='/adm/wrapper'.$url;
1276: } elsif ($embstyle eq 'ssi') {
1277: #do nothing with these
1278: } elsif ($url!~/\.(sequence|page)$/) {
1279: $url='/adm/coursedocs/showdoc'.$url;
1280: }
1.145 albertel 1281: } elsif ($url=~m|^/ext/|) {
1282: $url='/adm/wrapper'.$url;
1.127 albertel 1283: }
1.152 albertel 1284: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1285: if ($container eq 'page') {
1286: my $symb=$ENV{'form.pagesymb'};
1287:
1288: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.142 raeburn 1289: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1.152 albertel 1290: }
1.50 www 1291: }
1.120 www 1292: my $parameterset=' ';
1.114 albertel 1293: if ($isfolder) {
1294: my $foldername=&Apache::lonnet::escape($foldertitle);
1295: my $folderpath=$ENV{'form.folderpath'};
1296: if ($folderpath) { $folderpath.='&' };
1297: $folderpath.=$folderarg.'&'.$foldername;
1298: $url.='folderpath='.&Apache::lonnet::escape($folderpath);
1.147 matthew 1299: $parameterset='<label>'.&mt('Randomly Pick: ').
1.122 www 1300: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
1.147 matthew 1301: (&Apache::lonratedt::getparameter($orderidx,
1302: 'parameter_randompick'))[0].
1303: '" />'.'</label>';
1304:
1.114 albertel 1305: }
1.142 raeburn 1306: if ($ispage) {
1307: my $pagename=&Apache::lonnet::escape($pagetitle);
1308: my $pagepath;
1309: my $folderpath=$ENV{'form.folderpath'};
1310: if ($folderpath) { $pagepath = $folderpath.'&' };
1311: $pagepath.=$pagearg.'&'.$pagename;
1.152 albertel 1312: my $symb=$ENV{'form.pagesymb'};
1313: if (!$symb) {
1314: my $path='uploaded/'.
1315: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1316: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/';
1317: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1318: $residx,
1319: $path.$pagearg.'.page');
1320: }
1321: $url.='pagepath='.&Apache::lonnet::escape($pagepath).
1322: '&pagesymb='.&Apache::lonnet::escape($symb);
1.142 raeburn 1323: }
1.113 albertel 1324: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1325: '" border="0"></a></td>'.
1.119 www 1326: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120 www 1327: if (($allowed) && ($folder!~/^supplemental/)) {
1328: my %lt=&Apache::lonlocal::texthash(
1329: 'hd' => 'Hidden',
1330: 'ec' => 'URL hidden',
1331: 'sp' => 'Store Parameters');
1.122 www 1332: my $enctext=
1333: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1334: my $hidtext=
1335: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120 www 1336: $line.=(<<ENDPARMS);
1337: <td bgcolor="#BBBBFF"><font size='-2'>
1.147 matthew 1338: <nobr><label><input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</label></nobr></td>
1.149 albertel 1339: <td bgcolor="#BBBBFF"><font size='-2'>
1340: <nobr><label><input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</label></nobr></td>
1.120 www 1341: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1342: <td bgcolor="#BBBBFF"><font size='-2'>
1.121 www 1343: <input type="submit" value="$lt{'sp'}" />
1.120 www 1344: </font></td>
1345: ENDPARMS
1.119 www 1346: }
1.120 www 1347: $line.="</form></tr>";
1.8 www 1348: return $line;
1349: }
1350:
1.27 www 1351: # ---------------------------------------------------------------- tie the hash
1352:
1353: sub tiehash {
1.136 albertel 1354: my ($mode)=@_;
1.27 www 1355: $hashtied=0;
1356: if ($ENV{'request.course.fn'}) {
1.136 albertel 1357: if ($mode eq 'write') {
1358: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1359: &GDBM_WRCREAT(),0640)) {
1360: $hashtied=2;
1361: }
1362: } else {
1363: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1364: &GDBM_READER(),0640)) {
1.27 www 1365: $hashtied=1;
1.136 albertel 1366: }
1367: }
1.27 www 1368: }
1369: }
1370:
1371: sub untiehash {
1372: if ($hashtied) { untie %hash; }
1373: $hashtied=0;
1374: }
1375:
1.29 www 1376: # --------------------------------------------------------------- check on this
1377:
1378: sub checkonthis {
1379: my ($r,$url,$level,$title)=@_;
1.140 www 1380: $url=&Apache::lonnet::unescape($url);
1.29 www 1381: $alreadyseen{$url}=1;
1382: $r->rflush();
1.41 www 1383: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108 albertel 1384: $r->print("\n<br />");
1.29 www 1385: for (my $i=0;$i<=$level*5;$i++) {
1386: $r->print(' ');
1387: }
1388: $r->print('<a href="'.$url.'" target="cat">'.
1389: ($title?$title:$url).'</a> ');
1390: if ($url=~/^\/res\//) {
1391: my $result=&Apache::lonnet::repcopy(
1392: &Apache::lonnet::filelocation('',$url));
1393: if ($result==OK) {
1.87 www 1394: $r->print('<font color="green">'.&mt('ok').'</font>');
1.29 www 1395: $r->rflush();
1.34 www 1396: &Apache::lonnet::countacc($url);
1397: $url=~/\.(\w+)$/;
1398: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1399: $r->print('<br />');
1400: $r->rflush();
1401: for (my $i=0;$i<=$level*5;$i++) {
1402: $r->print(' ');
1403: }
1.84 www 1404: $r->print('- '.&mt('Rendering').': ');
1.69 albertel 1405: my $oldpath=$ENV{'request.filename'};
1406: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1.34 www 1407: &Apache::lonxml::xmlparse($r,'web',
1408: &Apache::lonnet::getfile(
1.35 albertel 1409: &Apache::lonnet::filelocation('',$url)));
1.94 www 1410: undef($Apache::lonhomework::parsing_a_problem);
1.69 albertel 1411: $ENV{'request.filename'}=$oldpath;
1.34 www 1412: if (($Apache::lonxml::errorcount) ||
1413: ($Apache::lonxml::warningcount)) {
1414: if ($Apache::lonxml::errorcount) {
1.98 www 1415: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.87 www 1416: $Apache::lonxml::errorcount.' '.
1417: &mt('error(s)').'</b></font> ');
1.34 www 1418: }
1419: if ($Apache::lonxml::warningcount) {
1420: $r->print('<font color="blue">'.
1.84 www 1421: $Apache::lonxml::warningcount.' '.
1422: &mt('warning(s)').'</font>');
1.34 www 1423: }
1424: } else {
1.87 www 1425: $r->print('<font color="green">'.&mt('ok').'</font>');
1.34 www 1426: }
1427: $r->rflush();
1428: }
1.29 www 1429: my $dependencies=
1430: &Apache::lonnet::metadata($url,'dependencies');
1431: foreach (split(/\,/,$dependencies)) {
1432: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1433: &checkonthis($r,$_,$level+1);
1434: }
1435: }
1436: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
1.84 www 1437: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.29 www 1438: } elsif ($result==HTTP_NOT_FOUND) {
1.100 www 1439: unless ($url=~/\$/) {
1440: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
1441: } else {
1442: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
1443: }
1.29 www 1444: } else {
1.84 www 1445: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29 www 1446: }
1447: }
1448: }
1449: }
1450:
1.1 www 1451:
1.75 www 1452: #
1453: # -------------------------------------------------------------- Verify Content
1454: #
1455: sub verifycontent {
1456: my $r=shift;
1.26 www 1457: my $loaderror=&Apache::lonnet::overloaderror($r);
1458: if ($loaderror) { return $loaderror; }
1459:
1460: $r->print('<html><head><title>Verify Content</title></head>'.
1461: &Apache::loncommon::bodytag('Verify Course Documents'));
1.27 www 1462: $hashtied=0;
1.30 www 1463: undef %alreadyseen;
1464: %alreadyseen=();
1.27 www 1465: &tiehash();
1466: foreach (keys %hash) {
1.140 www 1467: if ($hash{$_}=~/\.(page|sequence)$/) {
1468: if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1469: $r->print('<hr /><font color="red">'.
1470: &mt('The following sequence or page is included more than once in your course: ').
1471: &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
1472: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
1473: }
1474: }
1475: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1.29 www 1476: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 1477: }
1478: }
1479: &untiehash();
1.108 albertel 1480: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
1481: &mt('Return to DOCS').'</a>');
1.75 www 1482: }
1483:
1484: # -------------------------------------------------------------- Check Versions
1485:
1486: sub checkversions {
1487: my $r=shift;
1.89 www 1488: $r->print('<html><head><title>Check Versions</title></head>'.
1.26 www 1489: &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89 www 1490: my $header='';
1491: my $startsel='';
1492: my $monthsel='';
1493: my $weeksel='';
1494: my $daysel='';
1495: my $allsel='';
1496: my %changes=();
1497: my $starttime=0;
1.91 www 1498: my $haschanged=0;
1.92 www 1499: my %setversions=&Apache::lonnet::dump('resourceversions',
1500: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1501: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1502:
1503: $hashtied=0;
1504: &tiehash();
1505: my %newsetversions=();
1.91 www 1506: if ($ENV{'form.setmostrecent'}) {
1507: $haschanged=1;
1.92 www 1508: foreach (keys %hash) {
1509: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1510: $newsetversions{$1}='mostrecent';
1.92 www 1511: }
1512: }
1.91 www 1513: } elsif ($ENV{'form.setcurrent'}) {
1514: $haschanged=1;
1.92 www 1515: foreach (keys %hash) {
1516: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1517: my $getvers=&Apache::lonnet::getversion($1);
1518: if ($getvers>0) {
1519: $newsetversions{$1}=$getvers;
1520: }
1.92 www 1521: }
1522: }
1.91 www 1523: } elsif ($ENV{'form.setversions'}) {
1524: $haschanged=1;
1.92 www 1525: foreach (keys %ENV) {
1526: if ($_=~/^form\.set_version_(.+)$/) {
1527: my $src=$1;
1528: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
1529: $newsetversions{$src}=$ENV{$_};
1530: }
1531: }
1532: }
1.91 www 1533: }
1534: if ($haschanged) {
1.92 www 1535: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1536: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1537: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
1538: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1539: } else {
1540: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1541: }
1.136 albertel 1542: &mark_hash_old();
1.91 www 1543: }
1.136 albertel 1544: &changewarning($r,'');
1.89 www 1545: if ($ENV{'form.timerange'} eq 'all') {
1546: # show all documents
1547: $header=&mt('All Documents in Course');
1.91 www 1548: $allsel=1;
1.90 www 1549: foreach (keys %hash) {
1550: if ($_=~/^ids\_(\/res\/.+)$/) {
1551: my $src=$1;
1552: $changes{$src}=1;
1553: }
1554: }
1.89 www 1555: } else {
1556: # show documents which changed
1557: %changes=&Apache::lonnet::dump
1558: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.30 www 1559: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89 www 1560: my $firstkey=(keys %changes)[0];
1561: unless ($firstkey=~/^error\:/) {
1562: unless ($ENV{'form.timerange'}) {
1563: $ENV{'form.timerange'}=604800;
1564: }
1565: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
1566: .&mt('seconds');
1567: if ($ENV{'form.timerange'}==-1) {
1568: $seltext='since start of course';
1569: $startsel='selected';
1570: $ENV{'form.timerange'}=time;
1571: }
1572: $starttime=time-$ENV{'form.timerange'};
1573: if ($ENV{'form.timerange'}==2592000) {
1574: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1575: $monthsel='selected';
1576: } elsif ($ENV{'form.timerange'}==604800) {
1577: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1578: $weeksel='selected';
1579: } elsif ($ENV{'form.timerange'}==86400) {
1580: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1581: $daysel='selected';
1582: }
1583: $header=&mt('Content changed').' '.$seltext;
1584: } else {
1585: $header=&mt('No content modifications yet.');
1586: }
1587: }
1.92 www 1588: %setversions=&Apache::lonnet::dump('resourceversions',
1589: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1590: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89 www 1591: my %lt=&Apache::lonlocal::texthash
1.88 www 1592: ('st' => 'Version changes since start of Course',
1593: 'lm' => 'Version changes since last Month',
1594: 'lw' => 'Version changes since last Week',
1595: 'sy' => 'Version changes since Yesterday',
1.91 www 1596: 'al' => 'All Resources (possibly large output)',
1.88 www 1597: 'sd' => 'Display',
1.84 www 1598: 'fi' => 'File',
1599: 'md' => 'Modification Date',
1.87 www 1600: 'mr' => 'Most recently published Version',
1601: 've' => 'Version used in Course',
1.91 www 1602: 'vu' => 'Set Version to be used in Course',
1603: 'sv' => 'Set Versions to be used in Course according to Selections below',
1604: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1605: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84 www 1606: 'di' => 'Differences');
1.89 www 1607: $r->print(<<ENDHEADERS);
1.31 www 1608: <form action="/adm/coursedocs" method="post">
1.91 www 1609: <input type="hidden" name="versions" value="1" />
1610: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1611: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31 www 1612: <select name="timerange">
1.88 www 1613: <option value='all' $allsel>$lt{'al'}</option>
1.84 www 1614: <option value="-1" $startsel>$lt{'st'}</option>
1615: <option value="2592000" $monthsel>$lt{'lm'}</option>
1616: <option value="604800" $weeksel>$lt{'lw'}</option>
1617: <option value="86400" $daysel>$lt{'sy'}</option>
1.31 www 1618: </select>
1.91 www 1619: <input type="submit" name="display" value="$lt{'sd'}" />
1.89 www 1620: <h3>$header</h3>
1.91 www 1621: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103 matthew 1622: <table border="0">
1.31 www 1623: ENDHEADERS
1.91 www 1624: foreach (sort keys %changes) {
1.89 www 1625: if ($changes{$_}>$starttime) {
1626: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1627: my $currentversion=&Apache::lonnet::getversion($_);
1.93 www 1628: if ($currentversion<0) {
1629: $currentversion=&mt('Could not be determined.');
1630: }
1.89 www 1631: my $linkurl=&Apache::lonnet::clutter($_);
1632: $r->print(
1.103 matthew 1633: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91 www 1634: &Apache::lonnet::gettitle($linkurl).
1.103 matthew 1635: '</b></font></td></tr>'.
1636: '<tr><td> </td>'.
1637: '<td colspan="4">'.
1638: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1639: '</a></td></tr>'.
1640: '<tr><td></td>'.
1641: '<td title="'.$lt{'md'}.'">'.
1.102 matthew 1642: &Apache::lonlocal::locallocaltime(
1643: &Apache::lonnet::metadata($root.'.'.$extension,
1644: 'lastrevisiondate')
1645: ).
1.103 matthew 1646: '</td>'.
1647: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1648: '<font size="+1">'.$currentversion.'</font>'.
1649: '</nobr></td>'.
1650: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1651: '<font size="+1">');
1.87 www 1652: # Used in course
1.89 www 1653: my $usedversion=$hash{'version_'.$linkurl};
1.93 www 1654: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89 www 1655: $r->print($usedversion);
1656: } else {
1657: $r->print($currentversion);
1658: }
1.103 matthew 1659: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1660: '<nobr>Use: ');
1.87 www 1661: # Set version
1.92 www 1662: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89 www 1663: 'set_version_'.$linkurl,
1.136 albertel 1664: ('select_form_order' =>
1665: ['',1..$currentversion,'mostrecent'],
1666: '' => '',
1.93 www 1667: 'mostrecent' => 'most recent',
1.89 www 1668: map {$_,$_} (1..$currentversion))));
1.103 matthew 1669: $r->print('</nobr></td></tr><tr><td></td>');
1.89 www 1670: my $lastold=1;
1671: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1672: my $url=$root.'.'.$prevvers.'.'.$extension;
1673: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1674: $starttime) {
1675: $lastold=$prevvers;
1676: }
1677: }
1.103 matthew 1678: #
1679: # Code to figure out how many version entries should go in
1680: # each of the four columns
1681: my $entries_per_col = 0;
1682: my $num_entries = ($currentversion-$lastold);
1683: if ($num_entries % 4 == 0) {
1684: $entries_per_col = $num_entries/4;
1685: } else {
1686: $entries_per_col = $num_entries/4 + 1;
1687: }
1688: my $entries_count = 0;
1689: $r->print('<td valign="top"><font size="-2">');
1690: my $cols_output = 1;
1.32 www 1691: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89 www 1692: my $url=$root.'.'.$prevvers.'.'.$extension;
1.103 matthew 1693: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91 www 1694: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103 matthew 1695: &Apache::lonlocal::locallocaltime(
1696: &Apache::lonnet::metadata($url,
1697: 'lastrevisiondate')
1698: ).
1.91 www 1699: ')');
1.89 www 1700: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33 www 1701: $r->print(' <a href="/adm/diff?filename='.
1.89 www 1702: &Apache::lonnet::clutter($root.'.'.$extension).
1703: '&versionone='.$prevvers.
1704: '">'.&mt('Diffs').'</a>');
1705: }
1.103 matthew 1706: $r->print('</nobr><br />');
1707: if (++$entries_count % $entries_per_col == 0) {
1708: $r->print('</font></td>');
1709: if ($cols_output != 4) {
1710: $r->print('<td valign="top"><font size="-2">');
1711: $cols_output++;
1712: }
1713: }
1.89 www 1714: }
1.103 matthew 1715: while($cols_output++ < 4) {
1716: $r->print('</font></td><td><font>')
1717: }
1718: $r->print('</font></td></tr>'."\n");
1.89 www 1719: }
1720: }
1.92 www 1721: $r->print('</table></form>');
1.89 www 1722: $r->print('<h1>'.&mt('Done').'.</h1>');
1723:
1724: &untiehash();
1.75 www 1725: }
1726:
1.136 albertel 1727: sub mark_hash_old {
1728: my $retie_hash=0;
1729: if ($hashtied) {
1730: $retie_hash=1;
1731: &untiehash();
1732: }
1733: &tiehash('write');
1734: $hash{'old'}=1;
1735: &untiehash();
1736: if ($retie_hash) { &tiehash(); }
1737: }
1738:
1739: sub is_hash_old {
1740: my $untie_hash=0;
1741: if (!$hashtied) {
1742: $untie_hash=1;
1743: &tiehash();
1744: }
1745: my $return=$hash{'old'};
1746: if ($untie_hash) { &untiehash(); }
1747: return $return;
1748: }
1749:
1.91 www 1750: sub changewarning {
1751: my ($r,$postexec)=@_;
1.136 albertel 1752: if (!&is_hash_old()) { return; }
1.150 albertel 1753: my $pathvar='folderpath';
1754: my $path=&Apache::lonnet::escape($ENV{'form.folderpath'});
1755: if (defined($ENV{'form.pagepath'})) {
1756: $pathvar='pagepath';
1757: $path=&Apache::lonnet::escape($ENV{'form.pagepath'});
1.156 albertel 1758: $path.='&symb='.&Apache::lonnet::escape($ENV{'form.pagesymb'});
1.150 albertel 1759: }
1.91 www 1760: $r->print(
1761: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1762: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1.150 albertel 1763: '<input type="hidden" name="orgurl" value="/adm/coursedocs?'.
1764: $pathvar.'='.$path.
1.117 albertel 1765: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.91 www 1766: &mt('Changes will become active for your current session after').
1767: ' <input type="hidden" name="'.
1768: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1769: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1770: $help{'Caching'}.'</font></h3></form>');
1771: }
1772:
1.75 www 1773: # ================================================================ Main Handler
1774: sub handler {
1775: my $r = shift;
1.82 www 1776: &Apache::loncommon::content_type($r,'text/html');
1.75 www 1777: $r->send_http_header;
1778: return OK if $r->header_only;
1779:
1780: # --------------------------------------------- Initialize help topics for this
1781: foreach ('Adding_Course_Doc','Main_Course_Documents',
1782: 'Adding_External_Resource','Navigate_Content',
1783: 'Adding_Folders','Docs_Overview', 'Load_Map',
1.142 raeburn 1784: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.130 www 1785: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1786: 'Check_Resource_Versions','Verify_Content') {
1.75 www 1787: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1788: }
1789: # Composite help files
1790: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1791: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1792: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1793: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86 albertel 1794: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1795: 'Option_Response_Simple');
1.75 www 1796: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1797: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1798: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1799: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1800: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142 raeburn 1801:
1.75 www 1802: if ($ENV{'form.verify'}) {
1803: &verifycontent($r);
1804: } elsif ($ENV{'form.versions'}) {
1805: &checkversions($r);
1806: } elsif ($ENV{'form.dumpcourse'}) {
1807: &dumpcourse($r);
1.138 raeburn 1808: } elsif ($ENV{'form.exportcourse'}) {
1809: &exportcourse($r);
1.26 www 1810: } else {
1.7 www 1811: # is this a standard course?
1812:
1813: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.155 raeburn 1814: my $forcestandard = 0;
1.15 www 1815: my $forcesupplement;
1816: my $script='';
1817: my $allowed;
1818: my $events='';
1.19 www 1819: my $showdoc=0;
1.142 raeburn 1820: my $containertag;
1821: my $uploadtag;
1.15 www 1822: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.152 albertel 1823: ['folderpath','pagepath','pagesymb']);
1.114 albertel 1824: if ($ENV{'form.folderpath'}) {
1825: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1826: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1827: $ENV{'form.folder'}=pop(@folderpath);
1.142 raeburn 1828: }
1829: if ($ENV{'form.pagepath'}) {
1830: my (@pagepath)=split('&',$ENV{'form.pagepath'});
1831: $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
1832: $ENV{'form.folder'}=pop(@pagepath);
1.156 albertel 1833: $containertag = '<input type="hidden" name="pagepath" value="" />'.
1834: '<input type="hidden" name="pagesymb" value="" />';
1835: $uploadtag = '<input type="hidden" name="pagepath" value="'.$ENV{'form.pagepath'}.'" />'.
1836: '<input type="hidden" name="pagesymb" value="'.$ENV{'form.pagesymb'}.'" />';
1.142 raeburn 1837: }
1.21 www 1838: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127 albertel 1839: $showdoc='/'.$1;
1.21 www 1840: }
1841: unless ($showdoc) { # got called from remote
1.156 albertel 1842: if (($ENV{'form.folder'}=~/^default_/) ||
1.155 raeburn 1843: ($ENV{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1844: $forcestandard = 1;
1845: }
1.15 www 1846: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 1847:
1.4 www 1848: # does this user have privileges to post, etc?
1.77 www 1849: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.15 www 1850: if ($allowed) {
1851: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1852: $script=&Apache::lonratedt::editscript('simple');
1853: }
1854: } else { # got called in sequence from course
1855: $allowed=0;
1.49 www 1856: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1857: $events='onLoad="'.&Apache::lonmenu::loadevents.
1858: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3 www 1859: }
1.4 www 1860:
1861: # get course data
1862: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1863: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1864:
1.14 www 1865: # get personal data
1866:
1867: my $uname=$ENV{'user.name'};
1868: my $udom=$ENV{'user.domain'};
1869: my $plainname=&Apache::lonnet::escape(
1870: &Apache::loncommon::plainname($uname,$udom));
1871:
1.8 www 1872: # graphics settings
1.4 www 1873:
1.8 www 1874: $iconpath = $r->dir_config('lonIconsURL') . "/";
1875:
1.22 www 1876: my $now=time;
1.64 www 1877:
1.4 www 1878: # print screen
1.1 www 1879: $r->print(<<ENDDOCUMENT);
1880: <html>
1881: <head>
1882: <title>The LearningOnline Network with CAPA</title>
1.16 www 1883: <script>
1884: $script
1.20 www 1885: </script>
1.19 www 1886: ENDDOCUMENT
1887: if ($allowed) {
1888: $r->print(<<ENDNEWSCRIPT);
1.20 www 1889: <script>
1.16 www 1890: function makenewfolder(targetform,folderseq) {
1891: var foldername=prompt('Name of New Folder','New Folder');
1892: if (foldername) {
1893: targetform.importdetail.value=foldername+"="+folderseq;
1894: targetform.submit();
1895: }
1896: }
1897:
1.142 raeburn 1898: function makenewpage(targetform,folderseq) {
1899: var pagename=prompt('Name of New Page','New Page');
1900: if (pagename) {
1901: targetform.importdetail.value=pagename+"="+folderseq;
1902: targetform.submit();
1903: }
1904: }
1905:
1.18 www 1906: function makenewext(targetname) {
1907: this.document.forms.extimport.useform.value=targetname;
1908: window.open('/adm/rat/extpickframe.html');
1909: }
1910:
1.62 www 1911: function makeexamupload() {
1912: var title=prompt('Listed Title for the Uploaded Score');
1913: if (title) {
1914: this.document.forms.newexamupload.importdetail.value=
1915: title+'=/res/lib/templates/examupload.problem';
1916: this.document.forms.newexamupload.submit();
1917: }
1918: }
1919:
1.22 www 1920: function makesmppage() {
1.38 www 1921: var title=prompt('Listed Title for the Page');
1922: if (title) {
1.22 www 1923: this.document.forms.newsmppg.importdetail.value=
1924: title+'=/adm/$udom/$uname/$now/smppg';
1925: this.document.forms.newsmppg.submit();
1.38 www 1926: }
1.22 www 1927: }
1928:
1.55 www 1929: function makesmpproblem() {
1930: var title=prompt('Listed Title for the Problem');
1931: if (title) {
1932: this.document.forms.newsmpproblem.importdetail.value=
1.63 www 1933: title+'=/res/lib/templates/simpleproblem.problem';
1.55 www 1934: this.document.forms.newsmpproblem.submit();
1935: }
1936: }
1937:
1.22 www 1938: function makebulboard() {
1.38 www 1939: var title=prompt('Listed Title for the Bulletin Board');
1940: if (title) {
1.22 www 1941: this.document.forms.newbul.importdetail.value=
1942: title+'=/adm/$udom/$uname/$now/bulletinboard';
1943: this.document.forms.newbul.submit();
1.38 www 1944: }
1.22 www 1945: }
1946:
1.101 www 1947: function makeabout() {
1948: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1949: if (user) {
1950: var comp=new Array();
1951: comp=user.split('\@');
1952: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1953: if ((comp[0]) && (comp[1])) {
1954: this.document.forms.newaboutsomeone.importdetail.value=
1955: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1956: this.document.forms.newaboutsomeone.submit();
1957: }
1958: }
1959: }
1960: }
1961:
1.110 raeburn 1962: function makeims() {
1963: var caller = document.forms.ims.folder.value
1964: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1965: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1966: newWindow.location.href = newlocation
1967: }
1968:
1969:
1.18 www 1970: function finishpick() {
1971: var title=this.document.forms.extimport.title.value;
1972: var url=this.document.forms.extimport.url.value;
1973: var form=this.document.forms.extimport.useform.value;
1974: eval
1975: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1976: '";this.document.forms.'+form+'.submit();');
1.16 www 1977: }
1.36 www 1978:
1.156 albertel 1979: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.36 www 1980: var title=prompt('New Title',oldtitle);
1981: if (title) {
1982: this.document.forms.renameform.title.value=title;
1983: this.document.forms.renameform.cmd.value='rename_'+index;
1.142 raeburn 1984: if (container == 'sequence') {
1985: this.document.forms.renameform.folderpath.value=folderpath;
1986: }
1987: if (container == 'page') {
1988: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 1989: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 1990: }
1.54 www 1991: this.document.forms.renameform.submit();
1992: }
1993: }
1994:
1.156 albertel 1995: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1.106 www 1996: if (confirm('Remove "'+oldtitle+'"?')) {
1.54 www 1997: this.document.forms.renameform.cmd.value='del_'+index;
1.142 raeburn 1998: if (container == 'sequence') {
1999: this.document.forms.renameform.folderpath.value=folderpath;
2000: }
2001: if (container == 'page') {
2002: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 2003: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 2004: }
1.36 www 2005: this.document.forms.renameform.submit();
2006: }
2007: }
1.121 www 2008:
1.16 www 2009: </script>
1.42 www 2010:
2011: ENDNEWSCRIPT
2012: }
2013: # -------------------------------------------------------------------- Body tag
2014: $r->print('</head>'.
1.72 www 2015: &Apache::loncommon::bodytag('Course Documents','',$events,
1.99 www 2016: '','',$showdoc).
1.134 albertel 2017: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.42 www 2018: unless ($showdoc) {
1.81 www 2019: # -----------------------------------------------------------------------------
2020: my %lt=&Apache::lonlocal::texthash(
2021: 'uplm' => 'Upload a new main course document',
2022: 'upls' => 'Upload a new supplemental course document',
2023: 'impp' => 'Import a published document',
2024: 'spec' => 'Special documents',
2025: 'upld' => 'Upload Document',
2026: 'srch' => 'Search',
2027: 'impo' => 'Import',
2028: 'selm' => 'Select Map',
2029: 'load' => 'Load Map',
2030: 'newf' => 'New Folder',
1.142 raeburn 2031: 'newp' => 'New Composite Page',
1.81 www 2032: 'extr' => 'External Resource',
2033: 'syll' => 'Syllabus',
2034: 'navc' => 'Navigate Contents',
2035: 'sipa' => 'Simple Page',
2036: 'sipr' => 'Simple Problem',
2037: 'scuf' => 'Score Upload Form',
2038: 'bull' => 'Bulletin Board',
1.96 sakharuk 2039: 'mypi' => 'My Personal Info',
1.101 www 2040: 'abou' => 'About User',
1.110 raeburn 2041: 'imsf' => 'Import IMS package',
1.96 sakharuk 2042: 'file' => 'File',
2043: 'title' => 'Title',
2044: 'comment' => 'Comment'
1.81 www 2045: );
2046: # -----------------------------------------------------------------------------
1.42 www 2047: if ($allowed) {
1.74 www 2048: my $dumpbut=&dumpbutton();
1.138 raeburn 2049: my $exportbut=&exportbutton();
1.88 www 2050: my %lt=&Apache::lonlocal::texthash(
2051: 'vc' => 'Verify Content',
2052: 'cv' => 'Check/Set Resource Versions',
2053: );
1.118 albertel 2054:
2055: my $folderpath=$ENV{'form.folderpath'};
2056: if (!$folderpath) {
2057: if ($ENV{'form.folder'} eq '' ||
2058: $ENV{'form.folder'} eq 'supplemental') {
2059: $folderpath='default&'.
2060: &Apache::lonnet::escape(&mt('Main Course Documents'));
2061: }
2062: }
1.142 raeburn 2063: unless ($ENV{'form.pagepath'}) {
2064: $containertag = '<input type="hidden" name="folderpath" value="" />';
2065: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2066: }
2067:
1.42 www 2068: $r->print(<<ENDCOURSEVERIFY);
1.36 www 2069: <form name="renameform" method="post" action="/adm/coursedocs">
2070: <input type="hidden" name="title" />
2071: <input type="hidden" name="cmd" />
1.142 raeburn 2072: $containertag
1.36 www 2073: </form>
1.39 www 2074: <form name="simpleedit" method="post" action="/adm/coursedocs">
2075: <input type=hidden name="importdetail" value="">
1.142 raeburn 2076: $uploadtag
1.39 www 2077: </form>
1.26 www 2078: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74 www 2079: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2080: <tr><td bgcolor="#DDDDCC">
1.130 www 2081: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74 www 2082: </td><td bgcolor="#DDDDCC">
1.130 www 2083: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74 www 2084: $dumpbut
1.138 raeburn 2085: $exportbut
1.74 www 2086: </td></tr></table>
1.25 www 2087: </form>
2088: ENDCOURSEVERIFY
1.74 www 2089: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96 sakharuk 2090: &mt('Editing the Table of Contents for your Course')));
1.25 www 2091: }
1.17 www 2092: # --------------------------------------------------------- Standard documents
1.43 www 2093: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7 www 2094: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116 albertel 2095: $r->print('<tr><td bgcolor="#BBBBBB">');
2096: # '<h2>'.&mt('Main Course Documents').
2097: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7 www 2098: my $folder=$ENV{'form.folder'};
1.117 albertel 2099: if ($folder eq '' || $folder eq 'supplemental') {
1.112 raeburn 2100: $folder='default';
1.116 albertel 2101: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112 raeburn 2102: }
1.51 www 2103: my $postexec='';
2104: if ($folder eq 'default') {
2105: $r->print('<script>this.window.name="loncapaclient";</script>');
2106: } else {
1.117 albertel 2107: #$postexec='self.close();';
1.51 www 2108: }
1.40 www 2109: $hadchanges=0;
1.7 www 2110: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40 www 2111: if ($hadchanges) {
1.136 albertel 2112: &mark_hash_old()
1.40 www 2113: }
1.136 albertel 2114: &changewarning($r,$postexec);
1.16 www 2115: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2116: '.sequence';
1.142 raeburn 2117: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2118: '.page';
2119:
1.8 www 2120: $r->print(<<ENDFORM);
1.43 www 2121: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2122: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2123: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2124: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11 www 2125: </tr>
1.16 www 2126: <tr><td bgcolor="#DDDDDD">
1.96 sakharuk 2127: $lt{'file'}:<br />
1.10 www 2128: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2129: <input type="file" name="uploaddoc" size="40">
1.8 www 2130: <br />
1.96 sakharuk 2131: $lt{'title'}:<br />
1.11 www 2132: <input type="text" size="50" name="comment">
1.142 raeburn 2133: $uploadtag
1.10 www 2134: <input type="hidden" name="cmd" value="upload_default">
1.129 albertel 2135: <nobr>
1.81 www 2136: <input type="submit" value="$lt{'upld'}">
1.60 albertel 2137: $help{'Uploading_From_Harddrive'}
1.58 albertel 2138: </nobr>
1.60 albertel 2139: </form>
1.11 www 2140: </td>
1.16 www 2141: <td bgcolor="#DDDDDD">
1.39 www 2142: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.142 raeburn 2143: $uploadtag
1.115 albertel 2144: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58 albertel 2145: <nobr>
1.115 albertel 2146: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58 albertel 2147: $help{'Importing_LON-CAPA_Resource'}
2148: </nobr>
1.59 www 2149: <p>
2150: <hr />
1.68 bowersj2 2151: <input type="text" size="20" name="importmap"><br />
2152: <nobr><input type=button
1.52 www 2153: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81 www 2154: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68 bowersj2 2155: $help{'Load_Map'}</nobr>
1.59 www 2156: </p>
1.52 www 2157: </form>
1.142 raeburn 2158: </td>
2159: <td bgcolor="#DDDDDD">
2160: ENDFORM
2161: unless ($ENV{'form.pagepath'}) {
2162: $r->print(<<ENDFORM);
1.11 www 2163: <form action="/adm/coursedocs" method="post" name="newfolder">
1.115 albertel 2164: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.13 www 2165: <input type=hidden name="importdetail" value="">
1.58 albertel 2166: <nobr>
1.16 www 2167: <input name="newfolder" type="button"
2168: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2169: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58 albertel 2170: </nobr>
1.11 www 2171: </form>
1.142 raeburn 2172: <form action="/adm/coursedocs" method="post" name="newpage">
2173: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2174: <input type=hidden name="importdetail" value="">
2175: <nobr>
2176: <input name="newpage" type="button"
2177: onClick="javascript:makenewpage(this.form,'$pageseq');"
2178: value="$lt{'newp'}" />$help{'Adding_Pages'}
2179: </nobr>
2180: </form>
1.11 www 2181: <form action="/adm/coursedocs" method="post" name="newext">
1.142 raeburn 2182: $uploadtag
1.13 www 2183: <input type=hidden name="importdetail" value="">
1.58 albertel 2184: <nobr>
1.18 www 2185: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.81 www 2186: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58 albertel 2187: </nobr>
1.11 www 2188: </form>
2189: <form action="/adm/coursedocs" method="post" name="newsyl">
1.142 raeburn 2190: $uploadtag
1.14 www 2191: <input type=hidden name="importdetail"
2192: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2193: <nobr>
1.81 www 2194: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2195: $help{'Syllabus'}
1.58 albertel 2196: </nobr>
2197: </form>
1.17 www 2198: <form action="/adm/coursedocs" method="post" name="newnav">
1.142 raeburn 2199: $uploadtag
1.15 www 2200: <input type=hidden name="importdetail"
2201: value="Navigate Content=/adm/navmaps">
1.58 albertel 2202: <nobr>
1.81 www 2203: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47 www 2204: $help{'Navigate_Content'}
1.58 albertel 2205: </nobr>
1.22 www 2206: </form>
2207: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.142 raeburn 2208: $uploadtag
1.22 www 2209: <input type=hidden name="importdetail" value="">
1.58 albertel 2210: <nobr>
1.81 www 2211: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65 bowersj2 2212: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58 albertel 2213: </nobr>
1.55 www 2214: </form>
2215: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142 raeburn 2216: $uploadtag
1.55 www 2217: <input type=hidden name="importdetail" value="">
1.58 albertel 2218: <nobr>
1.81 www 2219: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65 bowersj2 2220: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62 www 2221: </nobr>
2222: </form>
2223: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 2224: $uploadtag
1.62 www 2225: <input type=hidden name="importdetail" value="">
2226: <nobr>
1.81 www 2227: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62 www 2228: onClick="javascript:makeexamupload();" />
1.66 bowersj2 2229: $help{'Score_Upload_Form'}
1.58 albertel 2230: </nobr>
1.22 www 2231: </form>
2232: <form action="/adm/coursedocs" method="post" name="newbul">
1.142 raeburn 2233: $uploadtag
1.22 www 2234: <input type=hidden name="importdetail" value="">
1.58 albertel 2235: <nobr>
1.81 www 2236: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22 www 2237: onClick="javascript:makebulboard();" />
1.65 bowersj2 2238: $help{'Bulletin Board'}
1.58 albertel 2239: </nobr>
2240: </form>
1.12 www 2241: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.142 raeburn 2242: $uploadtag
1.14 www 2243: <input type=hidden name="importdetail"
2244: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2245: <nobr>
1.81 www 2246: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2247: $help{'My Personal Info'}
1.101 www 2248: </nobr>
2249: </form>
2250: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142 raeburn 2251: $uploadtag
1.101 www 2252: <input type=hidden name="importdetail" value="">
2253: <nobr>
2254: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2255: onClick="javascript:makeabout();" />
1.110 raeburn 2256: </nobr>
1.142 raeburn 2257: ENDFORM
2258: }
2259: if ($ENV{'form.pagepath'}) {
2260: $r->print(<<ENDBLOCK);
2261: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2262: $uploadtag
2263: <input type=hidden name="importdetail" value="">
2264: <nobr>
2265: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2266: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2267: </nobr>
2268: </form>
2269: <form action="/adm/coursedocs" method="post" name="newexamupload">
2270: $uploadtag
2271: <input type=hidden name="importdetail" value="">
2272: <nobr>
2273: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2274: onClick="javascript:makeexamupload();" />
2275: $help{'Score_Upload_Form'}
2276: </nobr>
2277: </form>
2278: ENDBLOCK
2279: } else {
2280: $r->print(<<ENDFORM);
1.110 raeburn 2281: </form>
2282: <form action="/adm/imsimportdocs" method="post" name="ims">
1.118 albertel 2283: <input type="hidden" name="folder" value="$folder" />
1.110 raeburn 2284: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1.58 albertel 2285: </nobr>
2286: </form>
1.8 www 2287: ENDFORM
1.142 raeburn 2288: }
2289: $r->print('</td></tr>'."\n".
2290: '</table>');
1.24 www 2291: $r->print('</td></tr>');
1.7 www 2292: }
2293: # ----------------------------------------------------- Supplemental documents
2294: if (!$forcestandard) {
1.116 albertel 2295: $r->print('<tr><td bgcolor="#BBBBBB">');
2296: # '<h2>'.&mt('Supplemental Course Documents').
2297: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7 www 2298: my $folder=$ENV{'form.folder'};
1.117 albertel 2299: unless ($folder=~/^supplemental/) {
1.116 albertel 2300: $folder='supplemental';
1.117 albertel 2301: }
2302: if ($folder =~ /^supplemental$/ &&
2303: $ENV{'form.folderpath'} =~ /^default\&/) {
2304: $ENV{'form.folderpath'}='supplemental&'.
2305: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116 albertel 2306: }
1.7 www 2307: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 2308: if ($allowed) {
1.17 www 2309: my $folderseq=
2310: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2311: '.sequence';
2312:
1.8 www 2313: $r->print(<<ENDSUPFORM);
1.43 www 2314: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2315: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2316: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17 www 2317: </tr>
2318: <tr><td bgcolor="#DDDDDD">
1.10 www 2319: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2320: <input type="file" name="uploaddoc" size="40">
1.96 sakharuk 2321: <br />$lt{'comment'}:<br />
1.4 www 2322: <textarea cols=50 rows=4 name='comment'>
2323: </textarea>
1.115 albertel 2324: <br />
2325: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.10 www 2326: <input type="hidden" name="cmd" value="upload_supplemental">
1.58 albertel 2327: <nobr>
1.81 www 2328: <input type="submit" value="$lt{'upld'}">
1.58 albertel 2329: $help{'Uploading_From_Harddrive'}
2330: </nobr>
2331: </form>
1.17 www 2332: </td>
2333: <td bgcolor="#DDDDDD">
1.18 www 2334: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.115 albertel 2335: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2336: <input type=hidden name="importdetail" value="">
1.58 albertel 2337: <nobr>
1.17 www 2338: <input name="newfolder" type="button"
2339: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2340: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58 albertel 2341: </nobr>
1.17 www 2342: </form>
1.18 www 2343: <form action="/adm/coursedocs" method="post" name="supnewext">
1.115 albertel 2344: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2345: <input type=hidden name="importdetail" value="">
1.58 albertel 2346: <nobr>
1.18 www 2347: <input name="newext" type="button"
2348: onClick="javascript:makenewext('supnewext');"
1.81 www 2349: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58 albertel 2350: </nobr>
1.17 www 2351: </form>
1.18 www 2352: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.115 albertel 2353: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2354: <input type=hidden name="importdetail"
2355: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2356: <nobr>
1.81 www 2357: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2358: $help{'Syllabus'}
1.58 albertel 2359: </nobr>
2360: </form>
1.18 www 2361: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.115 albertel 2362: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2363: <input type=hidden name="importdetail"
2364: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2365: <nobr>
1.81 www 2366: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2367: $help{'My Personal Info'}
1.58 albertel 2368: </nobr>
2369: </form>
1.17 www 2370: </td></tr>
1.24 www 2371: </table></td></tr>
1.8 www 2372: ENDSUPFORM
2373: }
1.7 www 2374: }
1.18 www 2375: if ($allowed) {
2376: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
2377: }
1.24 www 2378: $r->print('</table>');
1.19 www 2379: } else {
2380: # -------------------------------------------------------- This is showdoc mode
1.141 albertel 2381: $r->print("<h1>".&mt('Uploaded Document').' - '.
2382: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81 www 2383: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
2384: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1.19 www 2385: }
1.26 www 2386: }
1.95 www 2387: $r->print('</body></html>');
1.26 www 2388: return OK;
1.1 www 2389: }
2390:
2391: 1;
2392: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>