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