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