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