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