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