File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.270:
download - view:
text,
annotated -
select for diffs
Fri Jan 26 23:37:53 2007 UTC (17 years, 7 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- removing some &colon manipulations to use the qt(un)escape ruotines
- switching qtesacpe to do no html escaping, the title as returned from it is the exact text to display (as most places expect)
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.270 2007/01/26 23:37:53 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use LONCAPA::map();
37: use Apache::lonratedt();
38: use Apache::lonxml;
39: use Apache::lonclonecourse;
40: use Apache::lonnavmaps;
41: use HTML::Entities;
42: use GDBM_File;
43: use Apache::lonlocal;
44: use Cwd;
45: use LONCAPA qw(:DEFAULT :match);
46:
47: my $iconpath;
48:
49: my %hash;
50:
51: my $hashtied;
52: my %alreadyseen=();
53:
54: my $hadchanges;
55:
56: # Available help topics
57:
58: my %help=();
59:
60: # Mapread read maps into LONCAPA::map:: global arrays
61: # @order and @resources, determines status
62: # sets @order - pointer to resources in right order
63: # sets @resources - array with the resources with correct idx
64: #
65:
66: sub mapread {
67: my ($coursenum,$coursedom,$map)=@_;
68: return
69: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
70: $map);
71: }
72:
73: sub storemap {
74: my ($coursenum,$coursedom,$map)=@_;
75: my ($outtext,$errtext)=
76: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
77: $map,1);
78: if ($errtext) { return ($errtext,2); }
79:
80: $hadchanges=1;
81: return ($errtext,0);
82: }
83:
84: # ----------------------------------------- Return hash with valid author names
85:
86: sub authorhosts {
87: my %outhash=();
88: my $home=0;
89: my $other=0;
90: foreach (keys %env) {
91: if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
92: my $role=$1;
93: my $realm=$2;
94: my ($start,$end)=split(/\./,$env{$_});
95: if (($start) && ($start>time)) { next; }
96: if (($end) && (time>$end)) { next; }
97: my $ca; my $cd;
98: if ($1 eq 'au') {
99: $ca=$env{'user.name'};
100: $cd=$env{'user.domain'};
101: } else {
102: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
103: }
104: my $allowed=0;
105: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
106: my @ids=&Apache::lonnet::current_machine_ids();
107: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
108: if ($allowed) {
109: $home++;
110: $outhash{'home_'.$ca.'@'.$cd}=1;
111: } else {
112: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
113: $other++;
114: }
115: }
116: }
117: return ($home,$other,%outhash);
118: }
119: # ------------------------------------------------------ Generate "dump" button
120:
121: sub dumpbutton {
122: my ($home,$other,%outhash)=&authorhosts();
123: my $type = &Apache::loncommon::course_type();
124: if ($home+$other==0) { return ''; }
125: my $output='</td><td bgcolor="#DDDDCC">';
126: if ($home) {
127: return '</td><td bgcolor="#DDDDCC">'.
128: '<input type="submit" name="dumpcourse" value="'.
129: &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
130: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
131: } else {
132: return'</td><td bgcolor="#DDDDCC">'.
133: &mt('Dump '.$type.
134: ' DOCS to Construction Space: available on other servers');
135: }
136: }
137:
138: sub clean {
139: my ($title)=@_;
140: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
141: return $title;
142: }
143: # -------------------------------------------------------- Actually dump course
144:
145: sub dumpcourse {
146: my ($r) = @_;
147: my $type = &Apache::loncommon::course_type();
148: $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
149: '<form name="dumpdoc" method="post">');
150: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
151: my ($home,$other,%outhash)=&authorhosts();
152: unless ($home) { return ''; }
153: my $origcrsid=$env{'request.course.id'};
154: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
155: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
156: # Do the dumping
157: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
158: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
159: $r->print('<h3>'.&mt('Copying Files').'</h3>');
160: my $title=$env{'form.authorfolder'};
161: $title=&clean($title);
162: my %replacehash=();
163: foreach (keys %env) {
164: if ($_=~/^form\.namefor\_(.+)/) {
165: $replacehash{$1}=$env{$_};
166: }
167: }
168: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
169: $crs=~s/\_/\//g;
170: foreach (keys %replacehash) {
171: my $newfilename=$title.'/'.$replacehash{$_};
172: $newfilename=~s/\.(\w+)$//;
173: my $ext=$1;
174: $newfilename=&clean($newfilename);
175: $newfilename.='.'.$ext;
176: my @dirs=split(/\//,$newfilename);
177: my $path='/home/'.$ca.'/public_html';
178: my $makepath=$path;
179: my $fail=0;
180: for (my $i=0;$i<$#dirs;$i++) {
181: $makepath.='/'.$dirs[$i];
182: unless (-e $makepath) {
183: unless(mkdir($makepath,0777)) { $fail=1; }
184: }
185: }
186: $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
187: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
188: if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
189: print $fh &Apache::lonclonecourse::rewritefile(
190: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_),
191: (%replacehash,$crs => '')
192: );
193: } else {
194: print $fh
195: &Apache::lonclonecourse::readfile($env{'request.course.id'},$_);
196: }
197: $fh->close();
198: } else {
199: $fail=1;
200: }
201: if ($fail) {
202: $r->print('<font color="red">fail</font>');
203: } else {
204: $r->print('<font color="green">ok</font>');
205: }
206: }
207: } else {
208: # Input form
209: unless ($home==1) {
210: $r->print(
211: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
212: }
213: foreach (sort keys %outhash) {
214: if ($_=~/^home_(.+)$/) {
215: if ($home==1) {
216: $r->print(
217: '<input type="hidden" name="authorspace" value="'.$1.'" />');
218: } else {
219: $r->print('<option value="'.$1.'">'.$1.' - '.
220: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
221: }
222: }
223: }
224: unless ($home==1) {
225: $r->print('</select>');
226: }
227: my $title=$origcrsdata{'description'};
228: $title=~s/[\/\s]+/\_/gs;
229: $title=&clean($title);
230: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
231: &tiehash();
232: $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>');
233: foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
234: $r->print('<tr><td>'.$_.'</td>');
235: my ($ext)=($_=~/\.(\w+)$/);
236: my $title=$hash{'title_'.$hash{
237: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
238: $r->print('<td>'.($title?$title:' ').'</td>');
239: if (!$title) {
240: $title=$_;
241: } else {
242: $title=~s|/|_|g;
243: }
244: $title=~s/\.(\w+)$//;
245: $title=&clean($title);
246: $title.='.'.$ext;
247: $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
248: }
249: $r->print("</table>\n");
250: &untiehash();
251: $r->print(
252: '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump [_1] DOCS',$type).'" /></p></form>');
253: }
254: }
255:
256: # ------------------------------------------------------ Generate "export" button
257:
258: sub exportbutton {
259: my $type = &Apache::loncommon::course_type();
260: return '</td><td bgcolor="#DDDDCC">'.
261: '<input type="submit" name="exportcourse" value="'.
262: &mt('Export '.$type.' to IMS').'" />'.
263: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
264: }
265:
266: sub exportcourse {
267: my $r=shift;
268: my $type = &Apache::loncommon::course_type();
269: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
270: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
271: my $numdisc = keys %discussiontime;
272: my $navmap = Apache::lonnavmaps::navmap->new();
273: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
274: my $curRes;
275: my $outcome;
276:
277: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
278: ['finishexport']);
279: if ($env{'form.finishexport'}) {
280: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
281: ['archive','discussion']);
282:
283: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
284: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
285: if (@exportitems == 0 && @discussions == 0) {
286: $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';
287: } else {
288: my $now = time;
289: my %symbs;
290: my $manifestok = 0;
291: my $imsresources;
292: my $tempexport;
293: my $copyresult;
294: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
295: if ($manifestok) {
296: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
297: close($ims_manifest);
298:
299: #Create zip file in prtspool
300: my $imszipfile = '/prtspool/'.
301: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
302: time.'_'.rand(1000000000).'.zip';
303: my $cwd = &Cwd::getcwd();
304: my $imszip = '/home/httpd/'.$imszipfile;
305: chdir $tempexport;
306: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
307: close(OUTPUT);
308: chdir $cwd;
309: $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);
310: if ($copyresult) {
311: $outcome .= 'The following errors occurred during export - '.$copyresult;
312: }
313: } else {
314: $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 />';
315: }
316: }
317: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
318: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
319: $r->print($outcome);
320: $r->print(&Apache::loncommon::end_page());
321: } else {
322: my $display;
323: $display = '<form name="exportdoc" method="post">'."\n";
324: $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');
325: $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
326: '<tr><td><fieldset><legend> <b>Content items</b></legend>'.
327: '<input type="button" value="check all" '.
328: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
329: ' <input type="button" value="uncheck all"'.
330: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
331: '<td> </td><td> </td>'.
332: '<td align="right"><fieldset><legend> <b>Discussion posts'.
333: '</b></legend><input type="button" value="check all"'.
334: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
335: ' <input type="button" value="uncheck all"'.
336: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
337: '</tr></table>';
338: my $curRes;
339: my $depth = 0;
340: my $count = 0;
341: my $boards = 0;
342: my $startcount = 5;
343: my %parent = ();
344: my %children = ();
345: my $lastcontainer = $startcount;
346: my @bgcolors = ('#F6F6F6','#FFFFFF');
347: $display .= '<table cellspacing="0"><tr>'.
348: '<td><b>Export content item?<br /></b></td><td> </td><td align="right">'."\n";
349: if ($numdisc > 0) {
350: $display.='<b>Export discussion posts?</b>'."\n";
351: }
352: $display.=' </td></tr>';
353: while ($curRes = $it->next()) {
354: if (ref($curRes)) {
355: $count ++;
356: }
357: if ($curRes == $it->BEGIN_MAP()) {
358: $depth++;
359: $parent{$depth} = $lastcontainer;
360: }
361: if ($curRes == $it->END_MAP()) {
362: $depth--;
363: $lastcontainer = $parent{$depth};
364: }
365: if (ref($curRes)) {
366: my $symb = $curRes->symb();
367: my $ressymb = $symb;
368: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
369: unless ($ressymb =~ m|adm/wrapper/adm|) {
370: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
371: }
372: }
373: my $color = $count%2;
374: $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
375: '<input type="checkbox" name="archive" value="'.$count.'" ';
376: if (($curRes->is_sequence()) || ($curRes->is_page())) {
377: my $checkitem = $count + $boards + $startcount;
378: $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
379: }
380: $display .= ' />'."\n";
381: for (my $i=0; $i<$depth; $i++) {
382: $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";
383: }
384: if ($curRes->is_sequence()) {
385: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
386: $lastcontainer = $count + $startcount + $boards;
387: } elsif ($curRes->is_page()) {
388: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
389: $lastcontainer = $count + $startcount + $boards;
390: }
391: my $currelem = $count+$boards+$startcount;
392: $children{$parent{$depth}} .= $currelem.':';
393: $display .= ' '.$curRes->title().'</td>';
394: if ($discussiontime{$ressymb} > 0) {
395: $boards ++;
396: $currelem = $count+$boards+$startcount;
397: $display .= '<td> </td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" /> </td>'."\n";
398: } else {
399: $display .= '<td colspan="2"> </td>'."\n";
400: }
401: }
402: }
403: my $scripttag = qq|
404: <script>
405:
406: function checkAll(field) {
407: if (field.length > 0) {
408: for (i = 0; i < field.length; i++) {
409: field[i].checked = true ;
410: }
411: } else {
412: field.checked = true
413: }
414: }
415:
416: function uncheckAll(field) {
417: if (field.length > 0) {
418: for (i = 0; i < field.length; i++) {
419: field[i].checked = false ;
420: }
421: } else {
422: field.checked = false ;
423: }
424: }
425:
426: function propagateCheck(item) {
427: if (document.exportdoc.elements[item].checked == true) {
428: containerCheck(item)
429: }
430: }
431:
432: function containerCheck(item) {
433: document.exportdoc.elements[item].checked = true
434: var numitems = $count + $boards + $startcount
435: var parents = new Array(numitems)
436: for (var i=$startcount; i<numitems; i++) {
437: parents[i] = new Array
438: }
439: |;
440:
441: foreach my $container (sort { $a <=> $b } keys %children) {
442: my @contents = split/:/,$children{$container};
443: for (my $i=0; $i<@contents; $i ++) {
444: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
445: }
446: }
447:
448: $scripttag .= qq|
449: if (parents[item].length > 0) {
450: for (var j=0; j<parents[item].length; j++) {
451: containerCheck(parents[item][j])
452: }
453: }
454: }
455:
456: </script>
457: |;
458: $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',
459: $scripttag));
460: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package'));
461: $r->print($display.'</table>'.
462: '<p><input type="hidden" name="finishexport" value="1">'.
463: '<input type="submit" name="exportcourse" value="'.
464: &mt('Export '.$type.' DOCS').'" /></p></form>'.
465: &Apache::loncommon::end_page());
466: }
467: }
468:
469: sub create_ims_store {
470: my ($now,$manifestok,$outcome,$tempexport) = @_;
471: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
472: my $ims_manifest;
473: if (!-e $$tempexport) {
474: mkdir($$tempexport,0700);
475: }
476: $$tempexport .= '/'.$now;
477: if (!-e $$tempexport) {
478: mkdir($$tempexport,0700);
479: }
480: $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
481: if (!-e $$tempexport) {
482: mkdir($$tempexport,0700);
483: }
484: if (!-e "$$tempexport/resources") {
485: mkdir("$$tempexport/resources",0700);
486: }
487: # open manifest file
488: my $manifest = '/imsmanifest.xml';
489: my $manifestfilename = $$tempexport.$manifest;
490: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
491: $$manifestok=1;
492: print $ims_manifest
493: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
494: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
495: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
496: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
497: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
498: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
499: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
500: ' <metadata>
501: <schema></schema>
502: <imsmd:lom>
503: <imsmd:general>
504: <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
505: <imsmd:title>
506: <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
507: </imsmd:title>
508: </imsmd:general>
509: </imsmd:lom>
510: </metadata>'."\n".
511: ' <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
512: ' <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
513: ' structure="hierarchical">'."\n".
514: ' <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
515: } else {
516: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
517: ;
518: }
519: return $ims_manifest;
520: }
521:
522: sub build_package {
523: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
524: # first iterator to look for dependencies
525: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
526: my $curRes;
527: my $count = 0;
528: my $depth = 0;
529: my $lastcontainer = 0;
530: my %parent = ();
531: my @dependencies = ();
532: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
533: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
534: while ($curRes = $it->next()) {
535: if (ref($curRes)) {
536: $count ++;
537: }
538: if ($curRes == $it->BEGIN_MAP()) {
539: $depth++;
540: $parent{$depth} = $lastcontainer;
541: }
542: if ($curRes == $it->END_MAP()) {
543: $depth--;
544: $lastcontainer = $parent{$depth};
545: }
546: if (ref($curRes)) {
547: if ($curRes->is_sequence() || $curRes->is_page()) {
548: $lastcontainer = $count;
549: }
550: if (grep/^$count$/,@$exportitems) {
551: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
552: }
553: }
554: }
555: # second iterator to build manifest and store resources
556: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
557: $depth = 0;
558: my $prevdepth;
559: $count = 0;
560: my $imsresources;
561: my $pkgdepth;
562: while ($curRes = $it->next()) {
563: if ($curRes == $it->BEGIN_MAP()) {
564: $prevdepth = $depth;
565: $depth++;
566: }
567: if ($curRes == $it->END_MAP()) {
568: $prevdepth = $depth;
569: $depth--;
570: }
571:
572: if (ref($curRes)) {
573: $count ++;
574: if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
575: my $symb = $curRes->symb();
576: my $isvisible = 'true';
577: my $resourceref;
578: if ($curRes->randomout()) {
579: $isvisible = 'false';
580: }
581: unless ($curRes->is_sequence()) {
582: $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
583: }
584: my $step = $prevdepth - $depth;
585: if (($step >= 0) && ($count > 1)) {
586: while ($step >= 0) {
587: print $ims_manifest "\n".' </item>'."\n";
588: $step --;
589: }
590: }
591: $prevdepth = $depth;
592:
593: my $itementry =
594: '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
595: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
596: '<title>'.$curRes->title().'</title>';
597: print $ims_manifest "\n".$itementry;
598:
599: unless ($curRes->is_sequence()) {
600: my $content_file;
601: my @hrefs = ();
602: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
603: if ($content_file) {
604: $imsresources .= "\n".
605: ' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
606: '" type="webcontent" href="'.$content_file.'">'."\n".
607: ' <file href="'.$content_file.'" />'."\n";
608: foreach (@hrefs) {
609: $imsresources .=
610: ' <file href="'.$_.'" />'."\n";
611: }
612: if (grep/^$count$/,@$discussions) {
613: my $ressymb = $symb;
614: my $mode;
615: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
616: unless ($ressymb =~ m|adm/wrapper/adm|) {
617: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
618: }
619: $mode = 'board';
620: }
621: my %extras = (
622: caller => 'imsexport',
623: tempexport => $tempexport.'/resources',
624: count => $count
625: );
626: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
627: }
628: $imsresources .= ' </resource>'."\n";
629: }
630: }
631: $pkgdepth = $depth;
632: }
633: }
634: }
635: while ($pkgdepth > 0) {
636: print $ims_manifest " </item>\n";
637: $pkgdepth --;
638: }
639: my $resource_text = qq|
640: </organization>
641: </organizations>
642: <resources>
643: $imsresources
644: </resources>
645: </manifest>
646: |;
647: print $ims_manifest $resource_text;
648: }
649:
650: sub get_dependencies {
651: my ($exportitems,$parent,$depth,$dependencies) = @_;
652: if ($depth > 1) {
653: if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
654: push @$dependencies, $$parent{$depth};
655: if ($depth > 2) {
656: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
657: }
658: }
659: }
660: }
661:
662: sub process_content {
663: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
664: my $content_type;
665: my $message;
666: my @uploads = ();
667: if ($curRes->is_sequence()) {
668: $content_type = 'sequence';
669: } elsif ($curRes->is_page()) {
670: $content_type = 'page'; # need to handle individual items in pages.
671: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
672: $content_type = 'syllabus';
673: my $contents = &Apache::imsexport::templatedpage($content_type);
674: if ($contents) {
675: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
676: }
677: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
678: $content_type = 'external';
679: my $title = $curRes->title;
680: my $contents = &Apache::imsexport::external($symb,$title);
681: if ($contents) {
682: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
683: }
684: } elsif ($symb =~ m-adm/navmaps$-) {
685: $content_type = 'navmap';
686: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
687: $content_type = 'simplepage';
688: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
689: if ($contents) {
690: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
691: }
692: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
693: $content_type = 'simpleproblem';
694: my $contents = &Apache::imsexport::simpleproblem($symb);
695: if ($contents) {
696: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
697: }
698: } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
699: $content_type = 'examupload';
700: } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
701: $content_type = 'bulletinboard';
702: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
703: if ($contents) {
704: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
705: }
706: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
707: $content_type = 'aboutme';
708: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
709: if ($contents) {
710: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
711: }
712: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
713: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
714: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
715: my $canedit = 0;
716: if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
717: $canedit= 1;
718: }
719: # only include problem code where current user is author
720: if ($canedit) {
721: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
722: } else {
723: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
724: }
725: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
726: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
727: }
728: if (@uploads > 0) {
729: foreach my $item (@uploads) {
730: my $uploadmsg = '';
731: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
732: if ($uploadmsg) {
733: $$copyresult .= $uploadmsg."\n";
734: }
735: }
736: }
737: if ($message) {
738: $$copyresult .= $message."\n";
739: }
740: }
741:
742: sub replicate_content {
743: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
744: my ($map,$ind,$url);
745: if ($caller eq 'templateupload') {
746: $url = $symb;
747: $url =~ s#//#/#g;
748: } else {
749: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
750: }
751: my $content;
752: my $filename;
753: my $repstatus;
754: my $content_name;
755: if ($url =~ m-/([^/]+)$-) {
756: $filename = $1;
757: if (!-e $tempexport.'/resources') {
758: mkdir($tempexport.'/resources',0700);
759: }
760: if (!-e $tempexport.'/resources/'.$count) {
761: mkdir($tempexport.'/resources/'.$count,0700);
762: }
763: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
764: my $copiedfile;
765: if ($copiedfile = Apache::File->new('>'.$destination)) {
766: my $content;
767: if ($caller eq 'resource') {
768: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
769: my $filepath = &Apache::lonnet::filelocation($respath,$url);
770: $content = &Apache::lonnet::getfile($filepath);
771: if ($content eq -1) {
772: $$message = 'Could not copy file '.$filename;
773: } else {
774: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
775: $repstatus = 'ok';
776: }
777: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
778: my $rtncode;
779: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
780: if ($repstatus eq 'ok') {
781: if ($url =~ /\.html?$/i) {
782: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
783: }
784: } else {
785: $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
786: }
787: } elsif ($caller eq 'noedit') {
788: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
789: $repstatus = 'ok';
790: $content = 'Not the owner of this resource';
791: }
792: if ($repstatus eq 'ok') {
793: print $copiedfile $content;
794: }
795: close($copiedfile);
796: } else {
797: $$message = 'Could not open destination file for '.$filename."<br />\n";
798: }
799: } else {
800: $$message = 'Could not determine name of file for '.$symb."<br />\n";
801: }
802: if ($repstatus eq 'ok') {
803: $content_name = 'resources/'.$count.'/'.$filename;
804: }
805: return $content_name;
806: }
807:
808: sub extract_media {
809: my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
810: my ($dirpath,$container);
811: my %allfiles = ();
812: my %codebase = ();
813: if ($url =~ m-(.*/)([^/]+)$-) {
814: $dirpath = $1;
815: $container = $2;
816: } else {
817: $dirpath = $url;
818: $container = '';
819: }
820: &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
821: foreach my $embed_file (keys(%allfiles)) {
822: my $filename;
823: if ($embed_file =~ m#([^/]+)$#) {
824: $filename = $1;
825: } else {
826: $filename = $embed_file;
827: }
828: my $newname = 'res/'.$filename;
829: my ($rtncode,$embed_content,$repstatus);
830: my $embed_url;
831: if ($embed_file =~ m-^/-) {
832: $embed_url = $embed_file; # points to absolute path
833: } else {
834: if ($embed_file =~ m-https?://-) {
835: next; # points to url
836: } else {
837: $embed_url = $dirpath.$embed_file; # points to relative path
838: }
839: }
840: if ($caller eq 'resource') {
841: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
842: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
843: $embed_content = &Apache::lonnet::getfile($embed_path);
844: unless ($embed_content eq -1) {
845: $repstatus = 'ok';
846: }
847: } elsif ($caller eq 'uploaded') {
848:
849: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
850: }
851: if ($repstatus eq 'ok') {
852: my $destination = $tempexport.'/resources/'.$count.'/res';
853: if (!-e "$destination") {
854: mkdir($destination,0755);
855: }
856: $destination .= '/'.$filename;
857: my $copiedfile;
858: if ($copiedfile = Apache::File->new('>'.$destination)) {
859: print $copiedfile $embed_content;
860: push @{$href}, 'resources/'.$count.'/res/'.$filename;
861: my $attrib_regexp = '';
862: if (@{$allfiles{$embed_file}} > 1) {
863: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
864: } else {
865: $attrib_regexp = $allfiles{$embed_file}[0];
866: }
867: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
868: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
869: $$content =~ s#\Q$embed_file\E#$newname#gi;
870: }
871: }
872: } else {
873: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
874: }
875: }
876: return;
877: }
878:
879: sub store_template {
880: my ($contents,$tempexport,$count,$content_type) = @_;
881: if ($contents) {
882: if ($tempexport) {
883: if (!-e $tempexport.'/resources') {
884: mkdir($tempexport.'/resources',0700);
885: }
886: if (!-e $tempexport.'/resources/'.$count) {
887: mkdir($tempexport.'/resources/'.$count,0700);
888: }
889: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
890: my $storetemplate;
891: if ($storetemplate = Apache::File->new('>'.$destination)) {
892: print $storetemplate $contents;
893: close($storetemplate);
894: }
895: if ($content_type eq 'external') {
896: return 'resources/'.$count.'/'.$content_type.'.html';
897: } else {
898: return 'resources/'.$count.'/'.$content_type.'.xml';
899: }
900: }
901: }
902: }
903:
904: # Imports the given (name, url) resources into the course
905: # coursenum, coursedom, and folder must precede the list
906: sub group_import {
907: my $coursenum = shift;
908: my $coursedom = shift;
909: my $folder = shift;
910: my $container = shift;
911: my $caller = shift;
912: while (@_) {
913: my $name = shift;
914: my $url = shift;
915: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs')) {
916: my $errtext = '';
917: my $fatal = 0;
918: my $newmapstr = '<map>'."\n".
919: '<resource id="1" src="" type="start"></resource>'."\n".
920: '<link from="1" to="2" index="1"></link>'."\n".
921: '<resource id="2" src="" type="finish"></resource>'."\n".
922: '</map>';
923: $env{'form.output'}=$newmapstr;
924: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
925: 'output',$1.$2);
926: if ($result != m|^/uploaded/|) {
927: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
928: $fatal = 2;
929: }
930: if ($fatal) {
931: return ($errtext,$fatal);
932: }
933: }
934: if ($url) {
935: my $idx = &LONCAPA::map::getresidx($url);
936: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
937: my $ext = 'false';
938: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
939: $url =~ &LONCAPA::map::qtunescape($url);
940: $name =~ &LONCAPA::map::qtunescape($name);
941: $LONCAPA::map::resources[$idx] =
942: join ':', ($name, $url, $ext, 'normal', 'res');
943: }
944: }
945: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
946: }
947:
948: sub breadcrumbs {
949: my ($where)=@_;
950: &Apache::lonhtmlcommon::clear_breadcrumbs();
951: my (@folders);
952: if ($env{'form.pagepath'}) {
953: @folders = split('&',$env{'form.pagepath'});
954: } else {
955: @folders=split('&',$env{'form.folderpath'});
956: }
957: my $folderpath;
958: my $cpinfo='';
959: my $plain='';
960: if ($env{'form.markedcopy_url'}) {
961: $cpinfo='&markedcopy_url='.
962: &escape($env{'form.markedcopy_url'}).
963: '&markedcopy_title='.
964: &escape($env{'form.markedcopy_title'});
965: }
966: my $randompick=-1;
967: my $isencrypted=0;
968: my $ishidden=0;
969: while (@folders) {
970: my $folder=shift(@folders);
971: my $foldername=shift(@folders);
972: if ($folderpath) {$folderpath.='&';}
973: $folderpath.=$folder.'&'.$foldername;
974: my $url='/adm/coursedocs?folderpath='.
975: &escape($folderpath);
976: my $name=&unescape($foldername);
977: # randompick number, hidden, encrypted is appended with ":"s to the foldername
978: $name=~s/\:(\d*)\:(\w*)\:(\w*)$//;
979: if ($1 ne '') {
980: $randompick=$1;
981: } else {
982: $randompick=-1;
983: }
984: if ($2) { $ishidden=1; }
985: if ($3) { $isencrypted=1; }
986: &Apache::lonhtmlcommon::add_breadcrumb(
987: {'href'=>$url.$cpinfo,
988: 'title'=>$name,
989: 'text'=>'<font size="+1">'.
990: $name.'</font>',
991: 'no_mt'=>1,
992: });
993: $plain.=$name.' > ';
994: }
995: $plain=~s/\>\;\s*$//;
996: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
997: 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain);
998: }
999:
1000: sub log_docs {
1001: return &Apache::lonnet::instructor_log('docslog',@_);
1002: }
1003:
1004: {
1005: my @oldresources=();
1006: my @oldorder=();
1007: my $parmidx;
1008: my %parmaction=();
1009: my %parmvalue=();
1010: my $changedflag;
1011:
1012: sub snapshotbefore {
1013: @oldresources=@LONCAPA::map::resources;
1014: @oldorder=@LONCAPA::map::order;
1015: $parmidx=undef;
1016: %parmaction=();
1017: %parmvalue=();
1018: $changedflag=0;
1019: }
1020:
1021: sub remember_parms {
1022: my ($idx,$parameter,$action,$value)=@_;
1023: $parmidx=$idx;
1024: $parmaction{$parameter}=$action;
1025: $parmvalue{$parameter}=$value;
1026: $changedflag=1;
1027: }
1028:
1029: sub log_differences {
1030: my ($plain)=@_;
1031: my %storehash=('folder' => $plain,
1032: 'currentfolder' => $env{'form.folder'});
1033: if ($parmidx) {
1034: $storehash{'parameter_res'}=$oldresources[$parmidx];
1035: foreach my $parm (keys %parmaction) {
1036: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1037: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1038: }
1039: }
1040: my $maxidx=$#oldresources;
1041: if ($#LONCAPA::map::resources>$#oldresources) {
1042: $maxidx=$#LONCAPA::map::resources;
1043: }
1044: for (my $idx=0; $idx<=$maxidx; $idx++) {
1045: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1046: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1047: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1048: $changedflag=1;
1049: }
1050: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1051: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1052: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1053: $changedflag=1;
1054: }
1055: }
1056: $storehash{'maxidx'}=$maxidx;
1057: if ($changedflag) { &log_docs(\%storehash); }
1058: }
1059: }
1060:
1061:
1062: #
1063: # Docs Change Log
1064: #
1065: sub docs_change_log {
1066: my ($r)=@_;
1067: my $folder=$env{'form.folder'};
1068: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1069: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1070: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1071: $env{'course.'.$env{'request.course.id'}.'.domain'},
1072: $env{'course.'.$env{'request.course.id'}.'.num'});
1073:
1074: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1075:
1076: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1077: '<input type="hidden" name="docslog" value="1" />');
1078:
1079: my %saveable_parameters = ('show' => 'scalar',);
1080: &Apache::loncommon::store_course_settings('docs_log',
1081: \%saveable_parameters);
1082: &Apache::loncommon::restore_course_settings('docs_log',
1083: \%saveable_parameters);
1084: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1085: my %lt=('hiddenresource' => 'Resources hidden',
1086: 'encrypturl' => 'URL hidden',
1087: 'randompick' => 'Randomly pick',
1088: 'set' => 'set to',
1089: 'del' => 'deleted');
1090: $r->print(&Apache::loncommon::display_filter().
1091: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1092: '<input type="submit" value="'.&mt('Display').'" /></form>');
1093: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1094: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1095: &mt('After').'</th>'.
1096: &Apache::loncommon::end_data_table_header_row());
1097: my $shown=0;
1098: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1099: if ($env{'form.displayfilter'} eq 'currentfolder') {
1100: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1101: }
1102: my @changes=keys(%{$docslog{$id}{'logentry'}});
1103: if ($env{'form.displayfilter'} eq 'containing') {
1104: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1105: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1106: foreach my $key (@changes) {
1107: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1108: }
1109: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1110: }
1111: my $count = 0;
1112: my $time =
1113: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1114: my $plainname =
1115: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1116: $docslog{$id}{'exe_udom'});
1117: my $about_me_link =
1118: &Apache::loncommon::aboutmewrapper($plainname,
1119: $docslog{$id}{'exe_uname'},
1120: $docslog{$id}{'exe_udom'});
1121: my $send_msg_link='';
1122: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1123: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1124: $send_msg_link ='<br />'.
1125: &Apache::loncommon::messagewrapper(&mt('Send message'),
1126: $docslog{$id}{'exe_uname'},
1127: $docslog{$id}{'exe_udom'});
1128: }
1129: $r->print(&Apache::loncommon::start_data_table_row());
1130: $r->print('<td>'.$time.'</td>
1131: <td>'.$about_me_link.
1132: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1133: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1134: $send_msg_link.'</td><td>'.
1135: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1136: # Before
1137: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1138: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1139: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1140: if ($oldname ne $newname) {
1141: $r->print(&LONCAPA::map::qtescape($oldname));
1142: }
1143: }
1144: $r->print('<ul>');
1145: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1146: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1147: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1148: }
1149: }
1150: $r->print('</ul>');
1151: # After
1152: $r->print('</td><td>');
1153:
1154: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1155: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1156: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1157: if ($oldname ne $newname) {
1158: $r->print(&LONCAPA::map::qtescape($newname));
1159: }
1160: }
1161: $r->print('<ul>');
1162: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1163: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1164: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1165: }
1166: }
1167: $r->print('</ul>');
1168: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1169: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1170: foreach my $parameter ('randompick','hiddenresource','encrypturl') {
1171: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1172: $r->print('<li>'.
1173: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1174: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1175: .'</li>');
1176: }
1177: }
1178: $r->print('</ul>');
1179: }
1180: # End
1181: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1182: $shown++;
1183: if (!($env{'form.show'} eq &mt('all')
1184: || $shown<=$env{'form.show'})) { last; }
1185: }
1186: $r->print(&Apache::loncommon::end_data_table());
1187: $r->print(&Apache::loncommon::end_page());
1188: }
1189:
1190: sub editor {
1191: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
1192: my $errtext='';
1193: my $fatal=0;
1194: my $container='sequence';
1195: if ($env{'form.pagepath'}) {
1196: $container='page';
1197: }
1198: ($errtext,$fatal)=
1199: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1200: if ($#LONCAPA::map::order<1) {
1201: my $idx=&LONCAPA::map::getresidx();
1202: if ($idx<=0) { $idx=1; }
1203: $LONCAPA::map::order[0]=$idx;
1204: $LONCAPA::map::resources[$idx]='';
1205: }
1206: if (defined($env{'form.markcopy'})) {
1207: # Mark for copying
1208: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1209: $env{'form.markedcopy_title'}=$title;
1210: $env{'form.markedcopy_url'}=$url;
1211: }
1212: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain)=&breadcrumbs($folder);
1213: $r->print($breadcrumbtrail);
1214: if ($fatal) {
1215: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1216: } else {
1217: # ------------------------------------------------------------ Process commands
1218:
1219: # ---------------- if they are for this folder and user allowed to make changes
1220: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1221: # set parameters and change order
1222: &snapshotbefore();
1223: if ($env{'form.changeparms'}) {
1224: my $idx=$env{'form.setparms'};
1225: # set parameters
1226: if ($env{'form.changeparms'} eq 'randompick') {
1227: if ($env{'form.randpick_'.$idx}) {
1228: &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
1229: &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx});
1230: } else {
1231: &LONCAPA::map::delparameter($idx,'parameter_randompick');
1232: &remember_parms($idx,'randompick','del');
1233: }
1234: }
1235: if ($env{'form.changeparms'} eq 'hiddenresource') {
1236: if ($env{'form.hidprs_'.$idx}) {
1237: &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1238: &remember_parms($idx,'hiddenresource','set',$env{'form.hidprs_'.$idx});
1239: } else {
1240: &LONCAPA::map::delparameter($idx,'parameter_hiddenresource');
1241: &remember_parms($idx,'hiddenresource','del');
1242: }
1243: }
1244: if ($env{'form.changeparms'} eq 'encrypturl') {
1245: if ($env{'form.encprs_'.$idx}) {
1246: &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1247: &remember_parms($idx,'encrypturl','set',$env{'form.encprs_'.$idx});
1248: } else {
1249: &LONCAPA::map::delparameter($idx,'parameter_encrypturl');
1250: &remember_parms($idx,'encrypturl','del');
1251: }
1252: }
1253: # store the changed version
1254: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1255: if ($fatal) {
1256: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1257: return;
1258: }
1259: }
1260:
1261: if ($env{'form.newpos'}) {
1262: # change order
1263: my $newpos=$env{'form.newpos'}-1;
1264: my $currentpos=$env{'form.currentpos'}-1;
1265: my $i;
1266: my @neworder=();
1267: if ($newpos>$currentpos) {
1268: # moving stuff up
1269: for ($i=0;$i<$currentpos;$i++) {
1270: $neworder[$i]=$LONCAPA::map::order[$i];
1271: }
1272: for ($i=$currentpos;$i<$newpos;$i++) {
1273: $neworder[$i]=$LONCAPA::map::order[$i+1];
1274: }
1275: $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
1276: for ($i=$newpos+1;$i<=$#LONCAPA::map::order;$i++) {
1277: $neworder[$i]=$LONCAPA::map::order[$i];
1278: }
1279: } else {
1280: # moving stuff down
1281: for ($i=0;$i<$newpos;$i++) {
1282: $neworder[$i]=$LONCAPA::map::order[$i];
1283: }
1284: $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
1285: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
1286: $neworder[$i]=$LONCAPA::map::order[$i-1];
1287: }
1288: for ($i=$currentpos+1;$i<=$#LONCAPA::map::order;$i++) {
1289: $neworder[$i]=$LONCAPA::map::order[$i];
1290: }
1291: }
1292: @LONCAPA::map::order=@neworder;
1293: # store the changed version
1294: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1295: if ($fatal) {
1296: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1297: return;
1298: }
1299: }
1300:
1301: if ($env{'form.pastemarked'}) {
1302: # paste resource to end of list
1303: my $url=$env{'form.markedcopy_url'};
1304: my $title=$env{'form.markedcopy_title'};
1305: # Maps need to be copied first
1306: if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
1307: $title=&mt('Copy of').' '.$title;
1308: my $newid=$$.time;
1309: $url=~/^(.+)\.(\w+)$/;
1310: my $newurl=$1.$newid.'.'.$2;
1311: my $storefn=$newurl;
1312: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1313: &Apache::lonclonecourse::writefile
1314: ($env{'request.course.id'},$storefn,
1315: &Apache::lonnet::getfile($url));
1316: $url=$newurl;
1317: }
1318: $title = &LONCAPA::map::qtunescape($title);
1319: my $ext='false';
1320: if ($url=~/^http\:\/\//) { $ext='true'; }
1321: $url = &LONCAPA::map::qtunescape($url);
1322: # Now insert the URL at the bottom
1323: my $newidx=&LONCAPA::map::getresidx($url);
1324: $LONCAPA::map::resources[$newidx]=
1325: $title.':'.$url.':'.$ext.':normal:res';
1326: $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
1327: # Store the result
1328: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1329: if ($fatal) {
1330: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1331: return;
1332: }
1333:
1334: }
1335: $r->print($upload_output);
1336: if ($env{'form.cmd'}) {
1337: my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
1338: if ($cmd eq 'del') {
1339: my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1340: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1341: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1342: &Apache::lonnet::removeuploadedurl($url);
1343: } else {
1344: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1345: }
1346: for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
1347: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1348: }
1349: $#LONCAPA::map::order--;
1350: } elsif ($cmd eq 'cut') {
1351: my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1352: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1353: for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
1354: $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
1355: }
1356: $#LONCAPA::map::order--;
1357: } elsif ($cmd eq 'up') {
1358: if (($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1359: my $i=$LONCAPA::map::order[$idx-1];
1360: $LONCAPA::map::order[$idx-1] = $LONCAPA::map::order[$idx];
1361: $LONCAPA::map::order[$idx] = $i;
1362: }
1363: } elsif ($cmd eq 'down') {
1364: if (defined($LONCAPA::map::order[$idx+1])) {
1365: my $i=$LONCAPA::map::order[$idx+1];
1366: $LONCAPA::map::order[$idx+1] = $LONCAPA::map::order[$idx];
1367: $LONCAPA::map::order[$idx] = $i;
1368: }
1369: } elsif ($cmd eq 'rename') {
1370: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1371: my ($rtitle,@rrest)=split(/\:/,
1372: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
1373: my $comment=$env{'form.title'};
1374: $comment = &LONCAPA::map::qtunescape($comment);
1375: if ($comment=~/\S/) {
1376: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1377: $comment.':'.join(':',@rrest);
1378: }
1379: # Devalidate title cache
1380: my $renamed_url=&LONCAPA::map::qtescape($rrest[0]);
1381: &Apache::lonnet::devalidate_title_cache($renamed_url);
1382: }
1383: # Store the changed version
1384: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1385: $folder.'.'.$container);
1386: if ($fatal) {
1387: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1388: return;
1389: }
1390: }
1391: # Group import/search
1392: if ($env{'form.importdetail'}) {
1393: my @imports;
1394: # &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
1395: foreach (split(/\&/,$env{'form.importdetail'})) {
1396: if (defined($_)) {
1397: my ($name,$url)=split(/\=/,$_);
1398: $name=&unescape($name);
1399: $url=&unescape($url);
1400: push @imports, $name, $url;
1401: }
1402: }
1403: # Store the changed version
1404: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1405: $container,'londocs',@imports);
1406: if ($fatal) {
1407: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1408: return;
1409: }
1410: }
1411: # Loading a complete map
1412: if ($env{'form.loadmap'}) {
1413: if ($env{'form.importmap'}=~/\w/) {
1414: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1415: my ($title,$url,$ext,$type)=split(/\:/,$_);
1416: my $idx=&LONCAPA::map::getresidx($url);
1417: $LONCAPA::map::resources[$idx]=$_;
1418: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1419: }
1420: # Store the changed version
1421: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1422: $folder.'.'.$container);
1423: if ($fatal) {
1424: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1425: return;
1426: }
1427: } else {
1428: $r->print('<p><font color="red">'.&mt('No map selected.').'</font></p>');
1429: }
1430: }
1431: &log_differences($plain);
1432: }
1433: # ---------------------------------------------------------------- End commands
1434: # ---------------------------------------------------------------- Print screen
1435: my $idx=0;
1436: my $shown=0;
1437: if (($ishidden) || ($isencrypted) || ($randompick>=0)) {
1438: $r->print('<p>'.&mt('Parameters').':<ul>'.
1439: ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
1440: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1441: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1442: '</ul></p>');
1443: }
1444: if ($randompick>=0) {
1445: $r->print('<p>'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'</p>');
1446: }
1447: $r->print('<table>');
1448: foreach (@LONCAPA::map::order) {
1449: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
1450: $name=&LONCAPA::map::qtescape($name);
1451: $url =&LONCAPA::map::qtescape($url);
1452: unless ($name) { $name=(split(/\//,$url))[-1]; }
1453: unless ($name) { $idx++; next; }
1454: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1455: $idx++;
1456: $shown++;
1457: }
1458: unless ($shown) {
1459: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1460: }
1461: $r->print("\n</table>\n");
1462: if ($env{'form.markedcopy_url'}) {
1463: $r->print(<<ENDPASTE);
1464: <p><form name="pasteform" action="/adm/coursedocs" method="post">
1465: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1466: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1467: ENDPASTE
1468: $r->print(
1469: '<input type="submit" name="pastemarked" value="'.&mt('Paste').
1470: '" /> '.&Apache::loncommon::filedescription(
1471: (split(/\./,$env{'form.markedcopy_url'}))[-1]).': '.
1472: $env{'form.markedcopy_title'});
1473: if ($container eq 'page') {
1474: $r->print(<<PAGEINFO);
1475: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
1476: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1477: PAGEINFO
1478: } else {
1479: $r->print(<<FOLDERINFO);
1480: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1481: FOLDERINFO
1482: }
1483: $r->print('</form></p>');
1484: }
1485: }
1486: }
1487:
1488: sub process_file_upload {
1489: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1490: # upload a file, if present
1491: my $parseaction;
1492: if ($env{'form.parserflag'}) {
1493: $parseaction = 'parse';
1494: }
1495: my $phase_status;
1496: my $folder=$env{'form.folder'};
1497: if ($folder eq '') {
1498: $folder='default';
1499: }
1500: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1501: my $errtext='';
1502: my $fatal=0;
1503: my $container='sequence';
1504: if ($env{'form.pagepath'}) {
1505: $container='page';
1506: }
1507: ($errtext,$fatal)=
1508: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1509: if ($#LONCAPA::map::order<1) {
1510: $LONCAPA::map::order[0]=1;
1511: $LONCAPA::map::resources[1]='';
1512: }
1513: if ($fatal) {
1514: return 'failed';
1515: }
1516: my $destination = 'docs/';
1517: if ($folder =~ /^supplemental/) {
1518: $destination = 'supplemental/';
1519: }
1520: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1521: $destination .= 'default/';
1522: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1523: $destination .= $2.'/';
1524: }
1525: # this is for a course, not a user, so set coursedoc flag
1526: # probably the only place in the system where this should be "1"
1527: my $newidx=&LONCAPA::map::getresidx();
1528: $destination .= $newidx;
1529: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1530: $parseaction,$allfiles,
1531: $codebase);
1532: my $ext='false';
1533: if ($url=~/^http\:\/\//) { $ext='true'; }
1534: $url = &LONCAPA::map::qtunescape($url);
1535: my $comment=$env{'form.comment'};
1536: $comment = &LONCAPA::map::qtunescape($comment);
1537: if ($folder=~/^supplemental/) {
1538: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1539: $env{'user.domain'}.'___&&&___'.$comment;
1540: }
1541:
1542: $LONCAPA::map::resources[$newidx]=
1543: $comment.':'.$url.':'.$ext.':normal:res';
1544: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1545: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1546: $folder.'.'.$container);
1547: if ($fatal) {
1548: $$upload_output .= '<p><font color="red">'.$errtext.'</font></p>';
1549: return 'failed';
1550: } else {
1551: if ($parseaction eq 'parse') {
1552: my $total_embedded = keys(%{$allfiles});
1553: if ($total_embedded > 0) {
1554: my $num = 0;
1555: my $state = '
1556: <input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />
1557: <input type="hidden" name="cmd" value="upload_embedded" />
1558: <input type="hidden" name="newidx" value="'.$newidx.'" />
1559: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1560: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1561: $phase_status = 'phasetwo';
1562:
1563: $$upload_output .=
1564: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1565: &ask_for_embedded_content('/adm/coursedocs',
1566: $state,$allfiles,$codebase);
1567: } else {
1568: $$upload_output .= 'No embedded items identified<br />';
1569: }
1570: }
1571: }
1572: }
1573: return $phase_status;
1574: }
1575:
1576: sub ask_for_embedded_content {
1577: my ($actionurl,$state,$allfiles,$codebase)=@_;
1578: my $upload_output = '
1579: <form name="upload_embedded" action="'.$actionurl.'"
1580: method="post" enctype="multipart/form-data">';
1581: $upload_output .= $state;
1582: $upload_output .= '<b>Upload embedded files</b>:<br />
1583: <table>';
1584:
1585: my $num = 0;
1586: foreach my $embed_file (keys(%{$allfiles})) {
1587: $upload_output .= '<tr><td>'.$embed_file.'</td><td>
1588: <input name="embedded_item_'.$num.'" type="file" value="bob" />
1589: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
1590: my $attrib = join(':',@{$$allfiles{$embed_file}});
1591: $upload_output .=
1592: "\n\t\t".
1593: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
1594: $attrib.'" />';
1595: if (exists($$codebase{$embed_file})) {
1596: $upload_output .=
1597: "\n\t\t".
1598: '<input name="codebase_'.$num.'" type="hidden" value="'.
1599: &escape($$codebase{$embed_file}).'" />';
1600: }
1601: $upload_output .= '</td></tr>';
1602: $num++;
1603: }
1604: $upload_output .= '</table><br />
1605: <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
1606: <input type ="submit" value="Complete upload" />
1607: </form>';
1608: return $upload_output;
1609: }
1610:
1611: sub process_secondary_uploads {
1612: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1613: my $folder=$env{'form.folder'};
1614: my $destination = 'docs/';
1615: if ($folder =~ /^supplemental/) {
1616: $destination = 'supplemental/';
1617: }
1618: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1619: $destination .= 'default/';
1620: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1621: $destination .= $2.'/';
1622: }
1623: $destination .= $newidx;
1624: my ($url,$filename);
1625: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1626: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1627: return $filename;
1628: }
1629:
1630: # --------------------------------------------------------------- An entry line
1631:
1632: sub entryline {
1633: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1634: $title=&HTML::Entities::encode($title,'"<>&\'');
1635: my $renametitle=$title;
1636: my $foldertitle=$title;
1637: my $pagetitle=$title;
1638: my $orderidx=$LONCAPA::map::order[$index];
1639: if ($title=~ /^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/ ) {
1640: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1641: $renametitle=$4;
1642: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
1643: &Apache::loncommon::plainname($2,$3).': <br />'.
1644: $foldertitle;
1645: }
1646: $renametitle=~s/\\/\\\\/g;
1647: $renametitle=~s/\"\;/\\\"/g;
1648: my $line='<tr>';
1649: # Edit commands
1650: my $container;
1651: my $folderpath;
1652: if ($env{'form.folderpath'}) {
1653: $container = 'sequence';
1654: $folderpath=&escape($env{'form.folderpath'});
1655: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1656: }
1657: my ($pagepath,$pagesymb);
1658: if ($env{'form.pagepath'}) {
1659: $container = 'page';
1660: $pagepath=&escape($env{'form.pagepath'});
1661: $pagesymb=&escape($env{'form.pagesymb'});
1662: }
1663: my $cpinfo='';
1664: if ($env{'form.markedcopy_url'}) {
1665: $cpinfo='&markedcopy_url='.
1666: &escape($env{'form.markedcopy_url'}).
1667: '&markedcopy_title='.
1668: &escape($env{'form.markedcopy_title'});
1669: }
1670: if ($allowed) {
1671: my $incindex=$index+1;
1672: my $selectbox='';
1673: if (($folder!~/^supplemental/) &&
1674: ($#LONCAPA::map::order>0) &&
1675: ((split(/\:/,
1676: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1677: ne '') &&
1678: ((split(/\:/,
1679: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1680: ne '')) {
1681: $selectbox=
1682: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1683: '<select name="newpos" onChange="this.form.submit()">';
1684: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1685: if ($i==$incindex) {
1686: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1687: } else {
1688: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1689: }
1690: }
1691: $selectbox.='</select>';
1692: }
1693: my %lt=&Apache::lonlocal::texthash(
1694: 'up' => 'Move Up',
1695: 'dw' => 'Move Down',
1696: 'rm' => 'Remove',
1697: 'ct' => 'Cut',
1698: 'rn' => 'Rename',
1699: 'cp' => 'Copy');
1700: my $nocopy=0;
1701: my $nocut=0;
1702: if ($url=~/\.(page|sequence)$/) {
1703: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
1704: my ($title,$url,$ext,$type)=split(/\:/,$_);
1705: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1706: $nocopy=1;
1707: last;
1708: }
1709: }
1710: }
1711: if ($url=~/^\/res\/lib\/templates\//) {
1712: $nocopy=1;
1713: $nocut=1;
1714: }
1715: my $copylink=' ';
1716: my $cutlink=' ';
1717: if ($env{'form.pagepath'}) {
1718: if (!$nocopy) {
1719: $copylink=(<<ENDCOPY);
1720: <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
1721: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1722: ENDCOPY
1723: }
1724: if (!$nocut) {
1725: $cutlink=(<<ENDCUT);
1726: <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1727: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1728: ENDCUT
1729: }
1730: $line.=(<<END);
1731: <form name="entry_$index" action="/adm/coursedocs" method="post">
1732: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
1733: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1734: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1735: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1736: <input type="hidden" name="setparms" value="$orderidx" />
1737: <input type="hidden" name="changeparms" value="0" />
1738: <td><table border='0' cellspacing='2' cellpadding='0'>
1739: <tr><td bgcolor="#DDDDDD">
1740: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1741: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1742: <tr><td bgcolor="#DDDDDD">
1743: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1744: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1745: </table></td>
1746: <td>$selectbox
1747: </td><td bgcolor="#DDDDDD">
1748: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1749: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1750: $cutlink
1751: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1752: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1753: $copylink
1754: END
1755: } else {
1756: if (!$nocopy) {
1757: $copylink=(<<ENDCOPY);
1758: <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
1759: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1760: ENDCOPY
1761: }
1762: if (!$nocut) {
1763: $cutlink=(<<ENDCUT);
1764: <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>
1765: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1766: ENDCUT
1767: }
1768: $line.=(<<END);
1769: <form name="entry_$index" action="/adm/coursedocs" method="post">
1770: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1771: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1772: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1773: <input type="hidden" name="setparms" value="$orderidx" />
1774: <input type="hidden" name="changeparms" value="0" />
1775: <td><table border='0' cellspacing='2' cellpadding='0'>
1776: <tr><td bgcolor="#DDDDDD">
1777: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
1778: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1779: <tr><td bgcolor="#DDDDDD">
1780: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
1781: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1782: </table></td>
1783: <td>$selectbox
1784: </td><td bgcolor="#DDDDDD">
1785: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1786: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1787: $cutlink
1788: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1789: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1790: $copylink
1791: END
1792: }
1793: }
1794: # Figure out what kind of a resource this is
1795: my ($extension)=($url=~/\.(\w+)$/);
1796: my $uploaded=($url=~/^\/*uploaded\//);
1797: my $icon=&Apache::loncommon::icon($url);
1798: my $isfolder=0;
1799: my $ispage=0;
1800: my $folderarg;
1801: my $pagearg;
1802: my $pagefile;
1803: if ($uploaded) {
1804: if ($extension eq 'sequence') {
1805: $icon=$iconpath.'/folder_closed.gif';
1806: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1807: $url='/adm/coursedocs?';
1808: $folderarg=$1;
1809: $isfolder=1;
1810: } elsif ($extension eq 'page') {
1811: $icon=$iconpath.'/page.gif';
1812: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1813: $pagearg=$1;
1814: $url='/adm/coursedocs?';
1815: $ispage=1;
1816: } else {
1817: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1818: }
1819: }
1820: $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
1821: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1822: my $symb=&Apache::lonnet::symbclean(
1823: &Apache::lonnet::declutter('uploaded/'.
1824: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1825: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1826: '.sequence').
1827: '___'.$residx.'___'.
1828: &Apache::lonnet::declutter($url));
1829: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1830: $url=&Apache::lonnet::clutter($url);
1831: if ($url=~/^\/*uploaded\//) {
1832: $url=~/\.(\w+)$/;
1833: my $embstyle=&Apache::loncommon::fileembstyle($1);
1834: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1835: $url='/adm/wrapper'.$url;
1836: } elsif ($embstyle eq 'ssi') {
1837: #do nothing with these
1838: } elsif ($url!~/\.(sequence|page)$/) {
1839: $url='/adm/coursedocs/showdoc'.$url;
1840: }
1841: } elsif ($url=~m|^/ext/|) {
1842: $url='/adm/wrapper'.$url;
1843: }
1844: if (&Apache::lonnet::symbverify($symb,$url)) {
1845: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1846: } else {
1847: $url='';
1848: }
1849: if ($container eq 'page') {
1850: my $symb=$env{'form.pagesymb'};
1851:
1852: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1853: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1854: }
1855: }
1856: my $parameterset=' ';
1857: if ($isfolder || $extension eq 'sequence') {
1858: my $foldername=&escape($foldertitle);
1859: my $folderpath=$env{'form.folderpath'};
1860: if ($folderpath) { $folderpath.='&' };
1861: # Append randompick number, hidden, and encrypted with ":" to foldername,
1862: # so it gets transferred between levels
1863: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
1864: 'parameter_randompick'))[0]
1865: .':'.((&LONCAPA::map::getparameter($orderidx,
1866: 'parameter_hiddenresource'))[0]=~/^yes$/i)
1867: .':'.((&LONCAPA::map::getparameter($orderidx,
1868: 'parameter_encrypturl'))[0]=~/^yes$/i);
1869: $url.='folderpath='.&escape($folderpath).$cpinfo;
1870: $parameterset='<label>'.&mt('Randomly Pick: ').
1871: '<input type="text" size="4" onChange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randpick_'.$orderidx.'" value="'.
1872: (&LONCAPA::map::getparameter($orderidx,
1873: 'parameter_randompick'))[0].
1874: '" />'.
1875: '<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
1876:
1877: }
1878: if ($ispage) {
1879: my $pagename=&escape($pagetitle);
1880: my $pagepath;
1881: my $folderpath=$env{'form.folderpath'};
1882: if ($folderpath) { $pagepath = $folderpath.'&' };
1883: $pagepath.=$pagearg.'&'.$pagename;
1884: my $symb=$env{'form.pagesymb'};
1885: if (!$symb) {
1886: my $path='uploaded/'.
1887: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1888: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1889: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1890: $residx,
1891: $path.$pagearg.'.page');
1892: }
1893: $url.='pagepath='.&escape($pagepath).
1894: '&pagesymb='.&escape($symb).$cpinfo;
1895: }
1896: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1897: '" border="0"></a></td>'.
1898: "<td bgcolor='#FFFFBB'>".($url?"<a href=\"$url\">":'').$title.
1899: ($url?'</a>':' <font size="-2">'.&mt('(re-initialize course to access)').'</font>')."</td>";
1900: if (($allowed) && ($folder!~/^supplemental/)) {
1901: my %lt=&Apache::lonlocal::texthash(
1902: 'hd' => 'Hidden',
1903: 'ec' => 'URL hidden');
1904: my $enctext=
1905: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1906: my $hidtext=
1907: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1908: $line.=(<<ENDPARMS);
1909: <td bgcolor="#BBBBFF"><font size='-2'>
1910: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
1911: <td bgcolor="#BBBBFF"><font size='-2'>
1912: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
1913: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1914: ENDPARMS
1915: }
1916: $line.="</form></tr>";
1917: return $line;
1918: }
1919:
1920: # ---------------------------------------------------------------- tie the hash
1921:
1922: sub tiehash {
1923: my ($mode)=@_;
1924: $hashtied=0;
1925: if ($env{'request.course.fn'}) {
1926: if ($mode eq 'write') {
1927: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1928: &GDBM_WRCREAT(),0640)) {
1929: $hashtied=2;
1930: }
1931: } else {
1932: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1933: &GDBM_READER(),0640)) {
1934: $hashtied=1;
1935: }
1936: }
1937: }
1938: }
1939:
1940: sub untiehash {
1941: if ($hashtied) { untie %hash; }
1942: $hashtied=0;
1943: return OK;
1944: }
1945:
1946: # --------------------------------------------------------------- check on this
1947:
1948: sub checkonthis {
1949: my ($r,$url,$level,$title)=@_;
1950: $url=&unescape($url);
1951: $alreadyseen{$url}=1;
1952: $r->rflush();
1953: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1954: $r->print("\n<br />");
1955: for (my $i=0;$i<=$level*5;$i++) {
1956: $r->print(' ');
1957: }
1958: $r->print('<a href="'.$url.'" target="cat">'.
1959: ($title?$title:$url).'</a> ');
1960: if ($url=~/^\/res\//) {
1961: my $result=&Apache::lonnet::repcopy(
1962: &Apache::lonnet::filelocation('',$url));
1963: if ($result eq 'ok') {
1964: $r->print('<font color="green">'.&mt('ok').'</font>');
1965: $r->rflush();
1966: &Apache::lonnet::countacc($url);
1967: $url=~/\.(\w+)$/;
1968: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1969: $r->print('<br />');
1970: $r->rflush();
1971: for (my $i=0;$i<=$level*5;$i++) {
1972: $r->print(' ');
1973: }
1974: $r->print('- '.&mt('Rendering').': ');
1975: my ($errorcount,$warningcount)=split(/:/,
1976: &Apache::lonnet::ssi_body($url,
1977: ('grade_target'=>'web',
1978: 'return_only_error_and_warning_counts' => 1)));
1979: if (($errorcount) ||
1980: ($warningcount)) {
1981: if ($errorcount) {
1982: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1983: $errorcount.' '.
1984: &mt('error(s)').'</b></font> ');
1985: }
1986: if ($warningcount) {
1987: $r->print('<font color="blue">'.
1988: $warningcount.' '.
1989: &mt('warning(s)').'</font>');
1990: }
1991: } else {
1992: $r->print('<font color="green">'.&mt('ok').'</font>');
1993: }
1994: $r->rflush();
1995: }
1996: my $dependencies=
1997: &Apache::lonnet::metadata($url,'dependencies');
1998: foreach (split(/\,/,$dependencies)) {
1999: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
2000: &checkonthis($r,$_,$level+1);
2001: }
2002: }
2003: } elsif ($result eq 'unavailable') {
2004: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
2005: } elsif ($result eq 'not_found') {
2006: unless ($url=~/\$/) {
2007: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
2008: } else {
2009: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
2010: }
2011: } else {
2012: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
2013: }
2014: }
2015: }
2016: }
2017:
2018:
2019: #
2020: # ----------------------------------------------------------------- List Symbs
2021: #
2022: sub list_symbs {
2023: my ($r) = @_;
2024:
2025: $r->print(&Apache::loncommon::start_page('Symb List'));
2026: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
2027: my $navmap = Apache::lonnavmaps::navmap->new();
2028: $r->print("<pre>\n");
2029: foreach my $res ($navmap->retrieveResources()) {
2030: $r->print($res->compTitle()."\t".$res->symb()."\n");
2031: }
2032: $r->print("\n</pre>\n");
2033: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
2034: }
2035:
2036:
2037: #
2038: # -------------------------------------------------------------- Verify Content
2039: #
2040: sub verifycontent {
2041: my ($r) = @_;
2042: my $type = &Apache::loncommon::course_type();
2043: my $loaderror=&Apache::lonnet::overloaderror($r);
2044: if ($loaderror) { return $loaderror; }
2045: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
2046: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
2047: $hashtied=0;
2048: undef %alreadyseen;
2049: %alreadyseen=();
2050: &tiehash();
2051: foreach (keys %hash) {
2052: if ($hash{$_}=~/\.(page|sequence)$/) {
2053: if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
2054: $r->print('<hr /><font color="red">'.
2055: &mt('The following sequence or page is included more than once in your '.$type.': ').
2056: &unescape($hash{$_}).'</font><br />'.
2057: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2058: }
2059: }
2060: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
2061: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
2062: }
2063: }
2064: &untiehash();
2065: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2066: &mt('Return to DOCS').'</a>');
2067: }
2068:
2069:
2070: # -------------------------------------------------------------- Check Versions
2071:
2072: sub devalidateversioncache {
2073: my $src=shift;
2074: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2075: &Apache::lonnet::clutter($src));
2076: }
2077:
2078: sub checkversions {
2079: my ($r) = @_;
2080: my $type = &Apache::loncommon::course_type();
2081: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
2082: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
2083: my $header='';
2084: my $startsel='';
2085: my $monthsel='';
2086: my $weeksel='';
2087: my $daysel='';
2088: my $allsel='';
2089: my %changes=();
2090: my $starttime=0;
2091: my $haschanged=0;
2092: my %setversions=&Apache::lonnet::dump('resourceversions',
2093: $env{'course.'.$env{'request.course.id'}.'.domain'},
2094: $env{'course.'.$env{'request.course.id'}.'.num'});
2095:
2096: $hashtied=0;
2097: &tiehash();
2098: my %newsetversions=();
2099: if ($env{'form.setmostrecent'}) {
2100: $haschanged=1;
2101: foreach (keys %hash) {
2102: if ($_=~/^ids\_(\/res\/.+)$/) {
2103: $newsetversions{$1}='mostrecent';
2104: &devalidateversioncache($1);
2105: }
2106: }
2107: } elsif ($env{'form.setcurrent'}) {
2108: $haschanged=1;
2109: foreach (keys %hash) {
2110: if ($_=~/^ids\_(\/res\/.+)$/) {
2111: my $getvers=&Apache::lonnet::getversion($1);
2112: if ($getvers>0) {
2113: $newsetversions{$1}=$getvers;
2114: &devalidateversioncache($1);
2115: }
2116: }
2117: }
2118: } elsif ($env{'form.setversions'}) {
2119: $haschanged=1;
2120: foreach (keys %env) {
2121: if ($_=~/^form\.set_version_(.+)$/) {
2122: my $src=$1;
2123: if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
2124: $newsetversions{$src}=$env{$_};
2125: &devalidateversioncache($src);
2126: }
2127: }
2128: }
2129: }
2130: if ($haschanged) {
2131: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2132: $env{'course.'.$env{'request.course.id'}.'.domain'},
2133: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
2134: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
2135: } else {
2136: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
2137: }
2138: &mark_hash_old();
2139: }
2140: &changewarning($r,'');
2141: if ($env{'form.timerange'} eq 'all') {
2142: # show all documents
2143: $header=&mt('All Documents in '.$type);
2144: $allsel=1;
2145: foreach (keys %hash) {
2146: if ($_=~/^ids\_(\/res\/.+)$/) {
2147: my $src=$1;
2148: $changes{$src}=1;
2149: }
2150: }
2151: } else {
2152: # show documents which changed
2153: %changes=&Apache::lonnet::dump
2154: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2155: $env{'course.'.$env{'request.course.id'}.'.num'});
2156: my $firstkey=(keys %changes)[0];
2157: unless ($firstkey=~/^error\:/) {
2158: unless ($env{'form.timerange'}) {
2159: $env{'form.timerange'}=604800;
2160: }
2161: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2162: .&mt('seconds');
2163: if ($env{'form.timerange'}==-1) {
2164: $seltext='since start of course';
2165: $startsel='selected';
2166: $env{'form.timerange'}=time;
2167: }
2168: $starttime=time-$env{'form.timerange'};
2169: if ($env{'form.timerange'}==2592000) {
2170: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2171: $monthsel='selected';
2172: } elsif ($env{'form.timerange'}==604800) {
2173: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2174: $weeksel='selected';
2175: } elsif ($env{'form.timerange'}==86400) {
2176: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2177: $daysel='selected';
2178: }
2179: $header=&mt('Content changed').' '.$seltext;
2180: } else {
2181: $header=&mt('No content modifications yet.');
2182: }
2183: }
2184: %setversions=&Apache::lonnet::dump('resourceversions',
2185: $env{'course.'.$env{'request.course.id'}.'.domain'},
2186: $env{'course.'.$env{'request.course.id'}.'.num'});
2187: my %lt=&Apache::lonlocal::texthash
2188: ('st' => 'Version changes since start of '.$type,
2189: 'lm' => 'Version changes since last Month',
2190: 'lw' => 'Version changes since last Week',
2191: 'sy' => 'Version changes since Yesterday',
2192: 'al' => 'All Resources (possibly large output)',
2193: 'sd' => 'Display',
2194: 'fi' => 'File',
2195: 'md' => 'Modification Date',
2196: 'mr' => 'Most recently published Version',
2197: 've' => 'Version used in '.$type,
2198: 'vu' => 'Set Version to be used in '.$type,
2199: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
2200: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2201: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
2202: 'di' => 'Differences');
2203: $r->print(<<ENDHEADERS);
2204: <form action="/adm/coursedocs" method="post">
2205: <input type="hidden" name="versions" value="1" />
2206: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2207: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
2208: <select name="timerange">
2209: <option value='all' $allsel>$lt{'al'}</option>
2210: <option value="-1" $startsel>$lt{'st'}</option>
2211: <option value="2592000" $monthsel>$lt{'lm'}</option>
2212: <option value="604800" $weeksel>$lt{'lw'}</option>
2213: <option value="86400" $daysel>$lt{'sy'}</option>
2214: </select>
2215: <input type="submit" name="display" value="$lt{'sd'}" />
2216: <h3>$header</h3>
2217: <input type="submit" name="setversions" value="$lt{'sv'}" />
2218: <table border="0">
2219: ENDHEADERS
2220: foreach (sort keys %changes) {
2221: if ($changes{$_}>$starttime) {
2222: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
2223: my $currentversion=&Apache::lonnet::getversion($_);
2224: if ($currentversion<0) {
2225: $currentversion=&mt('Could not be determined.');
2226: }
2227: my $linkurl=&Apache::lonnet::clutter($_);
2228: $r->print(
2229: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
2230: &Apache::lonnet::gettitle($linkurl).
2231: '</b></font></td></tr>'.
2232: '<tr><td> </td>'.
2233: '<td colspan="4">'.
2234: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2235: '</a></td></tr>'.
2236: '<tr><td></td>'.
2237: '<td title="'.$lt{'md'}.'">'.
2238: &Apache::lonlocal::locallocaltime(
2239: &Apache::lonnet::metadata($root.'.'.$extension,
2240: 'lastrevisiondate')
2241: ).
2242: '</td>'.
2243: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
2244: '<font size="+1">'.$currentversion.'</font>'.
2245: '</nobr></td>'.
2246: '<td title="'.$lt{'ve'}.'"><nobr>In '.$type.': '.
2247: '<font size="+1">');
2248: # Used in course
2249: my $usedversion=$hash{'version_'.$linkurl};
2250: if (($usedversion) && ($usedversion ne 'mostrecent')) {
2251: $r->print($usedversion);
2252: } else {
2253: $r->print($currentversion);
2254: }
2255: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
2256: '<nobr>Use: ');
2257: # Set version
2258: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2259: 'set_version_'.$linkurl,
2260: ('select_form_order' =>
2261: ['',1..$currentversion,'mostrecent'],
2262: '' => '',
2263: 'mostrecent' => 'most recent',
2264: map {$_,$_} (1..$currentversion))));
2265: $r->print('</nobr></td></tr><tr><td></td>');
2266: my $lastold=1;
2267: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2268: my $url=$root.'.'.$prevvers.'.'.$extension;
2269: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2270: $starttime) {
2271: $lastold=$prevvers;
2272: }
2273: }
2274: #
2275: # Code to figure out how many version entries should go in
2276: # each of the four columns
2277: my $entries_per_col = 0;
2278: my $num_entries = ($currentversion-$lastold);
2279: if ($num_entries % 4 == 0) {
2280: $entries_per_col = $num_entries/4;
2281: } else {
2282: $entries_per_col = $num_entries/4 + 1;
2283: }
2284: my $entries_count = 0;
2285: $r->print('<td valign="top"><font size="-2">');
2286: my $cols_output = 1;
2287: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2288: my $url=$root.'.'.$prevvers.'.'.$extension;
2289: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
2290: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2291: &Apache::lonlocal::locallocaltime(
2292: &Apache::lonnet::metadata($url,
2293: 'lastrevisiondate')
2294: ).
2295: ')');
2296: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2297: $r->print(' <a href="/adm/diff?filename='.
2298: &Apache::lonnet::clutter($root.'.'.$extension).
2299: '&versionone='.$prevvers.
2300: '">'.&mt('Diffs').'</a>');
2301: }
2302: $r->print('</nobr><br />');
2303: if (++$entries_count % $entries_per_col == 0) {
2304: $r->print('</font></td>');
2305: if ($cols_output != 4) {
2306: $r->print('<td valign="top"><font size="-2">');
2307: $cols_output++;
2308: }
2309: }
2310: }
2311: while($cols_output++ < 4) {
2312: $r->print('</font></td><td><font>')
2313: }
2314: $r->print('</font></td></tr>'."\n");
2315: }
2316: }
2317: $r->print('</table></form>');
2318: $r->print('<h1>'.&mt('Done').'.</h1>');
2319:
2320: &untiehash();
2321: }
2322:
2323: sub mark_hash_old {
2324: my $retie_hash=0;
2325: if ($hashtied) {
2326: $retie_hash=1;
2327: &untiehash();
2328: }
2329: &tiehash('write');
2330: $hash{'old'}=1;
2331: &untiehash();
2332: if ($retie_hash) { &tiehash(); }
2333: }
2334:
2335: sub is_hash_old {
2336: my $untie_hash=0;
2337: if (!$hashtied) {
2338: $untie_hash=1;
2339: &tiehash();
2340: }
2341: my $return=$hash{'old'};
2342: if ($untie_hash) { &untiehash(); }
2343: return $return;
2344: }
2345:
2346: sub changewarning {
2347: my ($r,$postexec,$message,$url)=@_;
2348: if (!&is_hash_old()) { return; }
2349: my $pathvar='folderpath';
2350: my $path=&escape($env{'form.folderpath'});
2351: if (!defined($url)) {
2352: if (defined($env{'form.pagepath'})) {
2353: $pathvar='pagepath';
2354: $path=&escape($env{'form.pagepath'});
2355: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2356: }
2357: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2358: }
2359: my $course_type = &Apache::loncommon::course_type();
2360: if (!defined($message)) {
2361: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2362: }
2363: $r->print("\n\n".
2364: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
2365: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
2366: '<input type="hidden" name="orgurl" value="'.$url.
2367: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
2368: &mt($message,' <input type="hidden" name="'.
2369: $env{'request.role'}.'" value="1" /><input type="button" value="'.
2370: &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
2371: $help{'Caching'}.'</font></h3></form>'."\n\n");
2372: }
2373:
2374: # =========================================== Breadcrumbs for special functions
2375:
2376: sub init_breadcrumbs {
2377: my ($form,$text)=@_;
2378: &Apache::lonhtmlcommon::clear_breadcrumbs();
2379: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
2380: text=>&Apache::loncommon::course_type()." Documents",
2381: faq=>273,
2382: bug=>'Instructor Interface',
2383: help => 'Docs_Adding_Course_Doc'});
2384: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2385: text=>$text,
2386: faq=>273,
2387: bug=>'Instructor Interface'});
2388: }
2389:
2390: # ================================================================ Main Handler
2391: sub handler {
2392: my $r = shift;
2393: &Apache::loncommon::content_type($r,'text/html');
2394: $r->send_http_header;
2395: return OK if $r->header_only;
2396: my $type = &Apache::loncommon::course_type();
2397:
2398: # --------------------------------------------- Initialize help topics for this
2399: foreach ('Adding_Course_Doc','Main_Course_Documents',
2400: 'Adding_External_Resource','Navigate_Content',
2401: 'Adding_Folders','Docs_Overview', 'Load_Map',
2402: 'Supplemental','Score_Upload_Form','Adding_Pages',
2403: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2404: 'Check_Resource_Versions','Verify_Content') {
2405: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
2406: }
2407: # Composite help files
2408: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2409: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2410: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2411: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2412: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2413: 'Option_Response_Simple');
2414: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2415: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2416: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2417: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2418: $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
2419: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2420:
2421: # does this user have privileges to modify docs
2422: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2423: if ($allowed && $env{'form.verify'}) {
2424: &init_breadcrumbs('verify','Verify Content');
2425: &verifycontent($r);
2426: } elsif ($allowed && $env{'form.listsymbs'}) {
2427: &init_breadcrumbs('listsymbs','List Symbs');
2428: &list_symbs($r);
2429: } elsif ($allowed && $env{'form.docslog'}) {
2430: &init_breadcrumbs('docslog','Show Log');
2431: &docs_change_log($r);
2432: } elsif ($allowed && $env{'form.versions'}) {
2433: &init_breadcrumbs('versions','Check/Set Resource Versions');
2434: &checkversions($r);
2435: } elsif ($allowed && $env{'form.dumpcourse'}) {
2436: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2437: &dumpcourse($r);
2438: } elsif ($allowed && $env{'form.exportcourse'}) {
2439: &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
2440: &exportcourse($r);
2441: } else {
2442: # is this a standard course?
2443:
2444: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2445: my $forcestandard = 0;
2446: my $forcesupplement;
2447: my $script='';
2448: my $showdoc=0;
2449: my $containertag;
2450: my $uploadtag;
2451: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2452: ['folderpath','pagepath',
2453: 'pagesymb','markedcopy_url',
2454: 'markedcopy_title']);
2455: if ($env{'form.folderpath'}) {
2456: my (@folderpath)=split('&',$env{'form.folderpath'});
2457: $env{'form.foldername'}=&unescape(pop(@folderpath));
2458: $env{'form.folder'}=pop(@folderpath);
2459: }
2460: if ($env{'form.pagepath'}) {
2461: my (@pagepath)=split('&',$env{'form.pagepath'});
2462: $env{'form.pagename'}=&unescape(pop(@pagepath));
2463: $env{'form.folder'}=pop(@pagepath);
2464: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2465: '<input type="hidden" name="pagesymb" value="" />';
2466: $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.
2467: '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';
2468: }
2469: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2470: $showdoc='/'.$1;
2471: }
2472: unless ($showdoc) { # got called from remote
2473: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
2474: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2475: $forcestandard = 1;
2476: }
2477: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2478:
2479: if ($allowed) {
2480: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2481: $script=&Apache::lonratedt::editscript('simple');
2482: }
2483: } else { # got called in sequence from course
2484: $allowed=0;
2485: }
2486:
2487: # get course data
2488: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2489: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2490:
2491: # get personal data
2492: my $uname=$env{'user.name'};
2493: my $udom=$env{'user.domain'};
2494: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2495:
2496: # graphics settings
2497:
2498: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2499:
2500: if ($allowed) {
2501: $script .= &editing_js($udom,$uname);
2502: }
2503: # -------------------------------------------------------------------- Body tag
2504: $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
2505: $r->print(&Apache::loncommon::start_page("$type Documents", $script,
2506: {'force_register' => $showdoc,}).
2507: &Apache::loncommon::help_open_menu('','',273,'RAT'));
2508:
2509: my %allfiles = ();
2510: my %codebase = ();
2511: my ($upload_result,$upload_output);
2512: if ($allowed) {
2513: if (($env{'form.uploaddoc.filename'}) &&
2514: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
2515: # Process file upload - phase one - upload and parse primary file.
2516: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2517: $coursedom,\%allfiles,
2518: \%codebase,$1);
2519: if ($upload_result eq 'phasetwo') {
2520: $r->print($upload_output);
2521: }
2522: } elsif ($env{'form.phasetwo'}) {
2523: my %newname = ();
2524: my %origname = ();
2525: my %attribs = ();
2526: my $updateflag = 0;
2527: my $residx = $env{'form.newidx'};
2528: my $primary_url = &unescape($env{'form.primaryurl'});
2529: # Process file upload - phase two - gather secondary files.
2530: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2531: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2532: my $javacodebase;
2533: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2534: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2535: if (exists($env{'form.embedded_codebase_'.$i})) {
2536: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2537: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2538: }
2539: my @attributes = ();
2540: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2541: @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
2542: } else {
2543: @attributes = ($env{'form.embedded_attrib_'.$i});
2544: }
2545: foreach (@attributes) {
2546: push(@{$attribs{$i}},&unescape($_));
2547: }
2548: if ($javacodebase) {
2549: $codebase{$i} = $javacodebase;
2550: $codebase{$i} =~ s#/$##;
2551: $updateflag = 1;
2552: }
2553: }
2554: unless ($newname{$i} eq $origname{$i}) {
2555: $updateflag = 1;
2556: }
2557: }
2558: # Process file upload - phase three - modify primary file
2559: if ($updateflag) {
2560: my ($content,$rtncode);
2561: my $updateflag = 0;
2562: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2563: if ($getstatus eq 'ok') {
2564: foreach my $item (keys %newname) {
2565: if ($newname{$item} ne $origname{$item}) {
2566: my $attrib_regexp = '';
2567: if (@{$attribs{$item}} > 1) {
2568: $attrib_regexp = join('|',@{$attribs{$item}});
2569: } else {
2570: $attrib_regexp = $attribs{$item}[0];
2571: }
2572: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2573: }
2574: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2575: }
2576: if (exists($codebase{$item})) {
2577: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2578: }
2579: }
2580: # Save edited file.
2581: my $saveresult;
2582: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2583: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2584: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2585: } else {
2586: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2587: }
2588: }
2589: }
2590: }
2591:
2592: unless ($showdoc || $upload_result eq 'phasetwo') {
2593: # -----------------------------------------------------------------------------
2594: my %lt=&Apache::lonlocal::texthash(
2595: 'uplm' => 'Upload a new main '.lc($type).' document',
2596: 'upls' => 'Upload a new supplemental '.lc($type).' document',
2597: 'impp' => 'Import a document',
2598: 'pubd' => 'Published documents',
2599: 'copm' => 'All documents out of a published map into this folder',
2600: 'spec' => 'Special documents',
2601: 'upld' => 'Upload Document',
2602: 'srch' => 'Search',
2603: 'impo' => 'Import',
2604: 'book' => 'Import Bookmarks',
2605: 'selm' => 'Select Map',
2606: 'load' => 'Load Map',
2607: 'reco' => 'Recover Deleted Resources',
2608: 'newf' => 'New Folder',
2609: 'newp' => 'New Composite Page',
2610: 'extr' => 'External Resource',
2611: 'syll' => 'Syllabus',
2612: 'navc' => 'Navigate Contents',
2613: 'sipa' => 'Simple Page',
2614: 'sipr' => 'Simple Problem',
2615: 'drbx' => 'Drop Box',
2616: 'scuf' => 'Score Upload Form',
2617: 'bull' => 'Bulletin Board',
2618: 'mypi' => 'My Personal Info',
2619: 'grpo' => 'Group Files',
2620: 'abou' => 'About User',
2621: 'imsf' => 'Import IMS package',
2622: 'file' => 'File',
2623: 'title' => 'Title',
2624: 'comment' => 'Comment',
2625: 'parse' => 'If HTML file, upload embedded images/multimedia files'
2626: );
2627: # -----------------------------------------------------------------------------
2628: if ($allowed) {
2629: my $dumpbut=&dumpbutton();
2630: my $exportbut=&exportbutton();
2631: my %lt=&Apache::lonlocal::texthash(
2632: 'vc' => 'Verify Content',
2633: 'cv' => 'Check/Set Resource Versions',
2634: 'ls' => 'List Symbs',
2635: 'sl' => 'Show Log'
2636: );
2637:
2638: my $folderpath=$env{'form.folderpath'};
2639: if (!$folderpath) {
2640: if ($env{'form.folder'} eq '' ||
2641: $env{'form.folder'} eq 'supplemental') {
2642: $folderpath='default&'.
2643: &escape(&mt('Main '.$type.' Documents'));
2644: }
2645: }
2646: unless ($env{'form.pagepath'}) {
2647: $containertag = '<input type="hidden" name="folderpath" value="" />';
2648: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2649: }
2650:
2651: $r->print(<<ENDCOURSEVERIFY);
2652: <form name="renameform" method="post" action="/adm/coursedocs">
2653: <input type="hidden" name="title" />
2654: <input type="hidden" name="cmd" />
2655: <input type="hidden" name="markcopy" />
2656: $containertag
2657: </form>
2658: <form name="simpleedit" method="post" action="/adm/coursedocs">
2659: <input type="hidden" name="importdetail" value="" />
2660: $uploadtag
2661: </form>
2662: <form action="/adm/coursedocs" method="post" name="courseverify">
2663: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2664: <tr><td bgcolor="#DDDDCC">
2665: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
2666: </td><td bgcolor="#DDDDCC">
2667: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
2668: $dumpbut
2669: $exportbut
2670: </td><td bgcolor="#DDDDCC">
2671: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
2672: </td><td bgcolor="#DDDDCC">
2673: <input type="hidden" name="folder" value="$env{'form.folder'}" />
2674: <input type="submit" name="docslog" value="$lt{'sl'}" />
2675: </td></tr></table>
2676: </form>
2677: ENDCOURSEVERIFY
2678: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2679: &mt('Editing the Table of Contents for your '.$type)));
2680: }
2681: # --------------------------------------------------------- Standard documents
2682: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
2683: if (($standard) && ($allowed) && (!$forcesupplement)) {
2684: $r->print('<tr><td bgcolor="#BBBBBB">');
2685: # '<h2>'.&mt('Main Course Documents').
2686: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
2687: my $folder=$env{'form.folder'};
2688: if ($folder eq '' || $folder eq 'supplemental') {
2689: $folder='default';
2690: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
2691: }
2692: my $postexec='';
2693: if ($folder eq 'default') {
2694: $r->print('<script>this.window.name="loncapaclient";</script>');
2695: } else {
2696: #$postexec='self.close();';
2697: }
2698: $hadchanges=0;
2699: &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
2700: if ($hadchanges) {
2701: &mark_hash_old()
2702: }
2703: &changewarning($r,$postexec);
2704: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2705: '.sequence';
2706: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2707: '.page';
2708: my $container='sequence';
2709: if ($env{'form.pagepath'}) {
2710: $container='page';
2711: }
2712: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2713: $r->print(<<ENDFORM);
2714: <table cellspacing=4 cellpadding=4><tr>
2715: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2716: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2717: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2718: </tr>
2719: <tr><td bgcolor="#DDDDDD">
2720: $lt{'file'}:<br />
2721: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2722: <input type="file" name="uploaddoc" size="40">
2723: <br />
2724: $lt{'title'}:<br />
2725: <input type="text" size="50" name="comment">
2726: $uploadtag
2727: <input type="hidden" name="cmd" value="upload_default">
2728: <br />
2729: <nobr>
2730: <label>$lt{'parse'}?
2731: <input type="checkbox" name="parserflag" />
2732: </label>
2733: </nobr>
2734: <br />
2735: <br />
2736: <nobr>
2737: <input type="submit" value="$lt{'upld'}">
2738: $help{'Uploading_From_Harddrive'}
2739: </nobr>
2740: </form>
2741: </td>
2742: <td bgcolor="#DDDDDD">
2743: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2744: $lt{'pubd'}<br />
2745: $uploadtag
2746: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}" />
2747: <br />
2748: <nobr>
2749: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}" />
2750: $help{'Importing_LON-CAPA_Resource'}
2751: </nobr>
2752: <br />
2753: <input type=button onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
2754: <p>
2755: <hr />
2756: $lt{'copm'}<br />
2757: <input type="text" size="40" name="importmap"><br />
2758: <nobr><input type=button
2759: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2760: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
2761: $help{'Load_Map'}</nobr>
2762: </p>
2763: </form>
2764: <hr />
2765: <form action="/adm/groupsort" method="post" name="recover">
2766: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
2767: </form>
2768: ENDFORM
2769: unless ($env{'form.pagepath'}) {
2770: $r->print(<<ENDFORM);
2771: <hr />
2772: <form action="/adm/coursedocs" method="post" name="newext">
2773: $uploadtag
2774: <input type="hidden" name="importdetail" value="" />
2775: <nobr>
2776: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2777: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2778: </nobr>
2779: </form>
2780: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
2781: <input type="hidden" name="folder" value="$folder" />
2782: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2783: </nobr>
2784: </form>
2785: ENDFORM
2786: }
2787: $r->print('</td><td bgcolor="#DDDDDD">');
2788: unless ($env{'form.pagepath'}) {
2789: $r->print(<<ENDFORM);
2790: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
2791: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2792: <input type="hidden" name="importdetail" value="" />
2793: <nobr>
2794: <input name="newfolder" type="button"
2795: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2796: value="$lt{'newf'}" />$help{'Adding_Folders'}
2797: </nobr>
2798: </form>
2799: <br /><form action="/adm/coursedocs" method="post" name="newpage">
2800: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2801: <input type="hidden" name="importdetail" value="" />
2802: <nobr>
2803: <input name="newpage" type="button"
2804: onClick="javascript:makenewpage(this.form,'$pageseq');"
2805: value="$lt{'newp'}" />$help{'Adding_Pages'}
2806: </nobr>
2807: </form>
2808: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
2809: $uploadtag
2810: <input type="hidden" name="importdetail"
2811: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
2812: <nobr>
2813: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2814: $help{'Syllabus'}
2815: </nobr>
2816: </form>
2817: <br /><form action="/adm/coursedocs" method="post" name="newnav">
2818: $uploadtag
2819: <input type="hidden" name="importdetail"
2820: value="Navigate Content=/adm/navmaps" />
2821: <nobr>
2822: <input name="newnav" type="submit" value="$lt{'navc'}" />
2823: $help{'Navigate_Content'}
2824: </nobr>
2825: </form>
2826: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
2827: $uploadtag
2828: <input type="hidden" name="importdetail" value="" />
2829: <nobr>
2830: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2831: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2832: </nobr>
2833: </form>
2834: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
2835: $uploadtag
2836: <input type="hidden" name="importdetail" value="" />
2837: <nobr>
2838: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2839: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2840: </nobr>
2841: </form>
2842: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
2843: $uploadtag
2844: <input type="hidden" name="importdetail" value="" />
2845: <nobr>
2846: <input name="newdropbox" type="button" value="$lt{'drbx'}"
2847: onClick="javascript:makedropbox();" />
2848: </nobr>
2849: </form>
2850: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
2851: $uploadtag
2852: <input type="hidden" name="importdetail" value="" />
2853: <nobr>
2854: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2855: onClick="javascript:makeexamupload();" />
2856: $help{'Score_Upload_Form'}
2857: </nobr>
2858: </form>
2859: <br /><form action="/adm/coursedocs" method="post" name="newbul">
2860: $uploadtag
2861: <input type="hidden" name="importdetail" value="" />
2862: <nobr>
2863: <input name="newbulletin" type="button" value="$lt{'bull'}"
2864: onClick="javascript:makebulboard();" />
2865: $help{'Bulletin Board'}
2866: </nobr>
2867: </form>
2868: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
2869: $uploadtag
2870: <input type="hidden" name="importdetail"
2871: value="$plainname=/adm/$udom/$uname/aboutme" />
2872: <nobr>
2873: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
2874: $help{'My Personal Info'}
2875: </nobr>
2876: </form>
2877: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
2878: $uploadtag
2879: <input type="hidden" name="importdetail" value="" />
2880: <nobr>
2881: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2882: onClick="javascript:makeabout();" />
2883: </nobr>
2884: </form>
2885: <br /><form action="/adm/coursedocs" method="post" name="newgroupfiles">
2886: $uploadtag
2887: <input type="hidden" name="importdetail"
2888: value="Group Files=/adm/$coursedom/$coursenum/aboutme" />
2889: <nobr>
2890: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
2891: $help{'Group Files'}
2892: </nobr>
2893: </form>
2894: ENDFORM
2895: }
2896: if ($env{'form.pagepath'}) {
2897: $r->print(<<ENDBLOCK);
2898: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2899: $uploadtag
2900: <input type="hidden" name="importdetail" value="" />
2901: <nobr>
2902: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2903: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2904: </nobr>
2905: </form>
2906: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
2907: $uploadtag
2908: <input type="hidden" name="importdetail" value="" />
2909: <nobr>
2910: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2911: onClick="javascript:makeexamupload();" />
2912: $help{'Score_Upload_Form'}
2913: </nobr>
2914: </form>
2915: ENDBLOCK
2916: }
2917: $r->print('</td></tr>'."\n".
2918: '</table>');
2919: $r->print('</td></tr>');
2920: }
2921: # ----------------------------------------------------- Supplemental documents
2922: if (!$forcestandard) {
2923: $r->print('<tr><td bgcolor="#BBBBBB">');
2924: # '<h2>'.&mt('Supplemental Course Documents').
2925: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
2926: my $folder=$env{'form.folder'};
2927: unless ($folder=~/^supplemental/) {
2928: $folder='supplemental';
2929: }
2930: if ($folder =~ /^supplemental$/ &&
2931: $env{'form.folderpath'} =~ /^default\&/) {
2932: $env{'form.folderpath'}='supplemental&'.
2933: &escape(&mt('Supplemental '.$type.' Documents'));
2934: }
2935: &editor($r,$coursenum,$coursedom,$folder,$allowed);
2936: if ($allowed) {
2937: my $folderseq=
2938: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2939: '.sequence';
2940:
2941: $r->print(<<ENDSUPFORM);
2942: <table cellspacing=4 cellpadding=4><tr>
2943: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2944: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
2945: </tr>
2946: <tr><td bgcolor="#DDDDDD">
2947: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2948: <input type="file" name="uploaddoc" size="40">
2949: <br />
2950: <br />
2951: <nobr>
2952: <label>$lt{'parse'}?
2953: <input type="checkbox" name="parserflag" />
2954: </label>
2955: </nobr>
2956: <br /><br />
2957: $lt{'comment'}:<br />
2958: <textarea cols=50 rows=4 name='comment'>
2959: </textarea>
2960: <br />
2961: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2962: <input type="hidden" name="cmd" value="upload_supplemental">
2963: <nobr>
2964: <input type="submit" value="$lt{'upld'}">
2965: $help{'Uploading_From_Harddrive'}
2966: </nobr>
2967: </form>
2968: </td>
2969: <td bgcolor="#DDDDDD">
2970: <form action="/adm/coursedocs" method="post" name="supnewfolder">
2971: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2972: <input type="hidden" name="importdetail" value="" />
2973: <nobr>
2974: <input name="newfolder" type="button"
2975: onClick="javascript:makenewfolder(this.form,'$folderseq');"
2976: value="$lt{'newf'}" /> $help{'Adding_Folders'}
2977: </nobr>
2978: </form>
2979: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
2980: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2981: <input type="hidden" name="importdetail" value="" />
2982: <nobr>
2983: <input name="newext" type="button"
2984: onClick="javascript:makenewext('supnewext');"
2985: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2986: </nobr>
2987: </form>
2988: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
2989: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2990: <input type="hidden" name="importdetail"
2991: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
2992: <nobr>
2993: <input name="newsyl" type="submit" value="$lt{'syll'}" />
2994: $help{'Syllabus'}
2995: </nobr>
2996: </form>
2997: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
2998: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
2999: <input type="hidden" name="importdetail"
3000: value="$plainname=/adm/$udom/$uname/aboutme" />
3001: <nobr>
3002: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3003: $help{'My Personal Info'}
3004: </nobr>
3005: </form>
3006: </td></tr>
3007: </table></td></tr>
3008: ENDSUPFORM
3009: }
3010: }
3011: if ($allowed) {
3012: $r->print('<form method="POST" name="extimport" action="/adm/coursedocs"><input type="hidden" name="title" /><input type="hidden" name="url" /><input type="hidden" name="useform" /></form>');
3013: }
3014: $r->print('</table>');
3015: } else {
3016: unless ($upload_result eq 'phasetwo') {
3017: # -------------------------------------------------------- This is showdoc mode
3018: $r->print("<h1>".&mt('Uploaded Document').' - '.
3019: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3020: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
3021: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
3022: }
3023: }
3024: }
3025: $r->print(&Apache::loncommon::end_page());
3026: return OK;
3027: }
3028:
3029:
3030: sub editing_js {
3031: my ($udom,$uname) = @_;
3032: my $now = time();
3033:
3034: return <<ENDNEWSCRIPT;
3035: function makenewfolder(targetform,folderseq) {
3036: var foldername=prompt('Name of New Folder','New Folder');
3037: if (foldername) {
3038: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3039: targetform.submit();
3040: }
3041: }
3042:
3043: function makenewpage(targetform,folderseq) {
3044: var pagename=prompt('Name of New Page','New Page');
3045: if (pagename) {
3046: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3047: targetform.submit();
3048: }
3049: }
3050:
3051: function makenewext(targetname) {
3052: this.document.forms.extimport.useform.value=targetname;
3053: window.open('/adm/rat/extpickframe.html');
3054: }
3055:
3056: function makeexamupload() {
3057: var title=prompt('Listed Title for the Uploaded Score');
3058: if (title) {
3059: this.document.forms.newexamupload.importdetail.value=
3060: escape(title)+'=/res/lib/templates/examupload.problem';
3061: this.document.forms.newexamupload.submit();
3062: }
3063: }
3064:
3065: function makesmppage() {
3066: var title=prompt('Listed Title for the Page');
3067: if (title) {
3068: this.document.forms.newsmppg.importdetail.value=
3069: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3070: this.document.forms.newsmppg.submit();
3071: }
3072: }
3073:
3074: function makesmpproblem() {
3075: var title=prompt('Listed Title for the Problem');
3076: if (title) {
3077: this.document.forms.newsmpproblem.importdetail.value=
3078: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3079: this.document.forms.newsmpproblem.submit();
3080: }
3081: }
3082:
3083: function makedropbox() {
3084: var title=prompt('Listed Title for the Drop Box');
3085: if (title) {
3086: this.document.forms.newdropbox.importdetail.value=
3087: escape(title)+'=/res/lib/templates/DropBox.problem';
3088: this.document.forms.newdropbox.submit();
3089: }
3090: }
3091:
3092: function makebulboard() {
3093: var title=prompt('Listed Title for the Bulletin Board');
3094: if (title) {
3095: this.document.forms.newbul.importdetail.value=
3096: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3097: this.document.forms.newbul.submit();
3098: }
3099: }
3100:
3101: function makeabout() {
3102: var user=prompt("Enter user:domain for User's 'About Me' Page");
3103: if (user) {
3104: var comp=new Array();
3105: comp=user.split(':');
3106: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3107: if ((comp[0]) && (comp[1])) {
3108: this.document.forms.newaboutsomeone.importdetail.value=
3109: 'About '+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
3110: this.document.forms.newaboutsomeone.submit();
3111: } else {
3112: alert("Not a valid user:domain");
3113: }
3114: } else {
3115: alert("Please enter both user and domain in the format user:domain");
3116: }
3117: }
3118: }
3119:
3120: function makeims() {
3121: var caller = document.forms.ims.folder.value;
3122: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3123: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3124: newWindow.location.href = newlocation;
3125: }
3126:
3127:
3128: function finishpick() {
3129: var title=this.document.forms.extimport.title.value;
3130: var url=this.document.forms.extimport.url.value;
3131: var form=this.document.forms.extimport.useform.value;
3132: eval
3133: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
3134: '";this.document.forms.'+form+'.submit();');
3135: }
3136:
3137: function changename(folderpath,index,oldtitle,container,pagesymb) {
3138: var title=prompt('New Title',oldtitle);
3139: if (title) {
3140: this.document.forms.renameform.title.value=title;
3141: this.document.forms.renameform.cmd.value='rename_'+index;
3142: if (container == 'sequence') {
3143: this.document.forms.renameform.folderpath.value=folderpath;
3144: }
3145: if (container == 'page') {
3146: this.document.forms.renameform.pagepath.value=folderpath;
3147: this.document.forms.renameform.pagesymb.value=pagesymb;
3148: }
3149: this.document.forms.renameform.submit();
3150: }
3151: }
3152:
3153: function removeres(folderpath,index,oldtitle,container,pagesymb) {
3154: if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
3155: this.document.forms.renameform.cmd.value='del_'+index;
3156: if (container == 'sequence') {
3157: this.document.forms.renameform.folderpath.value=folderpath;
3158: }
3159: if (container == 'page') {
3160: this.document.forms.renameform.pagepath.value=folderpath;
3161: this.document.forms.renameform.pagesymb.value=pagesymb;
3162: }
3163: this.document.forms.renameform.submit();
3164: }
3165: }
3166:
3167: function cutres(folderpath,index,oldtitle,container,pagesymb) {
3168: if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
3169: this.document.forms.renameform.cmd.value='cut_'+index;
3170: this.document.forms.renameform.markcopy.value=index;
3171: if (container == 'sequence') {
3172: this.document.forms.renameform.folderpath.value=folderpath;
3173: }
3174: if (container == 'page') {
3175: this.document.forms.renameform.pagepath.value=folderpath;
3176: this.document.forms.renameform.pagesymb.value=pagesymb;
3177: }
3178: this.document.forms.renameform.submit();
3179: }
3180: }
3181:
3182: function markcopy(folderpath,index,oldtitle,container,pagesymb) {
3183: this.document.forms.renameform.markcopy.value=index;
3184: if (container == 'sequence') {
3185: this.document.forms.renameform.folderpath.value=folderpath;
3186: }
3187: if (container == 'page') {
3188: this.document.forms.renameform.pagepath.value=folderpath;
3189: this.document.forms.renameform.pagesymb.value=pagesymb;
3190: }
3191: this.document.forms.renameform.submit();
3192: }
3193:
3194: ENDNEWSCRIPT
3195: }
3196: 1;
3197: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>