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