File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.383:
download - view:
text,
annotated -
select for diffs
Thu Aug 13 12:29:04 2009 UTC (15 years ago) by
tempelho
Branches:
MAIN
CVS tags:
HEAD
+ Replaced "Edit Course" buttons by text links. "Edit Course" buttons will get the same look as "Manage Course Users" (submenu links).
+ pic01 .. pic33 are wildcards and will be replaced by images for a better look.
+ Subroutine create_list_elements and create_form_ul were created to get the list structure for the form buttons.
+ Javascript function injectData was created to get hidden field values on demand into a form, using a hyperlink instead of a button.
+ Bug in Supplemental Docs was fixed, that didn't show any Supplemental Docs for the students.
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.383 2009/08/13 12:29:04 tempelho 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:
30:
31: package Apache::londocs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::imsexport;
36: use Apache::lonnet;
37: use Apache::loncommon;
38: use Apache::lonhtmlcommon;
39: use LONCAPA::map();
40: use Apache::lonratedt();
41: use Apache::lonxml;
42: use Apache::lonclonecourse;
43: use Apache::lonnavmaps;
44: use HTML::Entities;
45: use GDBM_File;
46: use Apache::lonlocal;
47: use Cwd;
48: use LONCAPA qw(:DEFAULT :match);
49:
50: my $iconpath;
51:
52: my %hash;
53:
54: my $hashtied;
55: my %alreadyseen=();
56:
57: my $hadchanges;
58:
59:
60: my %help=();
61:
62:
63: sub mapread {
64: my ($coursenum,$coursedom,$map)=@_;
65: return
66: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
67: $map);
68: }
69:
70: sub storemap {
71: my ($coursenum,$coursedom,$map)=@_;
72: my ($outtext,$errtext)=
73: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
74: $map,1);
75: if ($errtext) { return ($errtext,2); }
76:
77: $hadchanges=1;
78: return ($errtext,0);
79: }
80:
81:
82:
83: sub authorhosts {
84: my %outhash=();
85: my $home=0;
86: my $other=0;
87: foreach my $key (keys(%env)) {
88: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
89: my $role=$1;
90: my $realm=$2;
91: my ($start,$end)=split(/\./,$env{$key});
92: if (($start) && ($start>time)) { next; }
93: if (($end) && (time>$end)) { next; }
94: my ($ca,$cd);
95: if ($1 eq 'au') {
96: $ca=$env{'user.name'};
97: $cd=$env{'user.domain'};
98: } else {
99: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
100: }
101: my $allowed=0;
102: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
103: my @ids=&Apache::lonnet::current_machine_ids();
104: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
105: if ($allowed) {
106: $home++;
107: $outhash{'home_'.$ca.'@'.$cd}=1;
108: } else {
109: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
110: $other++;
111: }
112: }
113: }
114: return ($home,$other,%outhash);
115: }
116:
117:
118: sub dumpbutton {
119: my ($home,$other,%outhash)=&authorhosts();
120: my $type = &Apache::loncommon::course_type();
121: if ($home+$other==0) { return ''; }
122: if ($home) {
123: my $link = "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"dumpcourse\", \"".&mt('Dump '.$type.' DOCS to Construction Space')."\")'>".&mt('Dump '.$type.' DOCS to Construction Space')."</a>";
124: return $link.' '.
125: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'<br />';
126: } else {
127: return '<div>'.
128: &mt('Dump '.$type.
129: ' DOCS to Construction Space: available on other servers').
130: '</div>';
131: }
132: }
133:
134: sub clean {
135: my ($title)=@_;
136: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
137: return $title;
138: }
139:
140:
141:
142: sub dumpcourse {
143: my ($r) = @_;
144: my $type = &Apache::loncommon::course_type();
145: $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
146: '<form name="dumpdoc" action="" method="post">');
147: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
148: my ($home,$other,%outhash)=&authorhosts();
149: unless ($home) { return ''; }
150: my $origcrsid=$env{'request.course.id'};
151: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
152: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
153: # Do the dumping
154: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
155: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
174: my $path='/home/'.$ca.'/public_html';
175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
205: # Input form
206: unless ($home==1) {
207: $r->print(
208: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
209: }
210: foreach my $key (sort(keys(%outhash))) {
211: if ($key=~/^home_(.+)$/) {
212: if ($home==1) {
213: $r->print(
214: '<input type="hidden" name="authorspace" value="'.$1.'" />');
215: } else {
216: $r->print('<option value="'.$1.'">'.$1.' - '.
217: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
218: }
219: }
220: }
221: unless ($home==1) {
222: $r->print('</select>');
223: }
224: my $title=$origcrsdata{'description'};
225: $title=~s/[\/\s]+/\_/gs;
226: $title=&clean($title);
227: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
228: .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
229: &tiehash();
230: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
231: .&Apache::loncommon::start_data_table()
232: .&Apache::loncommon::start_data_table_header_row()
233: .'<th>'.&mt('Internal Filename').'</th>'
234: .'<th>'.&mt('Title').'</th>'
235: .'<th>'.&mt('Save as ...').'</th>'
236: .&Apache::loncommon::end_data_table_header_row());
237: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
238: $r->print(&Apache::loncommon::start_data_table_row()
239: .'<td>'.$file.'</td>');
240: my ($ext)=($file=~/\.(\w+)$/);
241: my $title=$hash{'title_'.$hash{
242: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
243: $r->print('<td>'.($title?$title:' ').'</td>');
244: if (!$title) {
245: $title=$file;
246: } else {
247: $title=~s|/|_|g;
248: }
249: $title=~s/\.(\w+)$//;
250: $title=&clean($title);
251: $title.='.'.$ext;
252: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
253: .&Apache::loncommon::end_data_table_row());
254: }
255: $r->print(&Apache::loncommon::end_data_table());
256: &untiehash();
257: $r->print(
258: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $type DOCS").'" /></p></form>');
259: }
260: }
261:
262:
263:
264: sub exportbutton {
265: my $type = &Apache::loncommon::course_type();
266: return "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"exportcourse\", \"".&mt('IMS Export')."\")'>".&mt('IMS Export')."</a>".
267: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'<br />';
268: }
269:
270:
271:
272: sub exportcourse {
273: my $r=shift;
274: my $type = &Apache::loncommon::course_type();
275: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
276: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
277: my $numdisc = keys(%discussiontime);
278: my $navmap = Apache::lonnavmaps::navmap->new();
279: if (!defined($navmap)) {
280: $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package').
281: '<h2>'.&mt('IMS Export Failed').'</h2>'.
282: '<div class="LC_error">'.
283: &mt('Unable to retrieve information about course contents').
284: '</div><a href="/adm/coursedocs">'.&mt('Return to Course Editor').'</a>');
285: &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
286: return;
287: }
288: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
289: my $curRes;
290: my $outcome;
291:
292: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
293: ['finishexport']);
294: if ($env{'form.finishexport'}) {
295: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
296: ['archive','discussion']);
297:
298: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
299: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
300: if (@exportitems == 0 && @discussions == 0) {
301: $outcome =
302: '<p class="LC_warning">'
303: .&mt('As you did not select any content items or discussions'
304: .' for export, an IMS package has not been created.')
305: .'</p>'
306: .'<p>'
307: .&mt('Please [_1]go back[_2] to select either content items'
308: .' or discussions for export.'
309: ,'<a href="javascript:history.go(-1)">'
310: ,'</a>')
311: .'</p>';
312: } else {
313: my $now = time;
314: my %symbs;
315: my $manifestok = 0;
316: my $imsresources;
317: my $tempexport;
318: my $copyresult;
319: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
320: if ($manifestok) {
321: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
322: close($ims_manifest);
323:
324: #Create zip file in prtspool
325: my $imszipfile = '/prtspool/'.
326: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
327: time.'_'.rand(1000000000).'.zip';
328: my $cwd = &Cwd::getcwd();
329: my $imszip = '/home/httpd/'.$imszipfile;
330: chdir $tempexport;
331: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
332: close(OUTPUT);
333: chdir $cwd;
334: if ($copyresult) {
335: $outcome .= '<p class="LC_error">'
336: .&mt('The following errors occurred during export - [_1]'
337: ,$copyresult)
338: .'</p>';
339: }
340: $outcome .= '<p>'
341: .&mt('[_1]Your IMS package[_2] is ready for download.'
342: ,'<a href="'.$imszipfile.'">','</a>')
343: .'</p>';
344: } else {
345: $outcome = '<p class="LC_error">'
346: .&mt('Unfortunately you will not be able to retrieve'
347: .' an IMS archive of this posts at this time,'
348: .' because there was a problem creating a'
349: .' manifest file.')
350: .'</p>'
351: .'<p><a href="javascript:history.go(-1)">'
352: .&mt('Go Back')
353: .'</a></p>';
354: }
355: }
356: $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package'));
357: $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
358: $r->print($outcome);
359: $r->print(&Apache::loncommon::end_page());
360: } else {
361: my $display;
362: $display = '<form name="exportdoc" action="" method="post">'."\n";
363: $display .= '<p>'
364: .&mt('Choose which items you wish to export from your '.$type.'.')
365: .'</p>';
366: $display .= '<div class="LC_columnSection"><fieldset>'.
367: '<legend>'.&mt('Content items').'</legend>'.
368: '<input type="button" value="'.&mt('check all').'" '.
369: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
370: ' <input type="button" value="'.&mt('uncheck all').'"'.
371: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset>'.
372: '<fieldset>'.
373: '<legend>'.&mt('Discussion posts').'</legend>'.
374: '<input type="button" value="'.&mt('check all').'"'.
375: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
376: ' <input type="button" value="'.&mt('uncheck all').'"'.
377: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" />'.
378: '</fieldset></div>';
379: my $curRes;
380: my $depth = 0;
381: my $count = 0;
382: my $boards = 0;
383: my $startcount = 5;
384: my %parent = ();
385: my %children = ();
386: my $lastcontainer = $startcount;
387: $display .= &Apache::loncommon::start_data_table()
388: .&Apache::loncommon::start_data_table_header_row()
389: .'<th>'.&mt('Export content item?').'</th>'
390: .'<th>';
391: if ($numdisc > 0) {
392: $display .= &mt('Export discussion posts?');
393: } else {
394: $display .= ' ';
395: }
396: $display .= '</th>'
397: .&Apache::loncommon::end_data_table_header_row();
398: while ($curRes = $it->next()) {
399: if (ref($curRes)) {
400: $count ++;
401: }
402: if ($curRes == $it->BEGIN_MAP()) {
403: $depth++;
404: $parent{$depth} = $lastcontainer;
405: }
406: if ($curRes == $it->END_MAP()) {
407: $depth--;
408: $lastcontainer = $parent{$depth};
409: }
410: if (ref($curRes)) {
411: my $symb = $curRes->symb();
412: my $ressymb = $symb;
413: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
414: unless ($ressymb =~ m|adm/wrapper/adm|) {
415: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
416: }
417: }
418: $display .= &Apache::loncommon::start_data_table_row()
419: .'<td>'."\n"
420: .'<input type="checkbox" name="archive" value="'.$count.'" ';
421: if (($curRes->is_sequence()) || ($curRes->is_page())) {
422: my $checkitem = $count + $boards + $startcount;
423: $display .= 'onclick="javascript:propagateCheck('."'$checkitem'".')"';
424: }
425: $display .= ' />'."\n";
426: for (my $i=0; $i<$depth; $i++) {
427: $display .= '<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />'
428: .'<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />'."\n";
429: }
430: if ($curRes->is_sequence()) {
431: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n";
432: $lastcontainer = $count + $startcount + $boards;
433: } elsif ($curRes->is_page()) {
434: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" /> '."\n";
435: $lastcontainer = $count + $startcount + $boards;
436: }
437: my $currelem = $count+$boards+$startcount;
438: $children{$parent{$depth}} .= $currelem.':';
439: $display .= ' '.$curRes->title().'</td>'."\n";
440:
441: # Existing discussion posts?
442: if ($discussiontime{$ressymb} > 0) {
443: $boards ++;
444: $currelem = $count+$boards+$startcount;
445: $display .= '<td align="right">'
446: .'<input type="checkbox" name="discussion" value="'.$count.'" />'
447: .'</td>'."\n";
448: } else {
449: $display .= '<td> </td>'."\n";
450: }
451: $display .= &Apache::loncommon::end_data_table_row();
452: }
453: }
454: $display .= &Apache::loncommon::end_data_table();
455: my $scripttag = qq|
456: <script type="text/javascript">
457: // <![CDATA[
458: function checkAll(field) {
459: if (field.length > 0) {
460: for (i = 0; i < field.length; i++) {
461: field[i].checked = true ;
462: }
463: } else {
464: field.checked = true
465: }
466: }
467:
468: function uncheckAll(field) {
469: if (field.length > 0) {
470: for (i = 0; i < field.length; i++) {
471: field[i].checked = false ;
472: }
473: } else {
474: field.checked = false ;
475: }
476: }
477:
478: function propagateCheck(item) {
479: if (document.exportdoc.elements[item].checked == true) {
480: containerCheck(item)
481: }
482: }
483:
484: function containerCheck(item) {
485: document.exportdoc.elements[item].checked = true
486: var numitems = $count + $boards + $startcount
487: var parents = new Array(numitems)
488: for (var i=$startcount; i<numitems; i++) {
489: parents[i] = new Array
490: }
491: |;
492:
493: foreach my $container (sort { $a <=> $b } (keys(%children))) {
494: my @contents = split(/:/,$children{$container});
495: for (my $i=0; $i<@contents; $i ++) {
496: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
497: }
498: }
499:
500: $scripttag .= qq|
501: if (parents[item].length > 0) {
502: for (var j=0; j<parents[item].length; j++) {
503: containerCheck(parents[item][j])
504: }
505: }
506: }
507: // ]]>
508: </script>
509: |;
510: $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package',
511: $scripttag));
512: $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
513: $r->print($display.
514: '<p><input type="hidden" name="finishexport" value="1" />'.
515: '<input type="submit" name="exportcourse" value="'.
516: &mt('Export').'" /></p></form>');
517: }
518: }
519:
520: sub create_ims_store {
521: my ($now,$manifestok,$outcome,$tempexport) = @_;
522: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
523: my $ims_manifest;
524: if (!-e $$tempexport) {
525: mkdir($$tempexport,0700);
526: }
527: $$tempexport .= '/'.$now;
528: if (!-e $$tempexport) {
529: mkdir($$tempexport,0700);
530: }
531: $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
532: if (!-e $$tempexport) {
533: mkdir($$tempexport,0700);
534: }
535: if (!-e "$$tempexport/resources") {
536: mkdir("$$tempexport/resources",0700);
537: }
538: # open manifest file
539: my $manifest = '/imsmanifest.xml';
540: my $manifestfilename = $$tempexport.$manifest;
541: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
542: $$manifestok=1;
543: print $ims_manifest
544: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
545: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
546: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
547: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
548: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
549: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
550: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
551: ' <metadata>
552: <schema></schema>
553: <imsmd:lom>
554: <imsmd:general>
555: <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
556: <imsmd:title>
557: <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
558: </imsmd:title>
559: </imsmd:general>
560: </imsmd:lom>
561: </metadata>'."\n".
562: ' <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
563: ' <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
564: ' structure="hierarchical">'."\n".
565: ' <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
566: } else {
567: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
568: ;
569: }
570: return $ims_manifest;
571: }
572:
573: sub build_package {
574: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
575: # first iterator to look for dependencies
576: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
577: my $curRes;
578: my $count = 0;
579: my $depth = 0;
580: my $lastcontainer = 0;
581: my %parent = ();
582: my @dependencies = ();
583: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
584: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
585: while ($curRes = $it->next()) {
586: if (ref($curRes)) {
587: $count ++;
588: }
589: if ($curRes == $it->BEGIN_MAP()) {
590: $depth++;
591: $parent{$depth} = $lastcontainer;
592: }
593: if ($curRes == $it->END_MAP()) {
594: $depth--;
595: $lastcontainer = $parent{$depth};
596: }
597: if (ref($curRes)) {
598: if ($curRes->is_sequence() || $curRes->is_page()) {
599: $lastcontainer = $count;
600: }
601: if (grep(/^$count$/,@$exportitems)) {
602: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
603: }
604: }
605: }
606: # second iterator to build manifest and store resources
607: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
608: $depth = 0;
609: my $prevdepth;
610: $count = 0;
611: my $imsresources;
612: my $pkgdepth;
613: while ($curRes = $it->next()) {
614: if ($curRes == $it->BEGIN_MAP()) {
615: $prevdepth = $depth;
616: $depth++;
617: }
618: if ($curRes == $it->END_MAP()) {
619: $prevdepth = $depth;
620: $depth--;
621: }
622:
623: if (ref($curRes)) {
624: $count ++;
625: if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
626: my $symb = $curRes->symb();
627: my $isvisible = 'true';
628: my $resourceref;
629: if ($curRes->randomout()) {
630: $isvisible = 'false';
631: }
632: unless ($curRes->is_sequence()) {
633: $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
634: }
635: my $step = $prevdepth - $depth;
636: if (($step >= 0) && ($count > 1)) {
637: while ($step >= 0) {
638: print $ims_manifest "\n".' </item>'."\n";
639: $step --;
640: }
641: }
642: $prevdepth = $depth;
643:
644: my $itementry =
645: '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
646: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
647: '<title>'.$curRes->title().'</title>';
648: print $ims_manifest "\n".$itementry;
649:
650: unless ($curRes->is_sequence()) {
651: my $content_file;
652: my @hrefs = ();
653: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
654: if ($content_file) {
655: $imsresources .= "\n".
656: ' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
657: '" type="webcontent" href="'.$content_file.'">'."\n".
658: ' <file href="'.$content_file.'" />'."\n";
659: foreach my $item (@hrefs) {
660: $imsresources .=
661: ' <file href="'.$item.'" />'."\n";
662: }
663: if (grep(/^$count$/,@$discussions)) {
664: my $ressymb = $symb;
665: my $mode;
666: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
667: unless ($ressymb =~ m|adm/wrapper/adm|) {
668: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
669: }
670: $mode = 'board';
671: }
672: my %extras = (
673: caller => 'imsexport',
674: tempexport => $tempexport.'/resources',
675: count => $count
676: );
677: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
678: }
679: $imsresources .= ' </resource>'."\n";
680: }
681: }
682: $pkgdepth = $depth;
683: }
684: }
685: }
686: while ($pkgdepth > 0) {
687: print $ims_manifest " </item>\n";
688: $pkgdepth --;
689: }
690: my $resource_text = qq|
691: </organization>
692: </organizations>
693: <resources>
694: $imsresources
695: </resources>
696: </manifest>
697: |;
698: print $ims_manifest $resource_text;
699: }
700:
701: sub get_dependencies {
702: my ($exportitems,$parent,$depth,$dependencies) = @_;
703: if ($depth > 1) {
704: if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
705: push(@{$dependencies},$$parent{$depth});
706: if ($depth > 2) {
707: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
708: }
709: }
710: }
711: }
712:
713: sub process_content {
714: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
715: my $content_type;
716: my $message;
717: my @uploads = ();
718: if ($curRes->is_sequence()) {
719: $content_type = 'sequence';
720: } elsif ($curRes->is_page()) {
721: $content_type = 'page'; # need to handle individual items in pages.
722: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
723: $content_type = 'syllabus';
724: my $contents = &Apache::imsexport::templatedpage($content_type);
725: if ($contents) {
726: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
727: }
728: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
729: $content_type = 'external';
730: my $title = $curRes->title;
731: my $contents = &Apache::imsexport::external($symb,$title);
732: if ($contents) {
733: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
734: }
735: } elsif ($symb =~ m-adm/navmaps$-) {
736: $content_type = 'navmap';
737: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
738: $content_type = 'simplepage';
739: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
740: if ($contents) {
741: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
742: }
743: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
744: $content_type = 'simpleproblem';
745: my $contents = &Apache::imsexport::simpleproblem($symb);
746: if ($contents) {
747: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
748: }
749: } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
750: $content_type = 'examupload';
751: } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
752: $content_type = 'bulletinboard';
753: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
754: if ($contents) {
755: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
756: }
757: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
758: $content_type = 'aboutme';
759: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
760: if ($contents) {
761: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
762: }
763: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
764: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
765: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
766: my $canedit = 0;
767: if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
768: $canedit= 1;
769: }
770: # only include problem code where current user is author
771: if ($canedit) {
772: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
773: } else {
774: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
775: }
776: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
777: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
778: }
779: if (@uploads > 0) {
780: foreach my $item (@uploads) {
781: my $uploadmsg = '';
782: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
783: if ($uploadmsg) {
784: $$copyresult .= $uploadmsg."\n";
785: }
786: }
787: }
788: if ($message) {
789: $$copyresult .= $message."\n";
790: }
791: }
792:
793: sub replicate_content {
794: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
795: my ($map,$ind,$url);
796: if ($caller eq 'templateupload') {
797: $url = $symb;
798: $url =~ s#//#/#g;
799: } else {
800: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
801: }
802: my $content;
803: my $filename;
804: my $repstatus;
805: my $content_name;
806: if ($url =~ m-/([^/]+)$-) {
807: $filename = $1;
808: if (!-e $tempexport.'/resources') {
809: mkdir($tempexport.'/resources',0700);
810: }
811: if (!-e $tempexport.'/resources/'.$count) {
812: mkdir($tempexport.'/resources/'.$count,0700);
813: }
814: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
815: my $copiedfile;
816: if ($copiedfile = Apache::File->new('>'.$destination)) {
817: my $content;
818: if ($caller eq 'resource') {
819: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
820: my $filepath = &Apache::lonnet::filelocation($respath,$url);
821: $content = &Apache::lonnet::getfile($filepath);
822: if ($content eq -1) {
823: $$message = 'Could not copy file '.$filename;
824: } else {
825: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
826: $repstatus = 'ok';
827: }
828: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
829: my $rtncode;
830: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
831: if ($repstatus eq 'ok') {
832: if ($url =~ /\.html?$/i) {
833: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
834: }
835: } else {
836: $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
837: }
838: } elsif ($caller eq 'noedit') {
839: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
840: $repstatus = 'ok';
841: $content = 'Not the owner of this resource';
842: }
843: if ($repstatus eq 'ok') {
844: print $copiedfile $content;
845: }
846: close($copiedfile);
847: } else {
848: $$message = 'Could not open destination file for '.$filename."<br />\n";
849: }
850: } else {
851: $$message = 'Could not determine name of file for '.$symb."<br />\n";
852: }
853: if ($repstatus eq 'ok') {
854: $content_name = 'resources/'.$count.'/'.$filename;
855: }
856: return $content_name;
857: }
858:
859: sub extract_media {
860: my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
861: my ($dirpath,$container);
862: my %allfiles = ();
863: my %codebase = ();
864: if ($url =~ m-(.*/)([^/]+)$-) {
865: $dirpath = $1;
866: $container = $2;
867: } else {
868: $dirpath = $url;
869: $container = '';
870: }
871: &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
872: foreach my $embed_file (keys(%allfiles)) {
873: my $filename;
874: if ($embed_file =~ m#([^/]+)$#) {
875: $filename = $1;
876: } else {
877: $filename = $embed_file;
878: }
879: my $newname = 'res/'.$filename;
880: my ($rtncode,$embed_content,$repstatus);
881: my $embed_url;
882: if ($embed_file =~ m-^/-) {
883: $embed_url = $embed_file; # points to absolute path
884: } else {
885: if ($embed_file =~ m-https?://-) {
886: next; # points to url
887: } else {
888: $embed_url = $dirpath.$embed_file; # points to relative path
889: }
890: }
891: if ($caller eq 'resource') {
892: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
893: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
894: $embed_content = &Apache::lonnet::getfile($embed_path);
895: unless ($embed_content eq -1) {
896: $repstatus = 'ok';
897: }
898: } elsif ($caller eq 'uploaded') {
899:
900: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
901: }
902: if ($repstatus eq 'ok') {
903: my $destination = $tempexport.'/resources/'.$count.'/res';
904: if (!-e "$destination") {
905: mkdir($destination,0755);
906: }
907: $destination .= '/'.$filename;
908: my $copiedfile;
909: if ($copiedfile = Apache::File->new('>'.$destination)) {
910: print $copiedfile $embed_content;
911: push(@{$href},'resources/'.$count.'/res/'.$filename);
912: my $attrib_regexp = '';
913: if (@{$allfiles{$embed_file}} > 1) {
914: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
915: } else {
916: $attrib_regexp = $allfiles{$embed_file}[0];
917: }
918: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
919: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
920: $$content =~ s#\Q$embed_file\E#$newname#gi;
921: }
922: }
923: } else {
924: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
925: }
926: }
927: return;
928: }
929:
930: sub store_template {
931: my ($contents,$tempexport,$count,$content_type) = @_;
932: if ($contents) {
933: if ($tempexport) {
934: if (!-e $tempexport.'/resources') {
935: mkdir($tempexport.'/resources',0700);
936: }
937: if (!-e $tempexport.'/resources/'.$count) {
938: mkdir($tempexport.'/resources/'.$count,0700);
939: }
940: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
941: my $storetemplate;
942: if ($storetemplate = Apache::File->new('>'.$destination)) {
943: print $storetemplate $contents;
944: close($storetemplate);
945: }
946: if ($content_type eq 'external') {
947: return 'resources/'.$count.'/'.$content_type.'.html';
948: } else {
949: return 'resources/'.$count.'/'.$content_type.'.xml';
950: }
951: }
952: }
953: }
954:
955:
956: sub group_import {
957: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
958:
959: while (@files) {
960: my ($name, $url, $residx) = @{ shift(@files) };
961: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
962: && ($caller eq 'londocs')
963: && (!&Apache::lonnet::stat_file($url))) {
964:
965: my $errtext = '';
966: my $fatal = 0;
967: my $newmapstr = '<map>'."\n".
968: '<resource id="1" src="" type="start"></resource>'."\n".
969: '<link from="1" to="2" index="1"></link>'."\n".
970: '<resource id="2" src="" type="finish"></resource>'."\n".
971: '</map>';
972: $env{'form.output'}=$newmapstr;
973: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
974: 'output',$1.$2);
975: if ($result != m|^/uploaded/|) {
976: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
977: $fatal = 2;
978: }
979: if ($fatal) {
980: return ($errtext,$fatal);
981: }
982: }
983: if ($url) {
984: if (!$residx
985: || defined($LONCAPA::map::zombies[$residx])) {
986: $residx = &LONCAPA::map::getresidx($url,$residx);
987: push(@LONCAPA::map::order, $residx);
988: }
989: my $ext = 'false';
990: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
991: $url = &LONCAPA::map::qtunescape($url);
992: $name = &LONCAPA::map::qtunescape($name);
993: $LONCAPA::map::resources[$residx] =
994: join(':', ($name, $url, $ext, 'normal', 'res'));
995: }
996: }
997: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
998: }
999:
1000: sub breadcrumbs {
1001: my ($where,$allowed,$type)=@_;
1002: &Apache::lonhtmlcommon::clear_breadcrumbs();
1003: my (@folders);
1004: if ($env{'form.pagepath'}) {
1005: @folders = split('&',$env{'form.pagepath'});
1006: } else {
1007: @folders=split('&',$env{'form.folderpath'});
1008: }
1009: my $folderpath;
1010: my $cpinfo='';
1011: my $plain='';
1012: my $randompick=-1;
1013: my $isencrypted=0;
1014: my $ishidden=0;
1015: my $is_random_order=0;
1016: while (@folders) {
1017: my $folder=shift(@folders);
1018: my $foldername=shift(@folders);
1019: if ($folderpath) {$folderpath.='&';}
1020: $folderpath.=$folder.'&'.$foldername;
1021: my $url='/adm/coursedocs?folderpath='.
1022: &escape($folderpath);
1023: my $name=&unescape($foldername);
1024: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1025: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
1026: if ($1 ne '') {
1027: $randompick=$1;
1028: } else {
1029: $randompick=-1;
1030: }
1031: if ($2) { $ishidden=1; }
1032: if ($3) { $isencrypted=1; }
1033: if ($4 ne '') { $is_random_order = 1; }
1034: if ($folder eq 'supplemental') {
1035: if ($allowed) {
1036: $name = &mt('Supplemental '.$type.' Documents');
1037: } else {
1038: $name = &mt($type.' Documents');
1039: }
1040: }
1041: &Apache::lonhtmlcommon::add_breadcrumb(
1042: {'href'=>$url.$cpinfo,
1043: 'title'=>$name,
1044: 'text'=>$name,
1045: 'no_mt'=>1,
1046: });
1047: $plain.=$name.' > ';
1048: }
1049: $plain=~s/\>\;\s*$//;
1050: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1051: undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1052: }
1053:
1054: sub log_docs {
1055: return &Apache::lonnet::instructor_log('docslog',@_);
1056: }
1057:
1058: {
1059: my @oldresources=();
1060: my @oldorder=();
1061: my $parmidx;
1062: my %parmaction=();
1063: my %parmvalue=();
1064: my $changedflag;
1065:
1066: sub snapshotbefore {
1067: @oldresources=@LONCAPA::map::resources;
1068: @oldorder=@LONCAPA::map::order;
1069: $parmidx=undef;
1070: %parmaction=();
1071: %parmvalue=();
1072: $changedflag=0;
1073: }
1074:
1075: sub remember_parms {
1076: my ($idx,$parameter,$action,$value)=@_;
1077: $parmidx=$idx;
1078: $parmaction{$parameter}=$action;
1079: $parmvalue{$parameter}=$value;
1080: $changedflag=1;
1081: }
1082:
1083: sub log_differences {
1084: my ($plain)=@_;
1085: my %storehash=('folder' => $plain,
1086: 'currentfolder' => $env{'form.folder'});
1087: if ($parmidx) {
1088: $storehash{'parameter_res'}=$oldresources[$parmidx];
1089: foreach my $parm (keys(%parmaction)) {
1090: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1091: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1092: }
1093: }
1094: my $maxidx=$#oldresources;
1095: if ($#LONCAPA::map::resources>$#oldresources) {
1096: $maxidx=$#LONCAPA::map::resources;
1097: }
1098: for (my $idx=0; $idx<=$maxidx; $idx++) {
1099: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1100: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1101: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1102: $changedflag=1;
1103: }
1104: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1105: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1106: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1107: $changedflag=1;
1108: }
1109: }
1110: $storehash{'maxidx'}=$maxidx;
1111: if ($changedflag) { &log_docs(\%storehash); }
1112: }
1113: }
1114:
1115:
1116:
1117:
1118:
1119: sub docs_change_log {
1120: my ($r)=@_;
1121: my $folder=$env{'form.folder'};
1122: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1123: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1124: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1125: $env{'course.'.$env{'request.course.id'}.'.domain'},
1126: $env{'course.'.$env{'request.course.id'}.'.num'});
1127:
1128: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1129:
1130: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1131: '<input type="hidden" name="docslog" value="1" />');
1132:
1133: my %saveable_parameters = ('show' => 'scalar',);
1134: &Apache::loncommon::store_course_settings('docs_log',
1135: \%saveable_parameters);
1136: &Apache::loncommon::restore_course_settings('docs_log',
1137: \%saveable_parameters);
1138: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1139: my %lt=('hiddenresource' => 'Resources hidden',
1140: 'encrypturl' => 'URL hidden',
1141: 'randompick' => 'Randomly pick',
1142: 'randomorder' => 'Randomly ordered',
1143: 'set' => 'set to',
1144: 'del' => 'deleted');
1145: $r->print(&Apache::loncommon::display_filter().
1146: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1147: '<input type="submit" value="'.&mt('Display').'" /></form>');
1148: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1149: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1150: &mt('After').'</th>'.
1151: &Apache::loncommon::end_data_table_header_row());
1152: my $shown=0;
1153: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1154: if ($env{'form.displayfilter'} eq 'currentfolder') {
1155: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1156: }
1157: my @changes=keys(%{$docslog{$id}{'logentry'}});
1158: if ($env{'form.displayfilter'} eq 'containing') {
1159: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1160: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1161: foreach my $key (@changes) {
1162: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1163: }
1164: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1165: }
1166: my $count = 0;
1167: my $time =
1168: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1169: my $plainname =
1170: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1171: $docslog{$id}{'exe_udom'});
1172: my $about_me_link =
1173: &Apache::loncommon::aboutmewrapper($plainname,
1174: $docslog{$id}{'exe_uname'},
1175: $docslog{$id}{'exe_udom'});
1176: my $send_msg_link='';
1177: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1178: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1179: $send_msg_link ='<br />'.
1180: &Apache::loncommon::messagewrapper(&mt('Send message'),
1181: $docslog{$id}{'exe_uname'},
1182: $docslog{$id}{'exe_udom'});
1183: }
1184: $r->print(&Apache::loncommon::start_data_table_row());
1185: $r->print('<td>'.$time.'</td>
1186: <td>'.$about_me_link.
1187: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1188: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1189: $send_msg_link.'</td><td>'.
1190: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1191: # Before
1192: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1193: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1194: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1195: if ($oldname ne $newname) {
1196: $r->print(&LONCAPA::map::qtescape($oldname));
1197: }
1198: }
1199: $r->print('<ul>');
1200: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1201: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1202: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1203: }
1204: }
1205: $r->print('</ul>');
1206: # After
1207: $r->print('</td><td>');
1208:
1209: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1210: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1211: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1212: if ($oldname ne '' && $oldname ne $newname) {
1213: $r->print(&LONCAPA::map::qtescape($newname));
1214: }
1215: }
1216: $r->print('<ul>');
1217: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1218: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1219: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1220: }
1221: }
1222: $r->print('</ul>');
1223: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1224: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1227: $r->print('<li>'.
1228: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1229: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1230: .'</li>');
1231: }
1232: }
1233: $r->print('</ul>');
1234: }
1235: # End
1236: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1237: $shown++;
1238: if (!($env{'form.show'} eq &mt('all')
1239: || $shown<=$env{'form.show'})) { last; }
1240: }
1241: $r->print(&Apache::loncommon::end_data_table());
1242: }
1243:
1244: sub update_paste_buffer {
1245: my ($coursenum,$coursedom) = @_;
1246:
1247: return if (!defined($env{'form.markcopy'}));
1248: return if (!defined($env{'form.copyfolder'}));
1249: return if ($env{'form.markcopy'} < 0);
1250:
1251: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1252: $env{'form.copyfolder'});
1253:
1254: return if ($fatal);
1255:
1256: # Mark for copying
1257: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1258: if (&is_supplemental_title($title)) {
1259: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1260: ($title) = &parse_supplemental_title($title);
1261: } elsif ($env{'docs.markedcopy_supplemental'}) {
1262: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1263: }
1264: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1265:
1266: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
1267: 'docs.markedcopy_url' => $url});
1268: delete($env{'form.markcopy'});
1269: }
1270:
1271: sub print_paste_buffer {
1272: my ($r,$container) = @_;
1273: return if (!defined($env{'docs.markedcopy_url'}));
1274:
1275: $r->print('<fieldset>'
1276: .'<legend>'.&mt('Clipboard').'</legend>'
1277: .'<form name="pasteform" action="/adm/coursedocs" method="post">'
1278: .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '
1279: );
1280:
1281: my $type;
1282: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1283: $type = &mt('External Resource');
1284: $r->print($type.': '.
1285: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1286: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
1287: } else {
1288: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1289: my $icon = &Apache::loncommon::icon($extension);
1290: if ($extension eq 'sequence' &&
1291: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
1292: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1293: $icon .= '/navmap.folder.closed.gif';
1294: }
1295: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1296: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1297: }
1298: if ($container eq 'page') {
1299: $r->print('
1300: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
1301: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
1302: ');
1303: } else {
1304: $r->print('
1305: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1306: ');
1307: }
1308: $r->print('</form></fieldset>');
1309: }
1310:
1311: sub do_paste_from_buffer {
1312: my ($coursenum,$coursedom,$folder) = @_;
1313:
1314: if (!$env{'form.pastemarked'}) {
1315: return;
1316: }
1317:
1318: # paste resource to end of list
1319: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
1320: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1321: # Maps need to be copied first
1322: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
1323: $title=&mt('Copy of').' '.$title;
1324: my $newid=$$.int(rand(100)).time;
1325: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1326: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
1327: my $path = $1;
1328: my $prefix = $2;
1329: my $ancestor = $3;
1330: if (length($ancestor) > 10) {
1331: $ancestor = substr($ancestor,-10,10);
1332: }
1333: $oldid = $path.$prefix.$ancestor;
1334: }
1335: my $counter = 0;
1336: my $newurl=$oldid.$newid.'.'.$ext;
1337: my $is_unique = &uniqueness_check($newurl);
1338: while (!$is_unique && $counter < 100) {
1339: $counter ++;
1340: $newid ++;
1341: $newurl = $oldid.$newid;
1342: $is_unique = &uniqueness_check($newurl);
1343: }
1344: if (!$is_unique) {
1345: if ($url=~/\.page$/) {
1346: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
1347: } else {
1348: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
1349: }
1350: }
1351: my $storefn=$newurl;
1352: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1353: my $paste_map_result =
1354: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1355: &Apache::lonnet::getfile($url));
1356: if ($paste_map_result eq '/adm/notfound.html') {
1357: if ($url=~/\.page$/) {
1358: return &mt('Paste failed: an error occurred saving the composite page');
1359: } else {
1360: return &mt('Paste failed: an error occurred saving the folder');
1361: }
1362: }
1363: $url = $newurl;
1364: }
1365: # published maps can only exists once, so remove it from paste buffer when done
1366: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
1367: &Apache::lonnet::delenv('docs.markedcopy');
1368: }
1369: if ($url=~ m{/smppg$}) {
1370: my $db_name = &Apache::lonsimplepage::get_db_name($url);
1371: if ($db_name =~ /^smppage_/) {
1372: #simple pages, need to copy the db contents to a new one.
1373: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
1374: my $now = time();
1375: $db_name =~ s{_\d*$ }{_$now}x;
1376: my $result=&Apache::lonnet::put($db_name,\%contents,
1377: $coursedom,$coursenum);
1378: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1379: $title=&mt('Copy of').' '.$title;
1380: }
1381: }
1382: $title = &LONCAPA::map::qtunescape($title);
1383: my $ext='false';
1384: if ($url=~m{^http(|s)://}) { $ext='true'; }
1385: $url = &LONCAPA::map::qtunescape($url);
1386: # Now insert the URL at the bottom
1387: my $newidx = &LONCAPA::map::getresidx($url);
1388: if ($env{'docs.markedcopy_supplemental'}) {
1389: if ($folder =~ /^supplemental/) {
1390: $title = $env{'docs.markedcopy_supplemental'};
1391: } else {
1392: (undef,undef,$title) =
1393: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1394: }
1395: } else {
1396: if ($folder=~/^supplemental/) {
1397: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1398: $env{'user.domain'}.'___&&&___'.$title;
1399: }
1400: }
1401:
1402: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1403: push(@LONCAPA::map::order, $newidx);
1404: return 'ok';
1405: # Store the result
1406: }
1407:
1408: sub uniqueness_check {
1409: my ($newurl) = @_;
1410: my $unique = 1;
1411: foreach my $res (@LONCAPA::map::order) {
1412: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1413: $url=&LONCAPA::map::qtescape($url);
1414: if ($newurl eq $url) {
1415: $unique = 0;
1416: last;
1417: }
1418: }
1419: return $unique;
1420: }
1421:
1422: my %parameter_type = ( 'randompick' => 'int_pos',
1423: 'hiddenresource' => 'string_yesno',
1424: 'encrypturl' => 'string_yesno',
1425: 'randomorder' => 'string_yesno',);
1426: my $valid_parameters_re = join('|',keys(%parameter_type));
1427: # set parameters
1428: sub update_parameter {
1429:
1430: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1431:
1432: my $which = $env{'form.changeparms'};
1433: my $idx = $env{'form.setparms'};
1434: if ($env{'form.'.$which.'_'.$idx}) {
1435: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
1436: : 'yes';
1437: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
1438: $parameter_type{$which});
1439: &remember_parms($idx,$which,'set',$value);
1440: } else {
1441: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1442:
1443: &remember_parms($idx,$which,'del');
1444: }
1445: return 1;
1446: }
1447:
1448:
1449: sub handle_edit_cmd {
1450: my ($coursenum,$coursedom) =@_;
1451:
1452: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1453:
1454: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1455: my ($title, $url, @rrest) = split(':', $ratstr);
1456:
1457: if ($cmd eq 'del') {
1458: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1459: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1460: &Apache::lonnet::removeuploadedurl($url);
1461: } else {
1462: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1463: }
1464: splice(@LONCAPA::map::order, $idx, 1);
1465:
1466: } elsif ($cmd eq 'cut') {
1467: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1468: splice(@LONCAPA::map::order, $idx, 1);
1469:
1470: } elsif ($cmd eq 'up'
1471: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1472: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1473:
1474: } elsif ($cmd eq 'down'
1475: && defined($LONCAPA::map::order[$idx+1])) {
1476: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1477:
1478: } elsif ($cmd eq 'rename') {
1479:
1480: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
1481: if ($comment=~/\S/) {
1482: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1483: $comment.':'.join(':', $url, @rrest);
1484: }
1485: # Devalidate title cache
1486: my $renamed_url=&LONCAPA::map::qtescape($url);
1487: &Apache::lonnet::devalidate_title_cache($renamed_url);
1488: } else {
1489: return 0;
1490: }
1491: return 1;
1492: }
1493:
1494: sub editor {
1495: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
1496:
1497: my $container= ($env{'form.pagepath'}) ? 'page'
1498: : 'sequence';
1499:
1500: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1501: $folder.'.'.$container);
1502: return $errtext if ($fatal);
1503:
1504: if ($#LONCAPA::map::order<1) {
1505: my $idx=&LONCAPA::map::getresidx();
1506: if ($idx<=0) { $idx=1; }
1507: $LONCAPA::map::order[0]=$idx;
1508: $LONCAPA::map::resources[$idx]='';
1509: }
1510:
1511: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
1512: &breadcrumbs($folder,$allowed,$type);
1513: $r->print($breadcrumbtrail);
1514:
1515: # ------------------------------------------------------------ Process commands
1516:
1517: # ---------------- if they are for this folder and user allowed to make changes
1518: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1519: # set parameters and change order
1520: &snapshotbefore();
1521:
1522: if (&update_parameter()) {
1523: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1524: return $errtext if ($fatal);
1525: }
1526:
1527: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
1528: # change order
1529: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
1530: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
1531:
1532: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1533: return $errtext if ($fatal);
1534: }
1535:
1536: if ($env{'form.pastemarked'}) {
1537: my $paste_res =
1538: &do_paste_from_buffer($coursenum,$coursedom,$folder);
1539: if ($paste_res eq 'ok') {
1540: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
1541: return $errtext if ($fatal);
1542: } elsif ($paste_res ne '') {
1543: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
1544: }
1545: }
1546:
1547: $r->print($upload_output);
1548:
1549: if (&handle_edit_cmd()) {
1550: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1551: return $errtext if ($fatal);
1552: }
1553: # Group import/search
1554: if ($env{'form.importdetail'}) {
1555: my @imports;
1556: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
1557: if (defined($item)) {
1558: my ($name,$url,$residx)=
1559: map {&unescape($_)} split(/\=/,$item);
1560: push(@imports, [$name, $url, $residx]);
1561: }
1562: }
1563: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1564: $container,'londocs',@imports);
1565: return $errtext if ($fatal);
1566: }
1567: # Loading a complete map
1568: if ($env{'form.loadmap'}) {
1569: if ($env{'form.importmap'}=~/\w/) {
1570: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1571: my ($title,$url,$ext,$type)=split(/\:/,$res);
1572: my $idx=&LONCAPA::map::getresidx($url);
1573: $LONCAPA::map::resources[$idx]=$res;
1574: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1575: }
1576: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1577: $folder.'.'.$container);
1578: return $errtext if ($fatal);
1579: } else {
1580: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1581:
1582: }
1583: }
1584: &log_differences($plain);
1585: }
1586: # ---------------------------------------------------------------- End commands
1587: # ---------------------------------------------------------------- Print screen
1588: my $idx=0;
1589: my $shown=0;
1590: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1591: $r->print('<div class="LC_Box">'.
1592: '<p>'.&mt('Parameters:').
1593: '<ul>'.
1594: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
1595: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1596: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1597: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1598: '</ul></p>');
1599: if ($randompick>=0) {
1600: $r->print('<p class="LC_warning">'
1601: .&mt('Caution: this folder is set to randomly pick a subset'
1602: .' of resources. Adding or removing resources from this'
1603: .' folder will change the set of resources that the'
1604: .' students see, resulting in spurious or missing credit'
1605: .' for completed problems, not limited to ones you'
1606: .' modify. Do not modify the contents of this folder if'
1607: .' it is in active student use.')
1608: .'</p>'
1609: );
1610: }
1611: if ($is_random_order) {
1612: $r->print('<p class="LC_warning">'
1613: .&mt('Caution: this folder is set to randomly order its'
1614: .' contents. Adding or removing resources from this folder'
1615: .' will change the order of resources shown.')
1616: .'</p>'
1617: );
1618: }
1619: $r->print('</div>');
1620: }
1621:
1622: my $output;
1623: foreach my $res (@LONCAPA::map::order) {
1624: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1625: $name=&LONCAPA::map::qtescape($name);
1626: $url=&LONCAPA::map::qtescape($url);
1627: unless ($name) { $name=(split(/\//,$url))[-1]; }
1628: unless ($name) { $idx++; next; }
1629: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1630: $coursenum);
1631: $idx++;
1632: $shown++;
1633: }
1634: if ($shown) {
1635: $r->print(&Apache::loncommon::start_data_table()
1636: .&Apache::loncommon::start_data_table_header_row()
1637: .'<th colspan="2">'.&mt('Move').'</th>'
1638: .'<th>'.&mt('Actions').'</th>'
1639: .'<th colspan="2">'.&mt('Document').'</th>'
1640: .'<th colspan="4">'.&mt('Settings').'</th>'
1641: .&Apache::loncommon::end_data_table_header_row()
1642: .$output
1643: .&Apache::loncommon::end_data_table()
1644: )
1645: }
1646: unless($shown) {
1647: $r->print('<p class="LC_info">'
1648: .&mt('Currently no documents.')
1649: .'</p>'
1650: );
1651: }
1652: if ($allowed) {
1653: &print_paste_buffer($r,$container);
1654: }
1655: return;
1656: }
1657:
1658: sub process_file_upload {
1659: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1660: # upload a file, if present
1661: my $parseaction;
1662: if ($env{'form.parserflag'}) {
1663: $parseaction = 'parse';
1664: }
1665: my $phase_status;
1666: my $folder=$env{'form.folder'};
1667: if ($folder eq '') {
1668: $folder='default';
1669: }
1670: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1671: my $errtext='';
1672: my $fatal=0;
1673: my $container='sequence';
1674: if ($env{'form.pagepath'}) {
1675: $container='page';
1676: }
1677: ($errtext,$fatal)=
1678: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1679: if ($#LONCAPA::map::order<1) {
1680: $LONCAPA::map::order[0]=1;
1681: $LONCAPA::map::resources[1]='';
1682: }
1683: if ($fatal) {
1684: return 'failed';
1685: }
1686: my $destination = 'docs/';
1687: if ($folder =~ /^supplemental/) {
1688: $destination = 'supplemental/';
1689: }
1690: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1691: $destination .= 'default/';
1692: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1693: $destination .= $2.'/';
1694: }
1695: # this is for a course, not a user, so set coursedoc flag
1696: # probably the only place in the system where this should be "1"
1697: my $newidx=&LONCAPA::map::getresidx();
1698: $destination .= $newidx;
1699: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1700: $parseaction,$allfiles,
1701: $codebase);
1702: my $ext='false';
1703: if ($url=~m{^http://}) { $ext='true'; }
1704: $url = &LONCAPA::map::qtunescape($url);
1705: my $comment=$env{'form.comment'};
1706: $comment = &LONCAPA::map::qtunescape($comment);
1707: if ($folder=~/^supplemental/) {
1708: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1709: $env{'user.domain'}.'___&&&___'.$comment;
1710: }
1711:
1712: $LONCAPA::map::resources[$newidx]=
1713: $comment.':'.$url.':'.$ext.':normal:res';
1714: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1715: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1716: $folder.'.'.$container);
1717: if ($fatal) {
1718: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1719: return 'failed';
1720: } else {
1721: if ($parseaction eq 'parse') {
1722: my $total_embedded = keys(%{$allfiles});
1723: if ($total_embedded > 0) {
1724: my $num = 0;
1725: my $state = '
1726: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1727: <input type="hidden" name="cmd" value="upload_embedded" />
1728: <input type="hidden" name="newidx" value="'.$newidx.'" />
1729: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1730: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1731: $phase_status = 'phasetwo';
1732:
1733: $$upload_output .=
1734: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1735: &Apache::loncommon::ask_for_embedded_content(
1736: '/adm/coursedocs',$state,$allfiles,$codebase);
1737: } else {
1738: $$upload_output .= 'No embedded items identified<br />';
1739: }
1740: }
1741: }
1742: }
1743: return $phase_status;
1744: }
1745:
1746: sub process_secondary_uploads {
1747: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1748: my $folder=$env{'form.folder'};
1749: my $destination = 'docs/';
1750: if ($folder =~ /^supplemental/) {
1751: $destination = 'supplemental/';
1752: }
1753: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1754: $destination .= 'default/';
1755: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1756: $destination .= $2.'/';
1757: }
1758: $destination .= $newidx;
1759: my ($url,$filename);
1760: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1761: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1762: return $filename;
1763: }
1764:
1765: sub is_supplemental_title {
1766: my ($title) = @_;
1767: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1768: }
1769:
1770: sub parse_supplemental_title {
1771: my ($title) = @_;
1772:
1773: my ($foldertitle,$renametitle);
1774: if ($title =~ /&&&/) {
1775: $title = &HTML::Entites::decode($title);
1776: }
1777: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1778: $renametitle=$4;
1779: my ($time,$uname,$udom) = ($1,$2,$3);
1780: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1781: my $name = &Apache::loncommon::plainname($uname,$udom);
1782: $name = &HTML::Entities::encode($name,'"<>&\'');
1783: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1784: $name.': <br />'.$foldertitle;
1785: }
1786: if (wantarray) {
1787: return ($title,$foldertitle,$renametitle);
1788: }
1789: return $title;
1790: }
1791:
1792: # --------------------------------------------------------------- An entry line
1793:
1794: sub entryline {
1795: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1796:
1797: my ($foldertitle,$pagetitle,$renametitle);
1798: if (&is_supplemental_title($title)) {
1799: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1800: $pagetitle = $foldertitle;
1801: } else {
1802: $title=&HTML::Entities::encode($title,'"<>&\'');
1803: $renametitle=$title;
1804: $foldertitle=$title;
1805: $pagetitle=$title;
1806: }
1807:
1808: my $orderidx=$LONCAPA::map::order[$index];
1809:
1810:
1811: $renametitle=~s/\\/\\\\/g;
1812: $renametitle=~s/\"\;/\\\"/g;
1813: $renametitle=~s/ /%20/g;
1814: my $line=&Apache::loncommon::start_data_table_row();
1815: my ($form_start,$form_end);
1816: # Edit commands
1817: my ($container, $type, $esc_path, $path, $symb);
1818: if ($env{'form.folderpath'}) {
1819: $type = 'folder';
1820: $container = 'sequence';
1821: $esc_path=&escape($env{'form.folderpath'});
1822: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1823: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1824: }
1825: if ($env{'form.pagepath'}) {
1826: $type = $container = 'page';
1827: $esc_path=&escape($path = $env{'form.pagepath'});
1828: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1829: $symb=&escape($env{'form.pagesymb'});
1830: }
1831: my $cpinfo='';
1832: if ($allowed) {
1833: my $incindex=$index+1;
1834: my $selectbox='';
1835: if (($folder!~/^supplemental/) &&
1836: ($#LONCAPA::map::order>0) &&
1837: ((split(/\:/,
1838: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1839: ne '') &&
1840: ((split(/\:/,
1841: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1842: ne '')) {
1843: $selectbox=
1844: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1845: '<select name="newpos" onchange="this.form.submit()">';
1846: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1847: if ($i==$incindex) {
1848: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1849: } else {
1850: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1851: }
1852: }
1853: $selectbox.='</select>';
1854: }
1855: my %lt=&Apache::lonlocal::texthash(
1856: 'up' => 'Move Up',
1857: 'dw' => 'Move Down',
1858: 'rm' => 'Remove',
1859: 'ct' => 'Cut',
1860: 'rn' => 'Rename',
1861: 'cp' => 'Copy');
1862: my $nocopy=0;
1863: my $nocut=0;
1864: if ($url=~/\.(page|sequence)$/) {
1865: if ($url =~ m{/res/}) {
1866: # no copy for published maps
1867: $nocopy = 1;
1868: } else {
1869: foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1870: my ($title,$url,$ext,$type)=split(/\:/,$item);
1871: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1872: $nocopy=1;
1873: last;
1874: }
1875: }
1876: }
1877: }
1878: if ($url=~/^\/res\/lib\/templates\//) {
1879: $nocopy=1;
1880: $nocut=1;
1881: }
1882: my $copylink=' ';
1883: my $cutlink=' ';
1884:
1885: my $skip_confirm = 0;
1886: if ( $folder =~ /^supplemental/
1887: || ($url =~ m{( /smppg$
1888: |/syllabus$
1889: |/aboutme$
1890: |/navmaps$
1891: |/bulletinboard$
1892: |\.html$
1893: |^/adm/wrapper/ext)}x)) {
1894: $skip_confirm = 1;
1895: }
1896:
1897: if (!$nocopy) {
1898: $copylink=(<<ENDCOPY);
1899: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
1900: ENDCOPY
1901: }
1902: if (!$nocut) {
1903: $cutlink=(<<ENDCUT);
1904: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
1905: ENDCUT
1906: }
1907: $form_start = (<<END);
1908: <form action="/adm/coursedocs" method="post">
1909: <input type="hidden" name="${type}path" value="$path" />
1910: <input type="hidden" name="${type}symb" value="$symb" />
1911: <input type="hidden" name="setparms" value="$orderidx" />
1912: <input type="hidden" name="changeparms" value="0" />
1913: END
1914: $form_end = '</form>';
1915: $line.=(<<END);
1916: <td>
1917: <div class="LC_docs_entry_move">
1918: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1919: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
1920: </a>
1921: </div>
1922: <div class="LC_docs_entry_move">
1923: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1924: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
1925: </a>
1926: </div>
1927: </td>
1928: <td>
1929: $form_start
1930: $selectbox
1931: $form_end
1932: </td>
1933: <td class="LC_docs_entry_commands">
1934: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1935: $cutlink
1936: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1937: $copylink
1938: </td>
1939: END
1940:
1941: }
1942: # Figure out what kind of a resource this is
1943: my ($extension)=($url=~/\.(\w+)$/);
1944: my $uploaded=($url=~/^\/*uploaded\//);
1945: my $icon=&Apache::loncommon::icon($url);
1946: my $isfolder=0;
1947: my $ispage=0;
1948: my $folderarg;
1949: my $pagearg;
1950: my $pagefile;
1951: if ($uploaded) {
1952: if ($extension eq 'sequence') {
1953: $icon=$iconpath.'/navmap.folder.closed.gif';
1954: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1955: $url='/adm/coursedocs?';
1956: $folderarg=$1;
1957: $isfolder=1;
1958: } elsif ($extension eq 'page') {
1959: $icon=$iconpath.'/page.gif';
1960: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1961: $pagearg=$1;
1962: $url='/adm/coursedocs?';
1963: $ispage=1;
1964: } else {
1965: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1966: }
1967: }
1968:
1969: my $orig_url = $url;
1970: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1971: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1972: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1973: my $symb=&Apache::lonnet::symbclean(
1974: &Apache::lonnet::declutter('uploaded/'.
1975: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1976: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1977: '.sequence').
1978: '___'.$residx.'___'.
1979: &Apache::lonnet::declutter($url));
1980: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1981: $url=&Apache::lonnet::clutter($url);
1982: if ($url=~/^\/*uploaded\//) {
1983: $url=~/\.(\w+)$/;
1984: my $embstyle=&Apache::loncommon::fileembstyle($1);
1985: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1986: $url='/adm/wrapper'.$url;
1987: } elsif ($embstyle eq 'ssi') {
1988: #do nothing with these
1989: } elsif ($url!~/\.(sequence|page)$/) {
1990: $url='/adm/coursedocs/showdoc'.$url;
1991: }
1992: } elsif ($url=~m|^/ext/|) {
1993: $url='/adm/wrapper'.$url;
1994: $external = 1;
1995: }
1996: if (&Apache::lonnet::symbverify($symb,$url)) {
1997: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1998: } else {
1999: $url='';
2000: }
2001: if ($container eq 'page') {
2002: my $symb=$env{'form.pagesymb'};
2003:
2004: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2005: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2006: }
2007: }
2008: my ($parameterset,$rand_order_text) = (' ', ' ');
2009: if ($isfolder || $extension eq 'sequence') {
2010: my $foldername=&escape($foldertitle);
2011: my $folderpath=$env{'form.folderpath'};
2012: if ($folderpath) { $folderpath.='&' };
2013: # Append randompick number, hidden, and encrypted with ":" to foldername,
2014: # so it gets transferred between levels
2015: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
2016: 'parameter_randompick'))[0]
2017: .':'.((&LONCAPA::map::getparameter($orderidx,
2018: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2019: .':'.((&LONCAPA::map::getparameter($orderidx,
2020: 'parameter_encrypturl'))[0]=~/^yes$/i)
2021: .':'.((&LONCAPA::map::getparameter($orderidx,
2022: 'parameter_randomorder'))[0]=~/^yes$/i);
2023: $url.='folderpath='.&escape($folderpath).$cpinfo;
2024: $parameterset='<label>'.&mt('Randomly Pick: ').
2025: '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
2026: (&LONCAPA::map::getparameter($orderidx,
2027: 'parameter_randompick'))[0].
2028: '" />'.
2029: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
2030: my $ro_set=
2031: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
2032: $rand_order_text ='
2033: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
2034: }
2035: if ($ispage) {
2036: my $pagename=&escape($pagetitle);
2037: my $pagepath;
2038: my $folderpath=$env{'form.folderpath'};
2039: if ($folderpath) { $pagepath = $folderpath.'&' };
2040: $pagepath.=$pagearg.'&'.$pagename;
2041: my $symb=$env{'form.pagesymb'};
2042: if (!$symb) {
2043: my $path='uploaded/'.
2044: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2045: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2046: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
2047: $residx,
2048: $path.$pagearg.'.page');
2049: }
2050: $url.='pagepath='.&escape($pagepath).
2051: '&pagesymb='.&escape($symb).$cpinfo;
2052: }
2053: if ($external) {
2054: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
2055: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
2056: } else {
2057: undef($external);
2058: }
2059: $line.='
2060: <td>
2061: '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
2062: </td>
2063: <td>
2064: '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
2065: </td>";
2066: if (($allowed) && ($folder!~/^supplemental/)) {
2067: my %lt=&Apache::lonlocal::texthash(
2068: 'hd' => 'Hidden',
2069: 'ec' => 'URL hidden');
2070: my $enctext=
2071: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
2072: my $hidtext=
2073: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
2074: $line.=(<<ENDPARMS);
2075: <td class="LC_docs_entry_parameter">
2076: $form_start
2077: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
2078: $form_end
2079: </td>
2080: <td class="LC_docs_entry_parameter">
2081: $form_start
2082: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
2083: $form_end
2084: </td>
2085: <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
2086: <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
2087: ENDPARMS
2088: }
2089: $line.=&Apache::loncommon::end_data_table_row();
2090: return $line;
2091: }
2092:
2093: =pod
2094:
2095: =item tiehash()
2096:
2097: tie the hash
2098:
2099: =cut
2100:
2101: sub tiehash {
2102: my ($mode)=@_;
2103: $hashtied=0;
2104: if ($env{'request.course.fn'}) {
2105: if ($mode eq 'write') {
2106: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2107: &GDBM_WRCREAT(),0640)) {
2108: $hashtied=2;
2109: }
2110: } else {
2111: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2112: &GDBM_READER(),0640)) {
2113: $hashtied=1;
2114: }
2115: }
2116: }
2117: }
2118:
2119: sub untiehash {
2120: if ($hashtied) { untie %hash; }
2121: $hashtied=0;
2122: return OK;
2123: }
2124:
2125:
2126:
2127:
2128: sub checkonthis {
2129: my ($r,$url,$level,$title)=@_;
2130: $url=&unescape($url);
2131: $alreadyseen{$url}=1;
2132: $r->rflush();
2133: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2134: $r->print("\n<br />");
2135: if ($level==0) {
2136: $r->print("<br />");
2137: }
2138: for (my $i=0;$i<=$level*5;$i++) {
2139: $r->print(' ');
2140: }
2141: $r->print('<a href="'.$url.'" target="cat">'.
2142: ($title?$title:$url).'</a> ');
2143: if ($url=~/^\/res\//) {
2144: my $result=&Apache::lonnet::repcopy(
2145: &Apache::lonnet::filelocation('',$url));
2146: if ($result eq 'ok') {
2147: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2148: $r->rflush();
2149: &Apache::lonnet::countacc($url);
2150: $url=~/\.(\w+)$/;
2151: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2152: $r->print('<br />');
2153: $r->rflush();
2154: for (my $i=0;$i<=$level*5;$i++) {
2155: $r->print(' ');
2156: }
2157: $r->print('- '.&mt('Rendering:').' ');
2158: my ($errorcount,$warningcount)=split(/:/,
2159: &Apache::lonnet::ssi_body($url,
2160: ('grade_target'=>'web',
2161: 'return_only_error_and_warning_counts' => 1)));
2162: if (($errorcount) ||
2163: ($warningcount)) {
2164: if ($errorcount) {
2165: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
2166: &mt('[quant,_1,error]',$errorcount).'</span>');
2167: }
2168: if ($warningcount) {
2169: $r->print('<span class="LC_warning">'.
2170: &mt('[quant,_1,warning]',$warningcount).'</span>');
2171: }
2172: } else {
2173: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2174: }
2175: $r->rflush();
2176: }
2177: my $dependencies=
2178: &Apache::lonnet::metadata($url,'dependencies');
2179: foreach my $dep (split(/\,/,$dependencies)) {
2180: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2181: &checkonthis($r,$dep,$level+1);
2182: }
2183: }
2184: } elsif ($result eq 'unavailable') {
2185: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2186: } elsif ($result eq 'not_found') {
2187: unless ($url=~/\$/) {
2188: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2189: } else {
2190: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
2191: }
2192: } else {
2193: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2194: }
2195: }
2196: }
2197: }
2198:
2199:
2200:
2201: =pod
2202:
2203: =item list_symbs()
2204:
2205: List Symbs
2206:
2207: =cut
2208:
2209: sub list_symbs {
2210: my ($r) = @_;
2211:
2212: my $type = &Apache::loncommon::course_type();
2213: $r->print(&Apache::loncommon::start_page('Symb List'));
2214: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
2215: my $navmap = Apache::lonnavmaps::navmap->new();
2216: if (!defined($navmap)) {
2217: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2218: '<div class="LC_error">'.
2219: &mt('Unable to retrieve information about course contents').
2220: '</div>');
2221: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
2222: } else {
2223: $r->print("<pre>\n");
2224: foreach my $res ($navmap->retrieveResources()) {
2225: $r->print($res->compTitle()."\t".$res->symb()."\n");
2226: }
2227: $r->print("\n</pre>\n");
2228: }
2229: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
2230: }
2231:
2232:
2233: sub verifycontent {
2234: my ($r) = @_;
2235: my $type = &Apache::loncommon::course_type();
2236: my $loaderror=&Apache::lonnet::overloaderror($r);
2237: if ($loaderror) { return $loaderror; }
2238: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
2239: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
2240: $hashtied=0;
2241: undef %alreadyseen;
2242: %alreadyseen=();
2243: &tiehash();
2244: foreach my $key (keys(%hash)) {
2245: if ($hash{$key}=~/\.(page|sequence)$/) {
2246: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2247: $r->print('<hr /><span class="LC_error">'.
2248: &mt('The following sequence or page is included more than once in your '.$type.': ').
2249: &unescape($hash{$key}).'</span><br />'.
2250: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2251: }
2252: }
2253: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2254: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2255: }
2256: }
2257: &untiehash();
2258: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2259: &mt('Return to DOCS').'</a>');
2260: }
2261:
2262:
2263: sub devalidateversioncache {
2264: my $src=shift;
2265: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2266: &Apache::lonnet::clutter($src));
2267: }
2268:
2269: sub checkversions {
2270: my ($r) = @_;
2271: my $type = &Apache::loncommon::course_type();
2272: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
2273: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
2274: my $header='';
2275: my $startsel='';
2276: my $monthsel='';
2277: my $weeksel='';
2278: my $daysel='';
2279: my $allsel='';
2280: my %changes=();
2281: my $starttime=0;
2282: my $haschanged=0;
2283: my %setversions=&Apache::lonnet::dump('resourceversions',
2284: $env{'course.'.$env{'request.course.id'}.'.domain'},
2285: $env{'course.'.$env{'request.course.id'}.'.num'});
2286:
2287: $hashtied=0;
2288: &tiehash();
2289: my %newsetversions=();
2290: if ($env{'form.setmostrecent'}) {
2291: $haschanged=1;
2292: foreach my $key (keys(%hash)) {
2293: if ($key=~/^ids\_(\/res\/.+)$/) {
2294: $newsetversions{$1}='mostrecent';
2295: &devalidateversioncache($1);
2296: }
2297: }
2298: } elsif ($env{'form.setcurrent'}) {
2299: $haschanged=1;
2300: foreach my $key (keys(%hash)) {
2301: if ($key=~/^ids\_(\/res\/.+)$/) {
2302: my $getvers=&Apache::lonnet::getversion($1);
2303: if ($getvers>0) {
2304: $newsetversions{$1}=$getvers;
2305: &devalidateversioncache($1);
2306: }
2307: }
2308: }
2309: } elsif ($env{'form.setversions'}) {
2310: $haschanged=1;
2311: foreach my $key (keys(%env)) {
2312: if ($key=~/^form\.set_version_(.+)$/) {
2313: my $src=$1;
2314: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2315: $newsetversions{$src}=$env{$key};
2316: &devalidateversioncache($src);
2317: }
2318: }
2319: }
2320: }
2321: if ($haschanged) {
2322: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2323: $env{'course.'.$env{'request.course.id'}.'.domain'},
2324: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
2325: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
2326: } else {
2327: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
2328: }
2329: &mark_hash_old();
2330: }
2331: &changewarning($r,'');
2332: if ($env{'form.timerange'} eq 'all') {
2333: # show all documents
2334: $header=&mt('All Documents in '.$type);
2335: $allsel=1;
2336: foreach my $key (keys(%hash)) {
2337: if ($key=~/^ids\_(\/res\/.+)$/) {
2338: my $src=$1;
2339: $changes{$src}=1;
2340: }
2341: }
2342: } else {
2343: # show documents which changed
2344: %changes=&Apache::lonnet::dump
2345: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2346: $env{'course.'.$env{'request.course.id'}.'.num'});
2347: my $firstkey=(keys(%changes))[0];
2348: unless ($firstkey=~/^error\:/) {
2349: unless ($env{'form.timerange'}) {
2350: $env{'form.timerange'}=604800;
2351: }
2352: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2353: .&mt('seconds');
2354: if ($env{'form.timerange'}==-1) {
2355: $seltext='since start of course';
2356: $startsel='selected';
2357: $env{'form.timerange'}=time;
2358: }
2359: $starttime=time-$env{'form.timerange'};
2360: if ($env{'form.timerange'}==2592000) {
2361: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2362: $monthsel='selected';
2363: } elsif ($env{'form.timerange'}==604800) {
2364: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2365: $weeksel='selected';
2366: } elsif ($env{'form.timerange'}==86400) {
2367: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2368: $daysel='selected';
2369: }
2370: $header=&mt('Content changed').' '.$seltext;
2371: } else {
2372: $header=&mt('No content modifications yet.');
2373: }
2374: }
2375: %setversions=&Apache::lonnet::dump('resourceversions',
2376: $env{'course.'.$env{'request.course.id'}.'.domain'},
2377: $env{'course.'.$env{'request.course.id'}.'.num'});
2378: my %lt=&Apache::lonlocal::texthash
2379: ('st' => 'Version changes since start of '.$type,
2380: 'lm' => 'Version changes since last Month',
2381: 'lw' => 'Version changes since last Week',
2382: 'sy' => 'Version changes since Yesterday',
2383: 'al' => 'All Resources (possibly large output)',
2384: 'sd' => 'Display',
2385: 'fi' => 'File',
2386: 'md' => 'Modification Date',
2387: 'mr' => 'Most recently published Version',
2388: 've' => 'Version used in '.$type,
2389: 'vu' => 'Set Version to be used in '.$type,
2390: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
2391: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2392: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
2393: 'di' => 'Differences');
2394: $r->print(<<ENDHEADERS);
2395: <form action="/adm/coursedocs" method="post">
2396: <input type="hidden" name="versions" value="1" />
2397: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2398: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
2399: <select name="timerange">
2400: <option value='all' $allsel>$lt{'al'}</option>
2401: <option value="-1" $startsel>$lt{'st'}</option>
2402: <option value="2592000" $monthsel>$lt{'lm'}</option>
2403: <option value="604800" $weeksel>$lt{'lw'}</option>
2404: <option value="86400" $daysel>$lt{'sy'}</option>
2405: </select>
2406: <input type="submit" name="display" value="$lt{'sd'}" />
2407: <h3>$header</h3>
2408: <input type="submit" name="setversions" value="$lt{'sv'}" />
2409: <table border="0">
2410: ENDHEADERS
2411: foreach my $key (sort(keys(%changes))) {
2412: if ($changes{$key}>$starttime) {
2413: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2414: my $currentversion=&Apache::lonnet::getversion($key);
2415: if ($currentversion<0) {
2416: $currentversion=&mt('Could not be determined.');
2417: }
2418: my $linkurl=&Apache::lonnet::clutter($key);
2419: $r->print(
2420: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
2421: &Apache::lonnet::gettitle($linkurl).
2422: '</b></font></td></tr>'.
2423: '<tr><td> </td>'.
2424: '<td colspan="4">'.
2425: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2426: '</a></td></tr>'.
2427: '<tr><td></td>'.
2428: '<td title="'.$lt{'md'}.'">'.
2429: &Apache::lonlocal::locallocaltime(
2430: &Apache::lonnet::metadata($root.'.'.$extension,
2431: 'lastrevisiondate')
2432: ).
2433: '</td>'.
2434: '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
2435: '<font size="+1">'.$currentversion.'</font>'.
2436: '</span></td>'.
2437: '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
2438: '<font size="+1">');
2439: # Used in course
2440: my $usedversion=$hash{'version_'.$linkurl};
2441: if (($usedversion) && ($usedversion ne 'mostrecent')) {
2442: $r->print($usedversion);
2443: } else {
2444: $r->print($currentversion);
2445: }
2446: $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
2447: '<span class="LC_nobreak">Use: ');
2448: # Set version
2449: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2450: 'set_version_'.$linkurl,
2451: ('select_form_order' =>
2452: ['',1..$currentversion,'mostrecent'],
2453: '' => '',
2454: 'mostrecent' => 'most recent',
2455: map {$_,$_} (1..$currentversion))));
2456: $r->print('</span></td></tr><tr><td></td>');
2457: my $lastold=1;
2458: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2459: my $url=$root.'.'.$prevvers.'.'.$extension;
2460: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2461: $starttime) {
2462: $lastold=$prevvers;
2463: }
2464: }
2465: #
2466: # Code to figure out how many version entries should go in
2467: # each of the four columns
2468: my $entries_per_col = 0;
2469: my $num_entries = ($currentversion-$lastold);
2470: if ($num_entries % 4 == 0) {
2471: $entries_per_col = $num_entries/4;
2472: } else {
2473: $entries_per_col = $num_entries/4 + 1;
2474: }
2475: my $entries_count = 0;
2476: $r->print('<td valign="top"><font size="-2">');
2477: my $cols_output = 1;
2478: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2479: my $url=$root.'.'.$prevvers.'.'.$extension;
2480: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
2481: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2482: &Apache::lonlocal::locallocaltime(
2483: &Apache::lonnet::metadata($url,
2484: 'lastrevisiondate')
2485: ).
2486: ')');
2487: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2488: $r->print(' <a href="/adm/diff?filename='.
2489: &Apache::lonnet::clutter($root.'.'.$extension).
2490: '&versionone='.$prevvers.
2491: '">'.&mt('Diffs').'</a>');
2492: }
2493: $r->print('</span><br />');
2494: if (++$entries_count % $entries_per_col == 0) {
2495: $r->print('</font></td>');
2496: if ($cols_output != 4) {
2497: $r->print('<td valign="top"><font size="-2">');
2498: $cols_output++;
2499: }
2500: }
2501: }
2502: while($cols_output++ < 4) {
2503: $r->print('</font></td><td><font>')
2504: }
2505: $r->print('</font></td></tr>'."\n");
2506: }
2507: }
2508: $r->print('</table></form>');
2509: $r->print('<h1>'.&mt('Done').'.</h1>');
2510:
2511: &untiehash();
2512: }
2513:
2514: sub mark_hash_old {
2515: my $retie_hash=0;
2516: if ($hashtied) {
2517: $retie_hash=1;
2518: &untiehash();
2519: }
2520: &tiehash('write');
2521: $hash{'old'}=1;
2522: &untiehash();
2523: if ($retie_hash) { &tiehash(); }
2524: }
2525:
2526: sub is_hash_old {
2527: my $untie_hash=0;
2528: if (!$hashtied) {
2529: $untie_hash=1;
2530: &tiehash();
2531: }
2532: my $return=$hash{'old'};
2533: if ($untie_hash) { &untiehash(); }
2534: return $return;
2535: }
2536:
2537: sub changewarning {
2538: my ($r,$postexec,$message,$url)=@_;
2539: if (!&is_hash_old()) { return; }
2540: my $pathvar='folderpath';
2541: my $path=&escape($env{'form.folderpath'});
2542: if (!defined($url)) {
2543: if (defined($env{'form.pagepath'})) {
2544: $pathvar='pagepath';
2545: $path=&escape($env{'form.pagepath'});
2546: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2547: }
2548: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2549: }
2550: my $course_type = &Apache::loncommon::course_type();
2551: if (!defined($message)) {
2552: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2553: }
2554: $r->print("\n\n".
2555: '<script type="text/javascript">'."\n".
2556: '// <![CDATA['."\n".
2557: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
2558: '// ]]>'."\n".
2559: '</script>'."\n".
2560: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
2561: '<input type="hidden" name="orgurl" value="'.$url.
2562: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
2563: &mt($message,' <input type="hidden" name="'.
2564: $env{'request.role'}.'" value="1" /><input type="button" value="'.
2565: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
2566: $help{'Caching'}.'</p></form>'."\n\n");
2567: }
2568:
2569:
2570: sub init_breadcrumbs {
2571: my ($form,$text)=@_;
2572: &Apache::lonhtmlcommon::clear_breadcrumbs();
2573: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
2574: text=>"Edit ".&Apache::loncommon::course_type(),
2575: faq=>273,
2576: bug=>'Instructor Interface',
2577: help => 'Docs_Adding_Course_Doc'});
2578: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2579: text=>$text,
2580: faq=>273,
2581: bug=>'Instructor Interface'});
2582: }
2583:
2584:
2585:
2586:
2587: sub handler {
2588: my $r = shift;
2589: &Apache::loncommon::content_type($r,'text/html');
2590: $r->send_http_header;
2591: return OK if $r->header_only;
2592: my $type = &Apache::loncommon::course_type();
2593:
2594:
2595: # --------------------------------------------- Initialize help topics for this
2596: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2597: 'Adding_External_Resource','Navigate_Content',
2598: 'Adding_Folders','Docs_Overview', 'Load_Map',
2599: 'Supplemental','Score_Upload_Form','Adding_Pages',
2600: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2601: 'Check_Resource_Versions','Verify_Content') {
2602: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2603: }
2604: # Composite help files
2605: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2606: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2607: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2608: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2609: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2610: 'Option_Response_Simple');
2611: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2612: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2613: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
2614: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2615: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
2616: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2617:
2618: # does this user have privileges to modify docs
2619: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2620: if ($allowed && $env{'form.verify'}) {
2621: &init_breadcrumbs('verify','Verify Content');
2622: &verifycontent($r);
2623: } elsif ($allowed && $env{'form.listsymbs'}) {
2624: &init_breadcrumbs('listsymbs','List Symbs');
2625: &list_symbs($r);
2626: } elsif ($allowed && $env{'form.docslog'}) {
2627: &init_breadcrumbs('docslog','Show Log');
2628: &docs_change_log($r);
2629: } elsif ($allowed && $env{'form.versions'}) {
2630: &init_breadcrumbs('versions','Check/Set Resource Versions');
2631: &checkversions($r);
2632: } elsif ($allowed && $env{'form.dumpcourse'}) {
2633: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2634: &dumpcourse($r);
2635: } elsif ($allowed && $env{'form.exportcourse'}) {
2636: &init_breadcrumbs('exportcourse','IMS Export');
2637: &exportcourse($r);
2638: } else {
2639: # is this a standard course?
2640:
2641: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2642: my $forcestandard = 0;
2643: my $forcesupplement;
2644: my $script='';
2645: my $showdoc=0;
2646: my $containertag;
2647: my $uploadtag;
2648:
2649:
2650: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2651: ['folderpath','pagepath',
2652: 'pagesymb']);
2653: # No folderpath, no pagepath, see if we have something stored
2654: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2655: &Apache::loncommon::restore_course_settings('docs_folderpath',
2656: {'folderpath' => 'scalar'});
2657: }
2658: if (!$env{'form.folderpath'}) {
2659: &Apache::loncommon::restore_course_settings('docs_folderpath',
2660: {'pagepath' => 'scalar'});
2661: }
2662: if ($env{'form.pagepath'}) {
2663: $env{'form.folderpath'}='';
2664: }
2665: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2666: $env{'form.folderpath'} = 'supplemental&'.
2667: &escape(&mt('Supplemental '.$type.' Documents')).'&'.
2668: $env{'form.folderpath'};
2669: }
2670: &Apache::loncommon::store_course_settings('docs_folderpath',
2671: {'pagepath' => 'scalar',
2672: 'folderpath' => 'scalar'});
2673: if ($env{'form.folderpath'}) {
2674: my (@folderpath)=split('&',$env{'form.folderpath'});
2675: $env{'form.foldername'}=&unescape(pop(@folderpath));
2676: $env{'form.folder'}=pop(@folderpath);
2677: }
2678: if ($env{'form.pagepath'}) {
2679: my (@pagepath)=split('&',$env{'form.pagepath'});
2680: $env{'form.pagename'}=&unescape(pop(@pagepath));
2681: $env{'form.folder'}=pop(@pagepath);
2682: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2683: '<input type="hidden" name="pagesymb" value="" />';
2684: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2685: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2686: }
2687: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2688: $showdoc='/'.$1;
2689: }
2690: unless ($showdoc) { # got called from remote
2691: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
2692: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2693: $forcestandard = 1;
2694: }
2695: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2696:
2697: if ($allowed) {
2698: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2699: $script=&Apache::lonratedt::editscript('simple');
2700: }
2701: } else { # got called in sequence from course
2702: $allowed=0;
2703: }
2704:
2705: # subroutine to list form elements
2706: sub create_list_elements {
2707: my @formarr = @_;
2708: my $list = '';
2709: for my $button (@formarr){
2710: for my $picture(keys %$button) {
2711: #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
2712: $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2713: }
2714: }
2715: return $list;
2716: }
2717:
2718: # subroutine to create ul from list elements
2719: sub create_form_ul {
2720: my $list = shift;
2721: my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2722: return $ul;
2723: }
2724:
2725: # get course data
2726: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2727: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2728:
2729: # get personal data
2730: my $uname=$env{'user.name'};
2731: my $udom=$env{'user.domain'};
2732: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2733:
2734: # graphics settings
2735:
2736: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2737:
2738: if ($allowed) {
2739: $script .= &editing_js($udom,$uname);
2740: }
2741: # -------------------------------------------------------------------- Body tag
2742: $script = '<script type="text/javascript">'."\n"
2743: .'// <![CDATA['."\n"
2744: .$script."\n"
2745: .'// ]]>'."\n"
2746: .'</script>'."\n";
2747: my $brcrum = [{href=>"/adm/createuser",text=>"$type Documents"}];
2748: $r->print(&Apache::loncommon::start_page("$type Documents", $script,
2749: {'force_register' => $showdoc,
2750: 'bread_crumbs' => $brcrum}).
2751: &Apache::loncommon::help_open_menu('','',273,'RAT'));
2752:
2753: my %allfiles = ();
2754: my %codebase = ();
2755: my ($upload_result,$upload_output);
2756: if ($allowed) {
2757: if (($env{'form.uploaddoc.filename'}) &&
2758: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
2759: # Process file upload - phase one - upload and parse primary file.
2760: undef($hadchanges);
2761: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2762: $coursedom,\%allfiles,
2763: \%codebase,$1);
2764: if ($hadchanges) {
2765: &mark_hash_old();
2766: }
2767: if ($upload_result eq 'phasetwo') {
2768: $r->print($upload_output);
2769: }
2770: } elsif ($env{'form.phasetwo'}) {
2771: my %newname = ();
2772: my %origname = ();
2773: my %attribs = ();
2774: my $updateflag = 0;
2775: my $residx = $env{'form.newidx'};
2776: my $primary_url = &unescape($env{'form.primaryurl'});
2777: # Process file upload - phase two - gather secondary files.
2778: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2779: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2780: my $javacodebase;
2781: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2782: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2783: if (exists($env{'form.embedded_codebase_'.$i})) {
2784: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2785: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2786: }
2787: my @attributes = ();
2788: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2789: @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
2790: } else {
2791: @attributes = ($env{'form.embedded_attrib_'.$i});
2792: }
2793: foreach my $attr (@attributes) {
2794: push(@{$attribs{$i}},&unescape($attr));
2795: }
2796: if ($javacodebase) {
2797: $codebase{$i} = $javacodebase;
2798: $codebase{$i} =~ s#/$##;
2799: $updateflag = 1;
2800: }
2801: }
2802: unless ($newname{$i} eq $origname{$i}) {
2803: $updateflag = 1;
2804: }
2805: }
2806: # Process file upload - phase three - modify primary file
2807: if ($updateflag) {
2808: my ($content,$rtncode);
2809: my $updateflag = 0;
2810: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2811: if ($getstatus eq 'ok') {
2812: foreach my $item (keys(%newname)) {
2813: if ($newname{$item} ne $origname{$item}) {
2814: my $attrib_regexp = '';
2815: if (@{$attribs{$item}} > 1) {
2816: $attrib_regexp = join('|',@{$attribs{$item}});
2817: } else {
2818: $attrib_regexp = $attribs{$item}[0];
2819: }
2820: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2821: }
2822: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2823: }
2824: if (exists($codebase{$item})) {
2825: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2826: }
2827: }
2828: # Save edited file.
2829: my $saveresult;
2830: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2831: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2832: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2833: } else {
2834: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2835: }
2836: }
2837: }
2838: }
2839:
2840: unless ($showdoc || $upload_result eq 'phasetwo') {
2841: # -----------------------------------------------------------------------------
2842: my %lt=&Apache::lonlocal::texthash(
2843: 'uplm' => 'Upload a new main '.lc($type).' document',
2844: 'upls' => 'Upload a new supplemental '.lc($type).' document',
2845: 'impp' => 'Import a document',
2846: 'copm' => 'All documents out of a published map into this folder',
2847: 'upld' => 'Upload Document',
2848: 'srch' => 'Search',
2849: 'impo' => 'Import',
2850: 'book' => 'Import Bookmarks',
2851: 'selm' => 'Select Map',
2852: 'load' => 'Load Map',
2853: 'reco' => 'Recover Deleted Resources',
2854: 'newf' => 'New Folder',
2855: 'newp' => 'New Composite Page',
2856: 'extr' => 'External Resource',
2857: 'syll' => 'Syllabus',
2858: 'navc' => 'Navigate Contents',
2859: 'sipa' => 'Simple Course Page',
2860: 'sipr' => 'Simple Problem',
2861: 'drbx' => 'Drop Box',
2862: 'scuf' => 'Score Upload Form',
2863: 'bull' => 'Discussion Board',
2864: 'mypi' => 'My Personal Information Page',
2865: 'grpo' => 'Group Portfolio',
2866: 'rost' => 'Course Roster',
2867: 'abou' => 'Personal Information Page for a User',
2868: 'imsf' => 'IMS Import',
2869: 'imsl' => 'Import IMS package',
2870: 'file' => 'File',
2871: 'title' => 'Title',
2872: 'comment' => 'Comment',
2873: 'parse' => 'Upload embedded images/multimedia files if HTML file!',
2874: 'nd' => 'Upload Document',
2875: 'pm' => 'Published Map',
2876: 'sd' => 'Special Document',
2877: 'mo' => 'More Options',
2878: );
2879: # -----------------------------------------------------------------------------
2880: my $fileupload=(<<FIUP);
2881: $lt{'file'}:<br />
2882: <input type="file" name="uploaddoc" size="40" />
2883: FIUP
2884:
2885: my $checkbox=(<<CHBO);
2886: <!-- <label>$lt{'parse'}?
2887: <input type="checkbox" name="parserflag" />
2888: </label> -->
2889: <label>
2890: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2891: </label>
2892: CHBO
2893:
2894: my @fileuploada = (
2895: { pic01 => "<a onclick='document.uploaddocument.submit()'>$lt{'upld'}</a> $help{'Uploading_From_Harddrive'}" },
2896: );
2897: my $fileuploadform=(<<FUFORM);
2898: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2899: <input type="hidden" name="active" value="aa" />
2900: $fileupload
2901: <br />
2902: $lt{'title'}:<br />
2903: <input type="text" size="50" name="comment" />
2904: $uploadtag
2905: <input type="hidden" name="cmd" value="upload_default" />
2906: <br />
2907: <span class="LC_nobreak">
2908: $checkbox
2909: </span>
2910: FUFORM
2911: $fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
2912: $fileuploadform .= (<<FUFORM);
2913: </form>
2914: FUFORM
2915:
2916: my $simpleeditdefaultform=(<<SEDFFORM);
2917: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2918: <input type="hidden" name="active" value="bb" />
2919: SEDFFORM
2920: my @simpleeditdefaultforma = (
2921: { pic03 => "$uploadtag<a onclick='javascript:groupsearch()'>$lt{'srch'}</a>" },
2922: { pic04 => "<a onclick='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
2923: { pic05 => "<a onclick='javascript:groupopen(0,1,1);'>$lt{'book'}</a>" },
2924: );
2925: $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
2926: $simpleeditdefaultform .=(<<SEDFFORM);
2927: <hr />
2928: <p>
2929: $lt{'copm'}<br />
2930: <input type="text" size="40" name="importmap" /><br />
2931: <span class="LC_nobreak"><input type="button"
2932: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2933: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2934: $help{'Load_Map'}</span>
2935: </p>
2936: </form>
2937: SEDFFORM
2938:
2939: my $extresourcesform=(<<ERFORM);
2940: <form action="/adm/coursedocs" method="post" name="newext">
2941: $uploadtag
2942: <input type="hidden" name="importdetail" value="" />
2943: <a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
2944: </form>
2945: ERFORM
2946:
2947: if ($allowed) {
2948: &update_paste_buffer($coursenum,$coursedom);
2949: my %lt=&Apache::lonlocal::texthash(
2950: 'vc' => 'Verify Content',
2951: 'cv' => 'Check/Set Resource Versions',
2952: 'ls' => 'List Symbs',
2953: 'sl' => 'Show Log'
2954: );
2955:
2956: my $folderpath=$env{'form.folderpath'};
2957: if (!$folderpath) {
2958: if ($env{'form.folder'} eq '' ||
2959: $env{'form.folder'} eq 'supplemental') {
2960: $folderpath='default&'.
2961: &escape(&mt('Main '.$type.' Documents'));
2962: }
2963: }
2964: unless ($env{'form.pagepath'}) {
2965: $containertag = '<input type="hidden" name="folderpath" value="" />';
2966: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
2967: }
2968: $r->print(<<HIDDENFORM);
2969: <form name="renameform" method="post" action="/adm/coursedocs">
2970: <input type="hidden" name="title" />
2971: <input type="hidden" name="cmd" />
2972: <input type="hidden" name="markcopy" />
2973: <input type="hidden" name="copyfolder" />
2974: $containertag
2975: </form>
2976: <form name="simpleedit" method="post" action="/adm/coursedocs">
2977: <input type="hidden" name="importdetail" value="" />
2978: $uploadtag
2979: </form>
2980: HIDDENFORM
2981: }
2982: # --------------------------------------------------------- Main tab structure
2983:
2984: my $activeClass = 1;
2985: my $active = '';
2986:
2987: $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
2988: if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
2989: if($activeClass == 1){
2990: $active = 'class="active"';
2991: $activeClass = 0;
2992: }
2993: }
2994: if($env{'request.role'}=~/^cc/){
2995: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.&mt('Main Course Documents').'</b></a></li>');
2996: }
2997: $active = '';
2998: if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
2999: if($activeClass == 1){
3000: $active = 'class="active"';
3001: }
3002: }
3003: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.&mt('Supplemental Course Documents').'</b></a></li>');
3004: $r->print('</ul>'
3005: .'<div class="LC_Box" style="clear:both;margin:0;">'
3006: .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
3007: # --------------------------------------------------------- Standard documents
3008: my $savefolderpath;
3009: my $active = 'style="display: none;"';
3010: if($activeClass == 0){
3011: $active = 'style="display: block;"';
3012: }
3013: if($env{'request.role'}=~/^cc/){
3014: $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
3015: my $folder=$env{'form.folder'};
3016: if ($folder eq '' || $folder=~/^supplemental/) {
3017: $folder='default';
3018: $savefolderpath = $env{'form.folderpath'};
3019: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
3020: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3021: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3022: }
3023: my $postexec='';
3024: if ($folder eq 'default') {
3025: $r->print('<script type="text/javascript">'."\n"
3026: .'// <![CDATA['."\n"
3027: .'this.window.name="loncapaclient";'."\n"
3028: .'// ]]>'."\n"
3029: .'</script>'."\n"
3030: );
3031: } else {
3032: #$postexec='self.close();';
3033: }
3034: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3035: '.sequence';
3036: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3037: '.page';
3038: my $container='sequence';
3039: if ($env{'form.pagepath'}) {
3040: $container='page';
3041: }
3042: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3043:
3044:
3045:
3046: my $recoverform=(<<RFORM);
3047: <form action="/adm/groupsort" method="post" name="recover">
3048: <a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
3049: </form>
3050: RFORM
3051:
3052: my $imspform=(<<IMSPFORM);
3053: <form action="/adm/imsimportdocs" method="post" name="ims">
3054: <input type="hidden" name="folder" value="$folder" />
3055: <a onclick="javascript:makeims();">$lt{'imsf'}</a>
3056: </form>
3057: IMSPFORM
3058:
3059: my $newnavform=(<<NNFORM);
3060: <form action="/adm/coursedocs" method="post" name="newnav">
3061: <input type="hidden" name="active" value="cc" />
3062: $uploadtag
3063: <input type="hidden" name="importdetail"
3064: value="$lt{'navc'}=/adm/navmaps" />
3065: <a onclick="document.newnav.submit()">$lt{'navc'}</a>
3066: $help{'Navigate_Content'}
3067: </form>
3068: NNFORM
3069: my $newsmppageform=(<<NSPFORM);
3070: <form action="/adm/coursedocs" method="post" name="newsmppg">
3071: <input type="hidden" name="active" value="cc" />
3072: $uploadtag
3073: <input type="hidden" name="importdetail" value="" />
3074: <a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
3075: $help{'Simple Page'}
3076: </form>
3077: NSPFORM
3078:
3079: my $newsmpproblemform=(<<NSPROBFORM);
3080: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
3081: <input type="hidden" name="active" value="cc" />
3082: $uploadtag
3083: <input type="hidden" name="importdetail" value="" />
3084: <a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
3085: $help{'Simple Problem'}
3086: </form>
3087:
3088: NSPROBFORM
3089:
3090: my $newdropboxform=(<<NDBFORM);
3091: <form action="/adm/coursedocs" method="post" name="newdropbox">
3092: <input type="hidden" name="active" value="cc" />
3093: $uploadtag
3094: <input type="hidden" name="importdetail" value="" />
3095: <a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
3096: </form>
3097: NDBFORM
3098:
3099: my $newexuploadform=(<<NEXUFORM);
3100: <form action="/adm/coursedocs" method="post" name="newexamupload">
3101: <input type="hidden" name="active" value="cc" />
3102: $uploadtag
3103: <input type="hidden" name="importdetail" value="" />
3104: <a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
3105: $help{'Score_Upload_Form'}
3106: </form>
3107: NEXUFORM
3108:
3109: my $newbulform=(<<NBFORM);
3110: <form action="/adm/coursedocs" method="post" name="newbul">
3111: <input type="hidden" name="active" value="cc" />
3112: $uploadtag
3113: <input type="hidden" name="importdetail" value="" />
3114: <a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
3115: $help{'Bulletin Board'}
3116: </form>
3117: NBFORM
3118:
3119: my $newaboutmeform=(<<NAMFORM);
3120: <form action="/adm/coursedocs" method="post" name="newaboutme">
3121: <input type="hidden" name="active" value="cc" />
3122: $uploadtag
3123: <input type="hidden" name="importdetail"
3124: value="$plainname=/adm/$udom/$uname/aboutme" />
3125: <a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
3126: $help{'My Personal Information Page'}
3127: </form>
3128: NAMFORM
3129:
3130: my $newaboutsomeoneform=(<<NASOFORM);
3131: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
3132: <input type="hidden" name="active" value="cc" />
3133: $uploadtag
3134: <input type="hidden" name="importdetail" value="" />
3135: <a onclick="javascript:makeabout();">$lt{'abou'}</a>
3136: </form>
3137: NASOFORM
3138:
3139:
3140: my $newrosterform=(<<NROSTFORM);
3141: <form action="/adm/coursedocs" method="post" name="newroster">
3142: <input type="hidden" name="active" value="cc" />
3143: $uploadtag
3144: <input type="hidden" name="importdetail"
3145: value="$lt{'rost'}=/adm/viewclasslist" />
3146: <a onclick="document.newroster.submit()">$lt{'rost'}</a>
3147: $help{'Course Roster'}
3148: </form>
3149: NROSTFORM
3150:
3151: my $specialdocumentsform;
3152: my @specialdocumentsforma;
3153: my $newfolderform;
3154:
3155: unless ($env{'form.pagepath'}) {
3156: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3157:
3158: my $newpageform=(<<NPFORM);
3159: <form action="/adm/coursedocs" method="post" name="newpage">
3160: <input type="hidden" name="folderpath" value="$path" />
3161: <input type="hidden" name="importdetail" value="" />
3162: <input type="hidden" name="active" value="cc" />
3163: <a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
3164: $help{'Adding_Pages'}
3165: </form>
3166: NPFORM
3167:
3168: $newfolderform=(<<NFFORM);
3169: <form action="/adm/coursedocs" method="post" name="newfolder">
3170: <input type="hidden" name="folderpath" value="$path" />
3171: <input type="hidden" name="importdetail" value="" />
3172: <input type="hidden" name="active" value="aa" />
3173: <a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
3174: </form>
3175: NFFORM
3176: my @newfolderforma= (
3177: { pic02 => "$newfolderform" }
3178: );
3179:
3180:
3181: $newfolderform = create_form_ul(create_list_elements(@newfolderforma));
3182:
3183: my $newsylform=(<<NSYLFORM);
3184: <form action="/adm/coursedocs" method="post" name="newsyl">
3185: <input type="hidden" name="active" value="cc" />
3186: $uploadtag
3187: <input type="hidden" name="importdetail"
3188: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
3189: <a onclick="document.newsyl.submit()">$lt{'syll'}</a>
3190: $help{'Syllabus'}
3191:
3192: </form>
3193: NSYLFORM
3194:
3195: my $newgroupfileform=(<<NGFFORM);
3196: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
3197: <input type="hidden" name="active" value="cc" />
3198: $uploadtag
3199: <input type="hidden" name="importdetail"
3200: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
3201: <a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
3202: $help{'Group Portfolio'}
3203: </form>
3204: NGFFORM
3205: @specialdocumentsforma=(
3206: {pic06=>$newpageform},
3207: {pic07=>$newsylform},
3208: {pic08=>$newgroupfileform},
3209: );
3210:
3211: }
3212: push @specialdocumentsforma, ({pic09=>$newnavform},
3213: {pic10=>$newsmppageform},
3214: {pic11=>$newsmpproblemform},
3215: {pic12=>$newdropboxform},
3216: {pic13=>$newexuploadform},
3217: {pic14=>$newbulform},
3218: {pic15=>$newaboutmeform},
3219: {pic16=>$newaboutsomeoneform},
3220: {pic17=>$newrosterform},);
3221:
3222: $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
3223:
3224: if($env{'form.pagepath'}) {
3225:
3226: @specialdocumentsforma=(
3227: {pic32=>$newsmpproblemform},
3228: {pic33=>$newexuploadform}
3229: );
3230: $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
3231: }
3232:
3233: my @tools = (
3234: {pic18=>$extresourcesform},
3235: {pic19=>$imspform},
3236: {pic20=>$recoverform},
3237: );
3238:
3239: my %orderhash = (
3240: 'aa' => ['Upload Document',$fileuploadform.''.$newfolderform],
3241: 'bb' => ['Published Resources',$simpleeditdefaultform],
3242: 'cc' => ['Special Documents',$specialdocumentsform],
3243: 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
3244: 'zz' => ['Hide'],
3245: );
3246: my $tid='1';
3247: my $varcd = 'Main Course Documents';
3248: $r->print(&generate_edit_table($tid,$varcd,\%orderhash));
3249: $hadchanges=0;
3250: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3251: if ($error) {
3252: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3253: }
3254: if ($hadchanges) {
3255: &mark_hash_old();
3256: }
3257:
3258: &changewarning($r,'');
3259: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
3260: &mt('Editing the Table of Contents for your '.$type)));
3261: $r->print('</div>');
3262: }
3263: if ($env{'form.pagepath'}) {
3264: }
3265: # ----------------------------------------------------- Supplemental documents
3266: my $active = 'style="display: none;"';
3267: if($activeClass == 1){
3268: $active = 'style="display: block;"';
3269: }
3270: $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
3271: my $folder=$env{'form.folder'};
3272: unless ($folder=~/^supplemental/) {
3273: $folder='supplemental';
3274: }
3275: if ($folder =~ /^supplemental$/ &&
3276: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3277: $env{'form.folderpath'} = 'supplemental&'.
3278: &escape(&mt('Supplemental '.$type.' Documents'));
3279: }else{
3280: $env{'form.folderpath'} = $savefolderpath;
3281: }
3282: $env{'form.pagepath'} = '';
3283: if ($allowed) {
3284: my $folderseq=
3285: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3286: '.sequence';
3287:
3288: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3289:
3290: my @supupdocform = (
3291: {pic27=>"<a onclick='document.supuploaddocument.submit()'>$lt{'upld'}</a>$help{'Uploading_From_Harddrive'}"},
3292: );
3293: my $supupdocform=(<<SUPDOCFORM);
3294: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
3295: <input type="hidden" name="active" value="ee" />
3296: $fileupload
3297: <br />
3298: <br />
3299: <span class="LC_nobreak">
3300: $checkbox
3301: </span>
3302: <br /><br />
3303: $lt{'comment'}:<br />
3304: <textarea cols="50" rows="4" name="comment"></textarea>
3305: <br />
3306: <input type="hidden" name="folderpath" value="$path" />
3307: <input type="hidden" name="cmd" value="upload_supplemental" />
3308: SUPDOCFORM
3309: $supupdocform .= create_form_ul(create_list_elements(@supupdocform))."</form>";
3310:
3311: my $supnewfolderform=(<<SNFFORM);
3312: <form action="/adm/coursedocs" method="post" name="supnewfolder">
3313: <input type="hidden" name="active" value="ee" />
3314: <input type="hidden" name="folderpath" value="$path" />
3315: <input type="hidden" name="importdetail" value="" />
3316: <a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
3317: $help{'Adding_Folders'}
3318: </form>
3319: SNFFORM
3320:
3321: my @supnewfolderforma = ({pic28=>$supnewfolderform});
3322: $supnewfolderform = create_form_ul(create_list_elements(@supnewfolderforma));
3323:
3324:
3325: my $supnewextform=(<<SNEFORM);
3326: <form action="/adm/coursedocs" method="post" name="supnewext">
3327: <input type="hidden" name="active" value="ff" />
3328: <input type="hidden" name="folderpath" value="$path" />
3329: <input type="hidden" name="importdetail" value="" />
3330: <a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
3331: </form>
3332: SNEFORM
3333:
3334: my $supnewsylform=(<<SNSFORM);
3335: <form action="/adm/coursedocs" method="post" name="supnewsyl">
3336: <input type="hidden" name="active" value="ff" />
3337: <input type="hidden" name="folderpath" value="$path" />
3338: <input type="hidden" name="importdetail"
3339: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
3340: <a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
3341: $help{'Syllabus'}
3342: </form>
3343: SNSFORM
3344:
3345: my $supnewaboutmeform=(<<SNAMFORM);
3346: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
3347: <input type="hidden" name="active" value="ff" />
3348: <input type="hidden" name="folderpath" value="$path" />
3349: <input type="hidden" name="importdetail"
3350: value="$plainname=/adm/$udom/$uname/aboutme" />
3351: <a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
3352: $help{'My Personal Information Page'}
3353: </form>
3354: SNAMFORM
3355:
3356:
3357: my @specialdocs = (
3358: {pic29=>$supnewextform},
3359: {pic30=>$supnewsylform},
3360: {pic31=>$supnewaboutmeform},
3361: );
3362: my %suporderhash = (
3363: 'ee' => ['Upload Document',$supupdocform.' '.$supnewfolderform],
3364: 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))],
3365: 'zz' => ['Hide'],
3366: );
3367:
3368: my $tid='2';
3369: my $varscd = 'Supplemental Course Documents';
3370:
3371: $r->print(&generate_edit_table($tid,$varscd,\%suporderhash));
3372: }
3373:
3374: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3375: if ($error) {
3376: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3377: }
3378: $r->print('</div>');
3379: $r->print('</div></div>');
3380:
3381:
3382: if ($allowed) {
3383: $r->print('
3384: <form method="post" name="extimport" action="/adm/coursedocs">
3385: <input type="hidden" name="title" />
3386: <input type="hidden" name="url" />
3387: <input type="hidden" name="useform" />
3388: <input type="hidden" name="residx" />
3389: </form>');
3390: }
3391: } else {
3392: unless ($upload_result eq 'phasetwo') {
3393: # -------------------------------------------------------- This is showdoc mode
3394: $r->print("<h1>".&mt('Uploaded Document').' - '.
3395: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3396: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3397: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3398: }
3399: }
3400: }
3401: $r->print(&Apache::loncommon::end_page());
3402: return OK;
3403: }
3404:
3405: sub generate_admin_options {
3406: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3407: my %lt=&Apache::lonlocal::texthash(
3408: 'vc' => 'Verify Content',
3409: 'cv' => 'Check/Set Resource Versions',
3410: 'ls' => 'List Symbs',
3411: 'sl' => 'Show Log'
3412: );
3413: my %help = %{$help_ref};
3414: my %env = %{$env_ref};
3415: my $dumpbut=&dumpbutton();
3416: my $exportbut=&exportbutton();
3417: my @list = (
3418: {pic21=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
3419: {pic22=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
3420: );
3421: if($dumpbut ne ''){
3422: push @list, {pic23=>$dumpbut};
3423: }
3424: push @list, ({pic24=>$exportbut},
3425: {pic25=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"listsymbs\", \"$lt{'ls'}\")'>$lt{'ls'}</a><input type='hidden' name='folder' value='$env{'form.folder'}' />"},
3426: {pic26=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
3427: );
3428: return '<form action="/adm/coursedocs" method="post" name="courseverify"><input type="hidden" id="dummy" />'.create_form_ul(create_list_elements(@list)).'</form>';
3429:
3430: }
3431:
3432:
3433: sub generate_edit_table {
3434: my ($tid,$varcd,$orderhash_ref) = @_;
3435: my %orderhash = %{$orderhash_ref};
3436: my $form;
3437: my $activetab;
3438: my $active;
3439: if($env{'form.active'} ne ''){
3440: $activetab = $env{'form.active'};
3441: }
3442: $form = '<div class="LC_Box">';
3443: $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
3444: foreach my $name (sort(keys(%orderhash))){
3445: if($name eq 'zz'){
3446: if($activetab ne ''){
3447: $active = 'class="right"';
3448: }else{
3449: $active = 'class="right active"';
3450: }
3451: $form .= '<li onclick="javascript:hideAll(this, \'navigation'.$tid.'\' ,\'content'.$tid.'\');" '.$active.'>'.&mt(${$orderhash{$name}}[0]).'</li>';
3452: }else{
3453: if($activetab eq '' || $activetab ne $name){
3454: $active = '';
3455: }elsif($activetab eq $name){
3456: $active = 'class="active"';
3457: }
3458: $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
3459: }
3460: }
3461: $form .= '</ul>';
3462: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0;">';
3463: foreach my $field (keys(%orderhash)){
3464: if($field ne 'zz'){
3465: if($activetab eq '' || $activetab ne $field){
3466: $active = 'style="display: none;"';
3467: }elsif($activetab eq $field){
3468: $active = 'style="display:block;"';
3469: }
3470: $form .= '<div id="'.$field.$tid.'"'
3471: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3472: .'</div>';
3473: }
3474: }
3475: $form .= '</div></div>';
3476:
3477: return $form;
3478: }
3479:
3480: sub editing_js {
3481: my ($udom,$uname) = @_;
3482: my $now = time();
3483: my %lt = &Apache::lonlocal::texthash(
3484: p_mnf => 'Name of New Folder',
3485: t_mnf => 'New Folder',
3486: p_mnp => 'Name of New Page',
3487: t_mnp => 'New Page',
3488: p_mxu => 'Title for the Uploaded Score',
3489: p_msp => 'Name of Simple Course Page',
3490: p_msb => 'Title for the Problem',
3491: p_mdb => 'Title for the Drop Box',
3492: p_mbb => 'Title for the Discussion Board',
3493: p_mab => "Enter user:domain for User's Personal Information Page",
3494: p_mab2 => 'Personal Information Page of ',
3495: p_mab_alrt1 => 'Not a valid user:domain',
3496: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3497: p_chn => 'New Title',
3498: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3499: p_rmr2a => 'Remove[_99]',
3500: p_rmr2b => '?[_99]',
3501: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3502: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3503: p_ctr2a => 'Cut[_98]',
3504: p_ctr2b => '?[_98]'
3505: );
3506:
3507: return <<ENDNEWSCRIPT;
3508: function makenewfolder(targetform,folderseq) {
3509: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3510: if (foldername) {
3511: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3512: targetform.submit();
3513: }
3514: }
3515:
3516: function makenewpage(targetform,folderseq) {
3517: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3518: if (pagename) {
3519: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3520: targetform.submit();
3521: }
3522: }
3523:
3524: function makenewext(targetname) {
3525: this.document.forms.extimport.useform.value=targetname;
3526: this.document.forms.extimport.title.value='';
3527: this.document.forms.extimport.url.value='';
3528: this.document.forms.extimport.residx.value='';
3529: window.open('/adm/rat/extpickframe.html');
3530: }
3531:
3532: function edittext(targetname,residx,title,url) {
3533: this.document.forms.extimport.useform.value=targetname;
3534: this.document.forms.extimport.residx.value=residx;
3535: this.document.forms.extimport.url.value=url;
3536: this.document.forms.extimport.title.value=title;
3537: window.open('/adm/rat/extpickframe.html');
3538: }
3539:
3540: function makeexamupload() {
3541: var title=prompt('$lt{"p_mxu"}');
3542: if (title) {
3543: this.document.forms.newexamupload.importdetail.value=
3544: escape(title)+'=/res/lib/templates/examupload.problem';
3545: this.document.forms.newexamupload.submit();
3546: }
3547: }
3548:
3549: function makesmppage() {
3550: var title=prompt('$lt{"p_msp"}');
3551: if (title) {
3552: this.document.forms.newsmppg.importdetail.value=
3553: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3554: this.document.forms.newsmppg.submit();
3555: }
3556: }
3557:
3558: function makesmpproblem() {
3559: var title=prompt('$lt{"p_msb"}');
3560: if (title) {
3561: this.document.forms.newsmpproblem.importdetail.value=
3562: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3563: this.document.forms.newsmpproblem.submit();
3564: }
3565: }
3566:
3567: function makedropbox() {
3568: var title=prompt('$lt{"p_mdb"}');
3569: if (title) {
3570: this.document.forms.newdropbox.importdetail.value=
3571: escape(title)+'=/res/lib/templates/DropBox.problem';
3572: this.document.forms.newdropbox.submit();
3573: }
3574: }
3575:
3576: function makebulboard() {
3577: var title=prompt('$lt{"p_mbb"}');
3578: if (title) {
3579: this.document.forms.newbul.importdetail.value=
3580: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3581: this.document.forms.newbul.submit();
3582: }
3583: }
3584:
3585: function makeabout() {
3586: var user=prompt("$lt{'p_mab'}");
3587: if (user) {
3588: var comp=new Array();
3589: comp=user.split(':');
3590: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3591: if ((comp[0]) && (comp[1])) {
3592: this.document.forms.newaboutsomeone.importdetail.value=
3593: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
3594: this.document.forms.newaboutsomeone.submit();
3595: } else {
3596: alert("$lt{'p_mab_alrt1'}");
3597: }
3598: } else {
3599: alert("$lt{'p_mab_alrt2'}");
3600: }
3601: }
3602: }
3603:
3604: function makeims() {
3605: var caller = document.forms.ims.folder.value;
3606: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3607: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3608: newWindow.location.href = newlocation;
3609: }
3610:
3611:
3612: function finishpick() {
3613: var title=this.document.forms.extimport.title.value;
3614: var url=this.document.forms.extimport.url.value;
3615: var form=this.document.forms.extimport.useform.value;
3616: var residx=this.document.forms.extimport.residx.value;
3617: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
3618: }
3619:
3620: function changename(folderpath,index,oldtitle,container,pagesymb) {
3621: var title=prompt('$lt{"p_chn"}',oldtitle);
3622: if (title) {
3623: this.document.forms.renameform.markcopy.value=-1;
3624: this.document.forms.renameform.title.value=title;
3625: this.document.forms.renameform.cmd.value='rename_'+index;
3626: if (container == 'sequence') {
3627: this.document.forms.renameform.folderpath.value=folderpath;
3628: }
3629: if (container == 'page') {
3630: this.document.forms.renameform.pagepath.value=folderpath;
3631: this.document.forms.renameform.pagesymb.value=pagesymb;
3632: }
3633: this.document.forms.renameform.submit();
3634: }
3635: }
3636:
3637: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
3638: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3639: this.document.forms.renameform.markcopy.value=-1;
3640: this.document.forms.renameform.cmd.value='del_'+index;
3641: if (container == 'sequence') {
3642: this.document.forms.renameform.folderpath.value=folderpath;
3643: }
3644: if (container == 'page') {
3645: this.document.forms.renameform.pagepath.value=folderpath;
3646: this.document.forms.renameform.pagesymb.value=pagesymb;
3647: }
3648: this.document.forms.renameform.submit();
3649: }
3650: }
3651:
3652: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
3653: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3654: this.document.forms.renameform.cmd.value='cut_'+index;
3655: this.document.forms.renameform.markcopy.value=index;
3656: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3657: if (container == 'sequence') {
3658: this.document.forms.renameform.folderpath.value=folderpath;
3659: }
3660: if (container == 'page') {
3661: this.document.forms.renameform.pagepath.value=folderpath;
3662: this.document.forms.renameform.pagesymb.value=pagesymb;
3663: }
3664: this.document.forms.renameform.submit();
3665: }
3666: }
3667:
3668: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
3669: this.document.forms.renameform.markcopy.value=index;
3670: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3671: if (container == 'sequence') {
3672: this.document.forms.renameform.folderpath.value=folderpath;
3673: }
3674: if (container == 'page') {
3675: this.document.forms.renameform.pagepath.value=folderpath;
3676: this.document.forms.renameform.pagesymb.value=pagesymb;
3677: }
3678: this.document.forms.renameform.submit();
3679: }
3680:
3681: function unselectInactive(nav) {
3682: currentNav = document.getElementById(nav);
3683: currentLis = currentNav.getElementsByTagName('LI');
3684: for (i = 0; i < currentLis.length; i++) {
3685: if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
3686: currentLis[i].className = 'right';
3687: }else{
3688: currentLis[i].className = 'i';
3689: }
3690: }
3691: }
3692:
3693: function hideAll(current, nav, data) {
3694: unselectInactive(nav);
3695: if(current.className == 'right'){
3696: current.className = 'right active'
3697: }else{
3698: current.className = 'active';
3699: }
3700: currentData = document.getElementById(data);
3701: currentDivs = currentData.getElementsByTagName('DIV');
3702: for (i = 0; i < currentDivs.length; i++) {
3703: if(currentDivs[i].className == 'LC_ContentBox'){
3704: currentDivs[i].style.display = 'none';
3705: }
3706: }
3707: }
3708:
3709: function openTabs(pageId) {
3710: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
3711: if(tabnav.length > 2 ){
3712: currentNav = document.getElementById(tabnav[0].id);
3713: currentLis = currentNav.getElementsByTagName('LI');
3714: for(i = 0; i< currentLis.length; i++){
3715: if(currentLis[i].className == 'active') {
3716: funcString = currentLis[i].onclick.toString();
3717: tab = funcString.split('"');
3718: currentData = document.getElementById(tab[1]);
3719: currentData.style.display = 'block';
3720: }
3721: }
3722: }
3723: }
3724:
3725: function showPage(current, pageId, nav, data) {
3726: hideAll(current, nav, data);
3727: openTabs(pageId);
3728: unselectInactive(nav);
3729: current.className = 'active';
3730: currentData = document.getElementById(pageId);
3731: currentData.style.display = 'block';
3732: return false;
3733: }
3734:
3735: function injectData(current, hiddenField, name, value) {
3736: currentElement = document.getElementById(hiddenField);
3737: currentElement.name = name;
3738: currentElement.value = value;
3739: current.submit();
3740: }
3741:
3742: ENDNEWSCRIPT
3743: }
3744: 1;
3745: __END__
3746:
3747:
3748: =head1 NAME
3749:
3750: Apache::londocs.pm
3751:
3752: =head1 SYNOPSIS
3753:
3754: This is part of the LearningOnline Network with CAPA project
3755: described at http://www.lon-capa.org.
3756:
3757: =head1 SUBROUTINES
3758:
3759: =over
3760:
3761: =item %help=()
3762:
3763: Available help topics
3764:
3765: =item mapread()
3766:
3767: Mapread read maps into LONCAPA::map:: global arrays
3768: @order and @resources, determines status
3769: sets @order - pointer to resources in right order
3770: sets @resources - array with the resources with correct idx
3771:
3772: =item authorhosts()
3773:
3774: Return hash with valid author names
3775:
3776: =item dumpbutton()
3777:
3778: Generate "dump" button
3779:
3780: =item clean()
3781:
3782: =item dumpcourse()
3783:
3784: Actually dump course
3785:
3786:
3787: =item exportbutton()
3788:
3789: Generate "export" button
3790:
3791: =item exportcourse()
3792:
3793: =item create_ims_store()
3794:
3795: =item build_package()
3796:
3797: =item get_dependencies()
3798:
3799: =item process_content()
3800:
3801: =item replicate_content()
3802:
3803: =item extract_media()
3804:
3805: =item store_template()
3806:
3807: =item group_import()
3808:
3809: Imports the given (name, url) resources into the course
3810: coursenum, coursedom, and folder must precede the list
3811:
3812: =item breadcrumbs()
3813:
3814: =item log_docs()
3815:
3816: =item docs_change_log()
3817:
3818: =item update_paste_buffer()
3819:
3820: =item print_paste_buffer()
3821:
3822: =item do_paste_from_buffer()
3823:
3824: =item update_parameter()
3825:
3826: =item handle_edit_cmd()
3827:
3828: =item editor()
3829:
3830: =item process_file_upload()
3831:
3832: =item process_secondary_uploads()
3833:
3834: =item is_supplemental_title()
3835:
3836: =item parse_supplemental_title()
3837:
3838: =item entryline()
3839:
3840: =item tiehash()
3841:
3842: =item untiehash()
3843:
3844: =item checkonthis()
3845:
3846: check on this
3847:
3848: =item verifycontent()
3849:
3850: Verify Content
3851:
3852: =item devalidateversioncache() & checkversions()
3853:
3854: Check Versions
3855:
3856: =item mark_hash_old()
3857:
3858: =item is_hash_old()
3859:
3860: =item changewarning()
3861:
3862: =item init_breadcrumbs()
3863:
3864: Breadcrumbs for special functions
3865:
3866: =back
3867:
3868: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>