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