Annotation of loncom/interface/londocs.pm, revision 1.392
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.392 ! raeburn 4: # $Id: londocs.pm,v 1.391 2009/10/16 00:38:10 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') {
1035: if ($allowed) {
1036: $name = &mt('Supplemental '.$type.' Documents');
1037: } else {
1038: $name = &mt($type.' Documents');
1039: }
1040: }
1041: &Apache::lonhtmlcommon::add_breadcrumb(
1042: {'href'=>$url.$cpinfo,
1043: 'title'=>$name,
1.367 droeschl 1044: 'text'=>$name,
1.329 droeschl 1045: 'no_mt'=>1,
1046: });
1047: $plain.=$name.' > ';
1048: }
1049: $plain=~s/\>\;\s*$//;
1050: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.379 bisitz 1051: undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1.329 droeschl 1052: }
1053:
1054: sub log_docs {
1055: return &Apache::lonnet::instructor_log('docslog',@_);
1056: }
1057:
1058: {
1059: my @oldresources=();
1060: my @oldorder=();
1061: my $parmidx;
1062: my %parmaction=();
1063: my %parmvalue=();
1064: my $changedflag;
1065:
1066: sub snapshotbefore {
1067: @oldresources=@LONCAPA::map::resources;
1068: @oldorder=@LONCAPA::map::order;
1069: $parmidx=undef;
1070: %parmaction=();
1071: %parmvalue=();
1072: $changedflag=0;
1073: }
1074:
1075: sub remember_parms {
1076: my ($idx,$parameter,$action,$value)=@_;
1077: $parmidx=$idx;
1078: $parmaction{$parameter}=$action;
1079: $parmvalue{$parameter}=$value;
1080: $changedflag=1;
1081: }
1082:
1083: sub log_differences {
1084: my ($plain)=@_;
1085: my %storehash=('folder' => $plain,
1086: 'currentfolder' => $env{'form.folder'});
1087: if ($parmidx) {
1088: $storehash{'parameter_res'}=$oldresources[$parmidx];
1089: foreach my $parm (keys(%parmaction)) {
1090: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1091: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1092: }
1093: }
1094: my $maxidx=$#oldresources;
1095: if ($#LONCAPA::map::resources>$#oldresources) {
1096: $maxidx=$#LONCAPA::map::resources;
1097: }
1098: for (my $idx=0; $idx<=$maxidx; $idx++) {
1099: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1100: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1101: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1102: $changedflag=1;
1103: }
1104: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1105: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1106: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1107: $changedflag=1;
1108: }
1109: }
1110: $storehash{'maxidx'}=$maxidx;
1111: if ($changedflag) { &log_docs(\%storehash); }
1112: }
1113: }
1114:
1115:
1116:
1117:
1118:
1119: sub docs_change_log {
1120: my ($r)=@_;
1121: my $folder=$env{'form.folder'};
1122: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1123: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1124: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1125: $env{'course.'.$env{'request.course.id'}.'.domain'},
1126: $env{'course.'.$env{'request.course.id'}.'.num'});
1127:
1128: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1129:
1130: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1131: '<input type="hidden" name="docslog" value="1" />');
1132:
1133: my %saveable_parameters = ('show' => 'scalar',);
1134: &Apache::loncommon::store_course_settings('docs_log',
1135: \%saveable_parameters);
1136: &Apache::loncommon::restore_course_settings('docs_log',
1137: \%saveable_parameters);
1138: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1139: my %lt=('hiddenresource' => 'Resources hidden',
1140: 'encrypturl' => 'URL hidden',
1141: 'randompick' => 'Randomly pick',
1142: 'randomorder' => 'Randomly ordered',
1143: 'set' => 'set to',
1144: 'del' => 'deleted');
1145: $r->print(&Apache::loncommon::display_filter().
1146: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1147: '<input type="submit" value="'.&mt('Display').'" /></form>');
1148: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1149: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1150: &mt('After').'</th>'.
1151: &Apache::loncommon::end_data_table_header_row());
1152: my $shown=0;
1153: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1154: if ($env{'form.displayfilter'} eq 'currentfolder') {
1155: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1156: }
1157: my @changes=keys(%{$docslog{$id}{'logentry'}});
1158: if ($env{'form.displayfilter'} eq 'containing') {
1159: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1160: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1161: foreach my $key (@changes) {
1162: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1163: }
1.344 bisitz 1164: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1165: }
1166: my $count = 0;
1167: my $time =
1168: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1169: my $plainname =
1170: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1171: $docslog{$id}{'exe_udom'});
1172: my $about_me_link =
1173: &Apache::loncommon::aboutmewrapper($plainname,
1174: $docslog{$id}{'exe_uname'},
1175: $docslog{$id}{'exe_udom'});
1176: my $send_msg_link='';
1177: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1178: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1179: $send_msg_link ='<br />'.
1180: &Apache::loncommon::messagewrapper(&mt('Send message'),
1181: $docslog{$id}{'exe_uname'},
1182: $docslog{$id}{'exe_udom'});
1183: }
1184: $r->print(&Apache::loncommon::start_data_table_row());
1185: $r->print('<td>'.$time.'</td>
1186: <td>'.$about_me_link.
1187: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1188: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1189: $send_msg_link.'</td><td>'.
1190: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1191: # Before
1192: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1193: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1194: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1195: if ($oldname ne $newname) {
1196: $r->print(&LONCAPA::map::qtescape($oldname));
1197: }
1198: }
1199: $r->print('<ul>');
1200: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1201: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1202: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1203: }
1204: }
1205: $r->print('</ul>');
1206: # After
1207: $r->print('</td><td>');
1208:
1209: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1210: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1211: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1212: if ($oldname ne '' && $oldname ne $newname) {
1213: $r->print(&LONCAPA::map::qtescape($newname));
1214: }
1.364 bisitz 1215: }
1.329 droeschl 1216: $r->print('<ul>');
1217: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1218: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1219: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1220: }
1221: }
1222: $r->print('</ul>');
1223: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1224: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1225: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1226: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1227: $r->print('<li>'.
1228: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1229: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1230: .'</li>');
1231: }
1232: }
1233: $r->print('</ul>');
1234: }
1235: # End
1236: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1237: $shown++;
1238: if (!($env{'form.show'} eq &mt('all')
1239: || $shown<=$env{'form.show'})) { last; }
1240: }
1241: $r->print(&Apache::loncommon::end_data_table());
1242: }
1243:
1244: sub update_paste_buffer {
1245: my ($coursenum,$coursedom) = @_;
1246:
1247: return if (!defined($env{'form.markcopy'}));
1248: return if (!defined($env{'form.copyfolder'}));
1249: return if ($env{'form.markcopy'} < 0);
1250:
1251: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1252: $env{'form.copyfolder'});
1.364 bisitz 1253:
1.329 droeschl 1254: return if ($fatal);
1255:
1256: # Mark for copying
1257: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1258: if (&is_supplemental_title($title)) {
1259: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1260: ($title) = &parse_supplemental_title($title);
1261: } elsif ($env{'docs.markedcopy_supplemental'}) {
1.346 raeburn 1262: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329 droeschl 1263: }
1264: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1265:
1266: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
1267: 'docs.markedcopy_url' => $url});
1268: delete($env{'form.markcopy'});
1269: }
1270:
1271: sub print_paste_buffer {
1272: my ($r,$container) = @_;
1273: return if (!defined($env{'docs.markedcopy_url'}));
1274:
1.381 bisitz 1275: $r->print('<fieldset>'
1276: .'<legend>'.&mt('Clipboard').'</legend>'
1277: .'<form name="pasteform" action="/adm/coursedocs" method="post">'
1278: .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '
1279: );
1.329 droeschl 1280:
1281: my $type;
1282: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1283: $type = &mt('External Resource');
1284: $r->print($type.': '.
1285: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1286: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
1287: } else {
1288: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1289: my $icon = &Apache::loncommon::icon($extension);
1290: if ($extension eq 'sequence' &&
1291: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
1292: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1.380 bisitz 1293: $icon .= '/navmap.folder.closed.gif';
1.329 droeschl 1294: }
1295: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1296: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1297: }
1298: if ($container eq 'page') {
1299: $r->print('
1300: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
1301: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
1302: ');
1303: } else {
1304: $r->print('
1305: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1306: ');
1307: }
1.381 bisitz 1308: $r->print('</form></fieldset>');
1.329 droeschl 1309: }
1310:
1311: sub do_paste_from_buffer {
1312: my ($coursenum,$coursedom,$folder) = @_;
1313:
1314: if (!$env{'form.pastemarked'}) {
1315: return;
1316: }
1317:
1318: # paste resource to end of list
1319: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
1320: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1321: # Maps need to be copied first
1322: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
1323: $title=&mt('Copy of').' '.$title;
1324: my $newid=$$.int(rand(100)).time;
1325: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1326: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
1327: my $path = $1;
1328: my $prefix = $2;
1329: my $ancestor = $3;
1330: if (length($ancestor) > 10) {
1331: $ancestor = substr($ancestor,-10,10);
1332: }
1333: $oldid = $path.$prefix.$ancestor;
1334: }
1335: my $counter = 0;
1336: my $newurl=$oldid.$newid.'.'.$ext;
1337: my $is_unique = &uniqueness_check($newurl);
1338: while (!$is_unique && $counter < 100) {
1339: $counter ++;
1340: $newid ++;
1341: $newurl = $oldid.$newid;
1342: $is_unique = &uniqueness_check($newurl);
1343: }
1344: if (!$is_unique) {
1345: if ($url=~/\.page$/) {
1346: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
1347: } else {
1348: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
1349: }
1350: }
1351: my $storefn=$newurl;
1352: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1353: my $paste_map_result =
1354: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1355: &Apache::lonnet::getfile($url));
1356: if ($paste_map_result eq '/adm/notfound.html') {
1357: if ($url=~/\.page$/) {
1358: return &mt('Paste failed: an error occurred saving the composite page');
1359: } else {
1360: return &mt('Paste failed: an error occurred saving the folder');
1361: }
1362: }
1363: $url = $newurl;
1364: }
1365: # published maps can only exists once, so remove it from paste buffer when done
1366: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
1.346 raeburn 1367: &Apache::lonnet::delenv('docs.markedcopy');
1.329 droeschl 1368: }
1369: if ($url=~ m{/smppg$}) {
1370: my $db_name = &Apache::lonsimplepage::get_db_name($url);
1371: if ($db_name =~ /^smppage_/) {
1372: #simple pages, need to copy the db contents to a new one.
1373: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
1374: my $now = time();
1375: $db_name =~ s{_\d*$ }{_$now}x;
1376: my $result=&Apache::lonnet::put($db_name,\%contents,
1377: $coursedom,$coursenum);
1.344 bisitz 1378: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1.329 droeschl 1379: $title=&mt('Copy of').' '.$title;
1380: }
1381: }
1382: $title = &LONCAPA::map::qtunescape($title);
1383: my $ext='false';
1384: if ($url=~m{^http(|s)://}) { $ext='true'; }
1385: $url = &LONCAPA::map::qtunescape($url);
1386: # Now insert the URL at the bottom
1387: my $newidx = &LONCAPA::map::getresidx($url);
1388: if ($env{'docs.markedcopy_supplemental'}) {
1389: if ($folder =~ /^supplemental/) {
1390: $title = $env{'docs.markedcopy_supplemental'};
1391: } else {
1.344 bisitz 1392: (undef,undef,$title) =
1.329 droeschl 1393: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1394: }
1395: } else {
1396: if ($folder=~/^supplemental/) {
1397: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1398: $env{'user.domain'}.'___&&&___'.$title;
1399: }
1400: }
1401:
1402: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1403: push(@LONCAPA::map::order, $newidx);
1404: return 'ok';
1405: # Store the result
1406: }
1407:
1408: sub uniqueness_check {
1409: my ($newurl) = @_;
1410: my $unique = 1;
1411: foreach my $res (@LONCAPA::map::order) {
1412: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1413: $url=&LONCAPA::map::qtescape($url);
1414: if ($newurl eq $url) {
1415: $unique = 0;
1.344 bisitz 1416: last;
1.329 droeschl 1417: }
1418: }
1419: return $unique;
1420: }
1421:
1422: my %parameter_type = ( 'randompick' => 'int_pos',
1423: 'hiddenresource' => 'string_yesno',
1424: 'encrypturl' => 'string_yesno',
1425: 'randomorder' => 'string_yesno',);
1426: my $valid_parameters_re = join('|',keys(%parameter_type));
1427: # set parameters
1428: sub update_parameter {
1429:
1430: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1431:
1432: my $which = $env{'form.changeparms'};
1433: my $idx = $env{'form.setparms'};
1434: if ($env{'form.'.$which.'_'.$idx}) {
1435: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
1436: : 'yes';
1437: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
1438: $parameter_type{$which});
1439: &remember_parms($idx,$which,'set',$value);
1440: } else {
1441: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1.364 bisitz 1442:
1.329 droeschl 1443: &remember_parms($idx,$which,'del');
1444: }
1445: return 1;
1446: }
1447:
1448:
1449: sub handle_edit_cmd {
1450: my ($coursenum,$coursedom) =@_;
1451:
1452: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1453:
1454: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1455: my ($title, $url, @rrest) = split(':', $ratstr);
1456:
1457: if ($cmd eq 'del') {
1458: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1459: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1460: &Apache::lonnet::removeuploadedurl($url);
1461: } else {
1462: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1463: }
1464: splice(@LONCAPA::map::order, $idx, 1);
1465:
1466: } elsif ($cmd eq 'cut') {
1467: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1468: splice(@LONCAPA::map::order, $idx, 1);
1469:
1.344 bisitz 1470: } elsif ($cmd eq 'up'
1.329 droeschl 1471: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1472: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1473:
1474: } elsif ($cmd eq 'down'
1475: && defined($LONCAPA::map::order[$idx+1])) {
1476: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1477:
1478: } elsif ($cmd eq 'rename') {
1479:
1480: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
1481: if ($comment=~/\S/) {
1482: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1483: $comment.':'.join(':', $url, @rrest);
1484: }
1485: # Devalidate title cache
1486: my $renamed_url=&LONCAPA::map::qtescape($url);
1487: &Apache::lonnet::devalidate_title_cache($renamed_url);
1488: } else {
1489: return 0;
1490: }
1491: return 1;
1492: }
1493:
1494: sub editor {
1495: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
1496:
1497: my $container= ($env{'form.pagepath'}) ? 'page'
1498: : 'sequence';
1499:
1500: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1501: $folder.'.'.$container);
1502: return $errtext if ($fatal);
1503:
1504: if ($#LONCAPA::map::order<1) {
1505: my $idx=&LONCAPA::map::getresidx();
1506: if ($idx<=0) { $idx=1; }
1507: $LONCAPA::map::order[0]=$idx;
1508: $LONCAPA::map::resources[$idx]='';
1509: }
1.364 bisitz 1510:
1.329 droeschl 1511: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
1512: &breadcrumbs($folder,$allowed,$type);
1513: $r->print($breadcrumbtrail);
1.364 bisitz 1514:
1.329 droeschl 1515: # ------------------------------------------------------------ Process commands
1516:
1517: # ---------------- if they are for this folder and user allowed to make changes
1518: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1519: # set parameters and change order
1520: &snapshotbefore();
1521:
1522: if (&update_parameter()) {
1523: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1524: return $errtext if ($fatal);
1525: }
1526:
1527: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
1528: # change order
1529: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
1530: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
1531:
1532: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1533: return $errtext if ($fatal);
1534: }
1.364 bisitz 1535:
1.329 droeschl 1536: if ($env{'form.pastemarked'}) {
1.344 bisitz 1537: my $paste_res =
1.329 droeschl 1538: &do_paste_from_buffer($coursenum,$coursedom,$folder);
1539: if ($paste_res eq 'ok') {
1540: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
1541: return $errtext if ($fatal);
1542: } elsif ($paste_res ne '') {
1543: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
1544: }
1545: }
1546:
1547: $r->print($upload_output);
1548:
1549: if (&handle_edit_cmd()) {
1550: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1551: return $errtext if ($fatal);
1552: }
1553: # Group import/search
1554: if ($env{'form.importdetail'}) {
1555: my @imports;
1556: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
1557: if (defined($item)) {
1558: my ($name,$url,$residx)=
1559: map {&unescape($_)} split(/\=/,$item);
1560: push(@imports, [$name, $url, $residx]);
1561: }
1562: }
1563: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1564: $container,'londocs',@imports);
1565: return $errtext if ($fatal);
1566: }
1567: # Loading a complete map
1568: if ($env{'form.loadmap'}) {
1569: if ($env{'form.importmap'}=~/\w/) {
1570: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1571: my ($title,$url,$ext,$type)=split(/\:/,$res);
1572: my $idx=&LONCAPA::map::getresidx($url);
1573: $LONCAPA::map::resources[$idx]=$res;
1574: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1575: }
1576: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1577: $folder.'.'.$container);
1578: return $errtext if ($fatal);
1579: } else {
1580: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 1581:
1.329 droeschl 1582: }
1583: }
1584: &log_differences($plain);
1585: }
1586: # ---------------------------------------------------------------- End commands
1587: # ---------------------------------------------------------------- Print screen
1588: my $idx=0;
1589: my $shown=0;
1590: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 1591: $r->print('<div class="LC_Box">'.
1592: '<p>'.&mt('Parameters:').
1593: '<ul>'.
1594: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
1.329 droeschl 1595: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1596: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1.381 bisitz 1597: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.329 droeschl 1598: '</ul></p>');
1.381 bisitz 1599: if ($randompick>=0) {
1600: $r->print('<p class="LC_warning">'
1601: .&mt('Caution: this folder is set to randomly pick a subset'
1602: .' of resources. Adding or removing resources from this'
1603: .' folder will change the set of resources that the'
1604: .' students see, resulting in spurious or missing credit'
1605: .' for completed problems, not limited to ones you'
1606: .' modify. Do not modify the contents of this folder if'
1607: .' it is in active student use.')
1608: .'</p>'
1609: );
1610: }
1611: if ($is_random_order) {
1612: $r->print('<p class="LC_warning">'
1613: .&mt('Caution: this folder is set to randomly order its'
1614: .' contents. Adding or removing resources from this folder'
1615: .' will change the order of resources shown.')
1616: .'</p>'
1617: );
1618: }
1619: $r->print('</div>');
1.364 bisitz 1620: }
1.381 bisitz 1621:
1622: my $output;
1623: foreach my $res (@LONCAPA::map::order) {
1624: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1625: $name=&LONCAPA::map::qtescape($name);
1626: $url=&LONCAPA::map::qtescape($url);
1627: unless ($name) { $name=(split(/\//,$url))[-1]; }
1628: unless ($name) { $idx++; next; }
1629: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1630: $coursenum);
1631: $idx++;
1632: $shown++;
1.329 droeschl 1633: }
1.381 bisitz 1634: if ($shown) {
1635: $r->print(&Apache::loncommon::start_data_table()
1636: .&Apache::loncommon::start_data_table_header_row()
1637: .'<th colspan="2">'.&mt('Move').'</th>'
1638: .'<th>'.&mt('Actions').'</th>'
1639: .'<th colspan="2">'.&mt('Document').'</th>'
1640: .'<th colspan="4">'.&mt('Settings').'</th>'
1641: .&Apache::loncommon::end_data_table_header_row()
1642: .$output
1643: .&Apache::loncommon::end_data_table()
1644: )
1.383 tempelho 1645: }
1646: unless($shown) {
1.381 bisitz 1647: $r->print('<p class="LC_info">'
1648: .&mt('Currently no documents.')
1649: .'</p>'
1650: );
1.329 droeschl 1651: }
1652: if ($allowed) {
1653: &print_paste_buffer($r,$container);
1654: }
1655: return;
1656: }
1657:
1658: sub process_file_upload {
1659: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1660: # upload a file, if present
1661: my $parseaction;
1662: if ($env{'form.parserflag'}) {
1663: $parseaction = 'parse';
1664: }
1665: my $phase_status;
1666: my $folder=$env{'form.folder'};
1667: if ($folder eq '') {
1668: $folder='default';
1669: }
1670: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1671: my $errtext='';
1672: my $fatal=0;
1673: my $container='sequence';
1674: if ($env{'form.pagepath'}) {
1675: $container='page';
1676: }
1677: ($errtext,$fatal)=
1678: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1679: if ($#LONCAPA::map::order<1) {
1680: $LONCAPA::map::order[0]=1;
1681: $LONCAPA::map::resources[1]='';
1682: }
1683: if ($fatal) {
1684: return 'failed';
1685: }
1686: my $destination = 'docs/';
1687: if ($folder =~ /^supplemental/) {
1688: $destination = 'supplemental/';
1689: }
1690: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1691: $destination .= 'default/';
1692: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1693: $destination .= $2.'/';
1694: }
1695: # this is for a course, not a user, so set coursedoc flag
1696: # probably the only place in the system where this should be "1"
1697: my $newidx=&LONCAPA::map::getresidx();
1698: $destination .= $newidx;
1699: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1700: $parseaction,$allfiles,
1701: $codebase);
1702: my $ext='false';
1703: if ($url=~m{^http://}) { $ext='true'; }
1704: $url = &LONCAPA::map::qtunescape($url);
1705: my $comment=$env{'form.comment'};
1706: $comment = &LONCAPA::map::qtunescape($comment);
1707: if ($folder=~/^supplemental/) {
1708: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1709: $env{'user.domain'}.'___&&&___'.$comment;
1710: }
1711:
1712: $LONCAPA::map::resources[$newidx]=
1713: $comment.':'.$url.':'.$ext.':normal:res';
1714: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1715: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1716: $folder.'.'.$container);
1717: if ($fatal) {
1718: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1719: return 'failed';
1720: } else {
1721: if ($parseaction eq 'parse') {
1.384 raeburn 1722: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 1723: if ($total_embedded > 0) {
1724: my $num = 0;
1725: my $state = '
1726: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1727: <input type="hidden" name="cmd" value="upload_embedded" />
1728: <input type="hidden" name="newidx" value="'.$newidx.'" />
1729: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1730: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1731: $phase_status = 'phasetwo';
1732:
1.344 bisitz 1733: $$upload_output .=
1.329 droeschl 1734: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1735: &Apache::loncommon::ask_for_embedded_content(
1736: '/adm/coursedocs',$state,$allfiles,$codebase);
1737: } else {
1738: $$upload_output .= 'No embedded items identified<br />';
1739: }
1740: }
1741: }
1742: }
1743: return $phase_status;
1744: }
1745:
1746: sub process_secondary_uploads {
1747: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1748: my $folder=$env{'form.folder'};
1749: my $destination = 'docs/';
1750: if ($folder =~ /^supplemental/) {
1751: $destination = 'supplemental/';
1752: }
1753: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1754: $destination .= 'default/';
1755: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1756: $destination .= $2.'/';
1757: }
1758: $destination .= $newidx;
1759: my ($url,$filename);
1760: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1761: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1762: return $filename;
1763: }
1764:
1765: sub is_supplemental_title {
1766: my ($title) = @_;
1767: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1768: }
1769:
1770: sub parse_supplemental_title {
1771: my ($title) = @_;
1772:
1773: my ($foldertitle,$renametitle);
1774: if ($title =~ /&&&/) {
1775: $title = &HTML::Entites::decode($title);
1776: }
1777: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1778: $renametitle=$4;
1779: my ($time,$uname,$udom) = ($1,$2,$3);
1780: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1781: my $name = &Apache::loncommon::plainname($uname,$udom);
1782: $name = &HTML::Entities::encode($name,'"<>&\'');
1783: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1784: $name.': <br />'.$foldertitle;
1785: }
1786: if (wantarray) {
1787: return ($title,$foldertitle,$renametitle);
1.364 bisitz 1788: }
1.329 droeschl 1789: return $title;
1790: }
1791:
1792: # --------------------------------------------------------------- An entry line
1793:
1794: sub entryline {
1795: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1796:
1797: my ($foldertitle,$pagetitle,$renametitle);
1798: if (&is_supplemental_title($title)) {
1799: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1800: $pagetitle = $foldertitle;
1801: } else {
1802: $title=&HTML::Entities::encode($title,'"<>&\'');
1803: $renametitle=$title;
1804: $foldertitle=$title;
1805: $pagetitle=$title;
1806: }
1807:
1808: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 1809:
1.329 droeschl 1810:
1811: $renametitle=~s/\\/\\\\/g;
1812: $renametitle=~s/\"\;/\\\"/g;
1813: $renametitle=~s/ /%20/g;
1.379 bisitz 1814: my $line=&Apache::loncommon::start_data_table_row();
1.329 droeschl 1815: my ($form_start,$form_end);
1816: # Edit commands
1817: my ($container, $type, $esc_path, $path, $symb);
1818: if ($env{'form.folderpath'}) {
1819: $type = 'folder';
1820: $container = 'sequence';
1821: $esc_path=&escape($env{'form.folderpath'});
1822: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1823: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1824: }
1825: if ($env{'form.pagepath'}) {
1826: $type = $container = 'page';
1827: $esc_path=&escape($path = $env{'form.pagepath'});
1828: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1829: $symb=&escape($env{'form.pagesymb'});
1830: }
1831: my $cpinfo='';
1832: if ($allowed) {
1833: my $incindex=$index+1;
1834: my $selectbox='';
1835: if (($folder!~/^supplemental/) &&
1.344 bisitz 1836: ($#LONCAPA::map::order>0) &&
1.329 droeschl 1837: ((split(/\:/,
1.344 bisitz 1838: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1839: ne '') &&
1.329 droeschl 1840: ((split(/\:/,
1.344 bisitz 1841: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 1842: ne '')) {
1843: $selectbox=
1844: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 1845: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 1846: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1847: if ($i==$incindex) {
1.358 bisitz 1848: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 1849: } else {
1850: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1851: }
1852: }
1853: $selectbox.='</select>';
1854: }
1855: my %lt=&Apache::lonlocal::texthash(
1856: 'up' => 'Move Up',
1857: 'dw' => 'Move Down',
1858: 'rm' => 'Remove',
1859: 'ct' => 'Cut',
1860: 'rn' => 'Rename',
1861: 'cp' => 'Copy');
1862: my $nocopy=0;
1863: my $nocut=0;
1864: if ($url=~/\.(page|sequence)$/) {
1865: if ($url =~ m{/res/}) {
1866: # no copy for published maps
1867: $nocopy = 1;
1868: } else {
1869: foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1870: my ($title,$url,$ext,$type)=split(/\:/,$item);
1871: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1872: $nocopy=1;
1873: last;
1874: }
1875: }
1876: }
1877: }
1.344 bisitz 1878: if ($url=~/^\/res\/lib\/templates\//) {
1879: $nocopy=1;
1.329 droeschl 1880: $nocut=1;
1881: }
1882: my $copylink=' ';
1883: my $cutlink=' ';
1.364 bisitz 1884:
1.329 droeschl 1885: my $skip_confirm = 0;
1886: if ( $folder =~ /^supplemental/
1887: || ($url =~ m{( /smppg$
1888: |/syllabus$
1889: |/aboutme$
1890: |/navmaps$
1891: |/bulletinboard$
1892: |\.html$
1893: |^/adm/wrapper/ext)}x)) {
1894: $skip_confirm = 1;
1895: }
1896:
1897: if (!$nocopy) {
1898: $copylink=(<<ENDCOPY);
1899: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
1900: ENDCOPY
1901: }
1902: if (!$nocut) {
1903: $cutlink=(<<ENDCUT);
1904: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
1905: ENDCUT
1906: }
1907: $form_start = (<<END);
1908: <form action="/adm/coursedocs" method="post">
1909: <input type="hidden" name="${type}path" value="$path" />
1910: <input type="hidden" name="${type}symb" value="$symb" />
1911: <input type="hidden" name="setparms" value="$orderidx" />
1912: <input type="hidden" name="changeparms" value="0" />
1913: END
1914: $form_end = '</form>';
1915: $line.=(<<END);
1916: <td>
1.379 bisitz 1917: <div class="LC_docs_entry_move">
1918: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1919: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
1920: </a>
1921: </div>
1922: <div class="LC_docs_entry_move">
1923: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1924: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
1925: </a>
1926: </div>
1.329 droeschl 1927: </td>
1928: <td>
1929: $form_start
1930: $selectbox
1931: $form_end
1932: </td>
1933: <td class="LC_docs_entry_commands">
1934: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1935: $cutlink
1936: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1937: $copylink
1938: </td>
1939: END
1940:
1941: }
1942: # Figure out what kind of a resource this is
1943: my ($extension)=($url=~/\.(\w+)$/);
1944: my $uploaded=($url=~/^\/*uploaded\//);
1945: my $icon=&Apache::loncommon::icon($url);
1946: my $isfolder=0;
1947: my $ispage=0;
1948: my $folderarg;
1949: my $pagearg;
1950: my $pagefile;
1951: if ($uploaded) {
1952: if ($extension eq 'sequence') {
1.380 bisitz 1953: $icon=$iconpath.'/navmap.folder.closed.gif';
1.329 droeschl 1954: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1955: $url='/adm/coursedocs?';
1956: $folderarg=$1;
1957: $isfolder=1;
1958: } elsif ($extension eq 'page') {
1959: $icon=$iconpath.'/page.gif';
1960: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1961: $pagearg=$1;
1962: $url='/adm/coursedocs?';
1963: $ispage=1;
1964: } else {
1965: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1966: }
1967: }
1.364 bisitz 1968:
1.329 droeschl 1969: my $orig_url = $url;
1.340 raeburn 1970: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.329 droeschl 1971: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1972: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1973: my $symb=&Apache::lonnet::symbclean(
1974: &Apache::lonnet::declutter('uploaded/'.
1975: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1976: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1977: '.sequence').
1978: '___'.$residx.'___'.
1979: &Apache::lonnet::declutter($url));
1980: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1981: $url=&Apache::lonnet::clutter($url);
1982: if ($url=~/^\/*uploaded\//) {
1983: $url=~/\.(\w+)$/;
1984: my $embstyle=&Apache::loncommon::fileembstyle($1);
1985: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1986: $url='/adm/wrapper'.$url;
1987: } elsif ($embstyle eq 'ssi') {
1988: #do nothing with these
1989: } elsif ($url!~/\.(sequence|page)$/) {
1990: $url='/adm/coursedocs/showdoc'.$url;
1991: }
1.344 bisitz 1992: } elsif ($url=~m|^/ext/|) {
1.329 droeschl 1993: $url='/adm/wrapper'.$url;
1994: $external = 1;
1995: }
1996: if (&Apache::lonnet::symbverify($symb,$url)) {
1997: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1998: } else {
1999: $url='';
2000: }
2001: if ($container eq 'page') {
2002: my $symb=$env{'form.pagesymb'};
1.364 bisitz 2003:
1.329 droeschl 2004: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2005: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2006: }
2007: }
2008: my ($parameterset,$rand_order_text) = (' ', ' ');
2009: if ($isfolder || $extension eq 'sequence') {
2010: my $foldername=&escape($foldertitle);
2011: my $folderpath=$env{'form.folderpath'};
2012: if ($folderpath) { $folderpath.='&' };
1.344 bisitz 2013: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2014: # so it gets transferred between levels
2015: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
2016: 'parameter_randompick'))[0]
2017: .':'.((&LONCAPA::map::getparameter($orderidx,
2018: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2019: .':'.((&LONCAPA::map::getparameter($orderidx,
2020: 'parameter_encrypturl'))[0]=~/^yes$/i)
2021: .':'.((&LONCAPA::map::getparameter($orderidx,
2022: 'parameter_randomorder'))[0]=~/^yes$/i);
2023: $url.='folderpath='.&escape($folderpath).$cpinfo;
2024: $parameterset='<label>'.&mt('Randomly Pick: ').
1.373 bisitz 2025: '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
1.329 droeschl 2026: (&LONCAPA::map::getparameter($orderidx,
2027: 'parameter_randompick'))[0].
2028: '" />'.
2029: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
2030: my $ro_set=
2031: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
2032: $rand_order_text ='
1.369 bisitz 2033: <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 2034: }
2035: if ($ispage) {
2036: my $pagename=&escape($pagetitle);
2037: my $pagepath;
2038: my $folderpath=$env{'form.folderpath'};
2039: if ($folderpath) { $pagepath = $folderpath.'&' };
2040: $pagepath.=$pagearg.'&'.$pagename;
2041: my $symb=$env{'form.pagesymb'};
2042: if (!$symb) {
2043: my $path='uploaded/'.
2044: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2045: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2046: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
2047: $residx,
2048: $path.$pagearg.'.page');
2049: }
2050: $url.='pagepath='.&escape($pagepath).
2051: '&pagesymb='.&escape($symb).$cpinfo;
2052: }
2053: if ($external) {
2054: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
2055: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
2056: } else {
2057: undef($external);
2058: }
2059: $line.='
1.379 bisitz 2060: <td>
1.329 droeschl 2061: '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
2062: </td>
1.379 bisitz 2063: <td>
1.329 droeschl 2064: '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.&mt('(re-initialize course to access)').'</span>').$external."
2065: </td>";
2066: if (($allowed) && ($folder!~/^supplemental/)) {
2067: my %lt=&Apache::lonlocal::texthash(
2068: 'hd' => 'Hidden',
2069: 'ec' => 'URL hidden');
2070: my $enctext=
1.358 bisitz 2071: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2072: my $hidtext=
1.358 bisitz 2073: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2074: $line.=(<<ENDPARMS);
2075: <td class="LC_docs_entry_parameter">
2076: $form_start
1.369 bisitz 2077: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2078: $form_end
2079: </td>
2080: <td class="LC_docs_entry_parameter">
2081: $form_start
1.369 bisitz 2082: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2083: $form_end
2084: </td>
2085: <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
2086: <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
2087: ENDPARMS
2088: }
1.379 bisitz 2089: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2090: return $line;
2091: }
2092:
2093: =pod
2094:
2095: =item tiehash()
2096:
2097: tie the hash
2098:
2099: =cut
2100:
2101: sub tiehash {
2102: my ($mode)=@_;
2103: $hashtied=0;
2104: if ($env{'request.course.fn'}) {
2105: if ($mode eq 'write') {
2106: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2107: &GDBM_WRCREAT(),0640)) {
2108: $hashtied=2;
2109: }
2110: } else {
2111: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2112: &GDBM_READER(),0640)) {
2113: $hashtied=1;
2114: }
2115: }
1.364 bisitz 2116: }
1.329 droeschl 2117: }
2118:
2119: sub untiehash {
2120: if ($hashtied) { untie %hash; }
2121: $hashtied=0;
2122: return OK;
2123: }
2124:
2125:
2126:
2127:
2128: sub checkonthis {
2129: my ($r,$url,$level,$title)=@_;
2130: $url=&unescape($url);
2131: $alreadyseen{$url}=1;
2132: $r->rflush();
2133: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2134: $r->print("\n<br />");
2135: if ($level==0) {
2136: $r->print("<br />");
2137: }
2138: for (my $i=0;$i<=$level*5;$i++) {
2139: $r->print(' ');
2140: }
2141: $r->print('<a href="'.$url.'" target="cat">'.
2142: ($title?$title:$url).'</a> ');
2143: if ($url=~/^\/res\//) {
2144: my $result=&Apache::lonnet::repcopy(
2145: &Apache::lonnet::filelocation('',$url));
2146: if ($result eq 'ok') {
2147: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2148: $r->rflush();
2149: &Apache::lonnet::countacc($url);
2150: $url=~/\.(\w+)$/;
2151: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2152: $r->print('<br />');
2153: $r->rflush();
2154: for (my $i=0;$i<=$level*5;$i++) {
2155: $r->print(' ');
2156: }
2157: $r->print('- '.&mt('Rendering:').' ');
2158: my ($errorcount,$warningcount)=split(/:/,
2159: &Apache::lonnet::ssi_body($url,
2160: ('grade_target'=>'web',
2161: 'return_only_error_and_warning_counts' => 1)));
2162: if (($errorcount) ||
2163: ($warningcount)) {
2164: if ($errorcount) {
1.369 bisitz 2165: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 2166: &mt('[quant,_1,error]',$errorcount).'</span>');
2167: }
2168: if ($warningcount) {
2169: $r->print('<span class="LC_warning">'.
2170: &mt('[quant,_1,warning]',$warningcount).'</span>');
2171: }
2172: } else {
2173: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2174: }
2175: $r->rflush();
2176: }
2177: my $dependencies=
2178: &Apache::lonnet::metadata($url,'dependencies');
2179: foreach my $dep (split(/\,/,$dependencies)) {
2180: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2181: &checkonthis($r,$dep,$level+1);
2182: }
2183: }
2184: } elsif ($result eq 'unavailable') {
2185: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2186: } elsif ($result eq 'not_found') {
2187: unless ($url=~/\$/) {
2188: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2189: } else {
1.366 bisitz 2190: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 2191: }
2192: } else {
2193: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2194: }
2195: }
2196: }
2197: }
2198:
2199:
2200:
2201: =pod
2202:
2203: =item list_symbs()
2204:
2205: List Symbs
2206:
2207: =cut
2208:
2209: sub list_symbs {
2210: my ($r) = @_;
2211:
2212: my $type = &Apache::loncommon::course_type();
2213: $r->print(&Apache::loncommon::start_page('Symb List'));
2214: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
2215: my $navmap = Apache::lonnavmaps::navmap->new();
2216: if (!defined($navmap)) {
2217: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2218: '<div class="LC_error">'.
2219: &mt('Unable to retrieve information about course contents').
2220: '</div>');
2221: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
2222: } else {
2223: $r->print("<pre>\n");
2224: foreach my $res ($navmap->retrieveResources()) {
2225: $r->print($res->compTitle()."\t".$res->symb()."\n");
2226: }
2227: $r->print("\n</pre>\n");
2228: }
2229: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
2230: }
2231:
2232:
2233: sub verifycontent {
2234: my ($r) = @_;
2235: my $type = &Apache::loncommon::course_type();
2236: my $loaderror=&Apache::lonnet::overloaderror($r);
2237: if ($loaderror) { return $loaderror; }
2238: $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
2239: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
2240: $hashtied=0;
2241: undef %alreadyseen;
2242: %alreadyseen=();
2243: &tiehash();
2244: foreach my $key (keys(%hash)) {
2245: if ($hash{$key}=~/\.(page|sequence)$/) {
2246: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2247: $r->print('<hr /><span class="LC_error">'.
2248: &mt('The following sequence or page is included more than once in your '.$type.': ').
2249: &unescape($hash{$key}).'</span><br />'.
2250: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2251: }
2252: }
2253: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2254: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2255: }
2256: }
2257: &untiehash();
2258: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2259: &mt('Return to DOCS').'</a>');
2260: }
2261:
2262:
2263: sub devalidateversioncache {
2264: my $src=shift;
2265: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2266: &Apache::lonnet::clutter($src));
2267: }
2268:
2269: sub checkversions {
2270: my ($r) = @_;
2271: my $type = &Apache::loncommon::course_type();
2272: $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
2273: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
2274: my $header='';
2275: my $startsel='';
2276: my $monthsel='';
2277: my $weeksel='';
2278: my $daysel='';
2279: my $allsel='';
2280: my %changes=();
2281: my $starttime=0;
2282: my $haschanged=0;
2283: my %setversions=&Apache::lonnet::dump('resourceversions',
2284: $env{'course.'.$env{'request.course.id'}.'.domain'},
2285: $env{'course.'.$env{'request.course.id'}.'.num'});
2286:
2287: $hashtied=0;
2288: &tiehash();
2289: my %newsetversions=();
2290: if ($env{'form.setmostrecent'}) {
2291: $haschanged=1;
2292: foreach my $key (keys(%hash)) {
2293: if ($key=~/^ids\_(\/res\/.+)$/) {
2294: $newsetversions{$1}='mostrecent';
2295: &devalidateversioncache($1);
2296: }
2297: }
2298: } elsif ($env{'form.setcurrent'}) {
2299: $haschanged=1;
2300: foreach my $key (keys(%hash)) {
2301: if ($key=~/^ids\_(\/res\/.+)$/) {
2302: my $getvers=&Apache::lonnet::getversion($1);
2303: if ($getvers>0) {
2304: $newsetversions{$1}=$getvers;
2305: &devalidateversioncache($1);
2306: }
2307: }
2308: }
2309: } elsif ($env{'form.setversions'}) {
2310: $haschanged=1;
2311: foreach my $key (keys(%env)) {
2312: if ($key=~/^form\.set_version_(.+)$/) {
2313: my $src=$1;
2314: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2315: $newsetversions{$src}=$env{$key};
2316: &devalidateversioncache($src);
2317: }
2318: }
2319: }
2320: }
2321: if ($haschanged) {
2322: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2323: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 2324: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.329 droeschl 2325: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
2326: } else {
2327: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
2328: }
2329: &mark_hash_old();
2330: }
2331: &changewarning($r,'');
2332: if ($env{'form.timerange'} eq 'all') {
2333: # show all documents
2334: $header=&mt('All Documents in '.$type);
2335: $allsel=1;
2336: foreach my $key (keys(%hash)) {
2337: if ($key=~/^ids\_(\/res\/.+)$/) {
2338: my $src=$1;
2339: $changes{$src}=1;
2340: }
2341: }
2342: } else {
2343: # show documents which changed
2344: %changes=&Apache::lonnet::dump
2345: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2346: $env{'course.'.$env{'request.course.id'}.'.num'});
2347: my $firstkey=(keys(%changes))[0];
2348: unless ($firstkey=~/^error\:/) {
2349: unless ($env{'form.timerange'}) {
2350: $env{'form.timerange'}=604800;
2351: }
2352: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2353: .&mt('seconds');
2354: if ($env{'form.timerange'}==-1) {
2355: $seltext='since start of course';
2356: $startsel='selected';
2357: $env{'form.timerange'}=time;
2358: }
2359: $starttime=time-$env{'form.timerange'};
2360: if ($env{'form.timerange'}==2592000) {
2361: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2362: $monthsel='selected';
2363: } elsif ($env{'form.timerange'}==604800) {
2364: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2365: $weeksel='selected';
2366: } elsif ($env{'form.timerange'}==86400) {
2367: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2368: $daysel='selected';
2369: }
2370: $header=&mt('Content changed').' '.$seltext;
2371: } else {
2372: $header=&mt('No content modifications yet.');
2373: }
2374: }
2375: %setversions=&Apache::lonnet::dump('resourceversions',
2376: $env{'course.'.$env{'request.course.id'}.'.domain'},
2377: $env{'course.'.$env{'request.course.id'}.'.num'});
2378: my %lt=&Apache::lonlocal::texthash
2379: ('st' => 'Version changes since start of '.$type,
2380: 'lm' => 'Version changes since last Month',
2381: 'lw' => 'Version changes since last Week',
2382: 'sy' => 'Version changes since Yesterday',
2383: 'al' => 'All Resources (possibly large output)',
2384: 'sd' => 'Display',
2385: 'fi' => 'File',
2386: 'md' => 'Modification Date',
2387: 'mr' => 'Most recently published Version',
2388: 've' => 'Version used in '.$type,
2389: 'vu' => 'Set Version to be used in '.$type,
2390: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
2391: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2392: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
2393: 'di' => 'Differences');
2394: $r->print(<<ENDHEADERS);
2395: <form action="/adm/coursedocs" method="post">
2396: <input type="hidden" name="versions" value="1" />
2397: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2398: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
2399: <select name="timerange">
2400: <option value='all' $allsel>$lt{'al'}</option>
2401: <option value="-1" $startsel>$lt{'st'}</option>
2402: <option value="2592000" $monthsel>$lt{'lm'}</option>
2403: <option value="604800" $weeksel>$lt{'lw'}</option>
2404: <option value="86400" $daysel>$lt{'sy'}</option>
2405: </select>
2406: <input type="submit" name="display" value="$lt{'sd'}" />
2407: <h3>$header</h3>
2408: <input type="submit" name="setversions" value="$lt{'sv'}" />
2409: <table border="0">
2410: ENDHEADERS
2411: foreach my $key (sort(keys(%changes))) {
2412: if ($changes{$key}>$starttime) {
2413: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2414: my $currentversion=&Apache::lonnet::getversion($key);
2415: if ($currentversion<0) {
2416: $currentversion=&mt('Could not be determined.');
2417: }
2418: my $linkurl=&Apache::lonnet::clutter($key);
2419: $r->print(
2420: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
2421: &Apache::lonnet::gettitle($linkurl).
2422: '</b></font></td></tr>'.
2423: '<tr><td> </td>'.
2424: '<td colspan="4">'.
2425: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2426: '</a></td></tr>'.
2427: '<tr><td></td>'.
2428: '<td title="'.$lt{'md'}.'">'.
2429: &Apache::lonlocal::locallocaltime(
2430: &Apache::lonnet::metadata($root.'.'.$extension,
2431: 'lastrevisiondate')
2432: ).
2433: '</td>'.
2434: '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
2435: '<font size="+1">'.$currentversion.'</font>'.
2436: '</span></td>'.
2437: '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$type.': '.
2438: '<font size="+1">');
2439: # Used in course
2440: my $usedversion=$hash{'version_'.$linkurl};
2441: if (($usedversion) && ($usedversion ne 'mostrecent')) {
2442: $r->print($usedversion);
2443: } else {
2444: $r->print($currentversion);
2445: }
2446: $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
2447: '<span class="LC_nobreak">Use: ');
2448: # Set version
2449: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2450: 'set_version_'.$linkurl,
2451: ('select_form_order' =>
2452: ['',1..$currentversion,'mostrecent'],
2453: '' => '',
2454: 'mostrecent' => 'most recent',
2455: map {$_,$_} (1..$currentversion))));
2456: $r->print('</span></td></tr><tr><td></td>');
2457: my $lastold=1;
2458: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2459: my $url=$root.'.'.$prevvers.'.'.$extension;
2460: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2461: $starttime) {
2462: $lastold=$prevvers;
2463: }
2464: }
1.364 bisitz 2465: #
1.329 droeschl 2466: # Code to figure out how many version entries should go in
2467: # each of the four columns
2468: my $entries_per_col = 0;
2469: my $num_entries = ($currentversion-$lastold);
2470: if ($num_entries % 4 == 0) {
2471: $entries_per_col = $num_entries/4;
2472: } else {
2473: $entries_per_col = $num_entries/4 + 1;
2474: }
2475: my $entries_count = 0;
1.344 bisitz 2476: $r->print('<td valign="top"><font size="-2">');
1.329 droeschl 2477: my $cols_output = 1;
2478: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2479: my $url=$root.'.'.$prevvers.'.'.$extension;
2480: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
2481: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2482: &Apache::lonlocal::locallocaltime(
2483: &Apache::lonnet::metadata($url,
2484: 'lastrevisiondate')
2485: ).
2486: ')');
2487: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2488: $r->print(' <a href="/adm/diff?filename='.
2489: &Apache::lonnet::clutter($root.'.'.$extension).
2490: '&versionone='.$prevvers.
2491: '">'.&mt('Diffs').'</a>');
2492: }
2493: $r->print('</span><br />');
2494: if (++$entries_count % $entries_per_col == 0) {
2495: $r->print('</font></td>');
2496: if ($cols_output != 4) {
2497: $r->print('<td valign="top"><font size="-2">');
2498: $cols_output++;
2499: }
2500: }
2501: }
2502: while($cols_output++ < 4) {
2503: $r->print('</font></td><td><font>')
2504: }
2505: $r->print('</font></td></tr>'."\n");
2506: }
2507: }
2508: $r->print('</table></form>');
2509: $r->print('<h1>'.&mt('Done').'.</h1>');
2510:
2511: &untiehash();
2512: }
2513:
2514: sub mark_hash_old {
2515: my $retie_hash=0;
2516: if ($hashtied) {
2517: $retie_hash=1;
2518: &untiehash();
2519: }
2520: &tiehash('write');
2521: $hash{'old'}=1;
2522: &untiehash();
2523: if ($retie_hash) { &tiehash(); }
2524: }
2525:
2526: sub is_hash_old {
2527: my $untie_hash=0;
2528: if (!$hashtied) {
2529: $untie_hash=1;
2530: &tiehash();
2531: }
2532: my $return=$hash{'old'};
2533: if ($untie_hash) { &untiehash(); }
2534: return $return;
2535: }
2536:
2537: sub changewarning {
2538: my ($r,$postexec,$message,$url)=@_;
2539: if (!&is_hash_old()) { return; }
2540: my $pathvar='folderpath';
2541: my $path=&escape($env{'form.folderpath'});
2542: if (!defined($url)) {
2543: if (defined($env{'form.pagepath'})) {
2544: $pathvar='pagepath';
2545: $path=&escape($env{'form.pagepath'});
2546: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2547: }
2548: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2549: }
2550: my $course_type = &Apache::loncommon::course_type();
2551: if (!defined($message)) {
2552: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2553: }
2554: $r->print("\n\n".
1.372 bisitz 2555: '<script type="text/javascript">'."\n".
2556: '// <![CDATA['."\n".
2557: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
2558: '// ]]>'."\n".
1.369 bisitz 2559: '</script>'."\n".
1.375 tempelho 2560: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 2561: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 2562: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 2563: &mt($message,' <input type="hidden" name="'.
2564: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 2565: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 2566: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 2567: }
2568:
2569:
2570: sub init_breadcrumbs {
2571: my ($form,$text)=@_;
2572: &Apache::lonhtmlcommon::clear_breadcrumbs();
2573: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
2574: text=>"Edit ".&Apache::loncommon::course_type(),
2575: faq=>273,
2576: bug=>'Instructor Interface',
2577: help => 'Docs_Adding_Course_Doc'});
2578: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2579: text=>$text,
2580: faq=>273,
2581: bug=>'Instructor Interface'});
2582: }
2583:
2584:
2585:
2586:
2587: sub handler {
2588: my $r = shift;
2589: &Apache::loncommon::content_type($r,'text/html');
2590: $r->send_http_header;
2591: return OK if $r->header_only;
2592: my $type = &Apache::loncommon::course_type();
2593:
2594:
2595: # --------------------------------------------- Initialize help topics for this
2596: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2597: 'Adding_External_Resource','Navigate_Content',
2598: 'Adding_Folders','Docs_Overview', 'Load_Map',
2599: 'Supplemental','Score_Upload_Form','Adding_Pages',
2600: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2601: 'Check_Resource_Versions','Verify_Content') {
2602: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2603: }
2604: # Composite help files
2605: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2606: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2607: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2608: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2609: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2610: 'Option_Response_Simple');
2611: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2612: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2613: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2614: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2615: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2616: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2617:
2618: # does this user have privileges to modify docs
2619: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2620: if ($allowed && $env{'form.verify'}) {
2621: &init_breadcrumbs('verify','Verify Content');
2622: &verifycontent($r);
2623: } elsif ($allowed && $env{'form.listsymbs'}) {
2624: &init_breadcrumbs('listsymbs','List Symbs');
2625: &list_symbs($r);
2626: } elsif ($allowed && $env{'form.docslog'}) {
2627: &init_breadcrumbs('docslog','Show Log');
2628: &docs_change_log($r);
2629: } elsif ($allowed && $env{'form.versions'}) {
2630: &init_breadcrumbs('versions','Check/Set Resource Versions');
2631: &checkversions($r);
2632: } elsif ($allowed && $env{'form.dumpcourse'}) {
2633: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2634: &dumpcourse($r);
2635: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2636: &init_breadcrumbs('exportcourse','IMS Export');
1.329 droeschl 2637: &exportcourse($r);
2638: } else {
2639: # is this a standard course?
2640:
2641: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2642: my $forcestandard = 0;
2643: my $forcesupplement;
2644: my $script='';
2645: my $showdoc=0;
2646: my $containertag;
2647: my $uploadtag;
2648:
2649:
2650: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2651: ['folderpath','pagepath',
2652: 'pagesymb']);
2653: # No folderpath, no pagepath, see if we have something stored
2654: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2655: &Apache::loncommon::restore_course_settings('docs_folderpath',
2656: {'folderpath' => 'scalar'});
2657: }
2658: if (!$env{'form.folderpath'}) {
2659: &Apache::loncommon::restore_course_settings('docs_folderpath',
2660: {'pagepath' => 'scalar'});
2661: }
2662: if ($env{'form.pagepath'}) {
2663: $env{'form.folderpath'}='';
2664: }
2665: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2666: $env{'form.folderpath'} = 'supplemental&'.
2667: &escape(&mt('Supplemental '.$type.' Documents')).'&'.
2668: $env{'form.folderpath'};
2669: }
2670: &Apache::loncommon::store_course_settings('docs_folderpath',
2671: {'pagepath' => 'scalar',
2672: 'folderpath' => 'scalar'});
2673: if ($env{'form.folderpath'}) {
2674: my (@folderpath)=split('&',$env{'form.folderpath'});
2675: $env{'form.foldername'}=&unescape(pop(@folderpath));
2676: $env{'form.folder'}=pop(@folderpath);
2677: }
2678: if ($env{'form.pagepath'}) {
2679: my (@pagepath)=split('&',$env{'form.pagepath'});
2680: $env{'form.pagename'}=&unescape(pop(@pagepath));
2681: $env{'form.folder'}=pop(@pagepath);
2682: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2683: '<input type="hidden" name="pagesymb" value="" />';
2684: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2685: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2686: }
2687: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2688: $showdoc='/'.$1;
2689: }
2690: unless ($showdoc) { # got called from remote
1.344 bisitz 2691: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.329 droeschl 2692: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2693: $forcestandard = 1;
1.364 bisitz 2694: }
1.329 droeschl 2695: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2696:
1.344 bisitz 2697: if ($allowed) {
1.329 droeschl 2698: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344 bisitz 2699: $script=&Apache::lonratedt::editscript('simple');
1.329 droeschl 2700: }
2701: } else { # got called in sequence from course
2702: $allowed=0;
2703: }
2704:
1.383 tempelho 2705: # subroutine to list form elements
2706: sub create_list_elements {
2707: my @formarr = @_;
2708: my $list = '';
2709: for my $button (@formarr){
2710: for my $picture(keys %$button) {
2711: #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
2712: $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2713: }
2714: }
2715: return $list;
2716: }
2717:
2718: # subroutine to create ul from list elements
2719: sub create_form_ul {
2720: my $list = shift;
2721: my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2722: return $ul;
2723: }
2724:
1.329 droeschl 2725: # get course data
2726: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2727: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2728:
1.344 bisitz 2729: # get personal data
1.329 droeschl 2730: my $uname=$env{'user.name'};
2731: my $udom=$env{'user.domain'};
2732: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2733:
2734: # graphics settings
2735:
2736: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2737:
2738: if ($allowed) {
2739: $script .= &editing_js($udom,$uname);
2740: }
2741: # -------------------------------------------------------------------- Body tag
1.369 bisitz 2742: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 2743: .'// <![CDATA['."\n"
2744: .$script."\n"
2745: .'// ]]>'."\n"
2746: .'</script>'."\n";
1.385 bisitz 2747:
2748: # Breadcrumbs
2749: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.392 ! raeburn 2750: if ($allowed) {
! 2751: &Apache::lonhtmlcommon::add_breadcrumb({
! 2752: href=>"/adm/coursedocs",text=>"$type Editor"});
! 2753:
! 2754: $r->print(&Apache::loncommon::start_page("$type Editor", $script,
! 2755: {'force_register' => $showdoc,})
! 2756: .&Apache::loncommon::help_open_menu('','',273,'RAT')
! 2757: .&Apache::lonhtmlcommon::breadcrumbs(
! 2758: 'Editing the Table of Contents for your '.$type,
! 2759: 'Docs_Adding_Course_Doc')
! 2760: );
! 2761: } else {
! 2762: my $lc_type = lc($type);
! 2763: &Apache::lonhtmlcommon::add_breadcrumb({
! 2764: href=>"/adm/coursedocs",text=>"Supplemental $lc_type documents"});
1.385 bisitz 2765:
1.392 ! raeburn 2766: $r->print(&Apache::loncommon::start_page("Supplemental documents").
! 2767: &Apache::lonhtmlcommon::breadcrumbs());
! 2768: }
1.364 bisitz 2769:
1.329 droeschl 2770: my %allfiles = ();
2771: my %codebase = ();
2772: my ($upload_result,$upload_output);
2773: if ($allowed) {
2774: if (($env{'form.uploaddoc.filename'}) &&
2775: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.344 bisitz 2776: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 2777: undef($hadchanges);
2778: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2779: $coursedom,\%allfiles,
2780: \%codebase,$1);
2781: if ($hadchanges) {
2782: &mark_hash_old();
2783: }
2784: if ($upload_result eq 'phasetwo') {
2785: $r->print($upload_output);
2786: }
2787: } elsif ($env{'form.phasetwo'}) {
2788: my %newname = ();
2789: my %origname = ();
2790: my %attribs = ();
2791: my $updateflag = 0;
2792: my $residx = $env{'form.newidx'};
2793: my $primary_url = &unescape($env{'form.primaryurl'});
2794: # Process file upload - phase two - gather secondary files.
2795: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2796: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2797: my $javacodebase;
2798: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2799: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2800: if (exists($env{'form.embedded_codebase_'.$i})) {
1.344 bisitz 2801: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2802: $origname{$i} =~ s#^\Q$javacodebase\E/##;
1.329 droeschl 2803: }
2804: my @attributes = ();
2805: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2806: @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
2807: } else {
2808: @attributes = ($env{'form.embedded_attrib_'.$i});
2809: }
2810: foreach my $attr (@attributes) {
2811: push(@{$attribs{$i}},&unescape($attr));
2812: }
2813: if ($javacodebase) {
2814: $codebase{$i} = $javacodebase;
2815: $codebase{$i} =~ s#/$##;
2816: $updateflag = 1;
2817: }
2818: }
2819: unless ($newname{$i} eq $origname{$i}) {
2820: $updateflag = 1;
2821: }
2822: }
2823: # Process file upload - phase three - modify primary file
2824: if ($updateflag) {
2825: my ($content,$rtncode);
2826: my $updateflag = 0;
2827: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2828: if ($getstatus eq 'ok') {
2829: foreach my $item (keys(%newname)) {
2830: if ($newname{$item} ne $origname{$item}) {
2831: my $attrib_regexp = '';
2832: if (@{$attribs{$item}} > 1) {
2833: $attrib_regexp = join('|',@{$attribs{$item}});
2834: } else {
2835: $attrib_regexp = $attribs{$item}[0];
2836: }
2837: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
1.364 bisitz 2838: }
1.344 bisitz 2839: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
1.329 droeschl 2840: }
2841: if (exists($codebase{$item})) {
2842: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2843: }
2844: }
2845: # Save edited file.
2846: my $saveresult;
2847: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2848: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2849: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2850: } else {
1.344 bisitz 2851: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
1.329 droeschl 2852: }
2853: }
2854: }
2855: }
2856:
2857: unless ($showdoc || $upload_result eq 'phasetwo') {
2858: # -----------------------------------------------------------------------------
2859: my %lt=&Apache::lonlocal::texthash(
2860: 'uplm' => 'Upload a new main '.lc($type).' document',
2861: 'upls' => 'Upload a new supplemental '.lc($type).' document',
2862: 'impp' => 'Import a document',
2863: 'copm' => 'All documents out of a published map into this folder',
2864: 'upld' => 'Upload Document',
2865: 'srch' => 'Search',
2866: 'impo' => 'Import',
2867: 'book' => 'Import Bookmarks',
2868: 'selm' => 'Select Map',
2869: 'load' => 'Load Map',
2870: 'reco' => 'Recover Deleted Resources',
2871: 'newf' => 'New Folder',
2872: 'newp' => 'New Composite Page',
2873: 'extr' => 'External Resource',
2874: 'syll' => 'Syllabus',
2875: 'navc' => 'Navigate Contents',
1.343 biermanm 2876: 'sipa' => 'Simple Course Page',
1.329 droeschl 2877: 'sipr' => 'Simple Problem',
2878: 'drbx' => 'Drop Box',
2879: 'scuf' => 'Score Upload Form',
1.336 schafran 2880: 'bull' => 'Discussion Board',
1.347 weissno 2881: 'mypi' => 'My Personal Information Page',
1.353 weissno 2882: 'grpo' => 'Group Portfolio',
1.329 droeschl 2883: 'rost' => 'Course Roster',
1.348 weissno 2884: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 2885: 'imsf' => 'IMS Import',
2886: 'imsl' => 'Import IMS package',
1.329 droeschl 2887: 'file' => 'File',
2888: 'title' => 'Title',
2889: 'comment' => 'Comment',
2890: 'parse' => 'Upload embedded images/multimedia files if HTML file!',
1.368 truskell 2891: 'nd' => 'Upload Document',
1.329 droeschl 2892: 'pm' => 'Published Map',
2893: 'sd' => 'Special Document',
2894: 'mo' => 'More Options',
2895: );
2896: # -----------------------------------------------------------------------------
2897: my $fileupload=(<<FIUP);
2898: $lt{'file'}:<br />
2899: <input type="file" name="uploaddoc" size="40" />
2900: FIUP
2901:
2902: my $checkbox=(<<CHBO);
2903: <!-- <label>$lt{'parse'}?
2904: <input type="checkbox" name="parserflag" />
2905: </label> -->
2906: <label>
2907: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2908: </label>
2909: CHBO
2910:
1.383 tempelho 2911: my @fileuploada = (
1.387 tempelho 2912: { '<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 2913: );
1.329 droeschl 2914: my $fileuploadform=(<<FUFORM);
2915: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 2916: <input type="hidden" name="active" value="aa" />
1.329 droeschl 2917: $fileupload
2918: <br />
2919: $lt{'title'}:<br />
2920: <input type="text" size="50" name="comment" />
2921: $uploadtag
2922: <input type="hidden" name="cmd" value="upload_default" />
2923: <br />
2924: <span class="LC_nobreak">
2925: $checkbox
2926: </span>
1.383 tempelho 2927: FUFORM
2928: $fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
2929: $fileuploadform .= (<<FUFORM);
1.329 droeschl 2930: </form>
2931: FUFORM
2932:
2933: my $simpleeditdefaultform=(<<SEDFFORM);
2934: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 2935: <input type="hidden" name="active" value="bb" />
1.383 tempelho 2936: SEDFFORM
2937: my @simpleeditdefaultforma = (
1.387 tempelho 2938: { '<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic03" />' => "$uploadtag<a onclick='javascript:groupsearch()'>$lt{'srch'}</a>" },
2939: { '<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'}" },
2940: { '<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 2941: );
2942: $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
2943: $simpleeditdefaultform .=(<<SEDFFORM);
1.329 droeschl 2944: <hr />
2945: <p>
2946: $lt{'copm'}<br />
2947: <input type="text" size="40" name="importmap" /><br />
1.344 bisitz 2948: <span class="LC_nobreak"><input type="button"
1.369 bisitz 2949: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 2950: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2951: $help{'Load_Map'}</span>
2952: </p>
2953: </form>
2954: SEDFFORM
2955:
2956: my $extresourcesform=(<<ERFORM);
2957: <form action="/adm/coursedocs" method="post" name="newext">
2958: $uploadtag
2959: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 2960: <a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.329 droeschl 2961: </form>
2962: ERFORM
2963:
2964: if ($allowed) {
2965: &update_paste_buffer($coursenum,$coursedom);
2966: my %lt=&Apache::lonlocal::texthash(
2967: 'vc' => 'Verify Content',
2968: 'cv' => 'Check/Set Resource Versions',
2969: 'ls' => 'List Symbs',
2970: 'sl' => 'Show Log'
2971: );
2972:
2973: my $folderpath=$env{'form.folderpath'};
2974: if (!$folderpath) {
2975: if ($env{'form.folder'} eq '' ||
2976: $env{'form.folder'} eq 'supplemental') {
2977: $folderpath='default&'.
2978: &escape(&mt('Main '.$type.' Documents'));
2979: }
2980: }
2981: unless ($env{'form.pagepath'}) {
2982: $containertag = '<input type="hidden" name="folderpath" value="" />';
2983: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
2984: }
1.337 ehlerst 2985: $r->print(<<HIDDENFORM);
2986: <form name="renameform" method="post" action="/adm/coursedocs">
2987: <input type="hidden" name="title" />
2988: <input type="hidden" name="cmd" />
2989: <input type="hidden" name="markcopy" />
2990: <input type="hidden" name="copyfolder" />
2991: $containertag
2992: </form>
2993: <form name="simpleedit" method="post" action="/adm/coursedocs">
2994: <input type="hidden" name="importdetail" value="" />
2995: $uploadtag
2996: </form>
2997: HIDDENFORM
1.329 droeschl 2998: }
1.335 ehlerst 2999: # --------------------------------------------------------- Main tab structure
1.383 tempelho 3000:
1.335 ehlerst 3001: my $activeClass = 1;
1.355 ehlerst 3002: my $active = '';
1.383 tempelho 3003:
1.339 ehlerst 3004: $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
1.378 tempelho 3005: if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
1.335 ehlerst 3006: if($activeClass == 1){
3007: $active = 'class="active"';
3008: $activeClass = 0;
3009: }
3010: }
1.383 tempelho 3011: if($env{'request.role'}=~/^cc/){
1.382 tempelho 3012: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.&mt('Main Course Documents').'</b></a></li>');
1.383 tempelho 3013: }
1.355 ehlerst 3014: $active = '';
1.356 tempelho 3015: if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
1.335 ehlerst 3016: if($activeClass == 1){
3017: $active = 'class="active"';
3018: }
3019: }
1.382 tempelho 3020: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.&mt('Supplemental Course Documents').'</b></a></li>');
1.376 bisitz 3021: $r->print('</ul>'
3022: .'<div class="LC_Box" style="clear:both;margin:0;">'
3023: .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
1.329 droeschl 3024: # --------------------------------------------------------- Standard documents
1.356 tempelho 3025: my $savefolderpath;
1.335 ehlerst 3026: my $active = 'style="display: none;"';
3027: if($activeClass == 0){
3028: $active = 'style="display: block;"';
3029: }
1.383 tempelho 3030: if($env{'request.role'}=~/^cc/){
1.359 tempelho 3031: $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
1.329 droeschl 3032: my $folder=$env{'form.folder'};
1.356 tempelho 3033: if ($folder eq '' || $folder=~/^supplemental/) {
1.329 droeschl 3034: $folder='default';
1.356 tempelho 3035: $savefolderpath = $env{'form.folderpath'};
1.329 droeschl 3036: $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
3037: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3038: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3039: }
3040: my $postexec='';
3041: if ($folder eq 'default') {
1.372 bisitz 3042: $r->print('<script type="text/javascript">'."\n"
3043: .'// <![CDATA['."\n"
3044: .'this.window.name="loncapaclient";'."\n"
3045: .'// ]]>'."\n"
3046: .'</script>'."\n"
1.369 bisitz 3047: );
1.329 droeschl 3048: } else {
3049: #$postexec='self.close();';
3050: }
3051: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3052: '.sequence';
3053: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3054: '.page';
3055: my $container='sequence';
3056: if ($env{'form.pagepath'}) {
3057: $container='page';
3058: }
3059: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3060:
3061:
3062:
3063: my $recoverform=(<<RFORM);
3064: <form action="/adm/groupsort" method="post" name="recover">
1.383 tempelho 3065: <a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
1.329 droeschl 3066: </form>
3067: RFORM
3068:
3069: my $imspform=(<<IMSPFORM);
3070: <form action="/adm/imsimportdocs" method="post" name="ims">
3071: <input type="hidden" name="folder" value="$folder" />
1.383 tempelho 3072: <a onclick="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 3073: </form>
3074: IMSPFORM
3075:
3076: my $newnavform=(<<NNFORM);
3077: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3078: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3079: $uploadtag
3080: <input type="hidden" name="importdetail"
3081: value="$lt{'navc'}=/adm/navmaps" />
1.383 tempelho 3082: <a onclick="document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3083: $help{'Navigate_Content'}
3084: </form>
3085: NNFORM
3086: my $newsmppageform=(<<NSPFORM);
3087: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3088: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3089: $uploadtag
3090: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3091: <a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
3092: $help{'Simple Page'}
1.329 droeschl 3093: </form>
3094: NSPFORM
3095:
3096: my $newsmpproblemform=(<<NSPROBFORM);
3097: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3098: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3099: $uploadtag
3100: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3101: <a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
3102: $help{'Simple Problem'}
1.329 droeschl 3103: </form>
3104:
3105: NSPROBFORM
3106:
3107: my $newdropboxform=(<<NDBFORM);
3108: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3109: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3110: $uploadtag
1.329 droeschl 3111: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3112: <a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3113: </form>
1.329 droeschl 3114: NDBFORM
3115:
3116: my $newexuploadform=(<<NEXUFORM);
3117: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3118: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3119: $uploadtag
3120: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3121: <a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3122: $help{'Score_Upload_Form'}
3123: </form>
3124: NEXUFORM
3125:
3126: my $newbulform=(<<NBFORM);
3127: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3128: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3129: $uploadtag
3130: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3131: <a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3132: $help{'Bulletin Board'}
3133: </form>
3134: NBFORM
3135:
3136: my $newaboutmeform=(<<NAMFORM);
3137: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3138: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3139: $uploadtag
3140: <input type="hidden" name="importdetail"
3141: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3142: <a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3143: $help{'My Personal Information Page'}
1.329 droeschl 3144: </form>
3145: NAMFORM
3146:
3147: my $newaboutsomeoneform=(<<NASOFORM);
3148: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3149: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3150: $uploadtag
3151: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3152: <a onclick="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3153: </form>
3154: NASOFORM
3155:
3156:
3157: my $newrosterform=(<<NROSTFORM);
3158: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3159: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3160: $uploadtag
3161: <input type="hidden" name="importdetail"
3162: value="$lt{'rost'}=/adm/viewclasslist" />
1.383 tempelho 3163: <a onclick="document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3164: $help{'Course Roster'}
3165: </form>
3166: NROSTFORM
3167:
1.342 ehlerst 3168: my $specialdocumentsform;
1.383 tempelho 3169: my @specialdocumentsforma;
1.351 ehlerst 3170: my $newfolderform;
1.390 tempelho 3171: my $newfolderb;
1.342 ehlerst 3172:
1.329 droeschl 3173: unless ($env{'form.pagepath'}) {
3174: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3175:
1.329 droeschl 3176: my $newpageform=(<<NPFORM);
3177: <form action="/adm/coursedocs" method="post" name="newpage">
3178: <input type="hidden" name="folderpath" value="$path" />
3179: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3180: <input type="hidden" name="active" value="cc" />
1.383 tempelho 3181: <a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
3182: $help{'Adding_Pages'}
1.329 droeschl 3183: </form>
3184: NPFORM
1.390 tempelho 3185:
3186:
1.351 ehlerst 3187: $newfolderform=(<<NFFORM);
1.329 droeschl 3188: <form action="/adm/coursedocs" method="post" name="newfolder">
3189: <input type="hidden" name="folderpath" value="$path" />
3190: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3191: <input type="hidden" name="active" value="aa" />
1.383 tempelho 3192: <a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3193: </form>
3194: NFFORM
3195:
3196: my $newsylform=(<<NSYLFORM);
3197: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3198: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3199: $uploadtag
3200: <input type="hidden" name="importdetail"
3201: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3202: <a onclick="document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3203: $help{'Syllabus'}
1.383 tempelho 3204:
1.329 droeschl 3205: </form>
3206: NSYLFORM
1.364 bisitz 3207:
1.329 droeschl 3208: my $newgroupfileform=(<<NGFFORM);
3209: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3210: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3211: $uploadtag
3212: <input type="hidden" name="importdetail"
3213: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.383 tempelho 3214: <a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3215: $help{'Group Portfolio'}
1.329 droeschl 3216: </form>
3217: NGFFORM
1.383 tempelho 3218: @specialdocumentsforma=(
1.387 tempelho 3219: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic06" />'=>$newpageform},
3220: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic07" />'=>$newsylform},
3221: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic08" />'=>$newgroupfileform},
1.383 tempelho 3222: );
3223:
3224: }
1.387 tempelho 3225: push @specialdocumentsforma, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic09" />'=>$newnavform},
3226: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic10" />'=>$newsmppageform},
3227: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic11" />'=>$newsmpproblemform},
3228: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic12" />'=>$newdropboxform},
3229: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic13" />'=>$newexuploadform},
3230: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic14" />'=>$newbulform},
3231: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic15" />'=>$newaboutmeform},
3232: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic16" />'=>$newaboutsomeoneform},
3233: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic17" />'=>$newrosterform},);
1.383 tempelho 3234:
3235: $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
1.329 droeschl 3236:
1.342 ehlerst 3237: if($env{'form.pagepath'}) {
1.383 tempelho 3238:
3239: @specialdocumentsforma=(
1.387 tempelho 3240: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic32" />'=>$newsmpproblemform},
3241: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic33" />'=>$newexuploadform}
1.383 tempelho 3242: );
3243: $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
1.342 ehlerst 3244: }
1.331 muellerd 3245:
1.383 tempelho 3246: my @tools = (
1.387 tempelho 3247: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic18" />'=>$extresourcesform},
3248: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic19" />'=>$imspform},
3249: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic20" />'=>$recoverform},
1.383 tempelho 3250: );
3251:
1.330 tempelho 3252: my %orderhash = (
1.390 tempelho 3253: '00' => ['Newfolder',$newfolderform],
3254: 'aa' => ['Upload Document',$fileuploadform],
1.377 bisitz 3255: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.363 ehlerst 3256: 'cc' => ['Special Documents',$specialdocumentsform],
1.383 tempelho 3257: 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
1.330 tempelho 3258: );
1.334 muellerd 3259: my $tid='1';
3260: my $varcd = 'Main Course Documents';
1.341 ehlerst 3261: $hadchanges=0;
3262: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
1.335 ehlerst 3263: if ($error) {
3264: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3265: }
1.341 ehlerst 3266: if ($hadchanges) {
3267: &mark_hash_old();
3268: }
3269:
3270: &changewarning($r,'');
1.389 tempelho 3271: $r->print(&generate_edit_table($tid,$varcd,\%orderhash));
3272:
1.335 ehlerst 3273: $r->print('</div>');
1.383 tempelho 3274: }
1.329 droeschl 3275: if ($env{'form.pagepath'}) {
3276: }
3277: # ----------------------------------------------------- Supplemental documents
1.335 ehlerst 3278: my $active = 'style="display: none;"';
3279: if($activeClass == 1){
3280: $active = 'style="display: block;"';
3281: }
1.373 bisitz 3282: $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
1.329 droeschl 3283: my $folder=$env{'form.folder'};
3284: unless ($folder=~/^supplemental/) {
3285: $folder='supplemental';
3286: }
3287: if ($folder =~ /^supplemental$/ &&
3288: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3289: $env{'form.folderpath'} = 'supplemental&'.
3290: &escape(&mt('Supplemental '.$type.' Documents'));
1.356 tempelho 3291: }else{
3292: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3293: }
1.362 ehlerst 3294: $env{'form.pagepath'} = '';
1.329 droeschl 3295: if ($allowed) {
3296: my $folderseq=
3297: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3298: '.sequence';
3299:
3300: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3301:
1.383 tempelho 3302: my @supupdocform = (
1.388 tempelho 3303: {'<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 3304: );
1.329 droeschl 3305: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 3306: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 3307: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3308: $fileupload
3309: <br />
3310: <br />
3311: <span class="LC_nobreak">
3312: $checkbox
3313: </span>
3314: <br /><br />
3315: $lt{'comment'}:<br />
1.383 tempelho 3316: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3317: <br />
3318: <input type="hidden" name="folderpath" value="$path" />
3319: <input type="hidden" name="cmd" value="upload_supplemental" />
3320: SUPDOCFORM
1.383 tempelho 3321: $supupdocform .= create_form_ul(create_list_elements(@supupdocform))."</form>";
1.329 droeschl 3322:
3323: my $supnewfolderform=(<<SNFFORM);
3324: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3325: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3326: <input type="hidden" name="folderpath" value="$path" />
3327: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3328: <a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
3329: $help{'Adding_Folders'}
1.329 droeschl 3330: </form>
3331: SNFFORM
1.383 tempelho 3332:
1.329 droeschl 3333:
3334: my $supnewextform=(<<SNEFORM);
3335: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 3336: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3337: <input type="hidden" name="folderpath" value="$path" />
3338: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3339: <a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 3340: </form>
3341: SNEFORM
3342:
3343: my $supnewsylform=(<<SNSFORM);
3344: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 3345: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3346: <input type="hidden" name="folderpath" value="$path" />
3347: <input type="hidden" name="importdetail"
3348: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3349: <a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3350: $help{'Syllabus'}
3351: </form>
3352: SNSFORM
3353:
3354: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 3355: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 3356: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3357: <input type="hidden" name="folderpath" value="$path" />
3358: <input type="hidden" name="importdetail"
3359: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3360: <a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3361: $help{'My Personal Information Page'}
1.329 droeschl 3362: </form>
3363: SNAMFORM
3364:
1.333 muellerd 3365:
1.383 tempelho 3366: my @specialdocs = (
1.387 tempelho 3367: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic29" />'=>$supnewextform},
3368: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic30" />'=>$supnewsylform},
3369: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic31" />'=>$supnewaboutmeform},
1.383 tempelho 3370: );
1.333 muellerd 3371: my %suporderhash = (
1.390 tempelho 3372: '00' => ['Supnewfolder', $supnewfolderform],
3373: 'ee' => ['Upload Document',$supupdocform],
3374: 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))]
1.333 muellerd 3375: );
1.334 muellerd 3376:
1.333 muellerd 3377: my $tid='2';
1.374 tempelho 3378: my $varscd = 'Supplemental Course Documents';
1.335 ehlerst 3379: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$type);
3380: if ($error) {
3381: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3382: }
1.389 tempelho 3383: $r->print(&generate_edit_table($tid,$varscd,\%suporderhash));
3384: }
3385:
3386:
1.335 ehlerst 3387: $r->print('</div>');
1.383 tempelho 3388: $r->print('</div></div>');
3389:
3390:
1.329 droeschl 3391: if ($allowed) {
3392: $r->print('
3393: <form method="post" name="extimport" action="/adm/coursedocs">
3394: <input type="hidden" name="title" />
3395: <input type="hidden" name="url" />
3396: <input type="hidden" name="useform" />
3397: <input type="hidden" name="residx" />
3398: </form>');
3399: }
3400: } else {
3401: unless ($upload_result eq 'phasetwo') {
3402: # -------------------------------------------------------- This is showdoc mode
3403: $r->print("<h1>".&mt('Uploaded Document').' - '.
3404: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3405: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3406: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3407: }
3408: }
3409: }
3410: $r->print(&Apache::loncommon::end_page());
3411: return OK;
1.364 bisitz 3412: }
1.329 droeschl 3413:
3414: sub generate_admin_options {
1.337 ehlerst 3415: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3416: my %lt=&Apache::lonlocal::texthash(
3417: 'vc' => 'Verify Content',
3418: 'cv' => 'Check/Set Resource Versions',
3419: 'ls' => 'List Symbs',
3420: 'sl' => 'Show Log'
3421: );
1.329 droeschl 3422: my %help = %{$help_ref};
3423: my %env = %{$env_ref};
3424: my $dumpbut=&dumpbutton();
3425: my $exportbut=&exportbutton();
1.383 tempelho 3426: my @list = (
1.387 tempelho 3427: {'<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'}"},
3428: {'<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 3429: );
3430: if($dumpbut ne ''){
1.387 tempelho 3431: push @list, {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic23" />'=>$dumpbut};
1.383 tempelho 3432: }
1.387 tempelho 3433: push @list, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/docspacer.gif" alt="pic24" />'=>$exportbut},
3434: {'<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'}' />"},
3435: {'<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 3436: );
3437: 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 3438:
1.329 droeschl 3439: }
3440:
1.330 tempelho 3441:
1.329 droeschl 3442: sub generate_edit_table {
1.363 ehlerst 3443: my ($tid,$varcd,$orderhash_ref) = @_;
1.342 ehlerst 3444: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3445: my $form;
1.371 tempelho 3446: my $activetab;
3447: my $active;
3448: if($env{'form.active'} ne ''){
3449: $activetab = $env{'form.active'};
3450: }
1.382 tempelho 3451: $form = '<div class="LC_Box">';
1.359 tempelho 3452: $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
1.329 droeschl 3453: foreach my $name (sort(keys(%orderhash))){
1.390 tempelho 3454: if($name ne '00'){
1.371 tempelho 3455: if($activetab eq '' || $activetab ne $name){
3456: $active = '';
3457: }elsif($activetab eq $name){
3458: $active = 'class="active"';
3459: }
1.374 tempelho 3460: $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
1.390 tempelho 3461: } else {
3462: $form .= '<li '.$active.'>'.${$orderhash{$name}}[1].'</li>';
3463:
3464: }
1.329 droeschl 3465: }
1.339 ehlerst 3466: $form .= '</ul>';
1.359 tempelho 3467: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0;">';
1.363 ehlerst 3468: foreach my $field (keys(%orderhash)){
1.390 tempelho 3469: if($field ne '00'){
1.371 tempelho 3470: if($activetab eq '' || $activetab ne $field){
3471: $active = 'style="display: none;"';
3472: }elsif($activetab eq $field){
3473: $active = 'style="display:block;"';
3474: }
1.374 tempelho 3475: $form .= '<div id="'.$field.$tid.'"'
1.373 bisitz 3476: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3477: .'</div>';
1.363 ehlerst 3478: }
3479: }
1.330 tempelho 3480: $form .= '</div></div>';
1.364 bisitz 3481:
1.329 droeschl 3482: return $form;
3483: }
3484:
3485: sub editing_js {
3486: my ($udom,$uname) = @_;
3487: my $now = time();
3488: my %lt = &Apache::lonlocal::texthash(
3489: p_mnf => 'Name of New Folder',
3490: t_mnf => 'New Folder',
3491: p_mnp => 'Name of New Page',
3492: t_mnp => 'New Page',
3493: p_mxu => 'Title for the Uploaded Score',
1.349 biermanm 3494: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3495: p_msb => 'Title for the Problem',
3496: p_mdb => 'Title for the Drop Box',
1.336 schafran 3497: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3498: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3499: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3500: p_mab_alrt1 => 'Not a valid user:domain',
3501: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3502: p_chn => 'New Title',
3503: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3504: p_rmr2a => 'Remove[_99]',
3505: p_rmr2b => '?[_99]',
3506: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3507: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3508: p_ctr2a => 'Cut[_98]',
3509: p_ctr2b => '?[_98]'
3510: );
3511:
3512: return <<ENDNEWSCRIPT;
3513: function makenewfolder(targetform,folderseq) {
3514: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3515: if (foldername) {
3516: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3517: targetform.submit();
3518: }
3519: }
3520:
3521: function makenewpage(targetform,folderseq) {
3522: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3523: if (pagename) {
3524: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3525: targetform.submit();
3526: }
3527: }
3528:
3529: function makenewext(targetname) {
3530: this.document.forms.extimport.useform.value=targetname;
3531: this.document.forms.extimport.title.value='';
3532: this.document.forms.extimport.url.value='';
3533: this.document.forms.extimport.residx.value='';
3534: window.open('/adm/rat/extpickframe.html');
3535: }
3536:
3537: function edittext(targetname,residx,title,url) {
3538: this.document.forms.extimport.useform.value=targetname;
3539: this.document.forms.extimport.residx.value=residx;
3540: this.document.forms.extimport.url.value=url;
3541: this.document.forms.extimport.title.value=title;
3542: window.open('/adm/rat/extpickframe.html');
3543: }
3544:
3545: function makeexamupload() {
3546: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3547: if (title) {
1.329 droeschl 3548: this.document.forms.newexamupload.importdetail.value=
3549: escape(title)+'=/res/lib/templates/examupload.problem';
3550: this.document.forms.newexamupload.submit();
3551: }
3552: }
3553:
3554: function makesmppage() {
3555: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3556: if (title) {
1.329 droeschl 3557: this.document.forms.newsmppg.importdetail.value=
3558: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3559: this.document.forms.newsmppg.submit();
3560: }
3561: }
3562:
3563: function makesmpproblem() {
3564: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3565: if (title) {
1.329 droeschl 3566: this.document.forms.newsmpproblem.importdetail.value=
3567: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3568: this.document.forms.newsmpproblem.submit();
3569: }
3570: }
3571:
3572: function makedropbox() {
3573: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3574: if (title) {
1.329 droeschl 3575: this.document.forms.newdropbox.importdetail.value=
3576: escape(title)+'=/res/lib/templates/DropBox.problem';
3577: this.document.forms.newdropbox.submit();
3578: }
3579: }
3580:
3581: function makebulboard() {
3582: var title=prompt('$lt{"p_mbb"}');
3583: if (title) {
3584: this.document.forms.newbul.importdetail.value=
3585: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3586: this.document.forms.newbul.submit();
3587: }
3588: }
3589:
3590: function makeabout() {
3591: var user=prompt("$lt{'p_mab'}");
3592: if (user) {
3593: var comp=new Array();
3594: comp=user.split(':');
3595: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3596: if ((comp[0]) && (comp[1])) {
3597: this.document.forms.newaboutsomeone.importdetail.value=
3598: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3599: this.document.forms.newaboutsomeone.submit();
3600: } else {
3601: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3602: }
1.335 ehlerst 3603: } else {
3604: alert("$lt{'p_mab_alrt2'}");
3605: }
3606: }
1.329 droeschl 3607: }
3608:
3609: function makeims() {
1.335 ehlerst 3610: var caller = document.forms.ims.folder.value;
3611: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3612: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3613: newWindow.location.href = newlocation;
1.329 droeschl 3614: }
3615:
3616:
3617: function finishpick() {
1.335 ehlerst 3618: var title=this.document.forms.extimport.title.value;
3619: var url=this.document.forms.extimport.url.value;
3620: var form=this.document.forms.extimport.useform.value;
3621: var residx=this.document.forms.extimport.residx.value;
3622: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3623: }
3624:
3625: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3626: var title=prompt('$lt{"p_chn"}',oldtitle);
3627: if (title) {
3628: this.document.forms.renameform.markcopy.value=-1;
3629: this.document.forms.renameform.title.value=title;
3630: this.document.forms.renameform.cmd.value='rename_'+index;
3631: if (container == 'sequence') {
3632: this.document.forms.renameform.folderpath.value=folderpath;
3633: }
3634: if (container == 'page') {
3635: this.document.forms.renameform.pagepath.value=folderpath;
3636: this.document.forms.renameform.pagesymb.value=pagesymb;
3637: }
3638: this.document.forms.renameform.submit();
3639: }
1.329 droeschl 3640: }
3641:
3642: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3643: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3644: this.document.forms.renameform.markcopy.value=-1;
3645: this.document.forms.renameform.cmd.value='del_'+index;
3646: if (container == 'sequence') {
3647: this.document.forms.renameform.folderpath.value=folderpath;
3648: }
3649: if (container == 'page') {
3650: this.document.forms.renameform.pagepath.value=folderpath;
3651: this.document.forms.renameform.pagesymb.value=pagesymb;
3652: }
3653: this.document.forms.renameform.submit();
3654: }
1.329 droeschl 3655: }
3656:
3657: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3658: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3659: this.document.forms.renameform.cmd.value='cut_'+index;
3660: this.document.forms.renameform.markcopy.value=index;
3661: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3662: if (container == 'sequence') {
3663: this.document.forms.renameform.folderpath.value=folderpath;
3664: }
3665: if (container == 'page') {
3666: this.document.forms.renameform.pagepath.value=folderpath;
3667: this.document.forms.renameform.pagesymb.value=pagesymb;
3668: }
3669: this.document.forms.renameform.submit();
3670: }
1.329 droeschl 3671: }
3672:
3673: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3674: this.document.forms.renameform.markcopy.value=index;
3675: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3676: if (container == 'sequence') {
3677: this.document.forms.renameform.folderpath.value=folderpath;
3678: }
3679: if (container == 'page') {
3680: this.document.forms.renameform.pagepath.value=folderpath;
3681: this.document.forms.renameform.pagesymb.value=pagesymb;
3682: }
3683: this.document.forms.renameform.submit();
1.329 droeschl 3684: }
3685:
1.334 muellerd 3686: function unselectInactive(nav) {
1.335 ehlerst 3687: currentNav = document.getElementById(nav);
3688: currentLis = currentNav.getElementsByTagName('LI');
3689: for (i = 0; i < currentLis.length; i++) {
1.374 tempelho 3690: if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
3691: currentLis[i].className = 'right';
3692: }else{
3693: currentLis[i].className = 'i';
3694: }
1.335 ehlerst 3695: }
1.332 tempelho 3696: }
3697:
1.334 muellerd 3698: function hideAll(current, nav, data) {
1.335 ehlerst 3699: unselectInactive(nav);
1.374 tempelho 3700: if(current.className == 'right'){
3701: current.className = 'right active'
3702: }else{
3703: current.className = 'active';
3704: }
1.335 ehlerst 3705: currentData = document.getElementById(data);
3706: currentDivs = currentData.getElementsByTagName('DIV');
3707: for (i = 0; i < currentDivs.length; i++) {
3708: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3709: currentDivs[i].style.display = 'none';
1.330 tempelho 3710: }
3711: }
1.335 ehlerst 3712: }
1.330 tempelho 3713:
1.374 tempelho 3714: function openTabs(pageId) {
3715: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 3716: if(tabnav.length > 2 ){
1.389 tempelho 3717: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 3718: currentLis = currentNav.getElementsByTagName('LI');
3719: for(i = 0; i< currentLis.length; i++){
3720: if(currentLis[i].className == 'active') {
1.375 tempelho 3721: funcString = currentLis[i].onclick.toString();
3722: tab = funcString.split('"');
3723: currentData = document.getElementById(tab[1]);
3724: currentData.style.display = 'block';
1.374 tempelho 3725: }
3726: }
3727: }
3728: }
3729:
1.334 muellerd 3730: function showPage(current, pageId, nav, data) {
3731: hideAll(current, nav, data);
1.375 tempelho 3732: openTabs(pageId);
1.334 muellerd 3733: unselectInactive(nav);
1.330 tempelho 3734: current.className = 'active';
3735: currentData = document.getElementById(pageId);
3736: currentData.style.display = 'block';
3737: return false;
3738: }
1.329 droeschl 3739:
1.383 tempelho 3740: function injectData(current, hiddenField, name, value) {
3741: currentElement = document.getElementById(hiddenField);
3742: currentElement.name = name;
3743: currentElement.value = value;
3744: current.submit();
3745: }
3746:
1.329 droeschl 3747: ENDNEWSCRIPT
3748: }
3749: 1;
3750: __END__
3751:
3752:
3753: =head1 NAME
3754:
3755: Apache::londocs.pm
3756:
3757: =head1 SYNOPSIS
3758:
3759: This is part of the LearningOnline Network with CAPA project
3760: described at http://www.lon-capa.org.
3761:
3762: =head1 SUBROUTINES
3763:
3764: =over
3765:
3766: =item %help=()
3767:
3768: Available help topics
3769:
3770: =item mapread()
3771:
1.344 bisitz 3772: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 3773: @order and @resources, determines status
3774: sets @order - pointer to resources in right order
3775: sets @resources - array with the resources with correct idx
3776:
3777: =item authorhosts()
3778:
3779: Return hash with valid author names
3780:
3781: =item dumpbutton()
3782:
3783: Generate "dump" button
3784:
3785: =item clean()
3786:
3787: =item dumpcourse()
3788:
3789: Actually dump course
3790:
3791:
3792: =item exportbutton()
3793:
3794: Generate "export" button
3795:
3796: =item exportcourse()
3797:
3798: =item create_ims_store()
3799:
3800: =item build_package()
3801:
3802: =item get_dependencies()
3803:
3804: =item process_content()
3805:
3806: =item replicate_content()
3807:
3808: =item extract_media()
3809:
3810: =item store_template()
3811:
3812: =item group_import()
3813:
3814: Imports the given (name, url) resources into the course
3815: coursenum, coursedom, and folder must precede the list
3816:
3817: =item breadcrumbs()
3818:
3819: =item log_docs()
3820:
3821: =item docs_change_log()
3822:
3823: =item update_paste_buffer()
3824:
3825: =item print_paste_buffer()
3826:
3827: =item do_paste_from_buffer()
3828:
3829: =item update_parameter()
3830:
3831: =item handle_edit_cmd()
3832:
3833: =item editor()
3834:
3835: =item process_file_upload()
3836:
3837: =item process_secondary_uploads()
3838:
3839: =item is_supplemental_title()
3840:
3841: =item parse_supplemental_title()
3842:
3843: =item entryline()
3844:
3845: =item tiehash()
3846:
3847: =item untiehash()
3848:
3849: =item checkonthis()
3850:
3851: check on this
3852:
3853: =item verifycontent()
3854:
3855: Verify Content
3856:
3857: =item devalidateversioncache() & checkversions()
3858:
3859: Check Versions
3860:
3861: =item mark_hash_old()
3862:
3863: =item is_hash_old()
3864:
3865: =item changewarning()
3866:
3867: =item init_breadcrumbs()
3868:
3869: Breadcrumbs for special functions
3870:
3871: =back
3872:
3873: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>