Annotation of loncom/interface/londocs.pm, revision 1.161
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.161 ! albertel 4: # $Id: londocs.pm,v 1.160 2004/12/23 17:28:31 raeburn 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.143 raeburn 708: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
1.157 raeburn 709: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
710: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
711: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
712: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/])/([^/])-) {
713: my $coauth = $3.':'.$2.':ca';
1.143 raeburn 714: my $canedit = 0;
1.157 raeburn 715: if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'}) {
1.143 raeburn 716: $canedit= 1;
717: }
718: if ($canedit) {
1.157 raeburn 719: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
1.143 raeburn 720: } else {
1.157 raeburn 721: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
1.143 raeburn 722: }
723: }
1.158 raeburn 724: if (@uploads > 0) {
725: foreach my $item (@uploads) {
726: my $uploadmsg = '';
1.159 raeburn 727: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
1.158 raeburn 728: if ($uploadmsg) {
729: $$copyresult .= $uploadmsg."\n";
730: }
731: }
732: }
1.157 raeburn 733: if ($message) {
734: $$copyresult .= $message."\n";
735: }
1.143 raeburn 736: }
737:
738: sub replicate_content {
1.157 raeburn 739: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
1.159 raeburn 740: my ($map,$ind,$url);
741: if ($caller eq 'templateupload') {
742: $url = $symb;
743: $url =~ s#//#/#g;
744: } else {
745: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
746: }
1.143 raeburn 747: my $content;
748: my $filename;
749: my $repstatus;
1.157 raeburn 750: my $content_name;
751: if ($url =~ m-/([^/]+)$-) {
1.143 raeburn 752: $filename = $1;
753: if (!-e $tempexport.'/resources') {
754: mkdir($tempexport.'/resources',0700);
755: }
1.157 raeburn 756: if (!-e $tempexport.'/resources/'.$count) {
1.143 raeburn 757: mkdir($tempexport.'/resources/'.$count,0700);
758: }
1.157 raeburn 759: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
1.143 raeburn 760: my $copiedfile;
761: if ($copiedfile = Apache::File->new('>'.$destination)) {
762: my $content;
1.157 raeburn 763: if ($caller eq 'resource') {
1.143 raeburn 764: $content = &Apache::lonnet::getfile($url);
765: if ($content eq -1) {
766: $$message = 'Could not copy file '.$filename;
767: } else {
1.157 raeburn 768: &extract_media($content,$count,$tempexport,$href,'resource');
1.143 raeburn 769: $repstatus = 'ok';
770: }
1.159 raeburn 771: } elsif ($caller eq 'noedit' || $caller eq 'uploaded' || $caller eq 'templateupload') {
1.143 raeburn 772: my $rtncode;
1.157 raeburn 773: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
774: if ($repstatus eq 'ok') {
775: if ($url =~ /\.html?$/i) {
776: &extract_media(\$content,$count,$tempexport,$href,'uploaded');
777: }
778: } else {
1.143 raeburn 779: $$message = 'Could not render '.$url.' server message - '.$rtncode;
780: }
781: }
782: if ($repstatus eq 'ok') {
783: print $copiedfile $content;
784: }
785: close($copiedfile);
786: } else {
787: $$message = 'Could not open destination file for '.$filename."\n";
788: }
789: } else {
1.159 raeburn 790: $$message = 'Could not determine name of file for '.$symb."\n";
1.143 raeburn 791: }
1.157 raeburn 792: if ($repstatus eq 'ok') {
793: $content_name = $count.'/'.$filename;
794: }
795: return $content_name;
796: }
797:
798: sub extract_media {
799: my ($content,$count,$tempexport,$href,$caller) = @_;
800: # @$href will contain path to any embedded resources in the content.
801: # For LON-CAPA problems this would be images. applets etc.
802: # For uploaded HTML files this would be images etc.
803: # paths will be in the form $count/res/$file, and urls in the $content will be rewritten with the new paths.
804: return;
1.143 raeburn 805: }
1.74 www 806:
1.158 raeburn 807: sub store_template {
808: my ($contents,$tempexport,$count,$content_type) = @_;
809: if ($contents) {
1.159 raeburn 810: if ($tempexport) {
811: if (!-e $tempexport.'/resources') {
812: mkdir($tempexport.'/resources',0700);
813: }
814: if (!-e $tempexport.'/resources/'.$count) {
815: mkdir($tempexport.'/resources/'.$count,0700);
816: }
817: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
818: my $storetemplate;
819: if ($storetemplate = Apache::File->new('>'.$destination)) {
820: print $storetemplate $contents;
821: close($storetemplate);
822: }
823: if ($content_type eq 'external') {
824: return $count.'/'.$content_type.'.html';
825: } else {
826: return $count.'/'.$content_type.'.xml';
827: }
1.158 raeburn 828: }
829: }
830: }
831:
1.73 bowersj2 832: # Imports the given (name, url) resources into the course
833: # coursenum, coursedom, and folder must precede the list
834: sub group_import {
835: my $coursenum = shift;
836: my $coursedom = shift;
837: my $folder = shift;
1.142 raeburn 838: my $container = shift;
839: my $caller = shift;
1.73 bowersj2 840: while (@_) {
841: my $name = shift;
842: my $url = shift;
1.142 raeburn 843: if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
844: my $errtext = '';
845: my $fatal = 0;
846: my $newmapstr = '<map>'."\n".
847: '<resource id="1" src="" type="start"></resource>'."\n".
848: '<link from="1" to="2" index="1"></link>'."\n".
849: '<resource id="2" src="" type="finish"></resource>'."\n".
850: '</map>';
851: $ENV{'form.output'}=$newmapstr;
852: my $home=&Apache::lonnet::homeserver($coursenum,$coursedom);
853: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$home,
854: 'output',$1.$2);
855: if ($result != m|^/uploaded/|) {
856: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
857: $fatal = 2;
858: }
859: if ($fatal) {
860: return ($errtext,$fatal);
861: }
862: }
1.73 bowersj2 863: if ($url) {
864: my $idx = $#Apache::lonratedt::resources + 1;
865: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
866: my $ext = 'false';
867: if ($url=~/^http:\/\//) { $ext = 'true'; }
868: $url =~ s/:/\:/g;
869: $name =~ s/:/\:/g;
870: $Apache::lonratedt::resources[$idx] =
871: join ':', ($name, $url, $ext, 'normal', 'res');
872: }
873: }
1.142 raeburn 874: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73 bowersj2 875: }
876:
1.114 albertel 877: sub breadcrumbs {
878: my ($where)=@_;
879: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142 raeburn 880: my (@folders);
881: if ($ENV{'form.pagepath'}) {
882: @folders = split('&',$ENV{'form.pagepath'});
883: } else {
884: @folders=split('&',$ENV{'form.folderpath'});
885: }
1.116 albertel 886: my $folderpath;
887: while (@folders) {
888: my $folder=shift(@folders);
889: my $foldername=shift(@folders);
890: if ($folderpath) {$folderpath.='&';}
891: $folderpath.=$folder.'&'.$foldername;
892: my $url='/adm/coursedocs?folderpath='.
893: &Apache::lonnet::escape($folderpath);
1.114 albertel 894: &Apache::lonhtmlcommon::add_breadcrumb(
895: {'href'=>$url,
896: 'title'=>&Apache::lonnet::unescape($foldername),
1.117 albertel 897: 'text'=>'<font size="+1">'.
898: &Apache::lonnet::unescape($foldername).'</font>'
899: });
1.114 albertel 900:
901:
902: }
1.137 albertel 903: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
904: 0,'nohelp');
1.114 albertel 905: }
906:
1.7 www 907: sub editor {
908: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.114 albertel 909:
910: $r->print(&breadcrumbs($folder));
1.10 www 911: my $errtext='';
912: my $fatal=0;
1.142 raeburn 913: my $container='sequence';
914: if ($ENV{'form.pagepath'}) {
915: $container='page';
916: }
1.10 www 917: ($errtext,$fatal)=
1.142 raeburn 918: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17 www 919: if ($#Apache::lonratedt::order<1) {
920: $Apache::lonratedt::order[0]=1;
921: $Apache::lonratedt::resources[1]='';
922: }
1.7 www 923: if ($fatal) {
924: $r->print('<p><font color="red">'.$errtext.'</font></p>');
925: } else {
926: # ------------------------------------------------------------ Process commands
1.121 www 927:
1.16 www 928: # ---------------- if they are for this folder and user allowed to make changes
929: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.123 www 930: # set parameters and change order
1.121 www 931: if (defined($ENV{'form.setparms'})) {
932: my $idx=$ENV{'form.setparms'};
1.123 www 933: # set parameters
1.121 www 934: if ($ENV{'form.randpick_'.$idx}) {
1.122 www 935: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
1.121 www 936: } else {
1.122 www 937: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121 www 938: }
939: if ($ENV{'form.hidprs_'.$idx}) {
1.122 www 940: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121 www 941: } else {
1.122 www 942: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121 www 943: }
944: if ($ENV{'form.encprs_'.$idx}) {
1.122 www 945: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121 www 946: } else {
1.122 www 947: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121 www 948: }
949:
1.123 www 950: if ($ENV{'form.newpos'}) {
951: # change order
952:
953: my $newpos=$ENV{'form.newpos'}-1;
1.124 www 954: my $currentpos=$ENV{'form.currentpos'}-1;
1.125 www 955: my $i;
956: my @neworder=();
957: if ($newpos>$currentpos) {
958: # moving stuff up
959: for ($i=0;$i<$currentpos;$i++) {
960: $neworder[$i]=$Apache::lonratedt::order[$i];
961: }
962: for ($i=$currentpos;$i<$newpos;$i++) {
963: $neworder[$i]=$Apache::lonratedt::order[$i+1];
964: }
965: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
966: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
967: $neworder[$i]=$Apache::lonratedt::order[$i];
968: }
969: } else {
970: # moving stuff down
971: for ($i=0;$i<$newpos;$i++) {
972: $neworder[$i]=$Apache::lonratedt::order[$i];
973: }
974: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
975: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
976: $neworder[$i]=$Apache::lonratedt::order[$i-1];
977: }
978: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
979: $neworder[$i]=$Apache::lonratedt::order[$i];
980: }
981: }
982: @Apache::lonratedt::order=@neworder;
1.124 www 983: }
984: # store the changed version
1.123 www 985:
1.142 raeburn 986: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124 www 987: if ($fatal) {
988: $r->print('<p><font color="red">'.$errtext.'</font></p>');
989: return;
1.123 www 990: }
1.124 www 991:
992: }
1.123 www 993:
1.10 www 994: # upload a file, if present
995: if (($ENV{'form.uploaddoc.filename'}) &&
996: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
1.112 raeburn 997: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
1.10 www 998: # this is for a course, not a user, so set coursedoc flag
999: # probably the only place in the system where this should be "1"
1.126 albertel 1000: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
1.10 www 1001: my $ext='false';
1002: if ($url=~/^http\:\/\//) { $ext='true'; }
1003: $url=~s/\:/\:/g;
1004: my $comment=$ENV{'form.comment'};
1005: $comment=~s/\</\<\;/g;
1006: $comment=~s/\>/\>\;/g;
1007: $comment=~s/\:/\:/g;
1.17 www 1008: if ($folder=~/^supplemental/) {
1009: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
1010: $ENV{'user.domain'}.'___&&&___'.$comment;
1011: }
1.10 www 1012: my $newidx=$#Apache::lonratedt::resources+1;
1013: $Apache::lonratedt::resources[$newidx]=
1014: $comment.':'.$url.':'.$ext.':normal:res';
1015: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
1016: $newidx;
1.104 albertel 1017:
1.142 raeburn 1018: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.104 albertel 1019: if ($fatal) {
1020: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1021: return;
1022: }
1.10 www 1023: }
1024: }
1.8 www 1025: if ($ENV{'form.cmd'}) {
1.10 www 1026: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
1027: if ($cmd eq 'del') {
1.128 albertel 1028: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1029: if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
1030: &Apache::lonnet::removeuploadedurl($url);
1031: }
1.10 www 1032: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
1033: $Apache::lonratedt::order[$i]=
1034: $Apache::lonratedt::order[$i+1];
1035: }
1036: $#Apache::lonratedt::order--;
1037: } elsif ($cmd eq 'up') {
1.38 www 1038: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10 www 1039: my $i=$Apache::lonratedt::order[$idx-1];
1040: $Apache::lonratedt::order[$idx-1]=
1041: $Apache::lonratedt::order[$idx];
1042: $Apache::lonratedt::order[$idx]=$i;
1.38 www 1043: }
1.10 www 1044: } elsif ($cmd eq 'down') {
1.38 www 1045: if (defined($Apache::lonratedt::order[$idx+1])) {
1.10 www 1046: my $i=$Apache::lonratedt::order[$idx+1];
1047: $Apache::lonratedt::order[$idx+1]=
1048: $Apache::lonratedt::order[$idx];
1049: $Apache::lonratedt::order[$idx]=$i;
1.38 www 1050: }
1.36 www 1051: } elsif ($cmd eq 'rename') {
1.142 raeburn 1052: my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36 www 1053: my ($rtitle,@rrest)=split(/\:/,
1054: $Apache::lonratedt::resources[
1055: $Apache::lonratedt::order[$idx]]);
1.38 www 1056: my $comment=
1057: &HTML::Entities::decode($ENV{'form.title'});
1.36 www 1058: $comment=~s/\</\<\;/g;
1059: $comment=~s/\>/\>\;/g;
1060: $comment=~s/\:/\:/g;
1.144 albertel 1061: if ($comment=~/\S/) {
1062: $Apache::lonratedt::resources[
1.36 www 1063: $Apache::lonratedt::order[$idx]]=
1.144 albertel 1064: $comment.':'.join(':',@rrest);
1065: }
1.10 www 1066: }
1067: # Store the changed version
1.104 albertel 1068: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1069: $folder.'.'.$container);
1.104 albertel 1070: if ($fatal) {
1071: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1072: return;
1073: }
1.8 www 1074: }
1.11 www 1075: # Group import/search
1076: if ($ENV{'form.importdetail'}) {
1.73 bowersj2 1077: my @imports;
1078: foreach (split(/\&/,$ENV{'form.importdetail'})) {
1079: if (defined($_)) {
1080: my ($name,$url)=split(/\=/,$_);
1081: $name=&Apache::lonnet::unescape($name);
1082: $url=&Apache::lonnet::unescape($url);
1083: push @imports, $name, $url;
1084: }
1085: }
1.11 www 1086: # Store the changed version
1.104 albertel 1087: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142 raeburn 1088: $container,'londocs',@imports);
1.104 albertel 1089: if ($fatal) {
1090: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1091: return;
1092: }
1.11 www 1093: }
1.53 www 1094: # Loading a complete map
1095: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1.104 albertel 1096: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.53 www 1097: my $idx=$#Apache::lonratedt::resources;
1098: $idx++;
1099: $Apache::lonratedt::resources[$idx]=$_;
1100: $Apache::lonratedt::order
1.104 albertel 1101: [$#Apache::lonratedt::order+1]=$idx;
1102: }
1.53 www 1103:
1104: # Store the changed version
1.104 albertel 1105: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1106: $folder.'.'.$container);
1.104 albertel 1107: if ($fatal) {
1108: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1109: return;
1110: }
1.53 www 1111: }
1.16 www 1112: }
1113: # ---------------------------------------------------------------- End commands
1.7 www 1114: # ---------------------------------------------------------------- Print screen
1.10 www 1115: my $idx=0;
1.148 www 1116: my $shown=0;
1.10 www 1117: $r->print('<table>');
1118: foreach (@Apache::lonratedt::order) {
1119: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1120: unless ($name) { $name=(split(/\//,$url))[-1]; }
1.148 www 1121: unless ($name) { $idx++; next; }
1.112 raeburn 1122: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10 www 1123: $idx++;
1.148 www 1124: $shown++;
1.10 www 1125: }
1.148 www 1126: unless ($shown) {
1.131 www 1127: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1128: }
1.10 www 1129: $r->print('</table>');
1.7 www 1130: }
1131: }
1.1 www 1132:
1.8 www 1133: # --------------------------------------------------------------- An entry line
1134:
1135: sub entryline {
1.112 raeburn 1136: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38 www 1137: $title=~s/\&colon\;/\:/g;
1138: $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109 albertel 1139: &Apache::lonnet::unescape($title)),'"<>&\'');
1.38 www 1140: my $renametitle=$title;
1141: my $foldertitle=$title;
1.142 raeburn 1142: my $pagetitle=$title;
1.122 www 1143: my $orderidx=$Apache::lonratedt::order[$index];
1.109 albertel 1144: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
1145: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1146: $renametitle=$4;
1147: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
1148: &Apache::loncommon::plainname($2,$3).': <br />'.
1149: $foldertitle;
1150: }
1.38 www 1151: $renametitle=~s/\"\;/\\\"/g;
1.8 www 1152: my $line='<tr>';
1153: # Edit commands
1.142 raeburn 1154: my $container;
1.120 www 1155: my $folderpath;
1156: if ($ENV{'form.folderpath'}) {
1.142 raeburn 1157: $container = 'sequence';
1.120 www 1158: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
1159: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
1160: }
1.156 albertel 1161: my ($pagepath,$pagesymb);
1.142 raeburn 1162: if ($ENV{'form.pagepath'}) {
1163: $container = 'page';
1164: $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
1.156 albertel 1165: $pagesymb=&Apache::lonnet::escape($ENV{'form.pagesymb'});
1.142 raeburn 1166: }
1.109 albertel 1167: if ($allowed) {
1.123 www 1168: my $incindex=$index+1;
1169: my $selectbox='';
1170: if ($folder!~/^supplemental/) {
1171: $selectbox=
1.124 www 1172: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123 www 1173: '<select name="newpos" onChange="this.form.submit()">';
1174: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
1175: if ($i==$incindex) {
1176: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1177: } else {
1178: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1179: }
1180: }
1181: $selectbox.='</select>';
1182: }
1.119 www 1183: my %lt=&Apache::lonlocal::texthash(
1184: 'up' => 'Move Up',
1.109 albertel 1185: 'dw' => 'Move Down',
1186: 'rm' => 'Remove',
1187: 'rn' => 'Rename');
1.142 raeburn 1188: if ($ENV{'form.pagepath'}) {
1189: $line.=(<<END);
1190: <form name="entry_$index" action="/adm/coursedocs" method="post">
1191: <input type="hidden" name="pagepath" value="$ENV{'form.pagepath'}" />
1.156 albertel 1192: <input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
1.142 raeburn 1193: <input type="hidden" name="setparms" value="$orderidx" />
1194: <td><table border='0' cellspacing='2' cellpadding='0'>
1195: <tr><td bgcolor="#DDDDDD">
1.156 albertel 1196: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1.142 raeburn 1197: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1198: <tr><td bgcolor="#DDDDDD">
1.156 albertel 1199: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1.142 raeburn 1200: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1201: </table></td>
1202: <td>$selectbox
1203: </td><td bgcolor="#DDDDDD">
1.156 albertel 1204: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142 raeburn 1205: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.156 albertel 1206: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142 raeburn 1207: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1208: END
1209: } else {
1210: $line.=(<<END);
1.121 www 1211: <form name="entry_$index" action="/adm/coursedocs" method="post">
1212: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.122 www 1213: <input type="hidden" name="setparms" value="$orderidx" />
1.54 www 1214: <td><table border='0' cellspacing='2' cellpadding='0'>
1215: <tr><td bgcolor="#DDDDDD">
1.115 albertel 1216: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1.90 www 1217: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54 www 1218: <tr><td bgcolor="#DDDDDD">
1.115 albertel 1219: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1.90 www 1220: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123 www 1221: </table></td>
1222: <td>$selectbox
1223: </td><td bgcolor="#DDDDDD">
1.142 raeburn 1224: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90 www 1225: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.142 raeburn 1226: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.90 www 1227: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1.8 www 1228: END
1.142 raeburn 1229: }
1.8 www 1230: }
1.16 www 1231: # Figure out what kind of a resource this is
1232: my ($extension)=($url=~/\.(\w+)$/);
1233: my $uploaded=($url=~/^\/*uploaded\//);
1.97 albertel 1234: my $icon=&Apache::loncommon::icon($url);
1.17 www 1235: my $isfolder=0;
1.142 raeburn 1236: my $ispage=0;
1.114 albertel 1237: my $folderarg;
1.142 raeburn 1238: my $pagearg;
1239: my $pagefile;
1.16 www 1240: if ($uploaded) {
1.135 albertel 1241: if ($extension eq 'sequence') {
1242: $icon=$iconpath.'/folder_closed.gif';
1243: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
1244: $url='/adm/coursedocs?';
1245: $folderarg=$1;
1246: $isfolder=1;
1.142 raeburn 1247: } elsif ($extension eq 'page') {
1248: $icon=$iconpath.'/page.gif';
1249: $url=~/$coursenum\/([\/\w]+)\.page$/;
1250: $pagearg=$1;
1251: $url='/adm/coursedocs?';
1252: $ispage=1;
1.135 albertel 1253: } else {
1254: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1255: }
1.16 www 1256: }
1.18 www 1257: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.142 raeburn 1258: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113 albertel 1259: my $symb=&Apache::lonnet::symbclean(
1.50 www 1260: &Apache::lonnet::declutter('uploaded/'.
1261: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1262: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
1263: '.sequence').
1264: '___'.$residx.'___'.
1.113 albertel 1265: &Apache::lonnet::declutter($url));
1266: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1267: $url=&Apache::lonnet::clutter($url);
1.127 albertel 1268: if ($url=~/^\/*uploaded\//) {
1269: $url=~/\.(\w+)$/;
1270: my $embstyle=&Apache::loncommon::fileembstyle($1);
1271: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1272: $url='/adm/wrapper'.$url;
1273: } elsif ($embstyle eq 'ssi') {
1274: #do nothing with these
1275: } elsif ($url!~/\.(sequence|page)$/) {
1276: $url='/adm/coursedocs/showdoc'.$url;
1277: }
1.145 albertel 1278: } elsif ($url=~m|^/ext/|) {
1279: $url='/adm/wrapper'.$url;
1.127 albertel 1280: }
1.152 albertel 1281: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1282: if ($container eq 'page') {
1283: my $symb=$ENV{'form.pagesymb'};
1284:
1285: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.142 raeburn 1286: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1.152 albertel 1287: }
1.50 www 1288: }
1.120 www 1289: my $parameterset=' ';
1.114 albertel 1290: if ($isfolder) {
1291: my $foldername=&Apache::lonnet::escape($foldertitle);
1292: my $folderpath=$ENV{'form.folderpath'};
1293: if ($folderpath) { $folderpath.='&' };
1294: $folderpath.=$folderarg.'&'.$foldername;
1295: $url.='folderpath='.&Apache::lonnet::escape($folderpath);
1.147 matthew 1296: $parameterset='<label>'.&mt('Randomly Pick: ').
1.122 www 1297: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
1.147 matthew 1298: (&Apache::lonratedt::getparameter($orderidx,
1299: 'parameter_randompick'))[0].
1300: '" />'.'</label>';
1301:
1.114 albertel 1302: }
1.142 raeburn 1303: if ($ispage) {
1304: my $pagename=&Apache::lonnet::escape($pagetitle);
1305: my $pagepath;
1306: my $folderpath=$ENV{'form.folderpath'};
1307: if ($folderpath) { $pagepath = $folderpath.'&' };
1308: $pagepath.=$pagearg.'&'.$pagename;
1.152 albertel 1309: my $symb=$ENV{'form.pagesymb'};
1310: if (!$symb) {
1311: my $path='uploaded/'.
1312: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
1313: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/';
1314: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1315: $residx,
1316: $path.$pagearg.'.page');
1317: }
1318: $url.='pagepath='.&Apache::lonnet::escape($pagepath).
1319: '&pagesymb='.&Apache::lonnet::escape($symb);
1.142 raeburn 1320: }
1.113 albertel 1321: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1322: '" border="0"></a></td>'.
1.119 www 1323: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120 www 1324: if (($allowed) && ($folder!~/^supplemental/)) {
1325: my %lt=&Apache::lonlocal::texthash(
1326: 'hd' => 'Hidden',
1327: 'ec' => 'URL hidden',
1328: 'sp' => 'Store Parameters');
1.122 www 1329: my $enctext=
1330: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1331: my $hidtext=
1332: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120 www 1333: $line.=(<<ENDPARMS);
1334: <td bgcolor="#BBBBFF"><font size='-2'>
1.147 matthew 1335: <nobr><label><input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</label></nobr></td>
1.149 albertel 1336: <td bgcolor="#BBBBFF"><font size='-2'>
1337: <nobr><label><input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</label></nobr></td>
1.120 www 1338: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1339: <td bgcolor="#BBBBFF"><font size='-2'>
1.121 www 1340: <input type="submit" value="$lt{'sp'}" />
1.120 www 1341: </font></td>
1342: ENDPARMS
1.119 www 1343: }
1.120 www 1344: $line.="</form></tr>";
1.8 www 1345: return $line;
1346: }
1347:
1.27 www 1348: # ---------------------------------------------------------------- tie the hash
1349:
1350: sub tiehash {
1.136 albertel 1351: my ($mode)=@_;
1.27 www 1352: $hashtied=0;
1353: if ($ENV{'request.course.fn'}) {
1.136 albertel 1354: if ($mode eq 'write') {
1355: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1356: &GDBM_WRCREAT(),0640)) {
1357: $hashtied=2;
1358: }
1359: } else {
1360: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
1361: &GDBM_READER(),0640)) {
1.27 www 1362: $hashtied=1;
1.136 albertel 1363: }
1364: }
1.27 www 1365: }
1366: }
1367:
1368: sub untiehash {
1369: if ($hashtied) { untie %hash; }
1370: $hashtied=0;
1371: }
1372:
1.29 www 1373: # --------------------------------------------------------------- check on this
1374:
1375: sub checkonthis {
1376: my ($r,$url,$level,$title)=@_;
1.140 www 1377: $url=&Apache::lonnet::unescape($url);
1.29 www 1378: $alreadyseen{$url}=1;
1379: $r->rflush();
1.41 www 1380: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108 albertel 1381: $r->print("\n<br />");
1.29 www 1382: for (my $i=0;$i<=$level*5;$i++) {
1383: $r->print(' ');
1384: }
1385: $r->print('<a href="'.$url.'" target="cat">'.
1386: ($title?$title:$url).'</a> ');
1387: if ($url=~/^\/res\//) {
1388: my $result=&Apache::lonnet::repcopy(
1389: &Apache::lonnet::filelocation('',$url));
1390: if ($result==OK) {
1.87 www 1391: $r->print('<font color="green">'.&mt('ok').'</font>');
1.29 www 1392: $r->rflush();
1.34 www 1393: &Apache::lonnet::countacc($url);
1394: $url=~/\.(\w+)$/;
1395: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1396: $r->print('<br />');
1397: $r->rflush();
1398: for (my $i=0;$i<=$level*5;$i++) {
1399: $r->print(' ');
1400: }
1.84 www 1401: $r->print('- '.&mt('Rendering').': ');
1.69 albertel 1402: my $oldpath=$ENV{'request.filename'};
1403: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1.34 www 1404: &Apache::lonxml::xmlparse($r,'web',
1405: &Apache::lonnet::getfile(
1.35 albertel 1406: &Apache::lonnet::filelocation('',$url)));
1.94 www 1407: undef($Apache::lonhomework::parsing_a_problem);
1.69 albertel 1408: $ENV{'request.filename'}=$oldpath;
1.34 www 1409: if (($Apache::lonxml::errorcount) ||
1410: ($Apache::lonxml::warningcount)) {
1411: if ($Apache::lonxml::errorcount) {
1.98 www 1412: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.87 www 1413: $Apache::lonxml::errorcount.' '.
1414: &mt('error(s)').'</b></font> ');
1.34 www 1415: }
1416: if ($Apache::lonxml::warningcount) {
1417: $r->print('<font color="blue">'.
1.84 www 1418: $Apache::lonxml::warningcount.' '.
1419: &mt('warning(s)').'</font>');
1.34 www 1420: }
1421: } else {
1.87 www 1422: $r->print('<font color="green">'.&mt('ok').'</font>');
1.34 www 1423: }
1424: $r->rflush();
1425: }
1.29 www 1426: my $dependencies=
1427: &Apache::lonnet::metadata($url,'dependencies');
1428: foreach (split(/\,/,$dependencies)) {
1429: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1430: &checkonthis($r,$_,$level+1);
1431: }
1432: }
1433: } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
1.84 www 1434: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.29 www 1435: } elsif ($result==HTTP_NOT_FOUND) {
1.100 www 1436: unless ($url=~/\$/) {
1437: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
1438: } else {
1439: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
1440: }
1.29 www 1441: } else {
1.84 www 1442: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29 www 1443: }
1444: }
1445: }
1446: }
1447:
1.1 www 1448:
1.75 www 1449: #
1450: # -------------------------------------------------------------- Verify Content
1451: #
1452: sub verifycontent {
1453: my $r=shift;
1.26 www 1454: my $loaderror=&Apache::lonnet::overloaderror($r);
1455: if ($loaderror) { return $loaderror; }
1456:
1457: $r->print('<html><head><title>Verify Content</title></head>'.
1458: &Apache::loncommon::bodytag('Verify Course Documents'));
1.27 www 1459: $hashtied=0;
1.30 www 1460: undef %alreadyseen;
1461: %alreadyseen=();
1.27 www 1462: &tiehash();
1463: foreach (keys %hash) {
1.140 www 1464: if ($hash{$_}=~/\.(page|sequence)$/) {
1465: if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1466: $r->print('<hr /><font color="red">'.
1467: &mt('The following sequence or page is included more than once in your course: ').
1468: &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
1469: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
1470: }
1471: }
1472: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1.29 www 1473: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 1474: }
1475: }
1476: &untiehash();
1.108 albertel 1477: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
1478: &mt('Return to DOCS').'</a>');
1.75 www 1479: }
1480:
1481: # -------------------------------------------------------------- Check Versions
1482:
1483: sub checkversions {
1484: my $r=shift;
1.89 www 1485: $r->print('<html><head><title>Check Versions</title></head>'.
1.26 www 1486: &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89 www 1487: my $header='';
1488: my $startsel='';
1489: my $monthsel='';
1490: my $weeksel='';
1491: my $daysel='';
1492: my $allsel='';
1493: my %changes=();
1494: my $starttime=0;
1.91 www 1495: my $haschanged=0;
1.92 www 1496: my %setversions=&Apache::lonnet::dump('resourceversions',
1497: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1498: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1499:
1500: $hashtied=0;
1501: &tiehash();
1502: my %newsetversions=();
1.91 www 1503: if ($ENV{'form.setmostrecent'}) {
1504: $haschanged=1;
1.92 www 1505: foreach (keys %hash) {
1506: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1507: $newsetversions{$1}='mostrecent';
1.92 www 1508: }
1509: }
1.91 www 1510: } elsif ($ENV{'form.setcurrent'}) {
1511: $haschanged=1;
1.92 www 1512: foreach (keys %hash) {
1513: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1514: my $getvers=&Apache::lonnet::getversion($1);
1515: if ($getvers>0) {
1516: $newsetversions{$1}=$getvers;
1517: }
1.92 www 1518: }
1519: }
1.91 www 1520: } elsif ($ENV{'form.setversions'}) {
1521: $haschanged=1;
1.92 www 1522: foreach (keys %ENV) {
1523: if ($_=~/^form\.set_version_(.+)$/) {
1524: my $src=$1;
1525: if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
1526: $newsetversions{$src}=$ENV{$_};
1527: }
1528: }
1529: }
1.91 www 1530: }
1531: if ($haschanged) {
1.92 www 1532: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1533: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1534: $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {
1535: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1536: } else {
1537: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1538: }
1.136 albertel 1539: &mark_hash_old();
1.91 www 1540: }
1.136 albertel 1541: &changewarning($r,'');
1.89 www 1542: if ($ENV{'form.timerange'} eq 'all') {
1543: # show all documents
1544: $header=&mt('All Documents in Course');
1.91 www 1545: $allsel=1;
1.90 www 1546: foreach (keys %hash) {
1547: if ($_=~/^ids\_(\/res\/.+)$/) {
1548: my $src=$1;
1549: $changes{$src}=1;
1550: }
1551: }
1.89 www 1552: } else {
1553: # show documents which changed
1554: %changes=&Apache::lonnet::dump
1555: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.30 www 1556: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89 www 1557: my $firstkey=(keys %changes)[0];
1558: unless ($firstkey=~/^error\:/) {
1559: unless ($ENV{'form.timerange'}) {
1560: $ENV{'form.timerange'}=604800;
1561: }
1562: my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
1563: .&mt('seconds');
1564: if ($ENV{'form.timerange'}==-1) {
1565: $seltext='since start of course';
1566: $startsel='selected';
1567: $ENV{'form.timerange'}=time;
1568: }
1569: $starttime=time-$ENV{'form.timerange'};
1570: if ($ENV{'form.timerange'}==2592000) {
1571: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1572: $monthsel='selected';
1573: } elsif ($ENV{'form.timerange'}==604800) {
1574: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1575: $weeksel='selected';
1576: } elsif ($ENV{'form.timerange'}==86400) {
1577: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1578: $daysel='selected';
1579: }
1580: $header=&mt('Content changed').' '.$seltext;
1581: } else {
1582: $header=&mt('No content modifications yet.');
1583: }
1584: }
1.92 www 1585: %setversions=&Apache::lonnet::dump('resourceversions',
1586: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1587: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89 www 1588: my %lt=&Apache::lonlocal::texthash
1.88 www 1589: ('st' => 'Version changes since start of Course',
1590: 'lm' => 'Version changes since last Month',
1591: 'lw' => 'Version changes since last Week',
1592: 'sy' => 'Version changes since Yesterday',
1.91 www 1593: 'al' => 'All Resources (possibly large output)',
1.88 www 1594: 'sd' => 'Display',
1.84 www 1595: 'fi' => 'File',
1596: 'md' => 'Modification Date',
1.87 www 1597: 'mr' => 'Most recently published Version',
1598: 've' => 'Version used in Course',
1.91 www 1599: 'vu' => 'Set Version to be used in Course',
1600: 'sv' => 'Set Versions to be used in Course according to Selections below',
1601: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1602: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84 www 1603: 'di' => 'Differences');
1.89 www 1604: $r->print(<<ENDHEADERS);
1.31 www 1605: <form action="/adm/coursedocs" method="post">
1.91 www 1606: <input type="hidden" name="versions" value="1" />
1607: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1608: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31 www 1609: <select name="timerange">
1.88 www 1610: <option value='all' $allsel>$lt{'al'}</option>
1.84 www 1611: <option value="-1" $startsel>$lt{'st'}</option>
1612: <option value="2592000" $monthsel>$lt{'lm'}</option>
1613: <option value="604800" $weeksel>$lt{'lw'}</option>
1614: <option value="86400" $daysel>$lt{'sy'}</option>
1.31 www 1615: </select>
1.91 www 1616: <input type="submit" name="display" value="$lt{'sd'}" />
1.89 www 1617: <h3>$header</h3>
1.91 www 1618: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103 matthew 1619: <table border="0">
1.31 www 1620: ENDHEADERS
1.91 www 1621: foreach (sort keys %changes) {
1.89 www 1622: if ($changes{$_}>$starttime) {
1623: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1624: my $currentversion=&Apache::lonnet::getversion($_);
1.93 www 1625: if ($currentversion<0) {
1626: $currentversion=&mt('Could not be determined.');
1627: }
1.89 www 1628: my $linkurl=&Apache::lonnet::clutter($_);
1629: $r->print(
1.103 matthew 1630: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91 www 1631: &Apache::lonnet::gettitle($linkurl).
1.103 matthew 1632: '</b></font></td></tr>'.
1633: '<tr><td> </td>'.
1634: '<td colspan="4">'.
1635: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1636: '</a></td></tr>'.
1637: '<tr><td></td>'.
1638: '<td title="'.$lt{'md'}.'">'.
1.102 matthew 1639: &Apache::lonlocal::locallocaltime(
1640: &Apache::lonnet::metadata($root.'.'.$extension,
1641: 'lastrevisiondate')
1642: ).
1.103 matthew 1643: '</td>'.
1644: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1645: '<font size="+1">'.$currentversion.'</font>'.
1646: '</nobr></td>'.
1647: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1648: '<font size="+1">');
1.87 www 1649: # Used in course
1.89 www 1650: my $usedversion=$hash{'version_'.$linkurl};
1.93 www 1651: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89 www 1652: $r->print($usedversion);
1653: } else {
1654: $r->print($currentversion);
1655: }
1.103 matthew 1656: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1657: '<nobr>Use: ');
1.87 www 1658: # Set version
1.92 www 1659: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89 www 1660: 'set_version_'.$linkurl,
1.136 albertel 1661: ('select_form_order' =>
1662: ['',1..$currentversion,'mostrecent'],
1663: '' => '',
1.93 www 1664: 'mostrecent' => 'most recent',
1.89 www 1665: map {$_,$_} (1..$currentversion))));
1.103 matthew 1666: $r->print('</nobr></td></tr><tr><td></td>');
1.89 www 1667: my $lastold=1;
1668: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1669: my $url=$root.'.'.$prevvers.'.'.$extension;
1670: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1671: $starttime) {
1672: $lastold=$prevvers;
1673: }
1674: }
1.103 matthew 1675: #
1676: # Code to figure out how many version entries should go in
1677: # each of the four columns
1678: my $entries_per_col = 0;
1679: my $num_entries = ($currentversion-$lastold);
1680: if ($num_entries % 4 == 0) {
1681: $entries_per_col = $num_entries/4;
1682: } else {
1683: $entries_per_col = $num_entries/4 + 1;
1684: }
1685: my $entries_count = 0;
1686: $r->print('<td valign="top"><font size="-2">');
1687: my $cols_output = 1;
1.32 www 1688: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89 www 1689: my $url=$root.'.'.$prevvers.'.'.$extension;
1.103 matthew 1690: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91 www 1691: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103 matthew 1692: &Apache::lonlocal::locallocaltime(
1693: &Apache::lonnet::metadata($url,
1694: 'lastrevisiondate')
1695: ).
1.91 www 1696: ')');
1.89 www 1697: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33 www 1698: $r->print(' <a href="/adm/diff?filename='.
1.89 www 1699: &Apache::lonnet::clutter($root.'.'.$extension).
1700: '&versionone='.$prevvers.
1701: '">'.&mt('Diffs').'</a>');
1702: }
1.103 matthew 1703: $r->print('</nobr><br />');
1704: if (++$entries_count % $entries_per_col == 0) {
1705: $r->print('</font></td>');
1706: if ($cols_output != 4) {
1707: $r->print('<td valign="top"><font size="-2">');
1708: $cols_output++;
1709: }
1710: }
1.89 www 1711: }
1.103 matthew 1712: while($cols_output++ < 4) {
1713: $r->print('</font></td><td><font>')
1714: }
1715: $r->print('</font></td></tr>'."\n");
1.89 www 1716: }
1717: }
1.92 www 1718: $r->print('</table></form>');
1.89 www 1719: $r->print('<h1>'.&mt('Done').'.</h1>');
1720:
1721: &untiehash();
1.75 www 1722: }
1723:
1.136 albertel 1724: sub mark_hash_old {
1725: my $retie_hash=0;
1726: if ($hashtied) {
1727: $retie_hash=1;
1728: &untiehash();
1729: }
1730: &tiehash('write');
1731: $hash{'old'}=1;
1732: &untiehash();
1733: if ($retie_hash) { &tiehash(); }
1734: }
1735:
1736: sub is_hash_old {
1737: my $untie_hash=0;
1738: if (!$hashtied) {
1739: $untie_hash=1;
1740: &tiehash();
1741: }
1742: my $return=$hash{'old'};
1743: if ($untie_hash) { &untiehash(); }
1744: return $return;
1745: }
1746:
1.91 www 1747: sub changewarning {
1748: my ($r,$postexec)=@_;
1.136 albertel 1749: if (!&is_hash_old()) { return; }
1.150 albertel 1750: my $pathvar='folderpath';
1751: my $path=&Apache::lonnet::escape($ENV{'form.folderpath'});
1752: if (defined($ENV{'form.pagepath'})) {
1753: $pathvar='pagepath';
1754: $path=&Apache::lonnet::escape($ENV{'form.pagepath'});
1.156 albertel 1755: $path.='&symb='.&Apache::lonnet::escape($ENV{'form.pagesymb'});
1.150 albertel 1756: }
1.91 www 1757: $r->print(
1758: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1759: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1.150 albertel 1760: '<input type="hidden" name="orgurl" value="/adm/coursedocs?'.
1761: $pathvar.'='.$path.
1.117 albertel 1762: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.91 www 1763: &mt('Changes will become active for your current session after').
1764: ' <input type="hidden" name="'.
1765: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
1766: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
1767: $help{'Caching'}.'</font></h3></form>');
1768: }
1769:
1.75 www 1770: # ================================================================ Main Handler
1771: sub handler {
1772: my $r = shift;
1.82 www 1773: &Apache::loncommon::content_type($r,'text/html');
1.75 www 1774: $r->send_http_header;
1775: return OK if $r->header_only;
1776:
1777: # --------------------------------------------- Initialize help topics for this
1778: foreach ('Adding_Course_Doc','Main_Course_Documents',
1779: 'Adding_External_Resource','Navigate_Content',
1780: 'Adding_Folders','Docs_Overview', 'Load_Map',
1.142 raeburn 1781: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.130 www 1782: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1783: 'Check_Resource_Versions','Verify_Content') {
1.75 www 1784: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
1785: }
1786: # Composite help files
1787: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
1788: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
1789: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
1790: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86 albertel 1791: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1792: 'Option_Response_Simple');
1.75 www 1793: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
1794: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1795: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
1796: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1797: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142 raeburn 1798:
1.75 www 1799: if ($ENV{'form.verify'}) {
1800: &verifycontent($r);
1801: } elsif ($ENV{'form.versions'}) {
1802: &checkversions($r);
1803: } elsif ($ENV{'form.dumpcourse'}) {
1804: &dumpcourse($r);
1.138 raeburn 1805: } elsif ($ENV{'form.exportcourse'}) {
1806: &exportcourse($r);
1.26 www 1807: } else {
1.7 www 1808: # is this a standard course?
1809:
1810: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.155 raeburn 1811: my $forcestandard = 0;
1.15 www 1812: my $forcesupplement;
1813: my $script='';
1814: my $allowed;
1815: my $events='';
1.19 www 1816: my $showdoc=0;
1.142 raeburn 1817: my $containertag;
1818: my $uploadtag;
1.15 www 1819: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.152 albertel 1820: ['folderpath','pagepath','pagesymb']);
1.114 albertel 1821: if ($ENV{'form.folderpath'}) {
1822: my (@folderpath)=split('&',$ENV{'form.folderpath'});
1823: $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
1824: $ENV{'form.folder'}=pop(@folderpath);
1.142 raeburn 1825: }
1826: if ($ENV{'form.pagepath'}) {
1827: my (@pagepath)=split('&',$ENV{'form.pagepath'});
1828: $ENV{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
1829: $ENV{'form.folder'}=pop(@pagepath);
1.156 albertel 1830: $containertag = '<input type="hidden" name="pagepath" value="" />'.
1831: '<input type="hidden" name="pagesymb" value="" />';
1832: $uploadtag = '<input type="hidden" name="pagepath" value="'.$ENV{'form.pagepath'}.'" />'.
1833: '<input type="hidden" name="pagesymb" value="'.$ENV{'form.pagesymb'}.'" />';
1.142 raeburn 1834: }
1.21 www 1835: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127 albertel 1836: $showdoc='/'.$1;
1.21 www 1837: }
1838: unless ($showdoc) { # got called from remote
1.156 albertel 1839: if (($ENV{'form.folder'}=~/^default_/) ||
1.155 raeburn 1840: ($ENV{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1841: $forcestandard = 1;
1842: }
1.15 www 1843: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7 www 1844:
1.4 www 1845: # does this user have privileges to post, etc?
1.77 www 1846: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.15 www 1847: if ($allowed) {
1848: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1849: $script=&Apache::lonratedt::editscript('simple');
1850: }
1851: } else { # got called in sequence from course
1852: $allowed=0;
1.49 www 1853: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1854: $events='onLoad="'.&Apache::lonmenu::loadevents.
1855: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3 www 1856: }
1.4 www 1857:
1858: # get course data
1859: my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1860: my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
1861:
1.14 www 1862: # get personal data
1863:
1864: my $uname=$ENV{'user.name'};
1865: my $udom=$ENV{'user.domain'};
1866: my $plainname=&Apache::lonnet::escape(
1867: &Apache::loncommon::plainname($uname,$udom));
1868:
1.8 www 1869: # graphics settings
1.4 www 1870:
1.8 www 1871: $iconpath = $r->dir_config('lonIconsURL') . "/";
1872:
1.22 www 1873: my $now=time;
1.64 www 1874:
1.4 www 1875: # print screen
1.1 www 1876: $r->print(<<ENDDOCUMENT);
1877: <html>
1878: <head>
1879: <title>The LearningOnline Network with CAPA</title>
1.16 www 1880: <script>
1881: $script
1.20 www 1882: </script>
1.19 www 1883: ENDDOCUMENT
1884: if ($allowed) {
1885: $r->print(<<ENDNEWSCRIPT);
1.20 www 1886: <script>
1.16 www 1887: function makenewfolder(targetform,folderseq) {
1888: var foldername=prompt('Name of New Folder','New Folder');
1889: if (foldername) {
1890: targetform.importdetail.value=foldername+"="+folderseq;
1891: targetform.submit();
1892: }
1893: }
1894:
1.142 raeburn 1895: function makenewpage(targetform,folderseq) {
1896: var pagename=prompt('Name of New Page','New Page');
1897: if (pagename) {
1898: targetform.importdetail.value=pagename+"="+folderseq;
1899: targetform.submit();
1900: }
1901: }
1902:
1.18 www 1903: function makenewext(targetname) {
1904: this.document.forms.extimport.useform.value=targetname;
1905: window.open('/adm/rat/extpickframe.html');
1906: }
1907:
1.62 www 1908: function makeexamupload() {
1909: var title=prompt('Listed Title for the Uploaded Score');
1910: if (title) {
1911: this.document.forms.newexamupload.importdetail.value=
1912: title+'=/res/lib/templates/examupload.problem';
1913: this.document.forms.newexamupload.submit();
1914: }
1915: }
1916:
1.22 www 1917: function makesmppage() {
1.38 www 1918: var title=prompt('Listed Title for the Page');
1919: if (title) {
1.22 www 1920: this.document.forms.newsmppg.importdetail.value=
1921: title+'=/adm/$udom/$uname/$now/smppg';
1922: this.document.forms.newsmppg.submit();
1.38 www 1923: }
1.22 www 1924: }
1925:
1.55 www 1926: function makesmpproblem() {
1927: var title=prompt('Listed Title for the Problem');
1928: if (title) {
1929: this.document.forms.newsmpproblem.importdetail.value=
1.63 www 1930: title+'=/res/lib/templates/simpleproblem.problem';
1.55 www 1931: this.document.forms.newsmpproblem.submit();
1932: }
1933: }
1934:
1.22 www 1935: function makebulboard() {
1.38 www 1936: var title=prompt('Listed Title for the Bulletin Board');
1937: if (title) {
1.22 www 1938: this.document.forms.newbul.importdetail.value=
1939: title+'=/adm/$udom/$uname/$now/bulletinboard';
1940: this.document.forms.newbul.submit();
1.38 www 1941: }
1.22 www 1942: }
1943:
1.101 www 1944: function makeabout() {
1945: var user=prompt("Enter user\@domain for User's 'About Me' Page");
1946: if (user) {
1947: var comp=new Array();
1948: comp=user.split('\@');
1949: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
1950: if ((comp[0]) && (comp[1])) {
1951: this.document.forms.newaboutsomeone.importdetail.value=
1952: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1953: this.document.forms.newaboutsomeone.submit();
1954: }
1955: }
1956: }
1957: }
1958:
1.110 raeburn 1959: function makeims() {
1960: var caller = document.forms.ims.folder.value
1961: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
1962: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
1963: newWindow.location.href = newlocation
1964: }
1965:
1966:
1.18 www 1967: function finishpick() {
1968: var title=this.document.forms.extimport.title.value;
1969: var url=this.document.forms.extimport.url.value;
1970: var form=this.document.forms.extimport.useform.value;
1971: eval
1972: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
1973: '";this.document.forms.'+form+'.submit();');
1.16 www 1974: }
1.36 www 1975:
1.156 albertel 1976: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.36 www 1977: var title=prompt('New Title',oldtitle);
1978: if (title) {
1979: this.document.forms.renameform.title.value=title;
1980: this.document.forms.renameform.cmd.value='rename_'+index;
1.142 raeburn 1981: if (container == 'sequence') {
1982: this.document.forms.renameform.folderpath.value=folderpath;
1983: }
1984: if (container == 'page') {
1985: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 1986: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 1987: }
1.54 www 1988: this.document.forms.renameform.submit();
1989: }
1990: }
1991:
1.156 albertel 1992: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1.106 www 1993: if (confirm('Remove "'+oldtitle+'"?')) {
1.54 www 1994: this.document.forms.renameform.cmd.value='del_'+index;
1.142 raeburn 1995: if (container == 'sequence') {
1996: this.document.forms.renameform.folderpath.value=folderpath;
1997: }
1998: if (container == 'page') {
1999: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 2000: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 2001: }
1.36 www 2002: this.document.forms.renameform.submit();
2003: }
2004: }
1.121 www 2005:
1.16 www 2006: </script>
1.42 www 2007:
2008: ENDNEWSCRIPT
2009: }
2010: # -------------------------------------------------------------------- Body tag
2011: $r->print('</head>'.
1.72 www 2012: &Apache::loncommon::bodytag('Course Documents','',$events,
1.99 www 2013: '','',$showdoc).
1.134 albertel 2014: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.42 www 2015: unless ($showdoc) {
1.81 www 2016: # -----------------------------------------------------------------------------
2017: my %lt=&Apache::lonlocal::texthash(
2018: 'uplm' => 'Upload a new main course document',
2019: 'upls' => 'Upload a new supplemental course document',
2020: 'impp' => 'Import a published document',
2021: 'spec' => 'Special documents',
2022: 'upld' => 'Upload Document',
2023: 'srch' => 'Search',
2024: 'impo' => 'Import',
2025: 'selm' => 'Select Map',
2026: 'load' => 'Load Map',
2027: 'newf' => 'New Folder',
1.142 raeburn 2028: 'newp' => 'New Composite Page',
1.81 www 2029: 'extr' => 'External Resource',
2030: 'syll' => 'Syllabus',
2031: 'navc' => 'Navigate Contents',
2032: 'sipa' => 'Simple Page',
2033: 'sipr' => 'Simple Problem',
2034: 'scuf' => 'Score Upload Form',
2035: 'bull' => 'Bulletin Board',
1.96 sakharuk 2036: 'mypi' => 'My Personal Info',
1.101 www 2037: 'abou' => 'About User',
1.110 raeburn 2038: 'imsf' => 'Import IMS package',
1.96 sakharuk 2039: 'file' => 'File',
2040: 'title' => 'Title',
2041: 'comment' => 'Comment'
1.81 www 2042: );
2043: # -----------------------------------------------------------------------------
1.42 www 2044: if ($allowed) {
1.74 www 2045: my $dumpbut=&dumpbutton();
1.138 raeburn 2046: my $exportbut=&exportbutton();
1.88 www 2047: my %lt=&Apache::lonlocal::texthash(
2048: 'vc' => 'Verify Content',
2049: 'cv' => 'Check/Set Resource Versions',
2050: );
1.118 albertel 2051:
2052: my $folderpath=$ENV{'form.folderpath'};
2053: if (!$folderpath) {
2054: if ($ENV{'form.folder'} eq '' ||
2055: $ENV{'form.folder'} eq 'supplemental') {
2056: $folderpath='default&'.
2057: &Apache::lonnet::escape(&mt('Main Course Documents'));
2058: }
2059: }
1.142 raeburn 2060: unless ($ENV{'form.pagepath'}) {
2061: $containertag = '<input type="hidden" name="folderpath" value="" />';
2062: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2063: }
2064:
1.42 www 2065: $r->print(<<ENDCOURSEVERIFY);
1.36 www 2066: <form name="renameform" method="post" action="/adm/coursedocs">
2067: <input type="hidden" name="title" />
2068: <input type="hidden" name="cmd" />
1.142 raeburn 2069: $containertag
1.36 www 2070: </form>
1.39 www 2071: <form name="simpleedit" method="post" action="/adm/coursedocs">
2072: <input type=hidden name="importdetail" value="">
1.142 raeburn 2073: $uploadtag
1.39 www 2074: </form>
1.26 www 2075: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74 www 2076: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2077: <tr><td bgcolor="#DDDDCC">
1.130 www 2078: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74 www 2079: </td><td bgcolor="#DDDDCC">
1.130 www 2080: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74 www 2081: $dumpbut
1.138 raeburn 2082: $exportbut
1.74 www 2083: </td></tr></table>
1.25 www 2084: </form>
2085: ENDCOURSEVERIFY
1.74 www 2086: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96 sakharuk 2087: &mt('Editing the Table of Contents for your Course')));
1.25 www 2088: }
1.17 www 2089: # --------------------------------------------------------- Standard documents
1.43 www 2090: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7 www 2091: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116 albertel 2092: $r->print('<tr><td bgcolor="#BBBBBB">');
2093: # '<h2>'.&mt('Main Course Documents').
2094: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7 www 2095: my $folder=$ENV{'form.folder'};
1.117 albertel 2096: if ($folder eq '' || $folder eq 'supplemental') {
1.112 raeburn 2097: $folder='default';
1.116 albertel 2098: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112 raeburn 2099: }
1.51 www 2100: my $postexec='';
2101: if ($folder eq 'default') {
2102: $r->print('<script>this.window.name="loncapaclient";</script>');
2103: } else {
1.117 albertel 2104: #$postexec='self.close();';
1.51 www 2105: }
1.40 www 2106: $hadchanges=0;
1.7 www 2107: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40 www 2108: if ($hadchanges) {
1.136 albertel 2109: &mark_hash_old()
1.40 www 2110: }
1.136 albertel 2111: &changewarning($r,$postexec);
1.16 www 2112: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2113: '.sequence';
1.142 raeburn 2114: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2115: '.page';
2116:
1.8 www 2117: $r->print(<<ENDFORM);
1.43 www 2118: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2119: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2120: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2121: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11 www 2122: </tr>
1.16 www 2123: <tr><td bgcolor="#DDDDDD">
1.96 sakharuk 2124: $lt{'file'}:<br />
1.10 www 2125: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2126: <input type="file" name="uploaddoc" size="40">
1.8 www 2127: <br />
1.96 sakharuk 2128: $lt{'title'}:<br />
1.11 www 2129: <input type="text" size="50" name="comment">
1.142 raeburn 2130: $uploadtag
1.10 www 2131: <input type="hidden" name="cmd" value="upload_default">
1.129 albertel 2132: <nobr>
1.81 www 2133: <input type="submit" value="$lt{'upld'}">
1.60 albertel 2134: $help{'Uploading_From_Harddrive'}
1.58 albertel 2135: </nobr>
1.60 albertel 2136: </form>
1.11 www 2137: </td>
1.16 www 2138: <td bgcolor="#DDDDDD">
1.39 www 2139: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.142 raeburn 2140: $uploadtag
1.115 albertel 2141: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58 albertel 2142: <nobr>
1.115 albertel 2143: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58 albertel 2144: $help{'Importing_LON-CAPA_Resource'}
2145: </nobr>
1.59 www 2146: <p>
2147: <hr />
1.68 bowersj2 2148: <input type="text" size="20" name="importmap"><br />
2149: <nobr><input type=button
1.52 www 2150: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81 www 2151: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68 bowersj2 2152: $help{'Load_Map'}</nobr>
1.59 www 2153: </p>
1.52 www 2154: </form>
1.142 raeburn 2155: </td>
2156: <td bgcolor="#DDDDDD">
2157: ENDFORM
2158: unless ($ENV{'form.pagepath'}) {
2159: $r->print(<<ENDFORM);
1.11 www 2160: <form action="/adm/coursedocs" method="post" name="newfolder">
1.115 albertel 2161: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.13 www 2162: <input type=hidden name="importdetail" value="">
1.58 albertel 2163: <nobr>
1.16 www 2164: <input name="newfolder" type="button"
2165: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2166: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58 albertel 2167: </nobr>
1.11 www 2168: </form>
1.142 raeburn 2169: <form action="/adm/coursedocs" method="post" name="newpage">
2170: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2171: <input type=hidden name="importdetail" value="">
2172: <nobr>
2173: <input name="newpage" type="button"
2174: onClick="javascript:makenewpage(this.form,'$pageseq');"
2175: value="$lt{'newp'}" />$help{'Adding_Pages'}
2176: </nobr>
2177: </form>
1.11 www 2178: <form action="/adm/coursedocs" method="post" name="newext">
1.142 raeburn 2179: $uploadtag
1.13 www 2180: <input type=hidden name="importdetail" value="">
1.58 albertel 2181: <nobr>
1.18 www 2182: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.81 www 2183: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58 albertel 2184: </nobr>
1.11 www 2185: </form>
2186: <form action="/adm/coursedocs" method="post" name="newsyl">
1.142 raeburn 2187: $uploadtag
1.14 www 2188: <input type=hidden name="importdetail"
2189: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2190: <nobr>
1.81 www 2191: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2192: $help{'Syllabus'}
1.58 albertel 2193: </nobr>
2194: </form>
1.17 www 2195: <form action="/adm/coursedocs" method="post" name="newnav">
1.142 raeburn 2196: $uploadtag
1.15 www 2197: <input type=hidden name="importdetail"
2198: value="Navigate Content=/adm/navmaps">
1.58 albertel 2199: <nobr>
1.81 www 2200: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47 www 2201: $help{'Navigate_Content'}
1.58 albertel 2202: </nobr>
1.22 www 2203: </form>
2204: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.142 raeburn 2205: $uploadtag
1.22 www 2206: <input type=hidden name="importdetail" value="">
1.58 albertel 2207: <nobr>
1.81 www 2208: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65 bowersj2 2209: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58 albertel 2210: </nobr>
1.55 www 2211: </form>
2212: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142 raeburn 2213: $uploadtag
1.55 www 2214: <input type=hidden name="importdetail" value="">
1.58 albertel 2215: <nobr>
1.81 www 2216: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65 bowersj2 2217: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62 www 2218: </nobr>
2219: </form>
2220: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 2221: $uploadtag
1.62 www 2222: <input type=hidden name="importdetail" value="">
2223: <nobr>
1.81 www 2224: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62 www 2225: onClick="javascript:makeexamupload();" />
1.66 bowersj2 2226: $help{'Score_Upload_Form'}
1.58 albertel 2227: </nobr>
1.22 www 2228: </form>
2229: <form action="/adm/coursedocs" method="post" name="newbul">
1.142 raeburn 2230: $uploadtag
1.22 www 2231: <input type=hidden name="importdetail" value="">
1.58 albertel 2232: <nobr>
1.81 www 2233: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22 www 2234: onClick="javascript:makebulboard();" />
1.65 bowersj2 2235: $help{'Bulletin Board'}
1.58 albertel 2236: </nobr>
2237: </form>
1.12 www 2238: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.142 raeburn 2239: $uploadtag
1.14 www 2240: <input type=hidden name="importdetail"
2241: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2242: <nobr>
1.81 www 2243: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2244: $help{'My Personal Info'}
1.101 www 2245: </nobr>
2246: </form>
2247: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142 raeburn 2248: $uploadtag
1.101 www 2249: <input type=hidden name="importdetail" value="">
2250: <nobr>
2251: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2252: onClick="javascript:makeabout();" />
1.110 raeburn 2253: </nobr>
1.142 raeburn 2254: ENDFORM
2255: }
2256: if ($ENV{'form.pagepath'}) {
2257: $r->print(<<ENDBLOCK);
2258: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2259: $uploadtag
2260: <input type=hidden name="importdetail" value="">
2261: <nobr>
2262: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2263: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2264: </nobr>
2265: </form>
2266: <form action="/adm/coursedocs" method="post" name="newexamupload">
2267: $uploadtag
2268: <input type=hidden name="importdetail" value="">
2269: <nobr>
2270: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2271: onClick="javascript:makeexamupload();" />
2272: $help{'Score_Upload_Form'}
2273: </nobr>
2274: </form>
2275: ENDBLOCK
2276: } else {
2277: $r->print(<<ENDFORM);
1.110 raeburn 2278: </form>
2279: <form action="/adm/imsimportdocs" method="post" name="ims">
1.118 albertel 2280: <input type="hidden" name="folder" value="$folder" />
1.110 raeburn 2281: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1.58 albertel 2282: </nobr>
2283: </form>
1.8 www 2284: ENDFORM
1.142 raeburn 2285: }
2286: $r->print('</td></tr>'."\n".
2287: '</table>');
1.24 www 2288: $r->print('</td></tr>');
1.7 www 2289: }
2290: # ----------------------------------------------------- Supplemental documents
2291: if (!$forcestandard) {
1.116 albertel 2292: $r->print('<tr><td bgcolor="#BBBBBB">');
2293: # '<h2>'.&mt('Supplemental Course Documents').
2294: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7 www 2295: my $folder=$ENV{'form.folder'};
1.117 albertel 2296: unless ($folder=~/^supplemental/) {
1.116 albertel 2297: $folder='supplemental';
1.117 albertel 2298: }
2299: if ($folder =~ /^supplemental$/ &&
2300: $ENV{'form.folderpath'} =~ /^default\&/) {
2301: $ENV{'form.folderpath'}='supplemental&'.
2302: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116 albertel 2303: }
1.7 www 2304: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 2305: if ($allowed) {
1.17 www 2306: my $folderseq=
2307: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2308: '.sequence';
2309:
1.8 www 2310: $r->print(<<ENDSUPFORM);
1.43 www 2311: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2312: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2313: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17 www 2314: </tr>
2315: <tr><td bgcolor="#DDDDDD">
1.10 www 2316: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2317: <input type="file" name="uploaddoc" size="40">
1.96 sakharuk 2318: <br />$lt{'comment'}:<br />
1.4 www 2319: <textarea cols=50 rows=4 name='comment'>
2320: </textarea>
1.115 albertel 2321: <br />
2322: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.10 www 2323: <input type="hidden" name="cmd" value="upload_supplemental">
1.58 albertel 2324: <nobr>
1.81 www 2325: <input type="submit" value="$lt{'upld'}">
1.58 albertel 2326: $help{'Uploading_From_Harddrive'}
2327: </nobr>
2328: </form>
1.17 www 2329: </td>
2330: <td bgcolor="#DDDDDD">
1.18 www 2331: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.115 albertel 2332: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2333: <input type=hidden name="importdetail" value="">
1.58 albertel 2334: <nobr>
1.17 www 2335: <input name="newfolder" type="button"
2336: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2337: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58 albertel 2338: </nobr>
1.17 www 2339: </form>
1.18 www 2340: <form action="/adm/coursedocs" method="post" name="supnewext">
1.115 albertel 2341: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2342: <input type=hidden name="importdetail" value="">
1.58 albertel 2343: <nobr>
1.18 www 2344: <input name="newext" type="button"
2345: onClick="javascript:makenewext('supnewext');"
1.81 www 2346: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58 albertel 2347: </nobr>
1.17 www 2348: </form>
1.18 www 2349: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.115 albertel 2350: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2351: <input type=hidden name="importdetail"
2352: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2353: <nobr>
1.81 www 2354: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2355: $help{'Syllabus'}
1.58 albertel 2356: </nobr>
2357: </form>
1.18 www 2358: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.115 albertel 2359: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17 www 2360: <input type=hidden name="importdetail"
2361: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2362: <nobr>
1.81 www 2363: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2364: $help{'My Personal Info'}
1.58 albertel 2365: </nobr>
2366: </form>
1.17 www 2367: </td></tr>
1.24 www 2368: </table></td></tr>
1.8 www 2369: ENDSUPFORM
2370: }
1.7 www 2371: }
1.18 www 2372: if ($allowed) {
2373: $r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
2374: }
1.24 www 2375: $r->print('</table>');
1.19 www 2376: } else {
2377: # -------------------------------------------------------- This is showdoc mode
1.141 albertel 2378: $r->print("<h1>".&mt('Uploaded Document').' - '.
2379: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81 www 2380: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
2381: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1.19 www 2382: }
1.26 www 2383: }
1.95 www 2384: $r->print('</body></html>');
1.26 www 2385: return OK;
1.1 www 2386: }
2387:
2388: 1;
2389: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>