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