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