Annotation of loncom/interface/londocs.pm, revision 1.408
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.408 ! raeburn 4: # $Id: londocs.pm,v 1.407 2009/10/30 20:24:39 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29:
30:
31: package Apache::londocs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::imsexport;
36: use Apache::lonnet;
37: use Apache::loncommon;
1.383 tempelho 38: use Apache::lonhtmlcommon;
1.329 droeschl 39: use LONCAPA::map();
40: use Apache::lonratedt();
41: use Apache::lonxml;
42: use Apache::lonclonecourse;
43: use Apache::lonnavmaps;
44: use HTML::Entities;
45: use GDBM_File;
46: use Apache::lonlocal;
47: use Cwd;
48: use LONCAPA qw(:DEFAULT :match);
49:
50: my $iconpath;
51:
52: my %hash;
53:
54: my $hashtied;
55: my %alreadyseen=();
56:
57: my $hadchanges;
58:
59:
60: my %help=();
61:
62:
63: sub mapread {
64: my ($coursenum,$coursedom,$map)=@_;
65: return
66: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
67: $map);
68: }
69:
70: sub storemap {
71: my ($coursenum,$coursedom,$map)=@_;
72: my ($outtext,$errtext)=
73: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
74: $map,1);
75: if ($errtext) { return ($errtext,2); }
1.364 bisitz 76:
1.329 droeschl 77: $hadchanges=1;
78: return ($errtext,0);
79: }
80:
81:
82:
83: sub authorhosts {
84: my %outhash=();
85: my $home=0;
86: my $other=0;
87: foreach my $key (keys(%env)) {
88: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
89: my $role=$1;
90: my $realm=$2;
91: my ($start,$end)=split(/\./,$env{$key});
92: if (($start) && ($start>time)) { next; }
93: if (($end) && (time>$end)) { next; }
94: my ($ca,$cd);
95: if ($1 eq 'au') {
96: $ca=$env{'user.name'};
97: $cd=$env{'user.domain'};
98: } else {
99: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
100: }
101: my $allowed=0;
102: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
103: my @ids=&Apache::lonnet::current_machine_ids();
104: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
105: if ($allowed) {
106: $home++;
107: $outhash{'home_'.$ca.'@'.$cd}=1;
108: } else {
109: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
110: $other++;
111: }
112: }
113: }
114: return ($home,$other,%outhash);
115: }
116:
117:
118: sub dumpbutton {
119: my ($home,$other,%outhash)=&authorhosts();
1.408 ! raeburn 120: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 121: if ($home+$other==0) { return ''; }
122: if ($home) {
1.408 ! raeburn 123: my $link = "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"dumpcourse\", \"".&mt('Dump '.$crstype.' DOCS to Construction Space')."\")'>".&mt('Dump '.$crstype.' DOCS to Construction Space')."</a>";
1.383 tempelho 124: return $link.' '.
1.362 ehlerst 125: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'<br />';
1.329 droeschl 126: } else {
127: return '<div>'.
1.408 ! raeburn 128: &mt('Dump '.$crstype.
1.329 droeschl 129: ' DOCS to Construction Space: available on other servers').
130: '</div>';
131: }
132: }
133:
134: sub clean {
135: my ($title)=@_;
136: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 137: return $title;
1.329 droeschl 138: }
139:
140:
141:
142: sub dumpcourse {
143: my ($r) = @_;
1.408 ! raeburn 144: my $crstype = &Apache::loncommon::course_type();
! 145: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' DOCS to Construction Space').
1.369 bisitz 146: '<form name="dumpdoc" action="" method="post">');
1.408 ! raeburn 147: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' DOCS to Construction Space'));
1.329 droeschl 148: my ($home,$other,%outhash)=&authorhosts();
149: unless ($home) { return ''; }
150: my $origcrsid=$env{'request.course.id'};
151: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
152: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
153: # Do the dumping
154: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
155: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
174: my $path='/home/'.$ca.'/public_html';
175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
1.344 bisitz 179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
205: # Input form
206: unless ($home==1) {
207: $r->print(
208: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
209: }
210: foreach my $key (sort(keys(%outhash))) {
211: if ($key=~/^home_(.+)$/) {
212: if ($home==1) {
213: $r->print(
214: '<input type="hidden" name="authorspace" value="'.$1.'" />');
215: } else {
216: $r->print('<option value="'.$1.'">'.$1.' - '.
217: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
218: }
219: }
220: }
221: unless ($home==1) {
222: $r->print('</select>');
223: }
224: my $title=$origcrsdata{'description'};
225: $title=~s/[\/\s]+/\_/gs;
226: $title=&clean($title);
227: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
228: .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
229: &tiehash();
230: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
231: .&Apache::loncommon::start_data_table()
232: .&Apache::loncommon::start_data_table_header_row()
233: .'<th>'.&mt('Internal Filename').'</th>'
234: .'<th>'.&mt('Title').'</th>'
235: .'<th>'.&mt('Save as ...').'</th>'
236: .&Apache::loncommon::end_data_table_header_row());
237: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
238: $r->print(&Apache::loncommon::start_data_table_row()
239: .'<td>'.$file.'</td>');
240: my ($ext)=($file=~/\.(\w+)$/);
241: my $title=$hash{'title_'.$hash{
242: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
243: $r->print('<td>'.($title?$title:' ').'</td>');
244: if (!$title) {
245: $title=$file;
246: } else {
247: $title=~s|/|_|g;
248: }
249: $title=~s/\.(\w+)$//;
250: $title=&clean($title);
251: $title.='.'.$ext;
252: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
253: .&Apache::loncommon::end_data_table_row());
254: }
255: $r->print(&Apache::loncommon::end_data_table());
256: &untiehash();
257: $r->print(
1.408 ! raeburn 258: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype DOCS").'" /></p></form>');
1.329 droeschl 259: }
260: }
261:
262:
263:
264: sub exportbutton {
1.408 ! raeburn 265: my $crstype = &Apache::loncommon::course_type();
1.383 tempelho 266: return "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"exportcourse\", \"".&mt('IMS Export')."\")'>".&mt('IMS Export')."</a>".
1.362 ehlerst 267: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'<br />';
1.329 droeschl 268: }
269:
270:
271:
272: sub exportcourse {
273: my $r=shift;
1.408 ! raeburn 274: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 275: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
276: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
277: my $numdisc = keys(%discussiontime);
278: my $navmap = Apache::lonnavmaps::navmap->new();
279: if (!defined($navmap)) {
1.408 ! raeburn 280: $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
1.376 bisitz 281: '<h2>'.&mt('IMS Export Failed').'</h2>'.
1.408 ! raeburn 282: '<div class="LC_error">');
! 283: if ($crstype eq 'Community') {
! 284: $r->print(&mt('Unable to retrieve information about community contents'));
! 285: } else {
! 286: $r->print(&mt('Unable to retrieve information about course contents'));
! 287: }
! 288: $r->print('</div><a href="/adm/coursedocs">');
! 289: if ($crstype eq 'Community') {
! 290: $r->print(&mt('Return to Community Editor'));
! 291: } else {
! 292: $r->print(&mt('Return to Course Editor'));
! 293: }
! 294: $r->print('</a>');
! 295: &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 296: return;
297: }
298: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
299: my $curRes;
300: my $outcome;
301:
302: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
303: ['finishexport']);
304: if ($env{'form.finishexport'}) {
305: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
306: ['archive','discussion']);
307:
308: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
309: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
310: if (@exportitems == 0 && @discussions == 0) {
1.377 bisitz 311: $outcome =
312: '<p class="LC_warning">'
313: .&mt('As you did not select any content items or discussions'
314: .' for export, an IMS package has not been created.')
315: .'</p>'
316: .'<p>'
317: .&mt('Please [_1]go back[_2] to select either content items'
318: .' or discussions for export.'
319: ,'<a href="javascript:history.go(-1)">'
320: ,'</a>')
321: .'</p>';
1.329 droeschl 322: } else {
323: my $now = time;
324: my %symbs;
325: my $manifestok = 0;
326: my $imsresources;
327: my $tempexport;
328: my $copyresult;
329: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
330: if ($manifestok) {
331: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
332: close($ims_manifest);
333:
334: #Create zip file in prtspool
335: my $imszipfile = '/prtspool/'.
336: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
337: time.'_'.rand(1000000000).'.zip';
338: my $cwd = &Cwd::getcwd();
339: my $imszip = '/home/httpd/'.$imszipfile;
340: chdir $tempexport;
341: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
342: close(OUTPUT);
343: chdir $cwd;
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: '' => '',
2481: 'mostrecent' => 'most recent',
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:
2621:
2622: # --------------------------------------------- Initialize help topics for this
2623: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2624: 'Adding_External_Resource','Navigate_Content',
2625: 'Adding_Folders','Docs_Overview', 'Load_Map',
2626: 'Supplemental','Score_Upload_Form','Adding_Pages',
2627: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2628: 'Check_Resource_Versions','Verify_Content') {
2629: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2630: }
2631: # Composite help files
2632: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2633: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2634: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2635: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2636: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2637: 'Option_Response_Simple');
2638: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2639: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2640: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2641: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2642: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2643: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2644:
2645: # does this user have privileges to modify docs
2646: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2647: if ($allowed && $env{'form.verify'}) {
2648: &init_breadcrumbs('verify','Verify Content');
2649: &verifycontent($r);
2650: } elsif ($allowed && $env{'form.listsymbs'}) {
2651: &init_breadcrumbs('listsymbs','List Symbs');
2652: &list_symbs($r);
2653: } elsif ($allowed && $env{'form.docslog'}) {
2654: &init_breadcrumbs('docslog','Show Log');
2655: &docs_change_log($r);
2656: } elsif ($allowed && $env{'form.versions'}) {
2657: &init_breadcrumbs('versions','Check/Set Resource Versions');
2658: &checkversions($r);
2659: } elsif ($allowed && $env{'form.dumpcourse'}) {
2660: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2661: &dumpcourse($r);
2662: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2663: &init_breadcrumbs('exportcourse','IMS Export');
1.329 droeschl 2664: &exportcourse($r);
2665: } else {
2666: # is this a standard course?
2667:
2668: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2669: my $forcestandard = 0;
2670: my $forcesupplement;
2671: my $script='';
2672: my $showdoc=0;
2673: my $containertag;
2674: my $uploadtag;
2675:
2676:
2677: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2678: ['folderpath','pagepath',
2679: 'pagesymb']);
2680: # No folderpath, no pagepath, see if we have something stored
2681: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2682: &Apache::loncommon::restore_course_settings('docs_folderpath',
2683: {'folderpath' => 'scalar'});
2684: }
2685: if (!$env{'form.folderpath'}) {
2686: &Apache::loncommon::restore_course_settings('docs_folderpath',
2687: {'pagepath' => 'scalar'});
2688: }
2689: if ($env{'form.pagepath'}) {
2690: $env{'form.folderpath'}='';
2691: }
2692: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2693: $env{'form.folderpath'} = 'supplemental&'.
1.408 ! raeburn 2694: &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
1.329 droeschl 2695: $env{'form.folderpath'};
2696: }
2697: &Apache::loncommon::store_course_settings('docs_folderpath',
2698: {'pagepath' => 'scalar',
2699: 'folderpath' => 'scalar'});
2700: if ($env{'form.folderpath'}) {
2701: my (@folderpath)=split('&',$env{'form.folderpath'});
2702: $env{'form.foldername'}=&unescape(pop(@folderpath));
2703: $env{'form.folder'}=pop(@folderpath);
2704: }
2705: if ($env{'form.pagepath'}) {
2706: my (@pagepath)=split('&',$env{'form.pagepath'});
2707: $env{'form.pagename'}=&unescape(pop(@pagepath));
2708: $env{'form.folder'}=pop(@pagepath);
2709: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2710: '<input type="hidden" name="pagesymb" value="" />';
2711: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2712: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2713: }
2714: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2715: $showdoc='/'.$1;
2716: }
1.402 raeburn 2717: if ($showdoc) { # got called in sequence from course
2718: $allowed=0;
2719: } else {
1.344 bisitz 2720: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.329 droeschl 2721: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2722: $forcestandard = 1;
1.364 bisitz 2723: }
1.329 droeschl 2724: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2725:
1.344 bisitz 2726: if ($allowed) {
1.329 droeschl 2727: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344 bisitz 2728: $script=&Apache::lonratedt::editscript('simple');
1.329 droeschl 2729: }
2730: }
2731:
1.383 tempelho 2732: # subroutine to list form elements
2733: sub create_list_elements {
2734: my @formarr = @_;
2735: my $list = '';
2736: for my $button (@formarr){
2737: for my $picture(keys %$button) {
2738: #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
2739: $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2740: }
2741: }
2742: return $list;
2743: }
2744:
2745: # subroutine to create ul from list elements
2746: sub create_form_ul {
2747: my $list = shift;
2748: my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2749: return $ul;
2750: }
2751:
1.329 droeschl 2752: # get course data
2753: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2754: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2755:
1.344 bisitz 2756: # get personal data
1.329 droeschl 2757: my $uname=$env{'user.name'};
2758: my $udom=$env{'user.domain'};
2759: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2760:
2761: # graphics settings
2762:
2763: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2764:
2765: if ($allowed) {
2766: $script .= &editing_js($udom,$uname);
2767: }
2768: # -------------------------------------------------------------------- Body tag
1.369 bisitz 2769: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 2770: .'// <![CDATA['."\n"
2771: .$script."\n"
2772: .'// ]]>'."\n"
2773: .'</script>'."\n";
1.385 bisitz 2774:
2775: # Breadcrumbs
2776: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.392 raeburn 2777: if ($allowed) {
2778: &Apache::lonhtmlcommon::add_breadcrumb({
1.408 ! raeburn 2779: href=>"/adm/coursedocs",text=>"$crstype Editor"});
1.392 raeburn 2780:
1.408 ! raeburn 2781: $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
1.392 raeburn 2782: {'force_register' => $showdoc,})
2783: .&Apache::loncommon::help_open_menu('','',273,'RAT')
2784: .&Apache::lonhtmlcommon::breadcrumbs(
1.408 ! raeburn 2785: 'Editing the Table of Contents for your '.$crstype,
1.392 raeburn 2786: 'Docs_Adding_Course_Doc')
2787: );
1.402 raeburn 2788: } elsif ($showdoc) {
1.408 ! raeburn 2789: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 2790: {'force_register' => $showdoc,}));
1.392 raeburn 2791: } else {
1.395 raeburn 2792: my $folder=$env{'form.folder'};
2793: if ($folder eq '' || $folder eq 'supplemental') {
2794: $env{'form.folderpath'} = 'supplemental&'.
1.408 ! raeburn 2795: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.395 raeburn 2796: }
1.408 ! raeburn 2797: my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
1.392 raeburn 2798: $r->print(&Apache::loncommon::start_page("Supplemental documents").
1.395 raeburn 2799: $breadcrumbtrail);
1.392 raeburn 2800: }
1.364 bisitz 2801:
1.329 droeschl 2802: my %allfiles = ();
2803: my %codebase = ();
2804: my ($upload_result,$upload_output);
2805: if ($allowed) {
2806: if (($env{'form.uploaddoc.filename'}) &&
2807: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.344 bisitz 2808: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 2809: undef($hadchanges);
2810: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2811: $coursedom,\%allfiles,
2812: \%codebase,$1);
2813: if ($hadchanges) {
2814: &mark_hash_old();
2815: }
2816: if ($upload_result eq 'phasetwo') {
2817: $r->print($upload_output);
2818: }
2819: } elsif ($env{'form.phasetwo'}) {
2820: my %newname = ();
2821: my %origname = ();
2822: my %attribs = ();
2823: my $updateflag = 0;
2824: my $residx = $env{'form.newidx'};
2825: my $primary_url = &unescape($env{'form.primaryurl'});
2826: # Process file upload - phase two - gather secondary files.
2827: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2828: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2829: my $javacodebase;
2830: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2831: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2832: if (exists($env{'form.embedded_codebase_'.$i})) {
1.344 bisitz 2833: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2834: $origname{$i} =~ s#^\Q$javacodebase\E/##;
1.329 droeschl 2835: }
2836: my @attributes = ();
2837: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2838: @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
2839: } else {
2840: @attributes = ($env{'form.embedded_attrib_'.$i});
2841: }
2842: foreach my $attr (@attributes) {
2843: push(@{$attribs{$i}},&unescape($attr));
2844: }
2845: if ($javacodebase) {
2846: $codebase{$i} = $javacodebase;
2847: $codebase{$i} =~ s#/$##;
2848: $updateflag = 1;
2849: }
2850: }
2851: unless ($newname{$i} eq $origname{$i}) {
2852: $updateflag = 1;
2853: }
2854: }
2855: # Process file upload - phase three - modify primary file
2856: if ($updateflag) {
2857: my ($content,$rtncode);
2858: my $updateflag = 0;
2859: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2860: if ($getstatus eq 'ok') {
2861: foreach my $item (keys(%newname)) {
2862: if ($newname{$item} ne $origname{$item}) {
2863: my $attrib_regexp = '';
2864: if (@{$attribs{$item}} > 1) {
2865: $attrib_regexp = join('|',@{$attribs{$item}});
2866: } else {
2867: $attrib_regexp = $attribs{$item}[0];
2868: }
2869: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
1.364 bisitz 2870: }
1.344 bisitz 2871: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
1.329 droeschl 2872: }
2873: if (exists($codebase{$item})) {
2874: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2875: }
2876: }
2877: # Save edited file.
2878: my $saveresult;
2879: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2880: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2881: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2882: } else {
1.344 bisitz 2883: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
1.329 droeschl 2884: }
2885: }
2886: }
2887: }
2888:
2889: unless ($showdoc || $upload_result eq 'phasetwo') {
2890: # -----------------------------------------------------------------------------
2891: my %lt=&Apache::lonlocal::texthash(
1.408 ! raeburn 2892: 'uplm' => 'Upload a new main '.lc($crstype).' document',
! 2893: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 2894: 'impp' => 'Import a document',
2895: 'copm' => 'All documents out of a published map into this folder',
2896: 'upld' => 'Upload Document',
2897: 'srch' => 'Search',
2898: 'impo' => 'Import',
2899: 'book' => 'Import Bookmarks',
2900: 'selm' => 'Select Map',
2901: 'load' => 'Load Map',
2902: 'reco' => 'Recover Deleted Resources',
2903: 'newf' => 'New Folder',
2904: 'newp' => 'New Composite Page',
2905: 'extr' => 'External Resource',
2906: 'syll' => 'Syllabus',
2907: 'navc' => 'Navigate Contents',
1.343 biermanm 2908: 'sipa' => 'Simple Course Page',
1.329 droeschl 2909: 'sipr' => 'Simple Problem',
2910: 'drbx' => 'Drop Box',
2911: 'scuf' => 'Score Upload Form',
1.336 schafran 2912: 'bull' => 'Discussion Board',
1.347 weissno 2913: 'mypi' => 'My Personal Information Page',
1.353 weissno 2914: 'grpo' => 'Group Portfolio',
1.329 droeschl 2915: 'rost' => 'Course Roster',
1.348 weissno 2916: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 2917: 'imsf' => 'IMS Import',
2918: 'imsl' => 'Import IMS package',
1.329 droeschl 2919: 'file' => 'File',
2920: 'title' => 'Title',
2921: 'comment' => 'Comment',
1.403 raeburn 2922: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 2923: 'nd' => 'Upload Document',
1.329 droeschl 2924: 'pm' => 'Published Map',
2925: 'sd' => 'Special Document',
2926: 'mo' => 'More Options',
2927: );
2928: # -----------------------------------------------------------------------------
2929: my $fileupload=(<<FIUP);
2930: $lt{'file'}:<br />
2931: <input type="file" name="uploaddoc" size="40" />
2932: FIUP
2933:
2934: my $checkbox=(<<CHBO);
2935: <!-- <label>$lt{'parse'}?
2936: <input type="checkbox" name="parserflag" />
2937: </label> -->
2938: <label>
2939: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2940: </label>
2941: CHBO
2942:
1.394 droeschl 2943: my $fileuploada = "<input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329 droeschl 2944: my $fileuploadform=(<<FUFORM);
2945: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 2946: <input type="hidden" name="active" value="aa" />
1.329 droeschl 2947: $fileupload
2948: <br />
2949: $lt{'title'}:<br />
2950: <input type="text" size="50" name="comment" />
2951: $uploadtag
2952: <input type="hidden" name="cmd" value="upload_default" />
2953: <br />
2954: <span class="LC_nobreak">
2955: $checkbox
2956: </span>
1.383 tempelho 2957: FUFORM
1.394 droeschl 2958: #$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2959: #$fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
2960: $fileuploadform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'}));
1.383 tempelho 2961: $fileuploadform .= (<<FUFORM);
1.329 droeschl 2962: </form>
2963: FUFORM
2964:
2965: my $simpleeditdefaultform=(<<SEDFFORM);
2966: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 2967: <input type="hidden" name="active" value="bb" />
1.383 tempelho 2968: SEDFFORM
2969: my @simpleeditdefaultforma = (
1.394 droeschl 2970: { '<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/src.png" alt="pic03" />' => "$uploadtag<a onclick='javascript:groupsearch()'>$lt{'srch'}</a>" },
2971: { '<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/res.png" alt="pic04" />' => "<a onclick='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
2972: { '<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/vbkm.png" alt="pic05" />' => "<a onclick='javascript:groupopen(0,1,1);'>$lt{'book'}</a>" },
1.383 tempelho 2973: );
2974: $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
2975: $simpleeditdefaultform .=(<<SEDFFORM);
1.329 droeschl 2976: <hr />
2977: <p>
2978: $lt{'copm'}<br />
2979: <input type="text" size="40" name="importmap" /><br />
1.344 bisitz 2980: <span class="LC_nobreak"><input type="button"
1.369 bisitz 2981: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 2982: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2983: $help{'Load_Map'}</span>
2984: </p>
2985: </form>
2986: SEDFFORM
2987:
2988: my $extresourcesform=(<<ERFORM);
2989: <form action="/adm/coursedocs" method="post" name="newext">
2990: $uploadtag
2991: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 2992: <a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.329 droeschl 2993: </form>
2994: ERFORM
2995:
2996: if ($allowed) {
2997: &update_paste_buffer($coursenum,$coursedom);
2998: my %lt=&Apache::lonlocal::texthash(
2999: 'vc' => 'Verify Content',
3000: 'cv' => 'Check/Set Resource Versions',
3001: 'ls' => 'List Symbs',
3002: 'sl' => 'Show Log'
3003: );
3004:
3005: my $folderpath=$env{'form.folderpath'};
3006: if (!$folderpath) {
3007: if ($env{'form.folder'} eq '' ||
3008: $env{'form.folder'} eq 'supplemental') {
3009: $folderpath='default&'.
1.408 ! raeburn 3010: &escape(&mt('Main '.$crstype.' Documents'));
1.329 droeschl 3011: }
3012: }
3013: unless ($env{'form.pagepath'}) {
3014: $containertag = '<input type="hidden" name="folderpath" value="" />';
3015: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
3016: }
1.337 ehlerst 3017: $r->print(<<HIDDENFORM);
3018: <form name="renameform" method="post" action="/adm/coursedocs">
3019: <input type="hidden" name="title" />
3020: <input type="hidden" name="cmd" />
3021: <input type="hidden" name="markcopy" />
3022: <input type="hidden" name="copyfolder" />
3023: $containertag
3024: </form>
3025: <form name="simpleedit" method="post" action="/adm/coursedocs">
3026: <input type="hidden" name="importdetail" value="" />
3027: $uploadtag
3028: </form>
3029: HIDDENFORM
1.329 droeschl 3030: }
1.335 ehlerst 3031: # --------------------------------------------------------- Main tab structure
1.395 raeburn 3032:
1.335 ehlerst 3033: my $activeClass = 1;
1.355 ehlerst 3034: my $active = '';
1.407 raeburn 3035: my %tabtitles = (
3036: main => {
3037: Course => &mt('Main Course Documents'),
3038: Community => &mt('Main Community Documents'),
3039: },
3040: supplemental => {
3041: Course => &mt('Supplemental Course Documents'),
3042: Community => &mt('Supplemental Community Documents'),
3043: },
3044: );
1.395 raeburn 3045: if ($allowed) {
3046: $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
3047: if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
3048: if($activeClass == 1){
3049: $active = 'class="active"';
3050: $activeClass = 0;
3051: }
3052: }
1.408 ! raeburn 3053: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'main'}{$crstype}.'</b></a></li>');
1.395 raeburn 3054: $active = '';
3055: if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
3056: if($activeClass == 1){
3057: $active = 'class="active"';
3058: }
1.335 ehlerst 3059: }
1.408 ! raeburn 3060: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'supplemental'}{$crstype}.'</b></a></li>');
1.395 raeburn 3061: $r->print('</ul>');
3062: } else {
3063: $r->print('<br />');
1.335 ehlerst 3064: }
1.395 raeburn 3065: $r->print('<div class="LC_Box" style="clear:both;margin:0;">'
1.376 bisitz 3066: .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
1.329 droeschl 3067: # --------------------------------------------------------- Standard documents
1.356 tempelho 3068: my $savefolderpath;
1.395 raeburn 3069: $active = 'style="display: none;"';
1.335 ehlerst 3070: if($activeClass == 0){
3071: $active = 'style="display: block;"';
3072: }
1.393 raeburn 3073: if ($allowed) {
1.359 tempelho 3074: $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
1.329 droeschl 3075: my $folder=$env{'form.folder'};
1.356 tempelho 3076: if ($folder eq '' || $folder=~/^supplemental/) {
1.329 droeschl 3077: $folder='default';
1.356 tempelho 3078: $savefolderpath = $env{'form.folderpath'};
1.408 ! raeburn 3079: $env{'form.folderpath'}='default&'.&escape($tabtitles{'main'}{$crstype});
1.329 droeschl 3080: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3081: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3082: }
3083: my $postexec='';
3084: if ($folder eq 'default') {
1.372 bisitz 3085: $r->print('<script type="text/javascript">'."\n"
3086: .'// <![CDATA['."\n"
3087: .'this.window.name="loncapaclient";'."\n"
3088: .'// ]]>'."\n"
3089: .'</script>'."\n"
1.369 bisitz 3090: );
1.329 droeschl 3091: } else {
3092: #$postexec='self.close();';
3093: }
3094: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3095: '.sequence';
3096: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3097: '.page';
3098: my $container='sequence';
3099: if ($env{'form.pagepath'}) {
3100: $container='page';
3101: }
3102: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3103:
3104:
3105:
3106: my $recoverform=(<<RFORM);
3107: <form action="/adm/groupsort" method="post" name="recover">
1.383 tempelho 3108: <a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
1.329 droeschl 3109: </form>
3110: RFORM
3111:
3112: my $imspform=(<<IMSPFORM);
3113: <form action="/adm/imsimportdocs" method="post" name="ims">
3114: <input type="hidden" name="folder" value="$folder" />
1.383 tempelho 3115: <a onclick="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 3116: </form>
3117: IMSPFORM
3118:
3119: my $newnavform=(<<NNFORM);
3120: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3121: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3122: $uploadtag
3123: <input type="hidden" name="importdetail"
3124: value="$lt{'navc'}=/adm/navmaps" />
1.383 tempelho 3125: <a onclick="document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3126: $help{'Navigate_Content'}
3127: </form>
3128: NNFORM
3129: my $newsmppageform=(<<NSPFORM);
3130: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3131: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3132: $uploadtag
3133: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3134: <a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
3135: $help{'Simple Page'}
1.329 droeschl 3136: </form>
3137: NSPFORM
3138:
3139: my $newsmpproblemform=(<<NSPROBFORM);
3140: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3141: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3142: $uploadtag
3143: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3144: <a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
3145: $help{'Simple Problem'}
1.329 droeschl 3146: </form>
3147:
3148: NSPROBFORM
3149:
3150: my $newdropboxform=(<<NDBFORM);
3151: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3152: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3153: $uploadtag
1.329 droeschl 3154: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3155: <a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3156: </form>
1.329 droeschl 3157: NDBFORM
3158:
3159: my $newexuploadform=(<<NEXUFORM);
3160: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3161: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3162: $uploadtag
3163: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3164: <a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3165: $help{'Score_Upload_Form'}
3166: </form>
3167: NEXUFORM
3168:
3169: my $newbulform=(<<NBFORM);
3170: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3171: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3172: $uploadtag
3173: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3174: <a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3175: $help{'Bulletin Board'}
3176: </form>
3177: NBFORM
3178:
3179: my $newaboutmeform=(<<NAMFORM);
3180: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3181: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3182: $uploadtag
3183: <input type="hidden" name="importdetail"
3184: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3185: <a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3186: $help{'My Personal Information Page'}
1.329 droeschl 3187: </form>
3188: NAMFORM
3189:
3190: my $newaboutsomeoneform=(<<NASOFORM);
3191: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3192: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3193: $uploadtag
3194: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3195: <a onclick="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3196: </form>
3197: NASOFORM
3198:
3199:
3200: my $newrosterform=(<<NROSTFORM);
3201: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3202: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3203: $uploadtag
3204: <input type="hidden" name="importdetail"
3205: value="$lt{'rost'}=/adm/viewclasslist" />
1.383 tempelho 3206: <a onclick="document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3207: $help{'Course Roster'}
3208: </form>
3209: NROSTFORM
3210:
1.342 ehlerst 3211: my $specialdocumentsform;
1.383 tempelho 3212: my @specialdocumentsforma;
1.351 ehlerst 3213: my $newfolderform;
1.390 tempelho 3214: my $newfolderb;
1.342 ehlerst 3215:
1.329 droeschl 3216: unless ($env{'form.pagepath'}) {
3217: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3218:
1.329 droeschl 3219: my $newpageform=(<<NPFORM);
3220: <form action="/adm/coursedocs" method="post" name="newpage">
3221: <input type="hidden" name="folderpath" value="$path" />
3222: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3223: <input type="hidden" name="active" value="cc" />
1.383 tempelho 3224: <a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
3225: $help{'Adding_Pages'}
1.329 droeschl 3226: </form>
3227: NPFORM
1.390 tempelho 3228:
3229:
1.351 ehlerst 3230: $newfolderform=(<<NFFORM);
1.329 droeschl 3231: <form action="/adm/coursedocs" method="post" name="newfolder">
3232: <input type="hidden" name="folderpath" value="$path" />
3233: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3234: <input type="hidden" name="active" value="aa" />
1.383 tempelho 3235: <a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3236: </form>
3237: NFFORM
3238:
3239: my $newsylform=(<<NSYLFORM);
3240: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3241: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3242: $uploadtag
3243: <input type="hidden" name="importdetail"
3244: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3245: <a onclick="document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3246: $help{'Syllabus'}
1.383 tempelho 3247:
1.329 droeschl 3248: </form>
3249: NSYLFORM
1.364 bisitz 3250:
1.329 droeschl 3251: my $newgroupfileform=(<<NGFFORM);
3252: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3253: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3254: $uploadtag
3255: <input type="hidden" name="importdetail"
3256: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.383 tempelho 3257: <a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3258: $help{'Group Portfolio'}
1.329 droeschl 3259: </form>
3260: NGFFORM
1.383 tempelho 3261: @specialdocumentsforma=(
1.399 droeschl 3262: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/page.png" alt="pic06" />'=>$newpageform},
1.394 droeschl 3263: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/syllabus.png" alt="pic07" />'=>$newsylform},
3264: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/groupportfolio.png" alt="pic08" />'=>$newgroupfileform},
1.383 tempelho 3265: );
3266:
3267: }
1.394 droeschl 3268: push @specialdocumentsforma, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/navigation.png" alt="pic09" />'=>$newnavform},
3269: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simple.png" alt="pic10" />'=>$newsmppageform},
3270: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simpprob.png" alt="pic11" />'=>$newsmpproblemform},
3271: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/dropbox.png" alt="pic12" />'=>$newdropboxform},
3272: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/scoreupfrm.png" alt="pic13" />'=>$newexuploadform},
3273: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/bchat.png" alt="pic14" />'=>$newbulform},
3274: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/myaboutme.png" alt="pic15" />'=>$newaboutmeform},
3275: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/aboutme.png" alt="pic16" />'=>$newaboutsomeoneform},
3276: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/chrt.png" alt="pic17" />'=>$newrosterform},);
1.383 tempelho 3277:
3278: $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
1.329 droeschl 3279:
1.342 ehlerst 3280: if($env{'form.pagepath'}) {
1.383 tempelho 3281:
3282: @specialdocumentsforma=(
1.397 wenzelju 3283: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simpprob.png" alt="pic32" />'=>$newsmpproblemform},
3284: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/scoreupfrm.png" alt="pic33" />'=>$newexuploadform}
1.383 tempelho 3285: );
3286: $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
1.342 ehlerst 3287: }
1.331 muellerd 3288:
1.383 tempelho 3289: my @tools = (
1.394 droeschl 3290: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="pic18" />'=>$extresourcesform},
3291: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="pic19" />'=>$imspform},
3292: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/recover.png" alt="pic20" />'=>$recoverform},
1.383 tempelho 3293: );
3294:
1.330 tempelho 3295: my %orderhash = (
1.390 tempelho 3296: '00' => ['Newfolder',$newfolderform],
3297: 'aa' => ['Upload Document',$fileuploadform],
1.377 bisitz 3298: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.363 ehlerst 3299: 'cc' => ['Special Documents',$specialdocumentsform],
1.383 tempelho 3300: 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
1.330 tempelho 3301: );
1.334 muellerd 3302: my $tid='1';
1.341 ehlerst 3303: $hadchanges=0;
1.408 ! raeburn 3304: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.335 ehlerst 3305: if ($error) {
3306: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3307: }
1.341 ehlerst 3308: if ($hadchanges) {
3309: &mark_hash_old();
3310: }
3311:
3312: &changewarning($r,'');
1.406 raeburn 3313: $r->print(&generate_edit_table($tid,\%orderhash));
1.389 tempelho 3314:
1.335 ehlerst 3315: $r->print('</div>');
1.383 tempelho 3316: }
1.329 droeschl 3317: if ($env{'form.pagepath'}) {
3318: }
3319: # ----------------------------------------------------- Supplemental documents
1.395 raeburn 3320: $active = 'style="display: none;"';
1.335 ehlerst 3321: if($activeClass == 1){
3322: $active = 'style="display: block;"';
3323: }
1.373 bisitz 3324: $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
1.329 droeschl 3325: my $folder=$env{'form.folder'};
3326: unless ($folder=~/^supplemental/) {
3327: $folder='supplemental';
3328: }
3329: if ($folder =~ /^supplemental$/ &&
3330: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3331: $env{'form.folderpath'} = 'supplemental&'.
1.408 ! raeburn 3332: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.393 raeburn 3333: } elsif ($allowed) {
1.356 tempelho 3334: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3335: }
1.362 ehlerst 3336: $env{'form.pagepath'} = '';
1.329 droeschl 3337: if ($allowed) {
3338: my $folderseq=
3339: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3340: '.sequence';
3341:
3342: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3343:
1.400 droeschl 3344: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329 droeschl 3345: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 3346: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 3347: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3348: $fileupload
3349: <br />
3350: <br />
3351: <span class="LC_nobreak">
3352: $checkbox
3353: </span>
3354: <br /><br />
3355: $lt{'comment'}:<br />
1.383 tempelho 3356: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3357: <br />
3358: <input type="hidden" name="folderpath" value="$path" />
3359: <input type="hidden" name="cmd" value="upload_supplemental" />
3360: SUPDOCFORM
1.400 droeschl 3361: $supupdocform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329 droeschl 3362:
3363: my $supnewfolderform=(<<SNFFORM);
3364: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3365: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3366: <input type="hidden" name="folderpath" value="$path" />
3367: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3368: <a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
3369: $help{'Adding_Folders'}
1.329 droeschl 3370: </form>
3371: SNFFORM
1.383 tempelho 3372:
1.329 droeschl 3373:
3374: my $supnewextform=(<<SNEFORM);
3375: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 3376: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3377: <input type="hidden" name="folderpath" value="$path" />
3378: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3379: <a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 3380: </form>
3381: SNEFORM
3382:
3383: my $supnewsylform=(<<SNSFORM);
3384: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 3385: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3386: <input type="hidden" name="folderpath" value="$path" />
3387: <input type="hidden" name="importdetail"
3388: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3389: <a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3390: $help{'Syllabus'}
3391: </form>
3392: SNSFORM
3393:
3394: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 3395: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 3396: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3397: <input type="hidden" name="folderpath" value="$path" />
3398: <input type="hidden" name="importdetail"
3399: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3400: <a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3401: $help{'My Personal Information Page'}
1.329 droeschl 3402: </form>
3403: SNAMFORM
3404:
1.333 muellerd 3405:
1.383 tempelho 3406: my @specialdocs = (
1.397 wenzelju 3407: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="pic29" />'=>$supnewextform},
3408: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/syllabus.png" alt="pic30" />'=>$supnewsylform},
3409: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/myaboutme.png" alt="pic31" />'=>$supnewaboutmeform},
1.383 tempelho 3410: );
1.333 muellerd 3411: my %suporderhash = (
1.390 tempelho 3412: '00' => ['Supnewfolder', $supnewfolderform],
3413: 'ee' => ['Upload Document',$supupdocform],
3414: 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))]
1.333 muellerd 3415: );
1.334 muellerd 3416:
1.408 ! raeburn 3417: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3418: if ($error) {
3419: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3420: }
3421: my $tid='2';
1.406 raeburn 3422: $r->print(&generate_edit_table($tid,\%suporderhash));
1.393 raeburn 3423: } else {
1.408 ! raeburn 3424: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3425: if ($error) {
3426: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3427: }
1.393 raeburn 3428: }
1.389 tempelho 3429:
3430:
1.335 ehlerst 3431: $r->print('</div>');
1.383 tempelho 3432: $r->print('</div></div>');
3433:
3434:
1.329 droeschl 3435: if ($allowed) {
3436: $r->print('
3437: <form method="post" name="extimport" action="/adm/coursedocs">
3438: <input type="hidden" name="title" />
3439: <input type="hidden" name="url" />
3440: <input type="hidden" name="useform" />
3441: <input type="hidden" name="residx" />
3442: </form>');
3443: }
3444: } else {
3445: unless ($upload_result eq 'phasetwo') {
3446: # -------------------------------------------------------- This is showdoc mode
3447: $r->print("<h1>".&mt('Uploaded Document').' - '.
3448: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3449: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3450: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3451: }
3452: }
3453: }
3454: $r->print(&Apache::loncommon::end_page());
3455: return OK;
1.364 bisitz 3456: }
1.329 droeschl 3457:
3458: sub generate_admin_options {
1.337 ehlerst 3459: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3460: my %lt=&Apache::lonlocal::texthash(
3461: 'vc' => 'Verify Content',
3462: 'cv' => 'Check/Set Resource Versions',
3463: 'ls' => 'List Symbs',
3464: 'sl' => 'Show Log'
3465: );
1.329 droeschl 3466: my %help = %{$help_ref};
3467: my %env = %{$env_ref};
3468: my $dumpbut=&dumpbutton();
3469: my $exportbut=&exportbutton();
1.383 tempelho 3470: my @list = (
1.394 droeschl 3471: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/verify.png" alt="pic21" />'=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
3472: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/resversion.png" alt="pic22" />'=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
1.383 tempelho 3473: );
3474: if($dumpbut ne ''){
1.394 droeschl 3475: push @list, {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/dump.png" alt="pic23" />'=>$dumpbut};
1.383 tempelho 3476: }
1.394 droeschl 3477: push @list, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/imsexport.png" alt="pic24" />'=>$exportbut},
3478: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/symbs.png" alt="pic25" />'=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"listsymbs\", \"$lt{'ls'}\")'>$lt{'ls'}</a><input type='hidden' name='folder' value='$env{'form.folder'}' />"},
3479: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/log.png" alt="pic26" />'=>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
1.383 tempelho 3480: );
3481: 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 3482:
1.329 droeschl 3483: }
3484:
1.330 tempelho 3485:
1.329 droeschl 3486: sub generate_edit_table {
1.406 raeburn 3487: my ($tid,$orderhash_ref) = @_;
3488: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 3489: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3490: my $form;
1.371 tempelho 3491: my $activetab;
3492: my $active;
3493: if($env{'form.active'} ne ''){
3494: $activetab = $env{'form.active'};
3495: }
1.382 tempelho 3496: $form = '<div class="LC_Box">';
1.359 tempelho 3497: $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
1.329 droeschl 3498: foreach my $name (sort(keys(%orderhash))){
1.390 tempelho 3499: if($name ne '00'){
1.371 tempelho 3500: if($activetab eq '' || $activetab ne $name){
3501: $active = '';
3502: }elsif($activetab eq $name){
3503: $active = 'class="active"';
3504: }
1.374 tempelho 3505: $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
1.390 tempelho 3506: } else {
3507: $form .= '<li '.$active.'>'.${$orderhash{$name}}[1].'</li>';
3508:
3509: }
1.329 droeschl 3510: }
1.339 ehlerst 3511: $form .= '</ul>';
1.398 bisitz 3512: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; clear: both;">';
1.363 ehlerst 3513: foreach my $field (keys(%orderhash)){
1.390 tempelho 3514: if($field ne '00'){
1.371 tempelho 3515: if($activetab eq '' || $activetab ne $field){
3516: $active = 'style="display: none;"';
3517: }elsif($activetab eq $field){
3518: $active = 'style="display:block;"';
3519: }
1.374 tempelho 3520: $form .= '<div id="'.$field.$tid.'"'
1.373 bisitz 3521: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3522: .'</div>';
1.363 ehlerst 3523: }
3524: }
1.330 tempelho 3525: $form .= '</div></div>';
1.364 bisitz 3526:
1.329 droeschl 3527: return $form;
3528: }
3529:
3530: sub editing_js {
3531: my ($udom,$uname) = @_;
3532: my $now = time();
3533: my %lt = &Apache::lonlocal::texthash(
3534: p_mnf => 'Name of New Folder',
3535: t_mnf => 'New Folder',
3536: p_mnp => 'Name of New Page',
3537: t_mnp => 'New Page',
3538: p_mxu => 'Title for the Uploaded Score',
1.349 biermanm 3539: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3540: p_msb => 'Title for the Problem',
3541: p_mdb => 'Title for the Drop Box',
1.336 schafran 3542: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3543: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3544: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3545: p_mab_alrt1 => 'Not a valid user:domain',
3546: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3547: p_chn => 'New Title',
3548: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3549: p_rmr2a => 'Remove[_99]',
3550: p_rmr2b => '?[_99]',
3551: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3552: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3553: p_ctr2a => 'Cut[_98]',
3554: p_ctr2b => '?[_98]'
3555: );
3556:
3557: return <<ENDNEWSCRIPT;
3558: function makenewfolder(targetform,folderseq) {
3559: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3560: if (foldername) {
3561: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3562: targetform.submit();
3563: }
3564: }
3565:
3566: function makenewpage(targetform,folderseq) {
3567: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3568: if (pagename) {
3569: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3570: targetform.submit();
3571: }
3572: }
3573:
3574: function makenewext(targetname) {
3575: this.document.forms.extimport.useform.value=targetname;
3576: this.document.forms.extimport.title.value='';
3577: this.document.forms.extimport.url.value='';
3578: this.document.forms.extimport.residx.value='';
3579: window.open('/adm/rat/extpickframe.html');
3580: }
3581:
3582: function edittext(targetname,residx,title,url) {
3583: this.document.forms.extimport.useform.value=targetname;
3584: this.document.forms.extimport.residx.value=residx;
3585: this.document.forms.extimport.url.value=url;
3586: this.document.forms.extimport.title.value=title;
3587: window.open('/adm/rat/extpickframe.html');
3588: }
3589:
3590: function makeexamupload() {
3591: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3592: if (title) {
1.329 droeschl 3593: this.document.forms.newexamupload.importdetail.value=
3594: escape(title)+'=/res/lib/templates/examupload.problem';
3595: this.document.forms.newexamupload.submit();
3596: }
3597: }
3598:
3599: function makesmppage() {
3600: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3601: if (title) {
1.329 droeschl 3602: this.document.forms.newsmppg.importdetail.value=
3603: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3604: this.document.forms.newsmppg.submit();
3605: }
3606: }
3607:
3608: function makesmpproblem() {
3609: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3610: if (title) {
1.329 droeschl 3611: this.document.forms.newsmpproblem.importdetail.value=
3612: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3613: this.document.forms.newsmpproblem.submit();
3614: }
3615: }
3616:
3617: function makedropbox() {
3618: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3619: if (title) {
1.329 droeschl 3620: this.document.forms.newdropbox.importdetail.value=
3621: escape(title)+'=/res/lib/templates/DropBox.problem';
3622: this.document.forms.newdropbox.submit();
3623: }
3624: }
3625:
3626: function makebulboard() {
3627: var title=prompt('$lt{"p_mbb"}');
3628: if (title) {
3629: this.document.forms.newbul.importdetail.value=
3630: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3631: this.document.forms.newbul.submit();
3632: }
3633: }
3634:
3635: function makeabout() {
3636: var user=prompt("$lt{'p_mab'}");
3637: if (user) {
3638: var comp=new Array();
3639: comp=user.split(':');
3640: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3641: if ((comp[0]) && (comp[1])) {
3642: this.document.forms.newaboutsomeone.importdetail.value=
3643: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3644: this.document.forms.newaboutsomeone.submit();
3645: } else {
3646: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3647: }
1.335 ehlerst 3648: } else {
3649: alert("$lt{'p_mab_alrt2'}");
3650: }
3651: }
1.329 droeschl 3652: }
3653:
3654: function makeims() {
1.335 ehlerst 3655: var caller = document.forms.ims.folder.value;
3656: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3657: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3658: newWindow.location.href = newlocation;
1.329 droeschl 3659: }
3660:
3661:
3662: function finishpick() {
1.335 ehlerst 3663: var title=this.document.forms.extimport.title.value;
3664: var url=this.document.forms.extimport.url.value;
3665: var form=this.document.forms.extimport.useform.value;
3666: var residx=this.document.forms.extimport.residx.value;
3667: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3668: }
3669:
3670: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3671: var title=prompt('$lt{"p_chn"}',oldtitle);
3672: if (title) {
3673: this.document.forms.renameform.markcopy.value=-1;
3674: this.document.forms.renameform.title.value=title;
3675: this.document.forms.renameform.cmd.value='rename_'+index;
3676: if (container == 'sequence') {
3677: this.document.forms.renameform.folderpath.value=folderpath;
3678: }
3679: if (container == 'page') {
3680: this.document.forms.renameform.pagepath.value=folderpath;
3681: this.document.forms.renameform.pagesymb.value=pagesymb;
3682: }
3683: this.document.forms.renameform.submit();
3684: }
1.329 droeschl 3685: }
3686:
3687: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3688: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3689: this.document.forms.renameform.markcopy.value=-1;
3690: this.document.forms.renameform.cmd.value='del_'+index;
3691: if (container == 'sequence') {
3692: this.document.forms.renameform.folderpath.value=folderpath;
3693: }
3694: if (container == 'page') {
3695: this.document.forms.renameform.pagepath.value=folderpath;
3696: this.document.forms.renameform.pagesymb.value=pagesymb;
3697: }
3698: this.document.forms.renameform.submit();
3699: }
1.329 droeschl 3700: }
3701:
3702: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3703: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3704: this.document.forms.renameform.cmd.value='cut_'+index;
3705: this.document.forms.renameform.markcopy.value=index;
3706: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3707: if (container == 'sequence') {
3708: this.document.forms.renameform.folderpath.value=folderpath;
3709: }
3710: if (container == 'page') {
3711: this.document.forms.renameform.pagepath.value=folderpath;
3712: this.document.forms.renameform.pagesymb.value=pagesymb;
3713: }
3714: this.document.forms.renameform.submit();
3715: }
1.329 droeschl 3716: }
3717:
3718: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3719: this.document.forms.renameform.markcopy.value=index;
3720: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3721: if (container == 'sequence') {
3722: this.document.forms.renameform.folderpath.value=folderpath;
3723: }
3724: if (container == 'page') {
3725: this.document.forms.renameform.pagepath.value=folderpath;
3726: this.document.forms.renameform.pagesymb.value=pagesymb;
3727: }
3728: this.document.forms.renameform.submit();
1.329 droeschl 3729: }
3730:
1.334 muellerd 3731: function unselectInactive(nav) {
1.335 ehlerst 3732: currentNav = document.getElementById(nav);
3733: currentLis = currentNav.getElementsByTagName('LI');
3734: for (i = 0; i < currentLis.length; i++) {
1.374 tempelho 3735: if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
3736: currentLis[i].className = 'right';
3737: }else{
3738: currentLis[i].className = 'i';
3739: }
1.335 ehlerst 3740: }
1.332 tempelho 3741: }
3742:
1.334 muellerd 3743: function hideAll(current, nav, data) {
1.335 ehlerst 3744: unselectInactive(nav);
1.374 tempelho 3745: if(current.className == 'right'){
3746: current.className = 'right active'
3747: }else{
3748: current.className = 'active';
3749: }
1.335 ehlerst 3750: currentData = document.getElementById(data);
3751: currentDivs = currentData.getElementsByTagName('DIV');
3752: for (i = 0; i < currentDivs.length; i++) {
3753: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3754: currentDivs[i].style.display = 'none';
1.330 tempelho 3755: }
3756: }
1.335 ehlerst 3757: }
1.330 tempelho 3758:
1.374 tempelho 3759: function openTabs(pageId) {
3760: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 3761: if(tabnav.length > 2 ){
1.389 tempelho 3762: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 3763: currentLis = currentNav.getElementsByTagName('LI');
3764: for(i = 0; i< currentLis.length; i++){
3765: if(currentLis[i].className == 'active') {
1.375 tempelho 3766: funcString = currentLis[i].onclick.toString();
3767: tab = funcString.split('"');
3768: currentData = document.getElementById(tab[1]);
3769: currentData.style.display = 'block';
1.374 tempelho 3770: }
3771: }
3772: }
3773: }
3774:
1.334 muellerd 3775: function showPage(current, pageId, nav, data) {
3776: hideAll(current, nav, data);
1.375 tempelho 3777: openTabs(pageId);
1.334 muellerd 3778: unselectInactive(nav);
1.330 tempelho 3779: current.className = 'active';
3780: currentData = document.getElementById(pageId);
3781: currentData.style.display = 'block';
3782: return false;
3783: }
1.329 droeschl 3784:
1.383 tempelho 3785: function injectData(current, hiddenField, name, value) {
3786: currentElement = document.getElementById(hiddenField);
3787: currentElement.name = name;
3788: currentElement.value = value;
3789: current.submit();
3790: }
3791:
1.329 droeschl 3792: ENDNEWSCRIPT
3793: }
3794: 1;
3795: __END__
3796:
3797:
3798: =head1 NAME
3799:
3800: Apache::londocs.pm
3801:
3802: =head1 SYNOPSIS
3803:
3804: This is part of the LearningOnline Network with CAPA project
3805: described at http://www.lon-capa.org.
3806:
3807: =head1 SUBROUTINES
3808:
3809: =over
3810:
3811: =item %help=()
3812:
3813: Available help topics
3814:
3815: =item mapread()
3816:
1.344 bisitz 3817: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 3818: @order and @resources, determines status
3819: sets @order - pointer to resources in right order
3820: sets @resources - array with the resources with correct idx
3821:
3822: =item authorhosts()
3823:
3824: Return hash with valid author names
3825:
3826: =item dumpbutton()
3827:
3828: Generate "dump" button
3829:
3830: =item clean()
3831:
3832: =item dumpcourse()
3833:
3834: Actually dump course
3835:
3836:
3837: =item exportbutton()
3838:
3839: Generate "export" button
3840:
3841: =item exportcourse()
3842:
3843: =item create_ims_store()
3844:
3845: =item build_package()
3846:
3847: =item get_dependencies()
3848:
3849: =item process_content()
3850:
3851: =item replicate_content()
3852:
3853: =item extract_media()
3854:
3855: =item store_template()
3856:
3857: =item group_import()
3858:
3859: Imports the given (name, url) resources into the course
3860: coursenum, coursedom, and folder must precede the list
3861:
3862: =item breadcrumbs()
3863:
3864: =item log_docs()
3865:
3866: =item docs_change_log()
3867:
3868: =item update_paste_buffer()
3869:
3870: =item print_paste_buffer()
3871:
3872: =item do_paste_from_buffer()
3873:
3874: =item update_parameter()
3875:
3876: =item handle_edit_cmd()
3877:
3878: =item editor()
3879:
3880: =item process_file_upload()
3881:
3882: =item process_secondary_uploads()
3883:
3884: =item is_supplemental_title()
3885:
3886: =item parse_supplemental_title()
3887:
3888: =item entryline()
3889:
3890: =item tiehash()
3891:
3892: =item untiehash()
3893:
3894: =item checkonthis()
3895:
3896: check on this
3897:
3898: =item verifycontent()
3899:
3900: Verify Content
3901:
3902: =item devalidateversioncache() & checkversions()
3903:
3904: Check Versions
3905:
3906: =item mark_hash_old()
3907:
3908: =item is_hash_old()
3909:
3910: =item changewarning()
3911:
3912: =item init_breadcrumbs()
3913:
3914: Breadcrumbs for special functions
3915:
3916: =back
3917:
3918: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>