Annotation of loncom/interface/londocs.pm, revision 1.338
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.338 ! ehlerst 4: # $Id: londocs.pm,v 1.337 2009/02/04 14:45:51 ehlerst 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',
1.336 schafran 2767: 'bull' => 'Discussion Board',
1.329 droeschl 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.337 ehlerst 2875: $r->print(<<HIDDENFORM);
2876: <form name="renameform" method="post" action="/adm/coursedocs">
2877: <input type="hidden" name="title" />
2878: <input type="hidden" name="cmd" />
2879: <input type="hidden" name="markcopy" />
2880: <input type="hidden" name="copyfolder" />
2881: $containertag
2882: </form>
2883: <form name="simpleedit" method="post" action="/adm/coursedocs">
2884: <input type="hidden" name="importdetail" value="" />
2885: $uploadtag
2886: </form>
2887: HIDDENFORM
1.329 droeschl 2888: }
1.335 ehlerst 2889: # --------------------------------------------------------- Main tab structure
2890: my $activeClass = 1;
1.338 ! ehlerst 2891: $r->print('<div class="LC_ContentBoxSpecial"><ul class="LC_TabContentBigger" id="mainnav">');
1.335 ehlerst 2892: if (($standard) && ($allowed) && (!$forcesupplement)) {
2893: my $active = '';
2894: if($activeClass == 1){
2895: $active = 'class="active"';
2896: $activeClass = 0;
2897: }
2898: $r->print('<li '.$active.'onclick="javascript:showPage(this,\'Main Course Documents\',\'mainnav\',\'maincoursedoc\');">'.&mt('Main Course Documents').'</li>');
2899: }
2900: if (!$forcestandard) {
2901: my $active = '';
2902: if($activeClass == 1){
2903: $active = 'class="active"';
2904: }
2905: $r->print('<li '.$active.'onclick="javascript:showPage(this,\'Supplemental Course Documents\',\'mainnav\',\'maincoursedoc\');">'.&mt('Supplemental Course Documents').'</li>');
2906: }
1.337 ehlerst 2907: $r->print('<li onclick="javascript:showPage(this,\'Special Admin Options\',\'mainnav\',\'maincoursedoc\');">'.&mt('Special Admin Options').'</li>');
1.335 ehlerst 2908: $r->print('</ul><div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
1.329 droeschl 2909: # --------------------------------------------------------- Standard documents
2910: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.335 ehlerst 2911: my $active = 'style="display: none;"';
2912: if($activeClass == 0){
2913: $active = 'style="display: block;"';
2914: }
2915: $r->print('<div class="LC_ContentBox" id="Main Course Documents" '.$active.'>');
2916: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
2917: &mt('Editing the Table of Contents for your '.$type)));
1.329 droeschl 2918: my $folder=$env{'form.folder'};
2919: if ($folder eq '' || $folder eq 'supplemental') {
2920: $folder='default';
2921: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
2922: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2923: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
2924: }
2925: my $postexec='';
2926: if ($folder eq 'default') {
2927: $r->print('<script type="text/javascript">this.window.name="loncapaclient";</script>');
2928: } else {
2929: #$postexec='self.close();';
2930: }
2931: $hadchanges=0;
2932: if ($hadchanges) {
2933: &mark_hash_old();
2934: }
2935: &changewarning($r,$postexec);
2936: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2937: '.sequence';
2938: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2939: '.page';
2940: my $container='sequence';
2941: if ($env{'form.pagepath'}) {
2942: $container='page';
2943: }
2944: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2945:
2946:
2947:
2948: my $recoverform=(<<RFORM);
2949: <form action="/adm/groupsort" method="post" name="recover">
2950: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
2951: </form>
2952: RFORM
2953:
2954: my $imspform=(<<IMSPFORM);
2955: <form action="/adm/imsimportdocs" method="post" name="ims">
2956: <input type="hidden" name="folder" value="$folder" />
2957: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2958: </form>
2959: IMSPFORM
2960:
2961: my $newnavform=(<<NNFORM);
2962: <form action="/adm/coursedocs" method="post" name="newnav">
2963: $uploadtag
2964: <input type="hidden" name="importdetail"
2965: value="$lt{'navc'}=/adm/navmaps" />
2966: <span class="LC_nobreak">
2967: <input name="newnav" type="submit" value="$lt{'navc'}" />
2968: $help{'Navigate_Content'}
2969: </span>
2970: </form>
2971: NNFORM
2972: my $newsmppageform=(<<NSPFORM);
2973: <form action="/adm/coursedocs" method="post" name="newsmppg">
2974: $uploadtag
2975: <input type="hidden" name="importdetail" value="" />
2976: <span class="LC_nobreak">
2977: <input name="newsmppg" type="button" value="$lt{'sipa'}"
2978: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
2979: </span>
2980: </form>
2981: NSPFORM
2982:
2983: my $newsmpproblemform=(<<NSPROBFORM);
2984: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2985: $uploadtag
2986: <input type="hidden" name="importdetail" value="" />
2987: <span class="LC_nobreak">
2988: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2989: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2990: </span>
2991: </form>
2992:
2993: NSPROBFORM
2994:
2995: my $newdropboxform=(<<NDBFORM);
2996: <form action="/adm/coursedocs" method="post" name="newdropbox">
2997: $uploadtag
2998: <input type="hidden" name="importdetail" value="" />
2999: <span class="LC_nobreak">
3000: <input name="newdropbox" type="button" value="$lt{'drbx'}"
3001: onClick="javascript:makedropbox();" />
3002: </span>
3003: </form>
3004: NDBFORM
3005:
3006: my $newexuploadform=(<<NEXUFORM);
3007: <form action="/adm/coursedocs" method="post" name="newexamupload">
3008: $uploadtag
3009: <input type="hidden" name="importdetail" value="" />
3010: <span class="LC_nobreak">
3011: <input name="newexamupload" type="button" value="$lt{'scuf'}"
3012: onClick="javascript:makeexamupload();" />
3013: $help{'Score_Upload_Form'}
3014: </span>
3015: </form>
3016: NEXUFORM
3017:
3018: my $newbulform=(<<NBFORM);
3019: <form action="/adm/coursedocs" method="post" name="newbul">
3020: $uploadtag
3021: <input type="hidden" name="importdetail" value="" />
3022: <span class="LC_nobreak">
3023: <input name="newbulletin" type="button" value="$lt{'bull'}"
3024: onClick="javascript:makebulboard();" />
3025: $help{'Bulletin Board'}
3026: </span>
3027: </form>
3028: NBFORM
3029:
3030: my $newaboutmeform=(<<NAMFORM);
3031: <form action="/adm/coursedocs" method="post" name="newaboutme">
3032: $uploadtag
3033: <input type="hidden" name="importdetail"
3034: value="$plainname=/adm/$udom/$uname/aboutme" />
3035: <span class="LC_nobreak">
3036: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3037: $help{'My Personal Info'}
3038: </span>
3039: </form>
3040: NAMFORM
3041:
3042: my $newaboutsomeoneform=(<<NASOFORM);
3043: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
3044: $uploadtag
3045: <input type="hidden" name="importdetail" value="" />
3046: <span class="LC_nobreak">
3047: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
3048: onClick="javascript:makeabout();" />
3049: </span>
3050: </form>
3051: NASOFORM
3052:
3053:
3054: my $newrosterform=(<<NROSTFORM);
3055: <form action="/adm/coursedocs" method="post" name="newroster">
3056: $uploadtag
3057: <input type="hidden" name="importdetail"
3058: value="$lt{'rost'}=/adm/viewclasslist" />
3059: <span class="LC_nobreak">
3060: <input name="newroster" type="submit" value="$lt{'rost'}" />
3061: $help{'Course Roster'}
3062: </span>
3063: </form>
3064: NROSTFORM
3065:
3066: unless ($env{'form.pagepath'}) {
3067: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3068:
3069: my $newpageform=(<<NPFORM);
3070: <form action="/adm/coursedocs" method="post" name="newpage">
3071: <input type="hidden" name="folderpath" value="$path" />
3072: <input type="hidden" name="importdetail" value="" />
3073: <span class="LC_nobreak">
3074: <input name="newpage" type="button"
3075: onClick="javascript:makenewpage(this.form,'$pageseq');"
3076: value="$lt{'newp'}" />$help{'Adding_Pages'}
3077: </span>
3078: </form>
3079: NPFORM
3080:
3081: my $newfolderform=(<<NFFORM);
3082: <form action="/adm/coursedocs" method="post" name="newfolder">
3083: <input type="hidden" name="folderpath" value="$path" />
3084: <input type="hidden" name="importdetail" value="" />
3085: <span class="LC_nobreak">
3086: <input name="newfolder" type="button"
3087: onClick="javascript:makenewfolder(this.form,'$folderseq');"
3088: value="$lt{'newf'}" />$help{'Adding_Folders'}
3089: </span>
3090: </form>
3091: NFFORM
3092:
3093: my $newsylform=(<<NSYLFORM);
3094: <form action="/adm/coursedocs" method="post" name="newsyl">
3095: $uploadtag
3096: <input type="hidden" name="importdetail"
3097: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
3098: <span class="LC_nobreak">
3099: <input name="newsyl" type="submit" value="$lt{'syll'}" />
3100: $help{'Syllabus'}
3101: </span>
3102: </form>
3103: NSYLFORM
3104:
3105: my $newgroupfileform=(<<NGFFORM);
3106: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
3107: $uploadtag
3108: <input type="hidden" name="importdetail"
3109: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
3110: <span class="LC_nobreak">
3111: <input name="newgroupfiles" type="submit" value="$lt{'grpo'}" />
3112: $help{'Group Files'}
3113: </span>
3114: </form>
3115: NGFFORM
3116:
3117:
1.333 muellerd 3118: my $specialdocumentsform=(<<SPDOFORM);
3119: <br />$newfolderform
3120: <br />$newpageform
3121: <br />$newsylform
3122: <br />$newnavform
3123: <br />$newsmppageform
3124: <br />$newsmpproblemform
3125: <br />$newdropboxform
3126: <br />$newexuploadform
3127: <br />$newbulform
3128: <br />$newaboutmeform
3129: <br />$newaboutsomeoneform
3130: <br />$newgroupfileform
3131: <br />$newrosterform
3132: SPDOFORM
1.330 tempelho 3133:
1.331 muellerd 3134:
1.330 tempelho 3135: my %orderhash = (
1.332 tempelho 3136: 'aa' => 'New Document',
3137: 'bb' => 'Published Documents',
3138: 'cc' => 'Special Documents',
3139: 'dd' => 'More Options',
1.334 muellerd 3140: 'zz' => 'Hide all Options',
1.330 tempelho 3141: );
3142: my %namehash = (
3143: 'New Document' => $fileuploadform,
3144: 'Published Documents' => $simpleeditdefaultform,
3145: 'Special Documents' => $specialdocumentsform,
3146: 'More Options' => $extresourcesform.'<br />'.$imspform.'<br />'.$recoverform,
3147: );
1.334 muellerd 3148: my $tid='1';
3149: my $content='content';
3150: my $navigation='navigation';
3151: my $varcd = 'Main Course Documents';
3152: $r->print(&generate_edit_table($tid,$content,$navigation,$varcd,\%namehash,\%orderhash));
1.335 ehlerst 3153: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3154: if ($error) {
3155: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3156: }
3157: $r->print('</div>');
1.330 tempelho 3158: }
1.329 droeschl 3159: if ($env{'form.pagepath'}) {
3160: }
3161: }
3162: # ----------------------------------------------------- Supplemental documents
3163: if (!$forcestandard) {
1.335 ehlerst 3164: my $active = 'style="display: none;"';
3165: if($activeClass == 1){
3166: $active = 'style="display: block;"';
3167: }
3168: $r->print('<div class="LC_ContentBox" id="Supplemental Course Documents" '.$active.'>');
1.329 droeschl 3169: my $folder=$env{'form.folder'};
3170: unless ($folder=~/^supplemental/) {
3171: $folder='supplemental';
3172: }
3173: if ($folder =~ /^supplemental$/ &&
3174: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3175: $env{'form.folderpath'} = 'supplemental&'.
3176: &escape(&mt('Supplemental '.$type.' Documents'));
3177: }
3178: if ($allowed) {
3179: my $folderseq=
3180: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3181: '.sequence';
3182:
3183: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3184:
3185: my $supupdocform=(<<SUPDOCFORM);
3186: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
3187: $fileupload
3188: <br />
3189: <br />
3190: <span class="LC_nobreak">
3191: $checkbox
3192: </span>
3193: <br /><br />
3194: $lt{'comment'}:<br />
3195: <textarea cols=50 rows=4 name='comment'>
3196: </textarea>
3197: <br />
3198: <input type="hidden" name="folderpath" value="$path" />
3199: <input type="hidden" name="cmd" value="upload_supplemental" />
3200: <span class="LC_nobreak">
3201: <input type="submit" value="$lt{'upld'}" />
3202: $help{'Uploading_From_Harddrive'}
3203: </span>
3204: </form>
3205: SUPDOCFORM
3206:
3207: my $supnewfolderform=(<<SNFFORM);
3208: <form action="/adm/coursedocs" method="post" name="supnewfolder">
3209: <input type="hidden" name="folderpath" value="$path" />
3210: <input type="hidden" name="importdetail" value="" />
3211: <span class="LC_nobreak">
3212: <input name="newfolder" type="button"
3213: onClick="javascript:makenewfolder(this.form,'$folderseq');"
3214: value="$lt{'newf'}" /> $help{'Adding_Folders'}
3215: </span>
3216: </form>
3217: SNFFORM
3218:
3219:
3220: my $supnewextform=(<<SNEFORM);
3221: <form action="/adm/coursedocs" method="post" name="supnewext">
3222: <input type="hidden" name="folderpath" value="$path" />
3223: <input type="hidden" name="importdetail" value="" />
3224: <span class="LC_nobreak">
3225: <input name="newext" type="button"
3226: onClick="javascript:makenewext('supnewext');"
3227: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
3228: </span>
3229: </form>
3230: SNEFORM
3231:
3232: my $supnewsylform=(<<SNSFORM);
3233: <form action="/adm/coursedocs" method="post" name="supnewsyl">
3234: <input type="hidden" name="folderpath" value="$path" />
3235: <input type="hidden" name="importdetail"
3236: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
3237: <span class="LC_nobreak">
3238: <input name="newsyl" type="submit" value="$lt{'syll'}" />
3239: $help{'Syllabus'}
3240: </span>
3241: </form>
3242: SNSFORM
3243:
3244: my $supnewaboutmeform=(<<SNAMFORM);
3245: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
3246: <input type="hidden" name="folderpath" value="$path" />
3247: <input type="hidden" name="importdetail"
3248: value="$plainname=/adm/$udom/$uname/aboutme" />
3249: <span class="LC_nobreak">
3250: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
3251: $help{'My Personal Info'}
3252: </span>
3253: </form>
3254: SNAMFORM
3255:
1.333 muellerd 3256:
3257:
3258: my %suporderhash = (
3259: 'ee' => 'New Document',
3260: 'ff' => 'Special Documents',
3261: 'zz' => 'Hide all Options',
3262: );
3263:
3264: my %supnamehash = (
3265: 'New Document' => $supupdocform,
3266: 'Special Documents' => $supnewfolderform.'<br />'.$supnewextform.'<br />'.$supnewsylform.'<br />'.$supnewaboutmeform,
3267: );
1.334 muellerd 3268:
1.333 muellerd 3269: my $tid='2';
1.334 muellerd 3270: my $content='content';
3271: my $navigation='navigation';
3272: my $varscd = 'Supplemental Course Documents';
1.333 muellerd 3273:
1.334 muellerd 3274: $r->print(&generate_edit_table($tid,$content,$navigation,$varscd,\%supnamehash,\%suporderhash));
1.335 ehlerst 3275: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3276: if ($error) {
3277: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3278: }
1.337 ehlerst 3279: $r->print('</div>');
1.333 muellerd 3280: }
3281: }
1.337 ehlerst 3282: $r->print('<div class="LC_ContentBox" id="Special Admin Options" style="display: none;">');
3283: $r->print(&generate_admin_options($containertag,$uploadtag,\%help,\%env));
3284: $r->print('</div>');
1.335 ehlerst 3285: $r->print('</div>');
1.329 droeschl 3286: if ($allowed) {
3287: $r->print('
3288: <form method="post" name="extimport" action="/adm/coursedocs">
3289: <input type="hidden" name="title" />
3290: <input type="hidden" name="url" />
3291: <input type="hidden" name="useform" />
3292: <input type="hidden" name="residx" />
3293: </form>');
3294: }
3295: } else {
3296: unless ($upload_result eq 'phasetwo') {
3297: # -------------------------------------------------------- This is showdoc mode
3298: $r->print("<h1>".&mt('Uploaded Document').' - '.
3299: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3300: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3301: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3302: }
3303: }
3304: }
3305: $r->print(&Apache::loncommon::end_page());
3306: return OK;
3307: }
3308:
3309: sub generate_admin_options {
1.337 ehlerst 3310: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3311: my %lt=&Apache::lonlocal::texthash(
3312: 'vc' => 'Verify Content',
3313: 'cv' => 'Check/Set Resource Versions',
3314: 'ls' => 'List Symbs',
3315: 'sl' => 'Show Log'
3316: );
1.329 droeschl 3317: my %help = %{$help_ref};
3318: my %env = %{$env_ref};
3319: my $dumpbut=&dumpbutton();
3320: my $exportbut=&exportbutton();
3321: return (<<ENDOPTIONFORM);
3322: <form action="/adm/coursedocs" method="post" name="courseverify">
3323: <ul style="list-style-type:none">
3324: <li>
3325: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
3326: </li>
3327: <li>
3328: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
3329: </li>
3330: <li>
3331: $dumpbut
3332: </li>
3333: <li>
3334: $exportbut
3335: </li>
3336: <li>
3337: <input type="submit" name="listsymbs" value="$lt{'ls'}" />
3338: </li>
3339: <li>
3340: <input type="hidden" name="folder" value="$env{'form.folder'}" />
3341: <input type="submit" name="docslog" value="$lt{'sl'}" />
3342: </li>
3343: </ul>
3344: </form>
1.337 ehlerst 3345: <!-- <div style="clear: both; height: 0px;"> </div>-->
1.329 droeschl 3346: ENDOPTIONFORM
1.330 tempelho 3347:
1.329 droeschl 3348: }
3349:
1.330 tempelho 3350:
1.329 droeschl 3351: sub generate_edit_table {
1.334 muellerd 3352: my ($tid,$content,$navigation,$varcd,$namehash_ref,$orderhash_ref) = @_;
1.329 droeschl 3353: my %namehash = %{$namehash_ref}; #name verlinkt mit id
3354: my %orderhash = %{$orderhash_ref}; #name mit kürzel verlinkt mit name
3355: my $form;
1.331 muellerd 3356:
1.334 muellerd 3357:
1.333 muellerd 3358:
1.334 muellerd 3359: $form = '<div class="LC_ContentBoxSpecial"><h4 class="LC_hcell">'.&mt($varcd).'</h4>';
3360: $form .= '<ul id="'.$navigation.$tid.'" class="LC_TabContent">';
1.329 droeschl 3361: foreach my $name (sort(keys(%orderhash))){
1.332 tempelho 3362: if($name eq 'zz'){
1.334 muellerd 3363: $form .= '<li onclick="javascript:hideAll(this, \''.$navigation.$tid.'\' ,\''.$content.$tid.'\');" class="active">'.&mt($orderhash{$name}).'</li>';
1.329 droeschl 3364: }else{
1.334 muellerd 3365: $form .= '<li onclick="javascript:showPage(this, \''.$tid.$orderhash{$name}.'\', \''.$navigation.$tid.'\',\''.$content.$tid.'\');">'.&mt($orderhash{$name}).'</li>';
1.329 droeschl 3366: }
3367: }
1.334 muellerd 3368: $form .= '<div id="'.$content.$tid.'" style="padding: 0 0; margin: 0 0;">';
1.330 tempelho 3369: foreach my $field (keys(%namehash)){
1.334 muellerd 3370: $form .= '<div id="'.$tid.$field.'" class="LC_ContentBox" style="display: none;">'.$namehash{$field}.'</div>';
1.332 tempelho 3371: }
1.330 tempelho 3372: $form .= '</div></div>';
1.334 muellerd 3373:
1.329 droeschl 3374: return $form;
3375: }
3376:
3377: sub editing_js {
3378: my ($udom,$uname) = @_;
3379: my $now = time();
3380: my %lt = &Apache::lonlocal::texthash(
3381: p_mnf => 'Name of New Folder',
3382: t_mnf => 'New Folder',
3383: p_mnp => 'Name of New Page',
3384: t_mnp => 'New Page',
3385: p_mxu => 'Title for the Uploaded Score',
3386: p_msp => 'Title for the Page',
3387: p_msb => 'Title for the Problem',
3388: p_mdb => 'Title for the Drop Box',
1.336 schafran 3389: p_mbb => 'Title for the Discussion Board',
1.329 droeschl 3390: p_mab => "Enter user:domain for User's 'About Me' Page",
3391: p_mab2 => "About [_99]",
3392: p_mab_alrt1 => 'Not a valid user:domain',
3393: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3394: p_chn => 'New Title',
3395: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3396: p_rmr2a => 'Remove[_99]',
3397: p_rmr2b => '?[_99]',
3398: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3399: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3400: p_ctr2a => 'Cut[_98]',
3401: p_ctr2b => '?[_98]'
3402: );
3403:
3404: return <<ENDNEWSCRIPT;
3405: function makenewfolder(targetform,folderseq) {
3406: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3407: if (foldername) {
3408: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3409: targetform.submit();
3410: }
3411: }
3412:
3413: function makenewpage(targetform,folderseq) {
3414: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3415: if (pagename) {
3416: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3417: targetform.submit();
3418: }
3419: }
3420:
3421: function makenewext(targetname) {
3422: this.document.forms.extimport.useform.value=targetname;
3423: this.document.forms.extimport.title.value='';
3424: this.document.forms.extimport.url.value='';
3425: this.document.forms.extimport.residx.value='';
3426: window.open('/adm/rat/extpickframe.html');
3427: }
3428:
3429: function edittext(targetname,residx,title,url) {
3430: this.document.forms.extimport.useform.value=targetname;
3431: this.document.forms.extimport.residx.value=residx;
3432: this.document.forms.extimport.url.value=url;
3433: this.document.forms.extimport.title.value=title;
3434: window.open('/adm/rat/extpickframe.html');
3435: }
3436:
3437: function makeexamupload() {
3438: var title=prompt('$lt{"p_mxu"}');
3439: if (title) {
3440: this.document.forms.newexamupload.importdetail.value=
3441: escape(title)+'=/res/lib/templates/examupload.problem';
3442: this.document.forms.newexamupload.submit();
3443: }
3444: }
3445:
3446: function makesmppage() {
3447: var title=prompt('$lt{"p_msp"}');
3448: if (title) {
3449: this.document.forms.newsmppg.importdetail.value=
3450: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3451: this.document.forms.newsmppg.submit();
3452: }
3453: }
3454:
3455: function makesmpproblem() {
3456: var title=prompt('$lt{"p_msb"}');
3457: if (title) {
3458: this.document.forms.newsmpproblem.importdetail.value=
3459: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3460: this.document.forms.newsmpproblem.submit();
3461: }
3462: }
3463:
3464: function makedropbox() {
3465: var title=prompt('$lt{"p_mdb"}');
3466: if (title) {
3467: this.document.forms.newdropbox.importdetail.value=
3468: escape(title)+'=/res/lib/templates/DropBox.problem';
3469: this.document.forms.newdropbox.submit();
3470: }
3471: }
3472:
3473: function makebulboard() {
3474: var title=prompt('$lt{"p_mbb"}');
3475: if (title) {
3476: this.document.forms.newbul.importdetail.value=
3477: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3478: this.document.forms.newbul.submit();
3479: }
3480: }
3481:
3482: function makeabout() {
3483: var user=prompt("$lt{'p_mab'}");
3484: if (user) {
3485: var comp=new Array();
3486: comp=user.split(':');
3487: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3488: if ((comp[0]) && (comp[1])) {
3489: this.document.forms.newaboutsomeone.importdetail.value=
3490: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3491: this.document.forms.newaboutsomeone.submit();
3492: } else {
3493: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3494: }
1.335 ehlerst 3495: } else {
3496: alert("$lt{'p_mab_alrt2'}");
3497: }
3498: }
1.329 droeschl 3499: }
3500:
3501: function makeims() {
1.335 ehlerst 3502: var caller = document.forms.ims.folder.value;
3503: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3504: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3505: newWindow.location.href = newlocation;
1.329 droeschl 3506: }
3507:
3508:
3509: function finishpick() {
1.335 ehlerst 3510: var title=this.document.forms.extimport.title.value;
3511: var url=this.document.forms.extimport.url.value;
3512: var form=this.document.forms.extimport.useform.value;
3513: var residx=this.document.forms.extimport.residx.value;
3514: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3515: }
3516:
3517: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3518: var title=prompt('$lt{"p_chn"}',oldtitle);
3519: if (title) {
3520: this.document.forms.renameform.markcopy.value=-1;
3521: this.document.forms.renameform.title.value=title;
3522: this.document.forms.renameform.cmd.value='rename_'+index;
3523: if (container == 'sequence') {
3524: this.document.forms.renameform.folderpath.value=folderpath;
3525: }
3526: if (container == 'page') {
3527: this.document.forms.renameform.pagepath.value=folderpath;
3528: this.document.forms.renameform.pagesymb.value=pagesymb;
3529: }
3530: this.document.forms.renameform.submit();
3531: }
1.329 droeschl 3532: }
3533:
3534: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3535: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3536: this.document.forms.renameform.markcopy.value=-1;
3537: this.document.forms.renameform.cmd.value='del_'+index;
3538: if (container == 'sequence') {
3539: this.document.forms.renameform.folderpath.value=folderpath;
3540: }
3541: if (container == 'page') {
3542: this.document.forms.renameform.pagepath.value=folderpath;
3543: this.document.forms.renameform.pagesymb.value=pagesymb;
3544: }
3545: this.document.forms.renameform.submit();
3546: }
1.329 droeschl 3547: }
3548:
3549: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3550: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3551: this.document.forms.renameform.cmd.value='cut_'+index;
3552: this.document.forms.renameform.markcopy.value=index;
3553: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3554: if (container == 'sequence') {
3555: this.document.forms.renameform.folderpath.value=folderpath;
3556: }
3557: if (container == 'page') {
3558: this.document.forms.renameform.pagepath.value=folderpath;
3559: this.document.forms.renameform.pagesymb.value=pagesymb;
3560: }
3561: this.document.forms.renameform.submit();
3562: }
1.329 droeschl 3563: }
3564:
3565: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3566: this.document.forms.renameform.markcopy.value=index;
3567: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3568: if (container == 'sequence') {
3569: this.document.forms.renameform.folderpath.value=folderpath;
3570: }
3571: if (container == 'page') {
3572: this.document.forms.renameform.pagepath.value=folderpath;
3573: this.document.forms.renameform.pagesymb.value=pagesymb;
3574: }
3575: this.document.forms.renameform.submit();
1.329 droeschl 3576: }
3577:
1.334 muellerd 3578: function unselectInactive(nav) {
1.335 ehlerst 3579: currentNav = document.getElementById(nav);
3580: currentLis = currentNav.getElementsByTagName('LI');
3581: for (i = 0; i < currentLis.length; i++) {
3582: currentLis[i].className = 'i';
3583: }
1.332 tempelho 3584: }
3585:
1.334 muellerd 3586: function hideAll(current, nav, data) {
1.335 ehlerst 3587: unselectInactive(nav);
3588: current.className = 'active';
3589: currentData = document.getElementById(data);
3590: currentDivs = currentData.getElementsByTagName('DIV');
3591: for (i = 0; i < currentDivs.length; i++) {
3592: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3593: currentDivs[i].style.display = 'none';
1.330 tempelho 3594: }
3595: }
1.335 ehlerst 3596: }
1.330 tempelho 3597:
1.334 muellerd 3598: function showPage(current, pageId, nav, data) {
3599: hideAll(current, nav, data);
3600: unselectInactive(nav);
1.330 tempelho 3601: current.className = 'active';
3602: currentData = document.getElementById(pageId);
3603: currentData.style.display = 'block';
3604: return false;
3605: }
1.329 droeschl 3606:
3607: ENDNEWSCRIPT
3608: }
3609: 1;
3610: __END__
3611:
3612:
3613: =head1 NAME
3614:
3615: Apache::londocs.pm
3616:
3617: =head1 SYNOPSIS
3618:
3619: This is part of the LearningOnline Network with CAPA project
3620: described at http://www.lon-capa.org.
3621:
3622: =head1 SUBROUTINES
3623:
3624: =over
3625:
3626: =item %help=()
3627:
3628: Available help topics
3629:
3630: =item mapread()
3631:
3632: Mapread read maps into LONCAPA::map:: global arrays
3633: @order and @resources, determines status
3634: sets @order - pointer to resources in right order
3635: sets @resources - array with the resources with correct idx
3636:
3637: =item authorhosts()
3638:
3639: Return hash with valid author names
3640:
3641: =item dumpbutton()
3642:
3643: Generate "dump" button
3644:
3645: =item clean()
3646:
3647: =item dumpcourse()
3648:
3649: Actually dump course
3650:
3651:
3652: =item exportbutton()
3653:
3654: Generate "export" button
3655:
3656: =item exportcourse()
3657:
3658: =item create_ims_store()
3659:
3660: =item build_package()
3661:
3662: =item get_dependencies()
3663:
3664: =item process_content()
3665:
3666: =item replicate_content()
3667:
3668: =item extract_media()
3669:
3670: =item store_template()
3671:
3672: =item group_import()
3673:
3674: Imports the given (name, url) resources into the course
3675: coursenum, coursedom, and folder must precede the list
3676:
3677: =item breadcrumbs()
3678:
3679: =item log_docs()
3680:
3681: =item docs_change_log()
3682:
3683: =item update_paste_buffer()
3684:
3685: =item print_paste_buffer()
3686:
3687: =item do_paste_from_buffer()
3688:
3689: =item update_parameter()
3690:
3691: =item handle_edit_cmd()
3692:
3693: =item editor()
3694:
3695: =item process_file_upload()
3696:
3697: =item process_secondary_uploads()
3698:
3699: =item is_supplemental_title()
3700:
3701: =item parse_supplemental_title()
3702:
3703: =item entryline()
3704:
3705: =item tiehash()
3706:
3707: =item untiehash()
3708:
3709: =item checkonthis()
3710:
3711: check on this
3712:
3713: =item verifycontent()
3714:
3715: Verify Content
3716:
3717: =item devalidateversioncache() & checkversions()
3718:
3719: Check Versions
3720:
3721: =item mark_hash_old()
3722:
3723: =item is_hash_old()
3724:
3725: =item changewarning()
3726:
3727: =item init_breadcrumbs()
3728:
3729: Breadcrumbs for special functions
3730:
3731: =back
3732:
3733: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>