Annotation of loncom/interface/londocs.pm, revision 1.330
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.330 ! tempelho 4: # $Id: londocs.pm,v 1.329 2009/01/28 18:10:04 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); }
75:
76: $hadchanges=1;
77: return ($errtext,0);
78: }
79:
80:
81:
82: sub authorhosts {
83: my %outhash=();
84: my $home=0;
85: my $other=0;
86: foreach my $key (keys(%env)) {
87: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
88: my $role=$1;
89: my $realm=$2;
90: my ($start,$end)=split(/\./,$env{$key});
91: if (($start) && ($start>time)) { next; }
92: if (($end) && (time>$end)) { next; }
93: my ($ca,$cd);
94: if ($1 eq 'au') {
95: $ca=$env{'user.name'};
96: $cd=$env{'user.domain'};
97: } else {
98: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
99: }
100: my $allowed=0;
101: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
102: my @ids=&Apache::lonnet::current_machine_ids();
103: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
104: if ($allowed) {
105: $home++;
106: $outhash{'home_'.$ca.'@'.$cd}=1;
107: } else {
108: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
109: $other++;
110: }
111: }
112: }
113: return ($home,$other,%outhash);
114: }
115:
116:
117: sub dumpbutton {
118: my ($home,$other,%outhash)=&authorhosts();
119: my $type = &Apache::loncommon::course_type();
120: if ($home+$other==0) { return ''; }
121: if ($home) {
122: return '<input type="submit" name="dumpcourse" value="'.
123: &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
124: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
125: } else {
126: return '<div>'.
127: &mt('Dump '.$type.
128: ' DOCS to Construction Space: available on other servers').
129: '</div>';
130: }
131: }
132:
133: sub clean {
134: my ($title)=@_;
135: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
136: return $title;
137: }
138:
139:
140:
141: sub dumpcourse {
142: my ($r) = @_;
143: my $type = &Apache::loncommon::course_type();
144: $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
145: '<form name="dumpdoc" method="post">');
146: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space'));
147: my ($home,$other,%outhash)=&authorhosts();
148: unless ($home) { return ''; }
149: my $origcrsid=$env{'request.course.id'};
150: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
151: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
152: # Do the dumping
153: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
154: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
155: $r->print('<h3>'.&mt('Copying Files').'</h3>');
156: my $title=$env{'form.authorfolder'};
157: $title=&clean($title);
158: my %replacehash=();
159: foreach my $key (keys(%env)) {
160: if ($key=~/^form\.namefor\_(.+)/) {
161: $replacehash{$1}=$env{$key};
162: }
163: }
164: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
165: $crs=~s/\_/\//g;
166: foreach my $item (keys(%replacehash)) {
167: my $newfilename=$title.'/'.$replacehash{$item};
168: $newfilename=~s/\.(\w+)$//;
169: my $ext=$1;
170: $newfilename=&clean($newfilename);
171: $newfilename.='.'.$ext;
172: my @dirs=split(/\//,$newfilename);
173: my $path='/home/'.$ca.'/public_html';
174: my $makepath=$path;
175: my $fail=0;
176: for (my $i=0;$i<$#dirs;$i++) {
177: $makepath.='/'.$dirs[$i];
178: unless (-e $makepath) {
179: unless(mkdir($makepath,0777)) { $fail=1; }
180: }
181: }
182: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
183: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
184: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
185: print $fh &Apache::lonclonecourse::rewritefile(
186: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
187: (%replacehash,$crs => '')
188: );
189: } else {
190: print $fh
191: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
192: }
193: $fh->close();
194: } else {
195: $fail=1;
196: }
197: if ($fail) {
198: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
199: } else {
200: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
201: }
202: }
203: } else {
204: # Input form
205: unless ($home==1) {
206: $r->print(
207: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
208: }
209: foreach my $key (sort(keys(%outhash))) {
210: if ($key=~/^home_(.+)$/) {
211: if ($home==1) {
212: $r->print(
213: '<input type="hidden" name="authorspace" value="'.$1.'" />');
214: } else {
215: $r->print('<option value="'.$1.'">'.$1.' - '.
216: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
217: }
218: }
219: }
220: unless ($home==1) {
221: $r->print('</select>');
222: }
223: my $title=$origcrsdata{'description'};
224: $title=~s/[\/\s]+/\_/gs;
225: $title=&clean($title);
226: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
227: .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
228: &tiehash();
229: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
230: .&Apache::loncommon::start_data_table()
231: .&Apache::loncommon::start_data_table_header_row()
232: .'<th>'.&mt('Internal Filename').'</th>'
233: .'<th>'.&mt('Title').'</th>'
234: .'<th>'.&mt('Save as ...').'</th>'
235: .&Apache::loncommon::end_data_table_header_row());
236: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
237: $r->print(&Apache::loncommon::start_data_table_row()
238: .'<td>'.$file.'</td>');
239: my ($ext)=($file=~/\.(\w+)$/);
240: my $title=$hash{'title_'.$hash{
241: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
242: $r->print('<td>'.($title?$title:' ').'</td>');
243: if (!$title) {
244: $title=$file;
245: } else {
246: $title=~s|/|_|g;
247: }
248: $title=~s/\.(\w+)$//;
249: $title=&clean($title);
250: $title.='.'.$ext;
251: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
252: .&Apache::loncommon::end_data_table_row());
253: }
254: $r->print(&Apache::loncommon::end_data_table());
255: &untiehash();
256: $r->print(
257: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $type DOCS").'" /></p></form>');
258: }
259: }
260:
261:
262:
263: sub exportbutton {
264: my $type = &Apache::loncommon::course_type();
265: return '<input type="submit" name="exportcourse" value="'.
266: &mt('Export '.$type.' to IMS').'" />'.
267: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
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()) {
400: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif"> '."\n";
401: $lastcontainer = $count + $startcount + $boards;
402: } elsif ($curRes->is_page()) {
403: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif"> '."\n";
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: }
430:
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: }
445: }
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: }
468: }
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>'.
477: '<p><input type="hidden" name="finishexport" value="1">'.
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;
762: } else {
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') {
802: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
803: $repstatus = 'ok';
804: $content = 'Not the owner of this resource';
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') {
855: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
856: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
857: $embed_content = &Apache::lonnet::getfile($embed_path);
858: unless ($embed_content eq -1) {
859: $repstatus = 'ok';
860: }
861: } elsif ($caller eq 'uploaded') {
862:
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) };
924: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
925: && ($caller eq 'londocs')
926: && (!&Apache::lonnet::stat_file($url))) {
927:
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) {
947: if (!$residx
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);
956: $LONCAPA::map::resources[$residx] =
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);
987: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
988: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
989: if ($1 ne '') {
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,
1007: 'text'=>'<font size="+1">'.
1008: $name.'</font>',
1009: 'no_mt'=>1,
1010: });
1011: $plain.=$name.' > ';
1012: }
1013: $plain=~s/\>\;\s*$//;
1014: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1015: 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1016: }
1017:
1018: sub log_docs {
1019: return &Apache::lonnet::instructor_log('docslog',@_);
1020: }
1021:
1022: {
1023: my @oldresources=();
1024: my @oldorder=();
1025: my $parmidx;
1026: my %parmaction=();
1027: my %parmvalue=();
1028: my $changedflag;
1029:
1030: sub snapshotbefore {
1031: @oldresources=@LONCAPA::map::resources;
1032: @oldorder=@LONCAPA::map::order;
1033: $parmidx=undef;
1034: %parmaction=();
1035: %parmvalue=();
1036: $changedflag=0;
1037: }
1038:
1039: sub remember_parms {
1040: my ($idx,$parameter,$action,$value)=@_;
1041: $parmidx=$idx;
1042: $parmaction{$parameter}=$action;
1043: $parmvalue{$parameter}=$value;
1044: $changedflag=1;
1045: }
1046:
1047: sub log_differences {
1048: my ($plain)=@_;
1049: my %storehash=('folder' => $plain,
1050: 'currentfolder' => $env{'form.folder'});
1051: if ($parmidx) {
1052: $storehash{'parameter_res'}=$oldresources[$parmidx];
1053: foreach my $parm (keys(%parmaction)) {
1054: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1055: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1056: }
1057: }
1058: my $maxidx=$#oldresources;
1059: if ($#LONCAPA::map::resources>$#oldresources) {
1060: $maxidx=$#LONCAPA::map::resources;
1061: }
1062: for (my $idx=0; $idx<=$maxidx; $idx++) {
1063: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1064: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1065: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1066: $changedflag=1;
1067: }
1068: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1069: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1070: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1071: $changedflag=1;
1072: }
1073: }
1074: $storehash{'maxidx'}=$maxidx;
1075: if ($changedflag) { &log_docs(\%storehash); }
1076: }
1077: }
1078:
1079:
1080:
1081:
1082:
1083: sub docs_change_log {
1084: my ($r)=@_;
1085: my $folder=$env{'form.folder'};
1086: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1087: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1088: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1089: $env{'course.'.$env{'request.course.id'}.'.domain'},
1090: $env{'course.'.$env{'request.course.id'}.'.num'});
1091:
1092: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1093:
1094: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1095: '<input type="hidden" name="docslog" value="1" />');
1096:
1097: my %saveable_parameters = ('show' => 'scalar',);
1098: &Apache::loncommon::store_course_settings('docs_log',
1099: \%saveable_parameters);
1100: &Apache::loncommon::restore_course_settings('docs_log',
1101: \%saveable_parameters);
1102: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1103: my %lt=('hiddenresource' => 'Resources hidden',
1104: 'encrypturl' => 'URL hidden',
1105: 'randompick' => 'Randomly pick',
1106: 'randomorder' => 'Randomly ordered',
1107: 'set' => 'set to',
1108: 'del' => 'deleted');
1109: $r->print(&Apache::loncommon::display_filter().
1110: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1111: '<input type="submit" value="'.&mt('Display').'" /></form>');
1112: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1113: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1114: &mt('After').'</th>'.
1115: &Apache::loncommon::end_data_table_header_row());
1116: my $shown=0;
1117: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1118: if ($env{'form.displayfilter'} eq 'currentfolder') {
1119: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1120: }
1121: my @changes=keys(%{$docslog{$id}{'logentry'}});
1122: if ($env{'form.displayfilter'} eq 'containing') {
1123: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1124: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1125: foreach my $key (@changes) {
1126: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1127: }
1128: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1129: }
1130: my $count = 0;
1131: my $time =
1132: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1133: my $plainname =
1134: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1135: $docslog{$id}{'exe_udom'});
1136: my $about_me_link =
1137: &Apache::loncommon::aboutmewrapper($plainname,
1138: $docslog{$id}{'exe_uname'},
1139: $docslog{$id}{'exe_udom'});
1140: my $send_msg_link='';
1141: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1142: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1143: $send_msg_link ='<br />'.
1144: &Apache::loncommon::messagewrapper(&mt('Send message'),
1145: $docslog{$id}{'exe_uname'},
1146: $docslog{$id}{'exe_udom'});
1147: }
1148: $r->print(&Apache::loncommon::start_data_table_row());
1149: $r->print('<td>'.$time.'</td>
1150: <td>'.$about_me_link.
1151: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1152: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1153: $send_msg_link.'</td><td>'.
1154: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1155: # Before
1156: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1157: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1158: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1159: if ($oldname ne $newname) {
1160: $r->print(&LONCAPA::map::qtescape($oldname));
1161: }
1162: }
1163: $r->print('<ul>');
1164: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1165: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1166: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1167: }
1168: }
1169: $r->print('</ul>');
1170: # After
1171: $r->print('</td><td>');
1172:
1173: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1174: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1175: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1176: if ($oldname ne '' && $oldname ne $newname) {
1177: $r->print(&LONCAPA::map::qtescape($newname));
1178: }
1179: }
1180: $r->print('<ul>');
1181: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1182: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1183: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1184: }
1185: }
1186: $r->print('</ul>');
1187: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1188: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1189: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1190: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1191: $r->print('<li>'.
1192: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1193: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1194: .'</li>');
1195: }
1196: }
1197: $r->print('</ul>');
1198: }
1199: # End
1200: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1201: $shown++;
1202: if (!($env{'form.show'} eq &mt('all')
1203: || $shown<=$env{'form.show'})) { last; }
1204: }
1205: $r->print(&Apache::loncommon::end_data_table());
1206: }
1207:
1208: sub update_paste_buffer {
1209: my ($coursenum,$coursedom) = @_;
1210:
1211: return if (!defined($env{'form.markcopy'}));
1212: return if (!defined($env{'form.copyfolder'}));
1213: return if ($env{'form.markcopy'} < 0);
1214:
1215: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1216: $env{'form.copyfolder'});
1217:
1218: return if ($fatal);
1219:
1220: # Mark for copying
1221: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1222: if (&is_supplemental_title($title)) {
1223: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1224: ($title) = &parse_supplemental_title($title);
1225: } elsif ($env{'docs.markedcopy_supplemental'}) {
1226: &Apache::lonnet::delenv('docs\\.markedcopy_supplemental');
1227: }
1228: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1229:
1230: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
1231: 'docs.markedcopy_url' => $url});
1232: delete($env{'form.markcopy'});
1233: }
1234:
1235: sub print_paste_buffer {
1236: my ($r,$container) = @_;
1237: return if (!defined($env{'docs.markedcopy_url'}));
1238:
1239: $r->print(<<ENDPASTE);
1240: <form name="pasteform" action="/adm/coursedocs" method="post"><p>
1241: ENDPASTE
1242: $r->print('<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> ');
1243:
1244: my $type;
1245: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1246: $type = &mt('External Resource');
1247: $r->print($type.': '.
1248: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1249: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
1250: } else {
1251: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1252: my $icon = &Apache::loncommon::icon($extension);
1253: if ($extension eq 'sequence' &&
1254: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
1255: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1256: $icon .= '/folder_closed.gif';
1257: }
1258: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1259: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1260: }
1261: if ($container eq 'page') {
1262: $r->print('
1263: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
1264: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
1265: ');
1266: } else {
1267: $r->print('
1268: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1269: ');
1270: }
1271: $r->print('</p></form>');
1272: }
1273:
1274: sub do_paste_from_buffer {
1275: my ($coursenum,$coursedom,$folder) = @_;
1276:
1277: if (!$env{'form.pastemarked'}) {
1278: return;
1279: }
1280:
1281: # paste resource to end of list
1282: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
1283: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1284: # Maps need to be copied first
1285: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
1286: $title=&mt('Copy of').' '.$title;
1287: my $newid=$$.int(rand(100)).time;
1288: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1289: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
1290: my $path = $1;
1291: my $prefix = $2;
1292: my $ancestor = $3;
1293: if (length($ancestor) > 10) {
1294: $ancestor = substr($ancestor,-10,10);
1295: }
1296: $oldid = $path.$prefix.$ancestor;
1297: }
1298: my $counter = 0;
1299: my $newurl=$oldid.$newid.'.'.$ext;
1300: my $is_unique = &uniqueness_check($newurl);
1301: while (!$is_unique && $counter < 100) {
1302: $counter ++;
1303: $newid ++;
1304: $newurl = $oldid.$newid;
1305: $is_unique = &uniqueness_check($newurl);
1306: }
1307: if (!$is_unique) {
1308: if ($url=~/\.page$/) {
1309: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
1310: } else {
1311: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
1312: }
1313: }
1314: my $storefn=$newurl;
1315: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1316: my $paste_map_result =
1317: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1318: &Apache::lonnet::getfile($url));
1319: if ($paste_map_result eq '/adm/notfound.html') {
1320: if ($url=~/\.page$/) {
1321: return &mt('Paste failed: an error occurred saving the composite page');
1322: } else {
1323: return &mt('Paste failed: an error occurred saving the folder');
1324: }
1325: }
1326: $url = $newurl;
1327: }
1328: # published maps can only exists once, so remove it from paste buffer when done
1329: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
1330: &Apache::lonnet::delenv('docs\\.markedcopy');
1331: }
1332: if ($url=~ m{/smppg$}) {
1333: my $db_name = &Apache::lonsimplepage::get_db_name($url);
1334: if ($db_name =~ /^smppage_/) {
1335: #simple pages, need to copy the db contents to a new one.
1336: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
1337: my $now = time();
1338: $db_name =~ s{_\d*$ }{_$now}x;
1339: my $result=&Apache::lonnet::put($db_name,\%contents,
1340: $coursedom,$coursenum);
1341: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1342: $title=&mt('Copy of').' '.$title;
1343: }
1344: }
1345: $title = &LONCAPA::map::qtunescape($title);
1346: my $ext='false';
1347: if ($url=~m{^http(|s)://}) { $ext='true'; }
1348: $url = &LONCAPA::map::qtunescape($url);
1349: # Now insert the URL at the bottom
1350: my $newidx = &LONCAPA::map::getresidx($url);
1351: if ($env{'docs.markedcopy_supplemental'}) {
1352: if ($folder =~ /^supplemental/) {
1353: $title = $env{'docs.markedcopy_supplemental'};
1354: } else {
1355: (undef,undef,$title) =
1356: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1357: }
1358: } else {
1359: if ($folder=~/^supplemental/) {
1360: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1361: $env{'user.domain'}.'___&&&___'.$title;
1362: }
1363: }
1364:
1365: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1366: push(@LONCAPA::map::order, $newidx);
1367: return 'ok';
1368: # Store the result
1369: }
1370:
1371: sub uniqueness_check {
1372: my ($newurl) = @_;
1373: my $unique = 1;
1374: foreach my $res (@LONCAPA::map::order) {
1375: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1376: $url=&LONCAPA::map::qtescape($url);
1377: if ($newurl eq $url) {
1378: $unique = 0;
1379: last;
1380: }
1381: }
1382: return $unique;
1383: }
1384:
1385: my %parameter_type = ( 'randompick' => 'int_pos',
1386: 'hiddenresource' => 'string_yesno',
1387: 'encrypturl' => 'string_yesno',
1388: 'randomorder' => 'string_yesno',);
1389: my $valid_parameters_re = join('|',keys(%parameter_type));
1390: # set parameters
1391: sub update_parameter {
1392:
1393: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1394:
1395: my $which = $env{'form.changeparms'};
1396: my $idx = $env{'form.setparms'};
1397: if ($env{'form.'.$which.'_'.$idx}) {
1398: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
1399: : 'yes';
1400: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
1401: $parameter_type{$which});
1402: &remember_parms($idx,$which,'set',$value);
1403: } else {
1404: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1405:
1406: &remember_parms($idx,$which,'del');
1407: }
1408: return 1;
1409: }
1410:
1411:
1412: sub handle_edit_cmd {
1413: my ($coursenum,$coursedom) =@_;
1414:
1415: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1416:
1417: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1418: my ($title, $url, @rrest) = split(':', $ratstr);
1419:
1420: if ($cmd eq 'del') {
1421: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1422: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1423: &Apache::lonnet::removeuploadedurl($url);
1424: } else {
1425: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1426: }
1427: splice(@LONCAPA::map::order, $idx, 1);
1428:
1429: } elsif ($cmd eq 'cut') {
1430: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1431: splice(@LONCAPA::map::order, $idx, 1);
1432:
1433: } elsif ($cmd eq 'up'
1434: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1435: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1436:
1437: } elsif ($cmd eq 'down'
1438: && defined($LONCAPA::map::order[$idx+1])) {
1439: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1440:
1441: } elsif ($cmd eq 'rename') {
1442:
1443: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
1444: if ($comment=~/\S/) {
1445: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1446: $comment.':'.join(':', $url, @rrest);
1447: }
1448: # Devalidate title cache
1449: my $renamed_url=&LONCAPA::map::qtescape($url);
1450: &Apache::lonnet::devalidate_title_cache($renamed_url);
1451: } else {
1452: return 0;
1453: }
1454: return 1;
1455: }
1456:
1457: sub editor {
1458: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
1459:
1460: my $container= ($env{'form.pagepath'}) ? 'page'
1461: : 'sequence';
1462:
1463: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1464: $folder.'.'.$container);
1465: return $errtext if ($fatal);
1466:
1467: if ($#LONCAPA::map::order<1) {
1468: my $idx=&LONCAPA::map::getresidx();
1469: if ($idx<=0) { $idx=1; }
1470: $LONCAPA::map::order[0]=$idx;
1471: $LONCAPA::map::resources[$idx]='';
1472: }
1473:
1474: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
1475: &breadcrumbs($folder,$allowed,$type);
1476: $r->print($breadcrumbtrail);
1477:
1478: # ------------------------------------------------------------ Process commands
1479:
1480: # ---------------- if they are for this folder and user allowed to make changes
1481: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1482: # set parameters and change order
1483: &snapshotbefore();
1484:
1485: if (&update_parameter()) {
1486: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1487: return $errtext if ($fatal);
1488: }
1489:
1490: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
1491: # change order
1492: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
1493: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
1494:
1495: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1496: return $errtext if ($fatal);
1497: }
1498:
1499: if ($env{'form.pastemarked'}) {
1500: my $paste_res =
1501: &do_paste_from_buffer($coursenum,$coursedom,$folder);
1502: if ($paste_res eq 'ok') {
1503: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
1504: return $errtext if ($fatal);
1505: } elsif ($paste_res ne '') {
1506: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
1507: }
1508: }
1509:
1510: $r->print($upload_output);
1511:
1512: if (&handle_edit_cmd()) {
1513: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1514: return $errtext if ($fatal);
1515: }
1516: # Group import/search
1517: if ($env{'form.importdetail'}) {
1518: my @imports;
1519: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
1520: if (defined($item)) {
1521: my ($name,$url,$residx)=
1522: map {&unescape($_)} split(/\=/,$item);
1523: push(@imports, [$name, $url, $residx]);
1524: }
1525: }
1526: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1527: $container,'londocs',@imports);
1528: return $errtext if ($fatal);
1529: }
1530: # Loading a complete map
1531: if ($env{'form.loadmap'}) {
1532: if ($env{'form.importmap'}=~/\w/) {
1533: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1534: my ($title,$url,$ext,$type)=split(/\:/,$res);
1535: my $idx=&LONCAPA::map::getresidx($url);
1536: $LONCAPA::map::resources[$idx]=$res;
1537: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1538: }
1539: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1540: $folder.'.'.$container);
1541: return $errtext if ($fatal);
1542: } else {
1543: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1544:
1545: }
1546: }
1547: &log_differences($plain);
1548: }
1549: # ---------------------------------------------------------------- End commands
1550: # ---------------------------------------------------------------- Print screen
1551: my $idx=0;
1552: my $shown=0;
1553: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1554: $r->print('<p>'.&mt('Parameters').':<ul>'.
1555: ($randompick>=0?'<li>'.&mt('randomly pick [_1] resources',$randompick).'</li>':'').
1556: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1557: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1558: '</ul></p>');
1559: }
1560: if ($randompick>=0) {
1561: $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>');
1562: }
1563: if ($is_random_order) {
1564: $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>');
1565: }
1566: $r->print('<table class="LC_docs_editor">');
1567: foreach my $res (@LONCAPA::map::order) {
1568: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1569: $name=&LONCAPA::map::qtescape($name);
1570: $url=&LONCAPA::map::qtescape($url);
1571: unless ($name) { $name=(split(/\//,$url))[-1]; }
1572: unless ($name) { $idx++; next; }
1573: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$res,
1574: $coursenum));
1575: $idx++;
1576: $shown++;
1577: }
1578: unless ($shown) {
1579: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1580: }
1581: $r->print("\n</table>\n");
1582: if ($allowed) {
1583: &print_paste_buffer($r,$container);
1584: }
1585: return;
1586: }
1587:
1588: sub process_file_upload {
1589: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1590: # upload a file, if present
1591: my $parseaction;
1592: if ($env{'form.parserflag'}) {
1593: $parseaction = 'parse';
1594: }
1595: my $phase_status;
1596: my $folder=$env{'form.folder'};
1597: if ($folder eq '') {
1598: $folder='default';
1599: }
1600: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1601: my $errtext='';
1602: my $fatal=0;
1603: my $container='sequence';
1604: if ($env{'form.pagepath'}) {
1605: $container='page';
1606: }
1607: ($errtext,$fatal)=
1608: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1609: if ($#LONCAPA::map::order<1) {
1610: $LONCAPA::map::order[0]=1;
1611: $LONCAPA::map::resources[1]='';
1612: }
1613: if ($fatal) {
1614: return 'failed';
1615: }
1616: my $destination = 'docs/';
1617: if ($folder =~ /^supplemental/) {
1618: $destination = 'supplemental/';
1619: }
1620: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1621: $destination .= 'default/';
1622: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1623: $destination .= $2.'/';
1624: }
1625: # this is for a course, not a user, so set coursedoc flag
1626: # probably the only place in the system where this should be "1"
1627: my $newidx=&LONCAPA::map::getresidx();
1628: $destination .= $newidx;
1629: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1630: $parseaction,$allfiles,
1631: $codebase);
1632: my $ext='false';
1633: if ($url=~m{^http://}) { $ext='true'; }
1634: $url = &LONCAPA::map::qtunescape($url);
1635: my $comment=$env{'form.comment'};
1636: $comment = &LONCAPA::map::qtunescape($comment);
1637: if ($folder=~/^supplemental/) {
1638: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1639: $env{'user.domain'}.'___&&&___'.$comment;
1640: }
1641:
1642: $LONCAPA::map::resources[$newidx]=
1643: $comment.':'.$url.':'.$ext.':normal:res';
1644: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1645: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1646: $folder.'.'.$container);
1647: if ($fatal) {
1648: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1649: return 'failed';
1650: } else {
1651: if ($parseaction eq 'parse') {
1652: my $total_embedded = keys(%{$allfiles});
1653: if ($total_embedded > 0) {
1654: my $num = 0;
1655: my $state = '
1656: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1657: <input type="hidden" name="cmd" value="upload_embedded" />
1658: <input type="hidden" name="newidx" value="'.$newidx.'" />
1659: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1660: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1661: $phase_status = 'phasetwo';
1662:
1663: $$upload_output .=
1664: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1665: &Apache::loncommon::ask_for_embedded_content(
1666: '/adm/coursedocs',$state,$allfiles,$codebase);
1667: } else {
1668: $$upload_output .= 'No embedded items identified<br />';
1669: }
1670: }
1671: }
1672: }
1673: return $phase_status;
1674: }
1675:
1676: sub process_secondary_uploads {
1677: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1678: my $folder=$env{'form.folder'};
1679: my $destination = 'docs/';
1680: if ($folder =~ /^supplemental/) {
1681: $destination = 'supplemental/';
1682: }
1683: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1684: $destination .= 'default/';
1685: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1686: $destination .= $2.'/';
1687: }
1688: $destination .= $newidx;
1689: my ($url,$filename);
1690: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1691: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1692: return $filename;
1693: }
1694:
1695: sub is_supplemental_title {
1696: my ($title) = @_;
1697: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1698: }
1699:
1700: sub parse_supplemental_title {
1701: my ($title) = @_;
1702:
1703: my ($foldertitle,$renametitle);
1704: if ($title =~ /&&&/) {
1705: $title = &HTML::Entites::decode($title);
1706: }
1707: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1708: $renametitle=$4;
1709: my ($time,$uname,$udom) = ($1,$2,$3);
1710: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1711: my $name = &Apache::loncommon::plainname($uname,$udom);
1712: $name = &HTML::Entities::encode($name,'"<>&\'');
1713: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1714: $name.': <br />'.$foldertitle;
1715: }
1716: if (wantarray) {
1717: return ($title,$foldertitle,$renametitle);
1718: }
1719: return $title;
1720: }
1721:
1722: # --------------------------------------------------------------- An entry line
1723:
1724: sub entryline {
1725: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1726:
1727: my ($foldertitle,$pagetitle,$renametitle);
1728: if (&is_supplemental_title($title)) {
1729: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1730: $pagetitle = $foldertitle;
1731: } else {
1732: $title=&HTML::Entities::encode($title,'"<>&\'');
1733: $renametitle=$title;
1734: $foldertitle=$title;
1735: $pagetitle=$title;
1736: }
1737:
1738: my $orderidx=$LONCAPA::map::order[$index];
1739:
1740:
1741: $renametitle=~s/\\/\\\\/g;
1742: $renametitle=~s/\"\;/\\\"/g;
1743: $renametitle=~s/ /%20/g;
1744: my $line='<tr>';
1745: my ($form_start,$form_end);
1746: # Edit commands
1747: my ($container, $type, $esc_path, $path, $symb);
1748: if ($env{'form.folderpath'}) {
1749: $type = 'folder';
1750: $container = 'sequence';
1751: $esc_path=&escape($env{'form.folderpath'});
1752: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1753: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1754: }
1755: if ($env{'form.pagepath'}) {
1756: $type = $container = 'page';
1757: $esc_path=&escape($path = $env{'form.pagepath'});
1758: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1759: $symb=&escape($env{'form.pagesymb'});
1760: }
1761: my $cpinfo='';
1762: if ($allowed) {
1763: my $incindex=$index+1;
1764: my $selectbox='';
1765: if (($folder!~/^supplemental/) &&
1766: ($#LONCAPA::map::order>0) &&
1767: ((split(/\:/,
1768: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1769: ne '') &&
1770: ((split(/\:/,
1771: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1772: ne '')) {
1773: $selectbox=
1774: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1775: '<select name="newpos" onChange="this.form.submit()">';
1776: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1777: if ($i==$incindex) {
1778: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1779: } else {
1780: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1781: }
1782: }
1783: $selectbox.='</select>';
1784: }
1785: my %lt=&Apache::lonlocal::texthash(
1786: 'up' => 'Move Up',
1787: 'dw' => 'Move Down',
1788: 'rm' => 'Remove',
1789: 'ct' => 'Cut',
1790: 'rn' => 'Rename',
1791: 'cp' => 'Copy');
1792: my $nocopy=0;
1793: my $nocut=0;
1794: if ($url=~/\.(page|sequence)$/) {
1795: if ($url =~ m{/res/}) {
1796: # no copy for published maps
1797: $nocopy = 1;
1798: } else {
1799: foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1800: my ($title,$url,$ext,$type)=split(/\:/,$item);
1801: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1802: $nocopy=1;
1803: last;
1804: }
1805: }
1806: }
1807: }
1808: if ($url=~/^\/res\/lib\/templates\//) {
1809: $nocopy=1;
1810: $nocut=1;
1811: }
1812: my $copylink=' ';
1813: my $cutlink=' ';
1814:
1815: my $skip_confirm = 0;
1816: if ( $folder =~ /^supplemental/
1817: || ($url =~ m{( /smppg$
1818: |/syllabus$
1819: |/aboutme$
1820: |/navmaps$
1821: |/bulletinboard$
1822: |\.html$
1823: |^/adm/wrapper/ext)}x)) {
1824: $skip_confirm = 1;
1825: }
1826:
1827: if (!$nocopy) {
1828: $copylink=(<<ENDCOPY);
1829: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
1830: ENDCOPY
1831: }
1832: if (!$nocut) {
1833: $cutlink=(<<ENDCUT);
1834: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
1835: ENDCUT
1836: }
1837: $form_start = (<<END);
1838: <form action="/adm/coursedocs" method="post">
1839: <input type="hidden" name="${type}path" value="$path" />
1840: <input type="hidden" name="${type}symb" value="$symb" />
1841: <input type="hidden" name="setparms" value="$orderidx" />
1842: <input type="hidden" name="changeparms" value="0" />
1843: END
1844: $form_end = '</form>';
1845: $line.=(<<END);
1846: <td>
1847: <table class="LC_docs_entry_move">
1848: <tr>
1849: <td>
1850: <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>
1851: </td>
1852: </tr>
1853: <tr>
1854: <td>
1855: <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>
1856: </td>
1857: </tr>
1858: </table>
1859: </td>
1860: <td>
1861: $form_start
1862: $selectbox
1863: $form_end
1864: </td>
1865: <td class="LC_docs_entry_commands">
1866: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1867: $cutlink
1868: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1869: $copylink
1870: </td>
1871: END
1872:
1873: }
1874: # Figure out what kind of a resource this is
1875: my ($extension)=($url=~/\.(\w+)$/);
1876: my $uploaded=($url=~/^\/*uploaded\//);
1877: my $icon=&Apache::loncommon::icon($url);
1878: my $isfolder=0;
1879: my $ispage=0;
1880: my $folderarg;
1881: my $pagearg;
1882: my $pagefile;
1883: if ($uploaded) {
1884: if ($extension eq 'sequence') {
1885: $icon=$iconpath.'/folder_closed.gif';
1886: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1887: $url='/adm/coursedocs?';
1888: $folderarg=$1;
1889: $isfolder=1;
1890: } elsif ($extension eq 'page') {
1891: $icon=$iconpath.'/page.gif';
1892: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1893: $pagearg=$1;
1894: $url='/adm/coursedocs?';
1895: $ispage=1;
1896: } else {
1897: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1898: }
1899: }
1900:
1901: my $orig_url = $url;
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: }
1923: } elsif ($url=~m|^/ext/|) {
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'};
1934:
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.='&' };
1944: # Append randompick number, hidden, and encrypted with ":" to foldername,
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 ='
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>';
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=
2002: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
2003: my $hidtext=
2004: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
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: }
2047: }
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) {
2096: $r->print('<img src="/adm/lonMisc/bomb.gif" /><span class="LC_error">'.
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 {
2121: $r->print('<span class="LC_unknown">'.&mt('unable to verify variable URL').'</span>');
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'},
2255: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
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: }
2396: #
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;
2407: $r->print('<td valign="top"><font size="-2">');
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".
2486: '<script type="text/javascript">function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
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');
2540: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2541: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2542: $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
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
2618: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
2619: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2620: $forcestandard = 1;
2621: }
2622: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2623:
2624: if ($allowed) {
2625: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2626: $script=&Apache::lonratedt::editscript('simple');
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:
2636: # get personal data
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'));
2655:
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+)/)) {
2662: # Process file upload - phase one - upload and parse primary file.
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})) {
2687: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2688: $origname{$i} =~ s#^\Q$javacodebase\E/##;
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(['"]?)#) {
2724: }
2725: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
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 {
2737: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
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',
2763: 'sipa' => 'Simple Page',
2764: 'sipr' => 'Simple Problem',
2765: 'drbx' => 'Drop Box',
2766: 'scuf' => 'Score Upload Form',
2767: 'bull' => 'Bulletin Board',
2768: 'mypi' => 'My Personal Info',
2769: 'grpo' => 'Group Files',
2770: 'rost' => 'Course Roster',
2771: 'abou' => 'About User',
2772: 'imsf' => 'Import IMS package',
2773: 'file' => 'File',
2774: 'title' => 'Title',
2775: 'comment' => 'Comment',
2776: 'parse' => 'Upload embedded images/multimedia files if HTML file!',
2777: 'nd' => 'New Document',
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 />
2835: <span class="LC_nobreak"><input type="button"
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.330 ! tempelho 2875: ##############alter hashaufruf
1.329 droeschl 2876: $r->print(&generate_admin_options($containertag,$uploadtag,\%lt,\%help,\%env));
2877: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2878: &mt('Editing the Table of Contents for your '.$type)));
2879: }
2880: # --------------------------------------------------------- Standard documents
2881: $r->print('<table class="LC_docs_documents">');
2882:
2883: if (($standard) && ($allowed) && (!$forcesupplement)) {
2884: $r->print('<tr><td class="LC_docs_document">');
2885: # '<h2>'.&mt('Main Course Documents').
2886: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
2887: my $folder=$env{'form.folder'};
2888: if ($folder eq '' || $folder eq 'supplemental') {
2889: $folder='default';
2890: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
2891: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2892: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
2893: }
2894: my $postexec='';
2895: if ($folder eq 'default') {
2896: $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
2897: } else {
2898: #$postexec='self.close();';
2899: }
2900: $hadchanges=0;
2901: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,
2902: $upload_output,$type);
2903: if ($error) {
2904: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
2905: }
2906: if ($hadchanges) {
2907: &mark_hash_old();
2908: }
2909: &changewarning($r,$postexec);
2910: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2911: '.sequence';
2912: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2913: '.page';
2914: my $container='sequence';
2915: if ($env{'form.pagepath'}) {
2916: $container='page';
2917: }
2918: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2919:
2920:
2921:
2922: my $recoverform=(<<RFORM);
2923: <form action="/adm/groupsort" method="post" name="recover">
2924: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
2925: </form>
2926: RFORM
2927:
2928: my $imspform=(<<IMSPFORM);
2929: <form action="/adm/imsimportdocs" method="post" name="ims">
2930: <input type="hidden" name="folder" value="$folder" />
2931: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2932: </form>
2933: IMSPFORM
2934:
2935: my $newnavform=(<<NNFORM);
2936: <form action="/adm/coursedocs" method="post" name="newnav">
2937: $uploadtag
2938: <input type="hidden" name="importdetail"
2939: value="$lt{'navc'}=/adm/navmaps" />
2940: <span class="LC_nobreak">
2941: <input name="newnav" type="submit" value="$lt{'navc'}" />
2942: $help{'Navigate_Content'}
2943: </span>
2944: </form>
2945: NNFORM
2946: my $newsmppageform=(<<NSPFORM);
2947: <form action="/adm/coursedocs" method="post" name="newsmppg">
2948: $uploadtag
2949: <input type="hidden" name="importdetail" value="" />
2950: <span class="LC_nobreak">
2951: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2952: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2953: </span>
2954: </form>
2955: NSPFORM
2956:
2957: my $newsmpproblemform=(<<NSPROBFORM);
2958: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2959: $uploadtag
2960: <input type="hidden" name="importdetail" value="" />
2961: <span class="LC_nobreak">
2962: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2963: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2964: </span>
2965: </form>
2966:
2967: NSPROBFORM
2968:
2969: my $newdropboxform=(<<NDBFORM);
2970: <form action="/adm/coursedocs" method="post" name="newdropbox">
2971: $uploadtag
2972: <input type="hidden" name="importdetail" value="" />
2973: <span class="LC_nobreak">
2974: <input name="newdropbox" type="button" value="$lt{'drbx'}"
2975: onClick="javascript:makedropbox();" />
2976: </span>
2977: </form>
2978: NDBFORM
2979:
2980: my $newexuploadform=(<<NEXUFORM);
2981: <form action="/adm/coursedocs" method="post" name="newexamupload">
2982: $uploadtag
2983: <input type="hidden" name="importdetail" value="" />
2984: <span class="LC_nobreak">
2985: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2986: onClick="javascript:makeexamupload();" />
2987: $help{'Score_Upload_Form'}
2988: </span>
2989: </form>
2990: NEXUFORM
2991:
2992: my $newbulform=(<<NBFORM);
2993: <form action="/adm/coursedocs" method="post" name="newbul">
2994: $uploadtag
2995: <input type="hidden" name="importdetail" value="" />
2996: <span class="LC_nobreak">
2997: <input name="newbulletin" type="button" value="$lt{'bull'}"
2998: onClick="javascript:makebulboard();" />
2999: $help{'Bulletin Board'}
3000: </span>
3001: </form>
3002: NBFORM
3003:
3004: my $newaboutmeform=(<<NAMFORM);
3005: <form action="/adm/coursedocs" method="post" name="newaboutme">
3006: $uploadtag
3007: <input type="hidden" name="importdetail"
3008: value="$plainname=/adm/$udom/$uname/aboutme" />
3009: <span class="LC_nobreak">
3010: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3011: $help{'My Personal Info'}
3012: </span>
3013: </form>
3014: NAMFORM
3015:
3016: my $newaboutsomeoneform=(<<NASOFORM);
3017: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
3018: $uploadtag
3019: <input type="hidden" name="importdetail" value="" />
3020: <span class="LC_nobreak">
3021: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
3022: onClick="javascript:makeabout();" />
3023: </span>
3024: </form>
3025: NASOFORM
3026:
3027:
3028: my $newrosterform=(<<NROSTFORM);
3029: <form action="/adm/coursedocs" method="post" name="newroster">
3030: $uploadtag
3031: <input type="hidden" name="importdetail"
3032: value="$lt{'rost'}=/adm/viewclasslist" />
3033: <span class="LC_nobreak">
3034: <input name="newroster" type="submit" value="$lt{'rost'}" />
3035: $help{'Course Roster'}
3036: </span>
3037: </form>
3038: NROSTFORM
3039:
3040: $r->print(<<ENDFORM);
3041:
3042:
3043: <table class="LC_docs_adddocs">
3044: <!-- <tr>
3045: <th>$lt{'uplm'}</th>
3046: <th>$lt{'impp'}</th>
3047: <th>$lt{'spec'}</th>
3048: </tr> -->
3049: <tr>
3050: <td>
3051: $fileuploadform
3052: </td>
3053: <td>
3054: $simpleeditdefaultform
3055: <hr />
3056: $recoverform
3057: ENDFORM
3058: unless ($env{'form.pagepath'}) {
3059: $r->print(<<ENDFORM);
3060: <hr />
3061: $extresourcesform
3062: <br />
3063: $imspform
3064: ENDFORM
3065: }
3066: $r->print('</td><td>');
3067: unless ($env{'form.pagepath'}) {
3068: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3069:
3070:
3071:
3072: my $newpageform=(<<NPFORM);
3073: <form action="/adm/coursedocs" method="post" name="newpage">
3074: <input type="hidden" name="folderpath" value="$path" />
3075: <input type="hidden" name="importdetail" value="" />
3076: <span class="LC_nobreak">
3077: <input name="newpage" type="button"
3078: onClick="javascript:makenewpage(this.form,'$pageseq');"
3079: value="$lt{'newp'}" />$help{'Adding_Pages'}
3080: </span>
3081: </form>
3082: NPFORM
3083:
3084: my $newfolderform=(<<NFFORM);
3085: <form action="/adm/coursedocs" method="post" name="newfolder">
3086: <input type="hidden" name="folderpath" value="$path" />
3087: <input type="hidden" name="importdetail" value="" />
3088: <span class="LC_nobreak">
3089: <input name="newfolder" type="button"
3090: onClick="javascript:makenewfolder(this.form,'$folderseq');"
3091: value="$lt{'newf'}" />$help{'Adding_Folders'}
3092: </span>
3093: </form>
3094: NFFORM
3095:
3096: my $newsylform=(<<NSYLFORM);
3097: <form action="/adm/coursedocs" method="post" name="newsyl">
3098: $uploadtag
3099: <input type="hidden" name="importdetail"
3100: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
3101: <span class="LC_nobreak">
3102: <input name="newsyl" type="submit" value="$lt{'syll'}" />
3103: $help{'Syllabus'}
3104: </span>
3105: </form>
3106: NSYLFORM
3107:
3108: my $newgroupfileform=(<<NGFFORM);
3109: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
3110: $uploadtag
3111: <input type="hidden" name="importdetail"
3112: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
3113: <span class="LC_nobreak">
3114: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
3115: $help{'Group Files'}
3116: </span>
3117: </form>
3118: NGFFORM
3119:
3120:
1.330 ! tempelho 3121: my $specialdocumentsform=(<<ENDFORM);
1.329 droeschl 3122: <br />
3123: $newfolderform
3124: <br />
3125: $newpageform
3126: <br />
3127: $newsylform
3128: <br />
3129: $newnavform
3130: <br />
3131: $newsmppageform
3132: <br />
3133: $newsmpproblemform
3134: <br />
3135: $newdropboxform
3136: <br />
3137: $newexuploadform
3138: <br />
3139: $newbulform
3140: <br />
3141: $newaboutmeform
3142: <br />
3143: $newaboutsomeoneform
3144: <br />
3145: $newgroupfileform
3146: <br />
3147: $newrosterform
3148: ENDFORM
1.330 ! tempelho 3149:
! 3150: $r->print($specialdocumentsform);
! 3151: my %orderhash = (
! 3152: 'aa_eins' => 'New Document',
! 3153: 'bb_zwei' => 'Published Documents',
! 3154: 'cc_drei' => 'Special Documents',
! 3155: 'dd_vier' => 'More Options',
! 3156: 'zz_hide' => 'Hide all Option',
! 3157: );
! 3158: my %namehash = (
! 3159: 'New Document' => $fileuploadform,
! 3160: 'Published Documents' => $simpleeditdefaultform,
! 3161: 'Special Documents' => $specialdocumentsform,
! 3162: 'More Options' => $extresourcesform.'<br />'.$imspform.'<br />'.$recoverform,
! 3163: 'drei' => 'dr',
! 3164: );
! 3165: $r->print(&generate_edit_table(\%namehash,\%orderhash));
! 3166: }
1.329 droeschl 3167: if ($env{'form.pagepath'}) {
3168: $r->print(<<ENDBLOCK);
3169: $newsmpproblemform
3170: <br />
3171: $newexuploadform
3172: ENDBLOCK
3173: }
3174: $r->print('</td></tr>'."\n".
3175: '</table>');
1.330 ! tempelho 3176: #$r->print(&generate_edit_table(\%namehash,\%orderhash));
1.329 droeschl 3177: $r->print('</td></tr>');
3178: }
3179: # ----------------------------------------------------- Supplemental documents
3180: if (!$forcestandard) {
3181: $r->print('<tr><td class="LC_docs_document">');
3182: # '<h2>'.&mt('Supplemental Course Documents').
3183: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
3184: my $folder=$env{'form.folder'};
3185: unless ($folder=~/^supplemental/) {
3186: $folder='supplemental';
3187: }
3188: if ($folder =~ /^supplemental$/ &&
3189: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3190: $env{'form.folderpath'} = 'supplemental&'.
3191: &escape(&mt('Supplemental '.$type.' Documents'));
3192: }
3193: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3194: if ($error) {
3195: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3196: }
3197: if ($allowed) {
3198: my $folderseq=
3199: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3200: '.sequence';
3201:
3202: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3203:
3204: my $supupdocform=(<<SUPDOCFORM);
3205: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
3206: $fileupload
3207: <br />
3208: <br />
3209: <span class="LC_nobreak">
3210: $checkbox
3211: </span>
3212: <br /><br />
3213: $lt{'comment'}:<br />
3214: <textarea cols=50 rows=4 name='comment'>
3215: </textarea>
3216: <br />
3217: <input type="hidden" name="folderpath" value="$path" />
3218: <input type="hidden" name="cmd" value="upload_supplemental" />
3219: <span class="LC_nobreak">
3220: <input type="submit" value="$lt{'upld'}" />
3221: $help{'Uploading_From_Harddrive'}
3222: </span>
3223: </form>
3224: SUPDOCFORM
3225:
3226: my $supnewfolderform=(<<SNFFORM);
3227: <form action="/adm/coursedocs" method="post" name="supnewfolder">
3228: <input type="hidden" name="folderpath" value="$path" />
3229: <input type="hidden" name="importdetail" value="" />
3230: <span class="LC_nobreak">
3231: <input name="newfolder" type="button"
3232: onClick="javascript:makenewfolder(this.form,'$folderseq');"
3233: value="$lt{'newf'}" /> $help{'Adding_Folders'}
3234: </span>
3235: </form>
3236: SNFFORM
3237:
3238:
3239: my $supnewextform=(<<SNEFORM);
3240: <form action="/adm/coursedocs" method="post" name="supnewext">
3241: <input type="hidden" name="folderpath" value="$path" />
3242: <input type="hidden" name="importdetail" value="" />
3243: <span class="LC_nobreak">
3244: <input name="newext" type="button"
3245: onClick="javascript:makenewext('supnewext');"
3246: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
3247: </span>
3248: </form>
3249: SNEFORM
3250:
3251: my $supnewsylform=(<<SNSFORM);
3252: <form action="/adm/coursedocs" method="post" name="supnewsyl">
3253: <input type="hidden" name="folderpath" value="$path" />
3254: <input type="hidden" name="importdetail"
3255: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
3256: <span class="LC_nobreak">
3257: <input name="newsyl" type="submit" value="$lt{'syll'}" />
3258: $help{'Syllabus'}
3259: </span>
3260: </form>
3261: SNSFORM
3262:
3263: my $supnewaboutmeform=(<<SNAMFORM);
3264: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
3265: <input type="hidden" name="folderpath" value="$path" />
3266: <input type="hidden" name="importdetail"
3267: value="$plainname=/adm/$udom/$uname/aboutme" />
3268: <span class="LC_nobreak">
3269: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3270: $help{'My Personal Info'}
3271: </span>
3272: </form>
3273: SNAMFORM
3274:
3275: $r->print(<<ENDSUPFORM);
3276: <ul class="LC_TabContent">
3277: <li>$lt{'nd'}</li>
3278: <li>$lt{'sd'}</li>
3279: <li>$lt{'hao'}</li>
3280: </ul>
3281: <table class="LC_docs_adddocs">
3282: <tr><td>
3283: $supupdocform
3284: </td>
3285: <td>
3286: $supnewfolderform
3287: <br />
3288: $supnewextform
3289: <br />
3290: $supnewsylform
3291: <br />
3292: $supnewaboutmeform
3293: </td></tr>
3294: </table></td></tr>
3295: ENDSUPFORM
3296: }
3297: }
3298: $r->print('</table>');
3299: if ($allowed) {
3300: $r->print('
3301: <form method="post" name="extimport" action="/adm/coursedocs">
3302: <input type="hidden" name="title" />
3303: <input type="hidden" name="url" />
3304: <input type="hidden" name="useform" />
3305: <input type="hidden" name="residx" />
3306: </form>');
3307: }
1.330 ! tempelho 3308:
1.329 droeschl 3309: } else {
3310: unless ($upload_result eq 'phasetwo') {
3311: # -------------------------------------------------------- This is showdoc mode
3312: $r->print("<h1>".&mt('Uploaded Document').' - '.
3313: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3314: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3315: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3316: }
3317: }
3318: }
3319: $r->print(&Apache::loncommon::end_page());
3320: return OK;
3321: }
3322:
3323: sub generate_admin_options {
3324: my ($containertag,$uploadtag,$lt_ref,$help_ref,$env_ref) = @_;
3325: my %lt = %{$lt_ref};
3326: my %help = %{$help_ref};
3327: my %env = %{$env_ref};
3328: my $dumpbut=&dumpbutton();
3329: my $exportbut=&exportbutton();
3330: return (<<ENDOPTIONFORM);
3331: <form name="renameform" method="post" action="/adm/coursedocs">
3332: <input type="hidden" name="title" />
3333: <input type="hidden" name="cmd" />
3334: <input type="hidden" name="markcopy" />
3335: <input type="hidden" name="copyfolder" />
3336: $containertag
3337: </form>
3338: <form name="simpleedit" method="post" action="/adm/coursedocs">
3339: <input type="hidden" name="importdetail" value="" />
3340: $uploadtag
3341: </form>
3342: <form action="/adm/coursedocs" method="post" name="courseverify">
3343: <ul style="list-style-type:none">
3344: <li>
3345: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
3346: </li>
3347: <li>
3348: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
3349: </li>
3350: <li>
3351: $dumpbut
3352: </li>
3353: <li>
3354: $exportbut
3355: </li>
3356: <li>
3357: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
3358: </li>
3359: <li>
3360: <input type="hidden" name="folder" value="$env{'form.folder'}" />
3361: <input type="submit" name="docslog" value="$lt{'sl'}" />
3362: </li>
3363: </ul>
3364: </form>
3365: <div style="clear: both; height: 0px;"> </div>
3366: ENDOPTIONFORM
1.330 ! tempelho 3367:
1.329 droeschl 3368: }
3369:
1.330 ! tempelho 3370:
1.329 droeschl 3371: sub generate_edit_table {
1.330 ! tempelho 3372: my ($namehash_ref,$orderhash_ref) = @_;
! 3373: #my %optionhash = %{$optionhash_ref}; #id verlinkt mit inhalt
1.329 droeschl 3374: my %namehash = %{$namehash_ref}; #name verlinkt mit id
3375: my %orderhash = %{$orderhash_ref}; #name mit kürzel verlinkt mit name
3376: my $form;
1.330 ! tempelho 3377: $form = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">'.&mt('Upload Course Documents').'</h4>';
1.329 droeschl 3378: $form .= '<ul class="LC_TabContent">';
3379: foreach my $name (sort(keys(%orderhash))){
3380: if($name eq 'zz_hide'){
1.330 ! tempelho 3381: $form .= '<li onclick="javascript:hideAll();">'.&mt($orderhash{$name}).'</li>';
1.329 droeschl 3382: }else{
1.330 ! tempelho 3383: $form .= '<li onclick="javascript:showPage(this, \''.$orderhash{$name}.'\');">'.&mt($orderhash{$name}).'</li>';
1.329 droeschl 3384: }
3385: }
1.330 ! tempelho 3386: $form .= '<div id="content" style="padding: 0 0; margin: 0 0;">';
! 3387: foreach my $field (keys(%namehash)){
! 3388: $form .= '<div id="'.$field.'" class="LC_ContentBox" style="display: none;">'.$namehash{$field}.'</div>';
1.329 droeschl 3389: }
1.330 ! tempelho 3390: $form .= '</div></div>';
1.329 droeschl 3391: return $form;
3392: }
3393:
3394: sub editing_js {
3395: my ($udom,$uname) = @_;
3396: my $now = time();
3397: my %lt = &Apache::lonlocal::texthash(
3398: p_mnf => 'Name of New Folder',
3399: t_mnf => 'New Folder',
3400: p_mnp => 'Name of New Page',
3401: t_mnp => 'New Page',
3402: p_mxu => 'Title for the Uploaded Score',
3403: p_msp => 'Title for the Page',
3404: p_msb => 'Title for the Problem',
3405: p_mdb => 'Title for the Drop Box',
3406: p_mbb => 'Title for the Bulletin Board',
3407: p_mab => "Enter user:domain for User's 'About Me' Page",
3408: p_mab2 => "About [_99]",
3409: p_mab_alrt1 => 'Not a valid user:domain',
3410: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3411: p_chn => 'New Title',
3412: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3413: p_rmr2a => 'Remove[_99]',
3414: p_rmr2b => '?[_99]',
3415: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3416: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3417: p_ctr2a => 'Cut[_98]',
3418: p_ctr2b => '?[_98]'
3419: );
3420:
3421: return <<ENDNEWSCRIPT;
3422: function makenewfolder(targetform,folderseq) {
3423: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3424: if (foldername) {
3425: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3426: targetform.submit();
3427: }
3428: }
3429:
3430: function makenewpage(targetform,folderseq) {
3431: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3432: if (pagename) {
3433: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3434: targetform.submit();
3435: }
3436: }
3437:
3438: function makenewext(targetname) {
3439: this.document.forms.extimport.useform.value=targetname;
3440: this.document.forms.extimport.title.value='';
3441: this.document.forms.extimport.url.value='';
3442: this.document.forms.extimport.residx.value='';
3443: window.open('/adm/rat/extpickframe.html');
3444: }
3445:
3446: function edittext(targetname,residx,title,url) {
3447: this.document.forms.extimport.useform.value=targetname;
3448: this.document.forms.extimport.residx.value=residx;
3449: this.document.forms.extimport.url.value=url;
3450: this.document.forms.extimport.title.value=title;
3451: window.open('/adm/rat/extpickframe.html');
3452: }
3453:
3454: function makeexamupload() {
3455: var title=prompt('$lt{"p_mxu"}');
3456: if (title) {
3457: this.document.forms.newexamupload.importdetail.value=
3458: escape(title)+'=/res/lib/templates/examupload.problem';
3459: this.document.forms.newexamupload.submit();
3460: }
3461: }
3462:
3463: function makesmppage() {
3464: var title=prompt('$lt{"p_msp"}');
3465: if (title) {
3466: this.document.forms.newsmppg.importdetail.value=
3467: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3468: this.document.forms.newsmppg.submit();
3469: }
3470: }
3471:
3472: function makesmpproblem() {
3473: var title=prompt('$lt{"p_msb"}');
3474: if (title) {
3475: this.document.forms.newsmpproblem.importdetail.value=
3476: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3477: this.document.forms.newsmpproblem.submit();
3478: }
3479: }
3480:
3481: function makedropbox() {
3482: var title=prompt('$lt{"p_mdb"}');
3483: if (title) {
3484: this.document.forms.newdropbox.importdetail.value=
3485: escape(title)+'=/res/lib/templates/DropBox.problem';
3486: this.document.forms.newdropbox.submit();
3487: }
3488: }
3489:
3490: function makebulboard() {
3491: var title=prompt('$lt{"p_mbb"}');
3492: if (title) {
3493: this.document.forms.newbul.importdetail.value=
3494: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3495: this.document.forms.newbul.submit();
3496: }
3497: }
3498:
3499: function makeabout() {
3500: var user=prompt("$lt{'p_mab'}");
3501: if (user) {
3502: var comp=new Array();
3503: comp=user.split(':');
3504: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3505: if ((comp[0]) && (comp[1])) {
3506: this.document.forms.newaboutsomeone.importdetail.value=
3507: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
3508: this.document.forms.newaboutsomeone.submit();
3509: } else {
3510: alert("$lt{'p_mab_alrt1'}");
3511: }
3512: } else {
3513: alert("$lt{'p_mab_alrt2'}");
3514: }
3515: }
3516: }
3517:
3518: function makeims() {
3519: var caller = document.forms.ims.folder.value;
3520: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3521: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3522: newWindow.location.href = newlocation;
3523: }
3524:
3525:
3526: function finishpick() {
3527: var title=this.document.forms.extimport.title.value;
3528: var url=this.document.forms.extimport.url.value;
3529: var form=this.document.forms.extimport.useform.value;
3530: var residx=this.document.forms.extimport.residx.value;
3531: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
3532: }
3533:
3534: function changename(folderpath,index,oldtitle,container,pagesymb) {
3535: var title=prompt('$lt{"p_chn"}',oldtitle);
3536: if (title) {
3537: this.document.forms.renameform.markcopy.value=-1;
3538: this.document.forms.renameform.title.value=title;
3539: this.document.forms.renameform.cmd.value='rename_'+index;
3540: if (container == 'sequence') {
3541: this.document.forms.renameform.folderpath.value=folderpath;
3542: }
3543: if (container == 'page') {
3544: this.document.forms.renameform.pagepath.value=folderpath;
3545: this.document.forms.renameform.pagesymb.value=pagesymb;
3546: }
3547: this.document.forms.renameform.submit();
3548: }
3549: }
3550:
3551: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
3552: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3553: this.document.forms.renameform.markcopy.value=-1;
3554: this.document.forms.renameform.cmd.value='del_'+index;
3555: if (container == 'sequence') {
3556: this.document.forms.renameform.folderpath.value=folderpath;
3557: }
3558: if (container == 'page') {
3559: this.document.forms.renameform.pagepath.value=folderpath;
3560: this.document.forms.renameform.pagesymb.value=pagesymb;
3561: }
3562: this.document.forms.renameform.submit();
3563: }
3564: }
3565:
3566: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
3567: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3568: this.document.forms.renameform.cmd.value='cut_'+index;
3569: this.document.forms.renameform.markcopy.value=index;
3570: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3571: if (container == 'sequence') {
3572: this.document.forms.renameform.folderpath.value=folderpath;
3573: }
3574: if (container == 'page') {
3575: this.document.forms.renameform.pagepath.value=folderpath;
3576: this.document.forms.renameform.pagesymb.value=pagesymb;
3577: }
3578: this.document.forms.renameform.submit();
3579: }
3580: }
3581:
3582: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
3583: this.document.forms.renameform.markcopy.value=index;
3584: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3585: if (container == 'sequence') {
3586: this.document.forms.renameform.folderpath.value=folderpath;
3587: }
3588: if (container == 'page') {
3589: this.document.forms.renameform.pagepath.value=folderpath;
3590: this.document.forms.renameform.pagesymb.value=pagesymb;
3591: }
3592: this.document.forms.renameform.submit();
3593: }
3594:
1.330 ! tempelho 3595: function hideAll() {
! 3596: currentData = document.getElementById('content');
! 3597: currentDivs = currentData.getElementsByTagName('div');
! 3598: for (i = 0; i < currentDivs.length; i++) {
! 3599: currentDivs[i].style.display = 'none';
! 3600: }
! 3601: }
! 3602:
! 3603: function showPage(current, pageId) {
! 3604: hideAll();
! 3605: current.className = 'active';
! 3606: currentData = document.getElementById(pageId);
! 3607: currentData.style.display = 'block';
! 3608: return false;
! 3609: }
1.329 droeschl 3610:
3611: ENDNEWSCRIPT
3612: }
3613: 1;
3614: __END__
3615:
3616:
3617: =head1 NAME
3618:
3619: Apache::londocs.pm
3620:
3621: =head1 SYNOPSIS
3622:
3623: This is part of the LearningOnline Network with CAPA project
3624: described at http://www.lon-capa.org.
3625:
3626: =head1 SUBROUTINES
3627:
3628: =over
3629:
3630: =item %help=()
3631:
3632: Available help topics
3633:
3634: =item mapread()
3635:
3636: Mapread read maps into LONCAPA::map:: global arrays
3637: @order and @resources, determines status
3638: sets @order - pointer to resources in right order
3639: sets @resources - array with the resources with correct idx
3640:
3641: =item authorhosts()
3642:
3643: Return hash with valid author names
3644:
3645: =item dumpbutton()
3646:
3647: Generate "dump" button
3648:
3649: =item clean()
3650:
3651: =item dumpcourse()
3652:
3653: Actually dump course
3654:
3655:
3656: =item exportbutton()
3657:
3658: Generate "export" button
3659:
3660: =item exportcourse()
3661:
3662: =item create_ims_store()
3663:
3664: =item build_package()
3665:
3666: =item get_dependencies()
3667:
3668: =item process_content()
3669:
3670: =item replicate_content()
3671:
3672: =item extract_media()
3673:
3674: =item store_template()
3675:
3676: =item group_import()
3677:
3678: Imports the given (name, url) resources into the course
3679: coursenum, coursedom, and folder must precede the list
3680:
3681: =item breadcrumbs()
3682:
3683: =item log_docs()
3684:
3685: =item docs_change_log()
3686:
3687: =item update_paste_buffer()
3688:
3689: =item print_paste_buffer()
3690:
3691: =item do_paste_from_buffer()
3692:
3693: =item update_parameter()
3694:
3695: =item handle_edit_cmd()
3696:
3697: =item editor()
3698:
3699: =item process_file_upload()
3700:
3701: =item process_secondary_uploads()
3702:
3703: =item is_supplemental_title()
3704:
3705: =item parse_supplemental_title()
3706:
3707: =item entryline()
3708:
3709: =item tiehash()
3710:
3711: =item untiehash()
3712:
3713: =item checkonthis()
3714:
3715: check on this
3716:
3717: =item verifycontent()
3718:
3719: Verify Content
3720:
3721: =item devalidateversioncache() & checkversions()
3722:
3723: Check Versions
3724:
3725: =item mark_hash_old()
3726:
3727: =item is_hash_old()
3728:
3729: =item changewarning()
3730:
3731: =item init_breadcrumbs()
3732:
3733: Breadcrumbs for special functions
3734:
3735: =back
3736:
3737: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>