File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.158:
download - view:
text,
annotated -
select for diffs
Thu Dec 23 14:00:58 2004 UTC (19 years, 8 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Export to IMS now exports discussion content - uses lonfeedback::listdiscussion(). Modification to export of templated documents (syllabus, aboutme, simplepage etc.) to IMS. Simple problems now converted to standard LON-CAPA problem format before export to IMS. Same routines could be used to dump simple problems to CSTR.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.158 2004/12/23 14:00:58 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonratedt;
37: use Apache::lonratsrv;
38: use Apache::lonxml;
39: use Apache::loncreatecourse;
40: use Apache::lonnavmaps;
41: use HTML::Entities;
42: use GDBM_File;
43: use Apache::lonlocal;
44: use Cwd;
45:
46: my $iconpath;
47:
48: my %hash;
49:
50: my $hashtied;
51: my %alreadyseen=();
52:
53: my $hadchanges;
54:
55: # Available help topics
56:
57: my %help=();
58:
59: # Mapread read maps into lonratedt::global arrays
60: # @order and @resources, determines status
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)=@_;
74: my ($outtext,$errtext)=
75: &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
76: $map,1);
77: if ($errtext) { return ($errtext,2); }
78:
79: $hadchanges=1;
80: return ($errtext,0);
81: }
82:
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: }
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) {
108: $home++;
109: $outhash{'home_'.$ca.'@'.$cd}=1;
110: } else {
111: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
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">'.
126: '<input type="submit" name="dumpcourse" value="'.
127: &mt('Dump Course DOCS to Construction Space').'" />'.
128: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
129: } else {
130: return'</td><td bgcolor="#DDDDCC">'.
131: &mt('Dump Course DOCS to Construction Space: available on other servers');
132: }
133: }
134:
135: # -------------------------------------------------------- Actually dump course
136:
137: sub dumpcourse {
138: my $r=shift;
139: $r->print('<html><head><title>Dump DOCS</title></head>'.
140: &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
141: '<form name="dumpdoc" method="post">');
142: my ($home,$other,%outhash)=&authorhosts();
143: unless ($home) { return ''; }
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
148: unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
149: my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
150: $r->print('<h3>'.&mt('Copying Files').'</h3>');
151: my $title=$ENV{'form.authorfolder'};
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{$_};
163: $newfilename=~s/[^\w\/\.\/]+/\_/g;
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: }
195: } else {
196: # Input form
197: unless ($home==1) {
198: $r->print(
199: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
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 {
207: $r->print('<option value="'.$1.'">'.$1.' - '.
208: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
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;
218: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
219: &tiehash();
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>');
221: foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
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+)$//;
231: $title=~s/[^\w\/]+/\_/gs;
232: $title.='.'.$ext;
233: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
234: }
235: $r->print("</table>\n");
236: &untiehash();
237: $r->print(
238: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
239: }
240: }
241:
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;
259: my $outcome;
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: }
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) {
294: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
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;
316: }
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 />';
319: }
320: }
321:
322: $r->print('<html><head><title>Export Course</title></head>'.
323: &Apache::loncommon::bodytag('Export course to IMS content package'));
324: $r->print($outcome);
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();
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: }
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>';
399: if ($discussiontime{$ressymb} > 0) {
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) {
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: }
419: }
420:
421: function uncheckAll(field) {
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: }
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>'.
464: &Apache::loncommon::bodytag('Export course to IMS content package'
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:
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".
502: ' <organizations default="ORG-'.$ENV{'request.course.id'}.'-'.$now.'">'."\n".
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 = ();
523: my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
524: my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
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;
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()) {
560: $prevdepth = $depth;
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;
581:
582: my $itementry =
583: '<item identifier="ITEM-'.$ENV{'request.course.id'}.'-'.$count.
584: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
585: '<title>'.$curRes->title().'</title>';
586: print $ims_manifest "\n".$itementry;
587:
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".
594: ' <resource identifier="RES-'.$ENV{'request.course.id'}.'-'.$count.
595: '" type="webcontent" href="'.$content_file.'">'."\n".
596: ' <file href="'.$content_file.'" />'."\n";
597: foreach (@hrefs) {
598: $imsresources .=
599: ' <file href="'.$_.'" />'."\n";
600: }
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: }
617: $imsresources .= ' </resource>'."\n";
618: }
619: }
620: $pkgdepth = $depth;
621: } else {
622: $included = 0;
623: }
624: }
625: }
626: while ($pkgdepth > 0) {
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) {
644: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
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
658: my %roleshash = &Apache::lonnet::get_my_roles();
659: my @uploads = ();
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.
664: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
665: $content_type = 'syllabus';
666: my $contents = &Apache::imsexport::templatedpage($content_type);
667: if ($contents) {
668: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
669: }
670: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
671: $content_type = 'external';
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: }
677: } elsif ($symb =~ m-adm/navmaps$-) {
678: $content_type = 'navmap';
679: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
680: $content_type = 'simplepage';
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$-) {
686: $content_type = 'simpleproblem';
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$-) {
694: $content_type = 'bulletinboard';
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$-) {
700: $content_type = 'aboutme';
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: }
705: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
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';
711: my $canedit = 0;
712: if ($2 eq $ENV{'user.domain'} && $3 eq $ENV{'user.name'}) {
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) {
724: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
725: } else {
726: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
727: }
728: }
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: }
738: if ($message) {
739: $$copyresult .= $message."\n";
740: }
741: }
742:
743: sub replicate_content {
744: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
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;
751: my $content_name;
752: if ($url =~ m-/([^/]+)$-) {
753: $filename = $1;
754: if (!-e $tempexport.'/resources') {
755: mkdir($tempexport.'/resources',0700);
756: }
757: if (!-e $tempexport.'/resources/'.$count) {
758: mkdir($tempexport.'/resources/'.$count,0700);
759: }
760: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
761: my $copiedfile;
762: if ($copiedfile = Apache::File->new('>'.$destination)) {
763: my $content;
764: if ($caller eq 'resource') {
765: $content = &Apache::lonnet::getfile($url);
766: if ($content eq -1) {
767: $$message = 'Could not copy file '.$filename;
768: } else {
769: &extract_media($content,$count,$tempexport,$href,'resource');
770: $repstatus = 'ok';
771: }
772: } elsif ($caller eq 'noedit' || $caller eq 'uploaded') {
773: my $rtncode;
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 {
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 {
791: $$message = 'Could not determine name of file for '.$url."\n";
792: }
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;
806: }
807:
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:
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;
827: my $container = shift;
828: my $caller = shift;
829: while (@_) {
830: my $name = shift;
831: my $url = shift;
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: }
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: }
863: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
864: }
865:
866: sub breadcrumbs {
867: my ($where)=@_;
868: &Apache::lonhtmlcommon::clear_breadcrumbs();
869: my (@folders);
870: if ($ENV{'form.pagepath'}) {
871: @folders = split('&',$ENV{'form.pagepath'});
872: } else {
873: @folders=split('&',$ENV{'form.folderpath'});
874: }
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);
883: &Apache::lonhtmlcommon::add_breadcrumb(
884: {'href'=>$url,
885: 'title'=>&Apache::lonnet::unescape($foldername),
886: 'text'=>'<font size="+1">'.
887: &Apache::lonnet::unescape($foldername).'</font>'
888: });
889:
890:
891: }
892: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
893: 0,'nohelp');
894: }
895:
896: sub editor {
897: my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
898:
899: $r->print(&breadcrumbs($folder));
900: my $errtext='';
901: my $fatal=0;
902: my $container='sequence';
903: if ($ENV{'form.pagepath'}) {
904: $container='page';
905: }
906: ($errtext,$fatal)=
907: &mapread($coursenum,$coursedom,$folder.'.'.$container);
908: if ($#Apache::lonratedt::order<1) {
909: $Apache::lonratedt::order[0]=1;
910: $Apache::lonratedt::resources[1]='';
911: }
912: if ($fatal) {
913: $r->print('<p><font color="red">'.$errtext.'</font></p>');
914: } else {
915: # ------------------------------------------------------------ Process commands
916:
917: # ---------------- if they are for this folder and user allowed to make changes
918: if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
919: # set parameters and change order
920: if (defined($ENV{'form.setparms'})) {
921: my $idx=$ENV{'form.setparms'};
922: # set parameters
923: if ($ENV{'form.randpick_'.$idx}) {
924: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
925: } else {
926: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
927: }
928: if ($ENV{'form.hidprs_'.$idx}) {
929: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
930: } else {
931: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
932: }
933: if ($ENV{'form.encprs_'.$idx}) {
934: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
935: } else {
936: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
937: }
938:
939: if ($ENV{'form.newpos'}) {
940: # change order
941:
942: my $newpos=$ENV{'form.newpos'}-1;
943: my $currentpos=$ENV{'form.currentpos'}-1;
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;
972: }
973: # store the changed version
974:
975: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
976: if ($fatal) {
977: $r->print('<p><font color="red">'.$errtext.'</font></p>');
978: return;
979: }
980:
981: }
982:
983: # upload a file, if present
984: if (($ENV{'form.uploaddoc.filename'}) &&
985: ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
986: if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
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"
989: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
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;
997: if ($folder=~/^supplemental/) {
998: $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
999: $ENV{'user.domain'}.'___&&&___'.$comment;
1000: }
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;
1006:
1007: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1008: if ($fatal) {
1009: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1010: return;
1011: }
1012: }
1013: }
1014: if ($ENV{'form.cmd'}) {
1015: my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
1016: if ($cmd eq 'del') {
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: }
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') {
1027: if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
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;
1032: }
1033: } elsif ($cmd eq 'down') {
1034: if (defined($Apache::lonratedt::order[$idx+1])) {
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;
1039: }
1040: } elsif ($cmd eq 'rename') {
1041: my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1042: my ($rtitle,@rrest)=split(/\:/,
1043: $Apache::lonratedt::resources[
1044: $Apache::lonratedt::order[$idx]]);
1045: my $comment=
1046: &HTML::Entities::decode($ENV{'form.title'});
1047: $comment=~s/\</\<\;/g;
1048: $comment=~s/\>/\>\;/g;
1049: $comment=~s/\:/\:/g;
1050: if ($comment=~/\S/) {
1051: $Apache::lonratedt::resources[
1052: $Apache::lonratedt::order[$idx]]=
1053: $comment.':'.join(':',@rrest);
1054: }
1055: }
1056: # Store the changed version
1057: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1058: $folder.'.'.$container);
1059: if ($fatal) {
1060: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1061: return;
1062: }
1063: }
1064: # Group import/search
1065: if ($ENV{'form.importdetail'}) {
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: }
1075: # Store the changed version
1076: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1077: $container,'londocs',@imports);
1078: if ($fatal) {
1079: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1080: return;
1081: }
1082: }
1083: # Loading a complete map
1084: if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1085: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1086: my $idx=$#Apache::lonratedt::resources;
1087: $idx++;
1088: $Apache::lonratedt::resources[$idx]=$_;
1089: $Apache::lonratedt::order
1090: [$#Apache::lonratedt::order+1]=$idx;
1091: }
1092:
1093: # Store the changed version
1094: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1095: $folder.'.'.$container);
1096: if ($fatal) {
1097: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1098: return;
1099: }
1100: }
1101: }
1102: # ---------------------------------------------------------------- End commands
1103: # ---------------------------------------------------------------- Print screen
1104: my $idx=0;
1105: my $shown=0;
1106: $r->print('<table>');
1107: foreach (@Apache::lonratedt::order) {
1108: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1109: unless ($name) { $name=(split(/\//,$url))[-1]; }
1110: unless ($name) { $idx++; next; }
1111: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1112: $idx++;
1113: $shown++;
1114: }
1115: unless ($shown) {
1116: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1117: }
1118: $r->print('</table>');
1119: }
1120: }
1121:
1122: # --------------------------------------------------------------- An entry line
1123:
1124: sub entryline {
1125: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1126: $title=~s/\&colon\;/\:/g;
1127: $title=&HTML::Entities::encode(&HTML::Entities::decode(
1128: &Apache::lonnet::unescape($title)),'"<>&\'');
1129: my $renametitle=$title;
1130: my $foldertitle=$title;
1131: my $pagetitle=$title;
1132: my $orderidx=$Apache::lonratedt::order[$index];
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: }
1140: $renametitle=~s/\"\;/\\\"/g;
1141: my $line='<tr>';
1142: # Edit commands
1143: my $container;
1144: my $folderpath;
1145: if ($ENV{'form.folderpath'}) {
1146: $container = 'sequence';
1147: $folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
1148: # $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
1149: }
1150: my ($pagepath,$pagesymb);
1151: if ($ENV{'form.pagepath'}) {
1152: $container = 'page';
1153: $pagepath=&Apache::lonnet::escape($ENV{'form.pagepath'});
1154: $pagesymb=&Apache::lonnet::escape($ENV{'form.pagesymb'});
1155: }
1156: if ($allowed) {
1157: my $incindex=$index+1;
1158: my $selectbox='';
1159: if ($folder!~/^supplemental/) {
1160: $selectbox=
1161: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
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: }
1172: my %lt=&Apache::lonlocal::texthash(
1173: 'up' => 'Move Up',
1174: 'dw' => 'Move Down',
1175: 'rm' => 'Remove',
1176: 'rn' => 'Rename');
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'}" />
1181: <input type="hidden" name="pagesymb" value="$ENV{'form.pagesymb'}" />
1182: <input type="hidden" name="setparms" value="$orderidx" />
1183: <td><table border='0' cellspacing='2' cellpadding='0'>
1184: <tr><td bgcolor="#DDDDDD">
1185: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
1186: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1187: <tr><td bgcolor="#DDDDDD">
1188: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb'>
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">
1193: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1194: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1195: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1196: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1197: END
1198: } else {
1199: $line.=(<<END);
1200: <form name="entry_$index" action="/adm/coursedocs" method="post">
1201: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1202: <input type="hidden" name="setparms" value="$orderidx" />
1203: <td><table border='0' cellspacing='2' cellpadding='0'>
1204: <tr><td bgcolor="#DDDDDD">
1205: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1206: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1207: <tr><td bgcolor="#DDDDDD">
1208: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1209: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1210: </table></td>
1211: <td>$selectbox
1212: </td><td bgcolor="#DDDDDD">
1213: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1214: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1215: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1216: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1217: END
1218: }
1219: }
1220: # Figure out what kind of a resource this is
1221: my ($extension)=($url=~/\.(\w+)$/);
1222: my $uploaded=($url=~/^\/*uploaded\//);
1223: my $icon=&Apache::loncommon::icon($url);
1224: my $isfolder=0;
1225: my $ispage=0;
1226: my $folderarg;
1227: my $pagearg;
1228: my $pagefile;
1229: if ($uploaded) {
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;
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;
1242: } else {
1243: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1244: }
1245: }
1246: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1247: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1248: my $symb=&Apache::lonnet::symbclean(
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.'___'.
1254: &Apache::lonnet::declutter($url));
1255: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1256: $url=&Apache::lonnet::clutter($url);
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: }
1267: } elsif ($url=~m|^/ext/|) {
1268: $url='/adm/wrapper'.$url;
1269: }
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]);
1275: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1276: }
1277: }
1278: my $parameterset=' ';
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);
1285: $parameterset='<label>'.&mt('Randomly Pick: ').
1286: '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
1287: (&Apache::lonratedt::getparameter($orderidx,
1288: 'parameter_randompick'))[0].
1289: '" />'.'</label>';
1290:
1291: }
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;
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);
1309: }
1310: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1311: '" border="0"></a></td>'.
1312: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1313: if (($allowed) && ($folder!~/^supplemental/)) {
1314: my %lt=&Apache::lonlocal::texthash(
1315: 'hd' => 'Hidden',
1316: 'ec' => 'URL hidden',
1317: 'sp' => 'Store Parameters');
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"':'');
1322: $line.=(<<ENDPARMS);
1323: <td bgcolor="#BBBBFF"><font size='-2'>
1324: <nobr><label><input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</label></nobr></td>
1325: <td bgcolor="#BBBBFF"><font size='-2'>
1326: <nobr><label><input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</label></nobr></td>
1327: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1328: <td bgcolor="#BBBBFF"><font size='-2'>
1329: <input type="submit" value="$lt{'sp'}" />
1330: </font></td>
1331: ENDPARMS
1332: }
1333: $line.="</form></tr>";
1334: return $line;
1335: }
1336:
1337: # ---------------------------------------------------------------- tie the hash
1338:
1339: sub tiehash {
1340: my ($mode)=@_;
1341: $hashtied=0;
1342: if ($ENV{'request.course.fn'}) {
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)) {
1351: $hashtied=1;
1352: }
1353: }
1354: }
1355: }
1356:
1357: sub untiehash {
1358: if ($hashtied) { untie %hash; }
1359: $hashtied=0;
1360: }
1361:
1362: # --------------------------------------------------------------- check on this
1363:
1364: sub checkonthis {
1365: my ($r,$url,$level,$title)=@_;
1366: $url=&Apache::lonnet::unescape($url);
1367: $alreadyseen{$url}=1;
1368: $r->rflush();
1369: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1370: $r->print("\n<br />");
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) {
1380: $r->print('<font color="green">'.&mt('ok').'</font>');
1381: $r->rflush();
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: }
1390: $r->print('- '.&mt('Rendering').': ');
1391: my $oldpath=$ENV{'request.filename'};
1392: $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1393: &Apache::lonxml::xmlparse($r,'web',
1394: &Apache::lonnet::getfile(
1395: &Apache::lonnet::filelocation('',$url)));
1396: undef($Apache::lonhomework::parsing_a_problem);
1397: $ENV{'request.filename'}=$oldpath;
1398: if (($Apache::lonxml::errorcount) ||
1399: ($Apache::lonxml::warningcount)) {
1400: if ($Apache::lonxml::errorcount) {
1401: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1402: $Apache::lonxml::errorcount.' '.
1403: &mt('error(s)').'</b></font> ');
1404: }
1405: if ($Apache::lonxml::warningcount) {
1406: $r->print('<font color="blue">'.
1407: $Apache::lonxml::warningcount.' '.
1408: &mt('warning(s)').'</font>');
1409: }
1410: } else {
1411: $r->print('<font color="green">'.&mt('ok').'</font>');
1412: }
1413: $r->rflush();
1414: }
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) {
1423: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1424: } elsif ($result==HTTP_NOT_FOUND) {
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: }
1430: } else {
1431: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1432: }
1433: }
1434: }
1435: }
1436:
1437:
1438: #
1439: # -------------------------------------------------------------- Verify Content
1440: #
1441: sub verifycontent {
1442: my $r=shift;
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'));
1448: $hashtied=0;
1449: undef %alreadyseen;
1450: %alreadyseen=();
1451: &tiehash();
1452: foreach (keys %hash) {
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{$_})})) {
1462: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1463: }
1464: }
1465: &untiehash();
1466: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
1467: &mt('Return to DOCS').'</a>');
1468: }
1469:
1470: # -------------------------------------------------------------- Check Versions
1471:
1472: sub checkversions {
1473: my $r=shift;
1474: $r->print('<html><head><title>Check Versions</title></head>'.
1475: &Apache::loncommon::bodytag('Check Course Document Versions'));
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;
1484: my $haschanged=0;
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=();
1492: if ($ENV{'form.setmostrecent'}) {
1493: $haschanged=1;
1494: foreach (keys %hash) {
1495: if ($_=~/^ids\_(\/res\/.+)$/) {
1496: $newsetversions{$1}='mostrecent';
1497: }
1498: }
1499: } elsif ($ENV{'form.setcurrent'}) {
1500: $haschanged=1;
1501: foreach (keys %hash) {
1502: if ($_=~/^ids\_(\/res\/.+)$/) {
1503: my $getvers=&Apache::lonnet::getversion($1);
1504: if ($getvers>0) {
1505: $newsetversions{$1}=$getvers;
1506: }
1507: }
1508: }
1509: } elsif ($ENV{'form.setversions'}) {
1510: $haschanged=1;
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: }
1519: }
1520: if ($haschanged) {
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: }
1528: &mark_hash_old();
1529: }
1530: &changewarning($r,'');
1531: if ($ENV{'form.timerange'} eq 'all') {
1532: # show all documents
1533: $header=&mt('All Documents in Course');
1534: $allsel=1;
1535: foreach (keys %hash) {
1536: if ($_=~/^ids\_(\/res\/.+)$/) {
1537: my $src=$1;
1538: $changes{$src}=1;
1539: }
1540: }
1541: } else {
1542: # show documents which changed
1543: %changes=&Apache::lonnet::dump
1544: ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1545: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
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: }
1574: %setversions=&Apache::lonnet::dump('resourceversions',
1575: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1576: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1577: my %lt=&Apache::lonlocal::texthash
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',
1582: 'al' => 'All Resources (possibly large output)',
1583: 'sd' => 'Display',
1584: 'fi' => 'File',
1585: 'md' => 'Modification Date',
1586: 'mr' => 'Most recently published Version',
1587: 've' => 'Version used in Course',
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)',
1592: 'di' => 'Differences');
1593: $r->print(<<ENDHEADERS);
1594: <form action="/adm/coursedocs" method="post">
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 />
1598: <select name="timerange">
1599: <option value='all' $allsel>$lt{'al'}</option>
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>
1604: </select>
1605: <input type="submit" name="display" value="$lt{'sd'}" />
1606: <h3>$header</h3>
1607: <input type="submit" name="setversions" value="$lt{'sv'}" />
1608: <table border="0">
1609: ENDHEADERS
1610: foreach (sort keys %changes) {
1611: if ($changes{$_}>$starttime) {
1612: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1613: my $currentversion=&Apache::lonnet::getversion($_);
1614: if ($currentversion<0) {
1615: $currentversion=&mt('Could not be determined.');
1616: }
1617: my $linkurl=&Apache::lonnet::clutter($_);
1618: $r->print(
1619: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1620: &Apache::lonnet::gettitle($linkurl).
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'}.'">'.
1628: &Apache::lonlocal::locallocaltime(
1629: &Apache::lonnet::metadata($root.'.'.$extension,
1630: 'lastrevisiondate')
1631: ).
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">');
1638: # Used in course
1639: my $usedversion=$hash{'version_'.$linkurl};
1640: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1641: $r->print($usedversion);
1642: } else {
1643: $r->print($currentversion);
1644: }
1645: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1646: '<nobr>Use: ');
1647: # Set version
1648: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1649: 'set_version_'.$linkurl,
1650: ('select_form_order' =>
1651: ['',1..$currentversion,'mostrecent'],
1652: '' => '',
1653: 'mostrecent' => 'most recent',
1654: map {$_,$_} (1..$currentversion))));
1655: $r->print('</nobr></td></tr><tr><td></td>');
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: }
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;
1677: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1678: my $url=$root.'.'.$prevvers.'.'.$extension;
1679: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1680: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1681: &Apache::lonlocal::locallocaltime(
1682: &Apache::lonnet::metadata($url,
1683: 'lastrevisiondate')
1684: ).
1685: ')');
1686: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1687: $r->print(' <a href="/adm/diff?filename='.
1688: &Apache::lonnet::clutter($root.'.'.$extension).
1689: '&versionone='.$prevvers.
1690: '">'.&mt('Diffs').'</a>');
1691: }
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: }
1700: }
1701: while($cols_output++ < 4) {
1702: $r->print('</font></td><td><font>')
1703: }
1704: $r->print('</font></td></tr>'."\n");
1705: }
1706: }
1707: $r->print('</table></form>');
1708: $r->print('<h1>'.&mt('Done').'.</h1>');
1709:
1710: &untiehash();
1711: }
1712:
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:
1736: sub changewarning {
1737: my ($r,$postexec)=@_;
1738: if (!&is_hash_old()) { return; }
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'});
1744: $path.='&symb='.&Apache::lonnet::escape($ENV{'form.pagesymb'});
1745: }
1746: $r->print(
1747: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'.
1748: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1749: '<input type="hidden" name="orgurl" value="/adm/coursedocs?'.
1750: $pathvar.'='.$path.
1751: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
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:
1759: # ================================================================ Main Handler
1760: sub handler {
1761: my $r = shift;
1762: &Apache::loncommon::content_type($r,'text/html');
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',
1770: 'Supplemental','Score_Upload_Form','Adding_Pages',
1771: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
1772: 'Check_Resource_Versions','Verify_Content') {
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');
1780: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
1781: 'Option_Response_Simple');
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');
1787:
1788: if ($ENV{'form.verify'}) {
1789: &verifycontent($r);
1790: } elsif ($ENV{'form.versions'}) {
1791: &checkversions($r);
1792: } elsif ($ENV{'form.dumpcourse'}) {
1793: &dumpcourse($r);
1794: } elsif ($ENV{'form.exportcourse'}) {
1795: &exportcourse($r);
1796: } else {
1797: # is this a standard course?
1798:
1799: my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1800: my $forcestandard = 0;
1801: my $forcesupplement;
1802: my $script='';
1803: my $allowed;
1804: my $events='';
1805: my $showdoc=0;
1806: my $containertag;
1807: my $uploadtag;
1808: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1809: ['folderpath','pagepath','pagesymb']);
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);
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);
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'}.'" />';
1823: }
1824: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1825: $showdoc='/'.$1;
1826: }
1827: unless ($showdoc) { # got called from remote
1828: if (($ENV{'form.folder'}=~/^default_/) ||
1829: ($ENV{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1830: $forcestandard = 1;
1831: }
1832: $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1833:
1834: # does this user have privileges to post, etc?
1835: $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
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;
1842: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
1843: $events='onLoad="'.&Apache::lonmenu::loadevents.
1844: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1845: }
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:
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:
1858: # graphics settings
1859:
1860: $iconpath = $r->dir_config('lonIconsURL') . "/";
1861:
1862: my $now=time;
1863:
1864: # print screen
1865: $r->print(<<ENDDOCUMENT);
1866: <html>
1867: <head>
1868: <title>The LearningOnline Network with CAPA</title>
1869: <script>
1870: $script
1871: </script>
1872: ENDDOCUMENT
1873: if ($allowed) {
1874: $r->print(<<ENDNEWSCRIPT);
1875: <script>
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:
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:
1892: function makenewext(targetname) {
1893: this.document.forms.extimport.useform.value=targetname;
1894: window.open('/adm/rat/extpickframe.html');
1895: }
1896:
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:
1906: function makesmppage() {
1907: var title=prompt('Listed Title for the Page');
1908: if (title) {
1909: this.document.forms.newsmppg.importdetail.value=
1910: title+'=/adm/$udom/$uname/$now/smppg';
1911: this.document.forms.newsmppg.submit();
1912: }
1913: }
1914:
1915: function makesmpproblem() {
1916: var title=prompt('Listed Title for the Problem');
1917: if (title) {
1918: this.document.forms.newsmpproblem.importdetail.value=
1919: title+'=/res/lib/templates/simpleproblem.problem';
1920: this.document.forms.newsmpproblem.submit();
1921: }
1922: }
1923:
1924: function makebulboard() {
1925: var title=prompt('Listed Title for the Bulletin Board');
1926: if (title) {
1927: this.document.forms.newbul.importdetail.value=
1928: title+'=/adm/$udom/$uname/$now/bulletinboard';
1929: this.document.forms.newbul.submit();
1930: }
1931: }
1932:
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:
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:
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();');
1963: }
1964:
1965: function changename(folderpath,index,oldtitle,container,pagesymb) {
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;
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;
1975: this.document.forms.renameform.pagesymb.value=pagesymb;
1976: }
1977: this.document.forms.renameform.submit();
1978: }
1979: }
1980:
1981: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1982: if (confirm('Remove "'+oldtitle+'"?')) {
1983: this.document.forms.renameform.cmd.value='del_'+index;
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;
1989: this.document.forms.renameform.pagesymb.value=pagesymb;
1990: }
1991: this.document.forms.renameform.submit();
1992: }
1993: }
1994:
1995: </script>
1996:
1997: ENDNEWSCRIPT
1998: }
1999: # -------------------------------------------------------------------- Body tag
2000: $r->print('</head>'.
2001: &Apache::loncommon::bodytag('Course Documents','',$events,
2002: '','',$showdoc).
2003: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
2004: unless ($showdoc) {
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',
2017: 'newp' => 'New Composite Page',
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',
2025: 'mypi' => 'My Personal Info',
2026: 'abou' => 'About User',
2027: 'imsf' => 'Import IMS package',
2028: 'file' => 'File',
2029: 'title' => 'Title',
2030: 'comment' => 'Comment'
2031: );
2032: # -----------------------------------------------------------------------------
2033: if ($allowed) {
2034: my $dumpbut=&dumpbutton();
2035: my $exportbut=&exportbutton();
2036: my %lt=&Apache::lonlocal::texthash(
2037: 'vc' => 'Verify Content',
2038: 'cv' => 'Check/Set Resource Versions',
2039: );
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: }
2049: unless ($ENV{'form.pagepath'}) {
2050: $containertag = '<input type="hidden" name="folderpath" value="" />';
2051: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2052: }
2053:
2054: $r->print(<<ENDCOURSEVERIFY);
2055: <form name="renameform" method="post" action="/adm/coursedocs">
2056: <input type="hidden" name="title" />
2057: <input type="hidden" name="cmd" />
2058: $containertag
2059: </form>
2060: <form name="simpleedit" method="post" action="/adm/coursedocs">
2061: <input type=hidden name="importdetail" value="">
2062: $uploadtag
2063: </form>
2064: <form action="/adm/coursedocs" method="post" name="courseverify">
2065: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2066: <tr><td bgcolor="#DDDDCC">
2067: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2068: </td><td bgcolor="#DDDDCC">
2069: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2070: $dumpbut
2071: $exportbut
2072: </td></tr></table>
2073: </form>
2074: ENDCOURSEVERIFY
2075: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2076: &mt('Editing the Table of Contents for your Course')));
2077: }
2078: # --------------------------------------------------------- Standard documents
2079: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
2080: if (($standard) && ($allowed) && (!$forcesupplement)) {
2081: $r->print('<tr><td bgcolor="#BBBBBB">');
2082: # '<h2>'.&mt('Main Course Documents').
2083: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
2084: my $folder=$ENV{'form.folder'};
2085: if ($folder eq '' || $folder eq 'supplemental') {
2086: $folder='default';
2087: $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
2088: }
2089: my $postexec='';
2090: if ($folder eq 'default') {
2091: $r->print('<script>this.window.name="loncapaclient";</script>');
2092: } else {
2093: #$postexec='self.close();';
2094: }
2095: $hadchanges=0;
2096: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2097: if ($hadchanges) {
2098: &mark_hash_old()
2099: }
2100: &changewarning($r,$postexec);
2101: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2102: '.sequence';
2103: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2104: '.page';
2105:
2106: $r->print(<<ENDFORM);
2107: <table cellspacing=4 cellpadding=4><tr>
2108: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2109: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2110: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2111: </tr>
2112: <tr><td bgcolor="#DDDDDD">
2113: $lt{'file'}:<br />
2114: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2115: <input type="file" name="uploaddoc" size="40">
2116: <br />
2117: $lt{'title'}:<br />
2118: <input type="text" size="50" name="comment">
2119: $uploadtag
2120: <input type="hidden" name="cmd" value="upload_default">
2121: <nobr>
2122: <input type="submit" value="$lt{'upld'}">
2123: $help{'Uploading_From_Harddrive'}
2124: </nobr>
2125: </form>
2126: </td>
2127: <td bgcolor="#DDDDDD">
2128: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2129: $uploadtag
2130: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
2131: <nobr>
2132: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
2133: $help{'Importing_LON-CAPA_Resource'}
2134: </nobr>
2135: <p>
2136: <hr />
2137: <input type="text" size="20" name="importmap"><br />
2138: <nobr><input type=button
2139: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2140: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
2141: $help{'Load_Map'}</nobr>
2142: </p>
2143: </form>
2144: </td>
2145: <td bgcolor="#DDDDDD">
2146: ENDFORM
2147: unless ($ENV{'form.pagepath'}) {
2148: $r->print(<<ENDFORM);
2149: <form action="/adm/coursedocs" method="post" name="newfolder">
2150: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2151: <input type=hidden name="importdetail" value="">
2152: <nobr>
2153: <input name="newfolder" type="button"
2154: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2155: value="$lt{'newf'}" />$help{'Adding_Folders'}
2156: </nobr>
2157: </form>
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>
2167: <form action="/adm/coursedocs" method="post" name="newext">
2168: $uploadtag
2169: <input type=hidden name="importdetail" value="">
2170: <nobr>
2171: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2172: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2173: </nobr>
2174: </form>
2175: <form action="/adm/coursedocs" method="post" name="newsyl">
2176: $uploadtag
2177: <input type=hidden name="importdetail"
2178: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
2179: <nobr>
2180: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2181: $help{'Syllabus'}
2182: </nobr>
2183: </form>
2184: <form action="/adm/coursedocs" method="post" name="newnav">
2185: $uploadtag
2186: <input type=hidden name="importdetail"
2187: value="Navigate Content=/adm/navmaps">
2188: <nobr>
2189: <input name="newnav" type="submit" value="$lt{'navc'}" />
2190: $help{'Navigate_Content'}
2191: </nobr>
2192: </form>
2193: <form action="/adm/coursedocs" method="post" name="newsmppg">
2194: $uploadtag
2195: <input type=hidden name="importdetail" value="">
2196: <nobr>
2197: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2198: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2199: </nobr>
2200: </form>
2201: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2202: $uploadtag
2203: <input type=hidden name="importdetail" value="">
2204: <nobr>
2205: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2206: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2207: </nobr>
2208: </form>
2209: <form action="/adm/coursedocs" method="post" name="newexamupload">
2210: $uploadtag
2211: <input type=hidden name="importdetail" value="">
2212: <nobr>
2213: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2214: onClick="javascript:makeexamupload();" />
2215: $help{'Score_Upload_Form'}
2216: </nobr>
2217: </form>
2218: <form action="/adm/coursedocs" method="post" name="newbul">
2219: $uploadtag
2220: <input type=hidden name="importdetail" value="">
2221: <nobr>
2222: <input name="newbulletin" type="button" value="$lt{'bull'}"
2223: onClick="javascript:makebulboard();" />
2224: $help{'Bulletin Board'}
2225: </nobr>
2226: </form>
2227: <form action="/adm/coursedocs" method="post" name="newaboutme">
2228: $uploadtag
2229: <input type=hidden name="importdetail"
2230: value="$plainname=/adm/$udom/$uname/aboutme">
2231: <nobr>
2232: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2233: $help{'My Personal Info'}
2234: </nobr>
2235: </form>
2236: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
2237: $uploadtag
2238: <input type=hidden name="importdetail" value="">
2239: <nobr>
2240: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2241: onClick="javascript:makeabout();" />
2242: </nobr>
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);
2267: </form>
2268: <form action="/adm/imsimportdocs" method="post" name="ims">
2269: <input type="hidden" name="folder" value="$folder" />
2270: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2271: </nobr>
2272: </form>
2273: ENDFORM
2274: }
2275: $r->print('</td></tr>'."\n".
2276: '</table>');
2277: $r->print('</td></tr>');
2278: }
2279: # ----------------------------------------------------- Supplemental documents
2280: if (!$forcestandard) {
2281: $r->print('<tr><td bgcolor="#BBBBBB">');
2282: # '<h2>'.&mt('Supplemental Course Documents').
2283: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
2284: my $folder=$ENV{'form.folder'};
2285: unless ($folder=~/^supplemental/) {
2286: $folder='supplemental';
2287: }
2288: if ($folder =~ /^supplemental$/ &&
2289: $ENV{'form.folderpath'} =~ /^default\&/) {
2290: $ENV{'form.folderpath'}='supplemental&'.
2291: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
2292: }
2293: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2294: if ($allowed) {
2295: my $folderseq=
2296: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2297: '.sequence';
2298:
2299: $r->print(<<ENDSUPFORM);
2300: <table cellspacing=4 cellpadding=4><tr>
2301: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2302: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2303: </tr>
2304: <tr><td bgcolor="#DDDDDD">
2305: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2306: <input type="file" name="uploaddoc" size="40">
2307: <br />$lt{'comment'}:<br />
2308: <textarea cols=50 rows=4 name='comment'>
2309: </textarea>
2310: <br />
2311: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2312: <input type="hidden" name="cmd" value="upload_supplemental">
2313: <nobr>
2314: <input type="submit" value="$lt{'upld'}">
2315: $help{'Uploading_From_Harddrive'}
2316: </nobr>
2317: </form>
2318: </td>
2319: <td bgcolor="#DDDDDD">
2320: <form action="/adm/coursedocs" method="post" name="supnewfolder">
2321: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2322: <input type=hidden name="importdetail" value="">
2323: <nobr>
2324: <input name="newfolder" type="button"
2325: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2326: value="$lt{'newf'}" /> $help{'Adding_Folders'}
2327: </nobr>
2328: </form>
2329: <form action="/adm/coursedocs" method="post" name="supnewext">
2330: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2331: <input type=hidden name="importdetail" value="">
2332: <nobr>
2333: <input name="newext" type="button"
2334: onClick="javascript:makenewext('supnewext');"
2335: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2336: </nobr>
2337: </form>
2338: <form action="/adm/coursedocs" method="post" name="supnewsyl">
2339: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2340: <input type=hidden name="importdetail"
2341: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
2342: <nobr>
2343: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2344: $help{'Syllabus'}
2345: </nobr>
2346: </form>
2347: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
2348: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
2349: <input type=hidden name="importdetail"
2350: value="$plainname=/adm/$udom/$uname/aboutme">
2351: <nobr>
2352: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2353: $help{'My Personal Info'}
2354: </nobr>
2355: </form>
2356: </td></tr>
2357: </table></td></tr>
2358: ENDSUPFORM
2359: }
2360: }
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: }
2364: $r->print('</table>');
2365: } else {
2366: # -------------------------------------------------------- This is showdoc mode
2367: $r->print("<h1>".&mt('Uploaded Document').' - '.
2368: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
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>');
2371: }
2372: }
2373: $r->print('</body></html>');
2374: return OK;
2375: }
2376:
2377: 1;
2378: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>