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