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