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