Annotation of loncom/interface/londocs.pm, revision 1.474
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.474 ! raeburn 4: # $Id: londocs.pm,v 1.473 2011/12/28 03:57:22 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");
1.474 ! raeburn 2794: $r->print('<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
! 2795: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
! 2796: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">');
1.442 www 2797: }
2798:
2799: #
2800: # End tabs
2801: #
2802:
2803: sub endContentScreen {
2804: my ($r)=@_;
2805: $r->print('</div></div></div>');
2806: }
1.329 droeschl 2807:
1.446 www 2808: sub supplemental_base {
1.472 raeburn 2809: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 2810: }
2811:
1.329 droeschl 2812: sub handler {
2813: my $r = shift;
2814: &Apache::loncommon::content_type($r,'text/html');
2815: $r->send_http_header;
2816: return OK if $r->header_only;
1.408 raeburn 2817: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 2818:
1.443 www 2819: #
1.329 droeschl 2820: # --------------------------------------------- Initialize help topics for this
2821: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2822: 'Adding_External_Resource','Navigate_Content',
2823: 'Adding_Folders','Docs_Overview', 'Load_Map',
2824: 'Supplemental','Score_Upload_Form','Adding_Pages',
2825: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2826: 'Check_Resource_Versions','Verify_Content') {
2827: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2828: }
2829: # Composite help files
2830: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2831: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2832: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2833: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2834: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2835: 'Option_Response_Simple');
2836: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2837: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2838: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2839: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2840: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2841: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2842:
1.472 raeburn 2843:
2844: my $allowed;
2845: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
2846: unless ($r->uri eq '/adm/supplemental') {
2847: # does this user have privileges to modify content.
2848: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2849: }
2850:
1.329 droeschl 2851: if ($allowed && $env{'form.verify'}) {
2852: &init_breadcrumbs('verify','Verify Content');
2853: &verifycontent($r);
2854: } elsif ($allowed && $env{'form.listsymbs'}) {
2855: &init_breadcrumbs('listsymbs','List Symbs');
2856: &list_symbs($r);
2857: } elsif ($allowed && $env{'form.docslog'}) {
2858: &init_breadcrumbs('docslog','Show Log');
2859: &docs_change_log($r);
2860: } elsif ($allowed && $env{'form.versions'}) {
2861: &init_breadcrumbs('versions','Check/Set Resource Versions');
2862: &checkversions($r);
2863: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.419 bisitz 2864: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Documents to Construction Space');
1.329 droeschl 2865: &dumpcourse($r);
2866: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2867: &init_breadcrumbs('exportcourse','IMS Export');
1.329 droeschl 2868: &exportcourse($r);
2869: } else {
1.445 www 2870: #
2871: # Done catching special calls
2872: # The whole rest is for course and supplemental documents
2873: # Get the parameters that may be needed
2874: #
2875: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2876: ['folderpath','pagepath',
1.466 www 2877: 'pagesymb','forcesupplement','forcestandard',
2878: 'symb','command']);
1.445 www 2879:
2880: # standard=1: this is a "new-style" course with an uploaded map as top level
2881: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 2882:
2883: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 2884:
2885: # Decide whether this should display supplemental or main content
2886: # supplementalflag=1: show supplemental documents
2887: # supplementalflag=0: show standard documents
2888:
2889:
2890: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
2891: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
2892: $supplementalflag=0;
2893: }
2894: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
2895: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
2896: unless ($allowed) { $supplementalflag=1; }
2897: unless ($standard) { $supplementalflag=1; }
2898:
1.329 droeschl 2899: my $script='';
2900: my $showdoc=0;
1.457 raeburn 2901: my $addentries = {};
1.329 droeschl 2902: my $containertag;
2903: my $uploadtag;
2904:
1.464 www 2905: # Do we directly jump somewhere?
1.466 www 2906:
1.464 www 2907: if ($env{'form.command'} eq 'direct') {
1.468 raeburn 2908: my ($mapurl,$id,$resurl);
1.472 raeburn 2909: if ($env{'form.symb'} ne '') {
1.468 raeburn 2910: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
2911: if ($resurl=~/\.(sequence|page)$/) {
2912: $mapurl=$resurl;
2913: } elsif ($resurl eq 'adm/navmaps') {
2914: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
2915: }
1.472 raeburn 2916: my $mapresobj;
2917: my $navmap = Apache::lonnavmaps::navmap->new();
2918: if (ref($navmap)) {
2919: $mapresobj = $navmap->getResourceByUrl($mapurl);
2920: }
2921: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
2922: my $type=$2;
2923: my $path;
2924: if (ref($mapresobj)) {
2925: my $pcslist = $mapresobj->map_hierarchy();
2926: if ($pcslist ne '') {
2927: foreach my $pc (split(/,/,$pcslist)) {
2928: next if ($pc <= 1);
2929: my $res = $navmap->getByMapPc($pc);
2930: if (ref($res)) {
2931: my $thisurl = $res->src();
2932: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
2933: my $thistitle = $res->title();
2934: $path .= '&'.
2935: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
2936: &Apache::lonhtmlcommon::entity_encode($thistitle).
2937: ':'.$res->randompick().
2938: ':'.$res->randomout().
2939: ':'.$res->encrypted().
2940: ':'.$res->randomorder();
2941: }
1.467 raeburn 2942: }
2943: }
1.472 raeburn 2944: $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467 raeburn 2945: &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
2946: ':'.$mapresobj->randompick().
2947: ':'.$mapresobj->randomout().
2948: ':'.$mapresobj->encrypted().
2949: ':'.$mapresobj->randomorder();
1.472 raeburn 2950: } else {
2951: my $maptitle = &Apache::lonnet::gettitle($mapurl);
2952: $path = '&default&...::::'.
2953: '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
2954: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
2955: }
2956: $path = 'default&'.
2957: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
2958: $path;
2959: if ($type eq 'sequence') {
2960: $env{'form.folderpath'}=$path;
2961: $env{'form.pagepath'}='';
2962: } else {
2963: $env{'form.pagepath'}=$path;
2964: $env{'form.folderpath'}='';
2965: }
2966: } elsif ($env{'form.supppath'} ne '') {
2967: $env{'form.folderpath'}=$env{'form.supppath'};
1.466 www 2968: }
1.472 raeburn 2969: } elsif ($env{'form.command'} eq 'editdocs') {
2970: $env{'form.folderpath'} = 'default&'.
2971: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
2972: $env{'form.pagepath'}='';
2973: } elsif ($env{'form.command'} eq 'editsupp') {
2974: $env{'form.folderpath'} = 'default&'.
2975: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
2976: $env{'form.pagepath'}='';
1.464 www 2977: }
2978:
1.445 www 2979: # Where do we store these for when we come back?
2980: my $stored_folderpath='docs_folderpath';
2981: if ($supplementalflag) {
2982: $stored_folderpath='docs_sup_folderpath';
2983: }
1.464 www 2984:
1.329 droeschl 2985: # No folderpath, no pagepath, see if we have something stored
2986: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445 www 2987: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 2988: {'folderpath' => 'scalar'});
2989: }
1.446 www 2990:
2991: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 2992: if (!$allowed) {
1.446 www 2993: $env{'form.pagepath'}='';
2994: unless ($env{'form.folderpath'} =~ /^supplemental/) {
2995: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 2996: }
2997: }
1.446 www 2998: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409 raeburn 2999: if (!$env{'form.folderpath'} && $allowed) {
1.445 www 3000: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3001: {'pagepath' => 'scalar'});
3002: }
1.446 www 3003: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3004: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3005: $env{'form.folderpath'} = &supplemental_base()
3006: .'&'.
1.329 droeschl 3007: $env{'form.folderpath'};
3008: }
1.446 www 3009: # If after all of this, we still don't have any paths, make them
3010: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
3011: if ($supplementalflag) {
3012: $env{'form.folderpath'}=&supplemental_base();
3013: } else {
3014: $env{'form.folderpath'}='default';
3015: }
1.472 raeburn 3016: }
1.446 www 3017:
1.445 www 3018: # Store this
1.447 www 3019: &Apache::loncommon::store_course_settings($stored_folderpath,
1.329 droeschl 3020: {'pagepath' => 'scalar',
3021: 'folderpath' => 'scalar'});
1.446 www 3022:
1.329 droeschl 3023: if ($env{'form.folderpath'}) {
3024: my (@folderpath)=split('&',$env{'form.folderpath'});
3025: $env{'form.foldername'}=&unescape(pop(@folderpath));
3026: $env{'form.folder'}=pop(@folderpath);
3027: }
3028: if ($env{'form.pagepath'}) {
3029: my (@pagepath)=split('&',$env{'form.pagepath'});
3030: $env{'form.pagename'}=&unescape(pop(@pagepath));
3031: $env{'form.folder'}=pop(@pagepath);
3032: $containertag = '<input type="hidden" name="pagepath" value="" />'.
1.434 raeburn 3033: '<input type="hidden" name="pagesymb" value="" />';
3034: $uploadtag =
3035: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
3036: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
3037: '<input type="hidden" name="folderpath" value="" />';
1.433 raeburn 3038: } else {
3039: my $folderpath=$env{'form.folderpath'};
3040: if (!$folderpath) {
3041: if ($env{'form.folder'} eq '' ||
3042: $env{'form.folder'} eq 'supplemental') {
3043: $folderpath='default&'.
3044: &escape(&mt('Main '.$crstype.' Documents'));
3045: }
3046: }
3047: $containertag = '<input type="hidden" name="folderpath" value="" />';
3048: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.329 droeschl 3049: }
3050: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3051: $showdoc='/'.$1;
3052: }
1.402 raeburn 3053: if ($showdoc) { # got called in sequence from course
3054: $allowed=0;
3055: } else {
1.344 bisitz 3056: if ($allowed) {
1.329 droeschl 3057: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344 bisitz 3058: $script=&Apache::lonratedt::editscript('simple');
1.329 droeschl 3059: }
3060: }
3061:
3062: # get course data
3063: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3064: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3065:
1.344 bisitz 3066: # get personal data
1.329 droeschl 3067: my $uname=$env{'user.name'};
3068: my $udom=$env{'user.domain'};
3069: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3070:
3071: # graphics settings
3072:
3073: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
3074:
3075: if ($allowed) {
1.458 raeburn 3076: my @tabids;
3077: if ($supplementalflag) {
3078: @tabids = ('002','ee2','ff2');
3079: } else {
3080: @tabids = ('aa1','bb1','cc1','ff1');
3081: unless ($env{'form.pagepath'}) {
3082: unshift(@tabids,'001');
3083: push(@tabids,('dd1','ee1'));
3084: }
3085: }
3086: my $tabidstr = join("','",@tabids);
1.472 raeburn 3087: $script .= &editing_js($udom,$uname,$supplementalflag).
1.458 raeburn 3088: &resize_contentdiv_js($tabidstr);
1.457 raeburn 3089: $addentries = {
1.458 raeburn 3090: onload => "javascript:resize_contentdiv('contentscroll','1','1');",
1.457 raeburn 3091: };
1.329 droeschl 3092: }
3093: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3094: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3095: .'// <![CDATA['."\n"
3096: .$script."\n"
3097: .'// ]]>'."\n"
3098: .'</script>'."\n";
1.385 bisitz 3099:
3100: # Breadcrumbs
3101: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446 www 3102: unless ($showdoc) {
1.392 raeburn 3103: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3104: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3105:
1.446 www 3106: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457 raeburn 3107: {'force_register' => $showdoc,
3108: 'add_entries' => $addentries,
3109: })
1.392 raeburn 3110: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3111: .&Apache::lonhtmlcommon::breadcrumbs(
1.408 raeburn 3112: 'Editing the Table of Contents for your '.$crstype,
1.392 raeburn 3113: 'Docs_Adding_Course_Doc')
3114: );
1.446 www 3115: } else {
1.408 raeburn 3116: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 3117: {'force_register' => $showdoc,}));
1.392 raeburn 3118: }
1.364 bisitz 3119:
1.329 droeschl 3120: my %allfiles = ();
3121: my %codebase = ();
1.440 raeburn 3122: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3123: if ($allowed) {
3124: if (($env{'form.uploaddoc.filename'}) &&
3125: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3126: my $context = $1;
3127: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3128: undef($hadchanges);
1.440 raeburn 3129: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3130: \%allfiles,\%codebase,$context);
1.329 droeschl 3131: if ($hadchanges) {
3132: &mark_hash_old();
3133: }
1.440 raeburn 3134: $r->print($upload_output);
3135: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3136: # Process file upload - phase two - upload embedded objects
3137: $uploadphase = 'check_embedded';
3138: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3139: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3140: $env{'form.newidx'});
3141: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3142: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3143: my ($destination,$dir_root) = &embedded_destination();
3144: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3145: my $actionurl = '/adm/coursedocs';
3146: my ($result,$flag) =
3147: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3148: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3149: $actionurl);
3150: $r->print($result.&return_to_editor());
3151: } elsif ($env{'form.phase'} eq 'check_embedded') {
3152: # Process file upload - phase three - modify references in HTML file
3153: $uploadphase = 'modified_orightml';
3154: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3155: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3156: my ($destination,$dir_root) = &embedded_destination();
3157: $r->print(&Apache::loncommon::modify_html_refs('coursedoc',$destination,
3158: $docuname,$docudom,undef,
3159: $dir_root).
3160: &return_to_editor());
1.329 droeschl 3161: }
3162: }
3163:
1.440 raeburn 3164: unless ($showdoc || $uploadphase) {
1.329 droeschl 3165: # -----------------------------------------------------------------------------
3166: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 3167: 'uplm' => 'Upload a new main '.lc($crstype).' document',
3168: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 3169: 'impp' => 'Import a document',
3170: 'copm' => 'All documents out of a published map into this folder',
1.417 droeschl 3171: 'upld' => 'Import Document',
1.329 droeschl 3172: 'srch' => 'Search',
3173: 'impo' => 'Import',
1.435 wenzelju 3174: 'wish' => 'Import from Wishlist',
1.329 droeschl 3175: 'selm' => 'Select Map',
3176: 'load' => 'Load Map',
1.419 bisitz 3177: 'reco' => 'Recover Deleted Documents',
1.329 droeschl 3178: 'newf' => 'New Folder',
3179: 'newp' => 'New Composite Page',
3180: 'extr' => 'External Resource',
3181: 'syll' => 'Syllabus',
1.425 raeburn 3182: 'navc' => 'Table of Contents',
1.343 biermanm 3183: 'sipa' => 'Simple Course Page',
1.329 droeschl 3184: 'sipr' => 'Simple Problem',
3185: 'drbx' => 'Drop Box',
1.451 www 3186: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3187: 'bull' => 'Discussion Board',
1.347 weissno 3188: 'mypi' => 'My Personal Information Page',
1.353 weissno 3189: 'grpo' => 'Group Portfolio',
1.329 droeschl 3190: 'rost' => 'Course Roster',
1.348 weissno 3191: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3192: 'imsf' => 'IMS Import',
3193: 'imsl' => 'Import IMS package',
1.329 droeschl 3194: 'file' => 'File',
3195: 'title' => 'Title',
3196: 'comment' => 'Comment',
1.403 raeburn 3197: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 3198: 'nd' => 'Upload Document',
1.329 droeschl 3199: 'pm' => 'Published Map',
3200: 'sd' => 'Special Document',
3201: 'mo' => 'More Options',
3202: );
3203: # -----------------------------------------------------------------------------
3204: my $fileupload=(<<FIUP);
3205: $lt{'file'}:<br />
3206: <input type="file" name="uploaddoc" size="40" />
3207: FIUP
3208:
3209: my $checkbox=(<<CHBO);
3210: <!-- <label>$lt{'parse'}?
3211: <input type="checkbox" name="parserflag" />
3212: </label> -->
3213: <label>
3214: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3215: </label>
3216: CHBO
3217:
1.458 raeburn 3218: my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329 droeschl 3219: my $fileuploadform=(<<FUFORM);
3220: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 3221: <input type="hidden" name="active" value="aa" />
1.329 droeschl 3222: $fileupload
3223: <br />
3224: $lt{'title'}:<br />
1.458 raeburn 3225: <input type="text" size="60" name="comment" />
1.329 droeschl 3226: $uploadtag
3227: <input type="hidden" name="cmd" value="upload_default" />
3228: <br />
1.458 raeburn 3229: <span class="LC_nobreak" style="float:left">
1.329 droeschl 3230: $checkbox
3231: </span>
1.383 tempelho 3232: FUFORM
1.459 raeburn 3233: $fileuploadform .= $fileuploada.'</form>';
1.329 droeschl 3234:
3235: my $simpleeditdefaultform=(<<SEDFFORM);
3236: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 3237: <input type="hidden" name="active" value="bb" />
1.383 tempelho 3238: SEDFFORM
3239: my @simpleeditdefaultforma = (
1.423 onken 3240: { '<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>" },
3241: { '<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 3242: { '<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 3243: );
1.443 www 3244: $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
1.383 tempelho 3245: $simpleeditdefaultform .=(<<SEDFFORM);
1.459 raeburn 3246: <hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
1.329 droeschl 3247: $lt{'copm'}<br />
3248: <input type="text" size="40" name="importmap" /><br />
1.458 raeburn 3249: <span class="LC_nobreak" style="float:left"><input type="button"
1.369 bisitz 3250: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 3251: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
3252: $help{'Load_Map'}</span>
3253: </form>
3254: SEDFFORM
3255:
1.442 www 3256: my $extresourcesform=(<<ERFORM);
3257: <form action="/adm/coursedocs" method="post" name="newext">
3258: $uploadtag
3259: <input type="hidden" name="importdetail" value="" />
3260: <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
3261: </form>
1.329 droeschl 3262: ERFORM
3263:
1.442 www 3264:
1.329 droeschl 3265: if ($allowed) {
3266: &update_paste_buffer($coursenum,$coursedom);
3267: my %lt=&Apache::lonlocal::texthash(
3268: 'vc' => 'Verify Content',
3269: 'cv' => 'Check/Set Resource Versions',
3270: 'ls' => 'List Symbs',
3271: 'sl' => 'Show Log'
3272: );
3273:
1.337 ehlerst 3274: $r->print(<<HIDDENFORM);
3275: <form name="renameform" method="post" action="/adm/coursedocs">
3276: <input type="hidden" name="title" />
3277: <input type="hidden" name="cmd" />
3278: <input type="hidden" name="markcopy" />
3279: <input type="hidden" name="copyfolder" />
3280: $containertag
3281: </form>
3282: <form name="simpleedit" method="post" action="/adm/coursedocs">
3283: <input type="hidden" name="importdetail" value="" />
3284: $uploadtag
3285: </form>
3286: HIDDENFORM
1.329 droeschl 3287: }
1.442 www 3288:
3289: # Generate the tabs
1.472 raeburn 3290: my $mode;
3291: if (($supplementalflag) && (!$allowed)) {
3292: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
3293: } else {
3294: &startContentScreen($r,($supplementalflag?'suppdocs':'docs'));
3295: }
1.443 www 3296:
1.442 www 3297: #
3298:
3299: my $savefolderpath;
3300:
1.395 raeburn 3301: if ($allowed) {
1.329 droeschl 3302: my $folder=$env{'form.folder'};
1.443 www 3303: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 3304: $folder='default';
1.356 tempelho 3305: $savefolderpath = $env{'form.folderpath'};
1.442 www 3306: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.329 droeschl 3307: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3308: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3309: }
3310: my $postexec='';
3311: if ($folder eq 'default') {
1.372 bisitz 3312: $r->print('<script type="text/javascript">'."\n"
3313: .'// <![CDATA['."\n"
3314: .'this.window.name="loncapaclient";'."\n"
3315: .'// ]]>'."\n"
3316: .'</script>'."\n"
1.369 bisitz 3317: );
1.329 droeschl 3318: } else {
3319: #$postexec='self.close();';
3320: }
3321: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3322: '.sequence';
3323: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3324: '.page';
3325: my $container='sequence';
3326: if ($env{'form.pagepath'}) {
3327: $container='page';
3328: }
3329: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3330:
3331:
3332:
3333: my $recoverform=(<<RFORM);
3334: <form action="/adm/groupsort" method="post" name="recover">
1.436 wenzelju 3335: <a class="LC_menubuttons_link" href="javascript:groupopen('$readfile',1)">$lt{'reco'}</a>
1.329 droeschl 3336: </form>
3337: RFORM
3338:
3339: my $imspform=(<<IMSPFORM);
3340: <form action="/adm/imsimportdocs" method="post" name="ims">
3341: <input type="hidden" name="folder" value="$folder" />
1.423 onken 3342: <a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 3343: </form>
3344: IMSPFORM
3345:
3346: my $newnavform=(<<NNFORM);
3347: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3348: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3349: $uploadtag
3350: <input type="hidden" name="importdetail"
3351: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 3352: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3353: $help{'Navigate_Content'}
3354: </form>
3355: NNFORM
3356: my $newsmppageform=(<<NSPFORM);
3357: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3358: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3359: $uploadtag
3360: <input type="hidden" name="importdetail" value="" />
1.423 onken 3361: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 3362: $help{'Simple Page'}
1.329 droeschl 3363: </form>
3364: NSPFORM
3365:
3366: my $newsmpproblemform=(<<NSPROBFORM);
3367: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3368: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3369: $uploadtag
3370: <input type="hidden" name="importdetail" value="" />
1.423 onken 3371: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 3372: $help{'Simple Problem'}
1.329 droeschl 3373: </form>
3374:
3375: NSPROBFORM
3376:
3377: my $newdropboxform=(<<NDBFORM);
3378: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3379: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3380: $uploadtag
1.329 droeschl 3381: <input type="hidden" name="importdetail" value="" />
1.423 onken 3382: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3383: </form>
1.329 droeschl 3384: NDBFORM
3385:
3386: my $newexuploadform=(<<NEXUFORM);
3387: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3388: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3389: $uploadtag
3390: <input type="hidden" name="importdetail" value="" />
1.423 onken 3391: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3392: $help{'Score_Upload_Form'}
3393: </form>
3394: NEXUFORM
3395:
3396: my $newbulform=(<<NBFORM);
3397: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3398: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3399: $uploadtag
3400: <input type="hidden" name="importdetail" value="" />
1.423 onken 3401: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3402: $help{'Bulletin Board'}
3403: </form>
3404: NBFORM
3405:
3406: my $newaboutmeform=(<<NAMFORM);
3407: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3408: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3409: $uploadtag
3410: <input type="hidden" name="importdetail"
3411: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3412: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3413: $help{'My Personal Information Page'}
1.329 droeschl 3414: </form>
3415: NAMFORM
3416:
3417: my $newaboutsomeoneform=(<<NASOFORM);
3418: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3419: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3420: $uploadtag
3421: <input type="hidden" name="importdetail" value="" />
1.423 onken 3422: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3423: </form>
3424: NASOFORM
3425:
3426:
3427: my $newrosterform=(<<NROSTFORM);
3428: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3429: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3430: $uploadtag
3431: <input type="hidden" name="importdetail"
3432: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 3433: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3434: $help{'Course Roster'}
3435: </form>
3436: NROSTFORM
3437:
1.342 ehlerst 3438: my $specialdocumentsform;
1.383 tempelho 3439: my @specialdocumentsforma;
1.451 www 3440: my $gradingform;
3441: my @gradingforma;
3442: my $communityform;
3443: my @communityforma;
1.351 ehlerst 3444: my $newfolderform;
1.390 tempelho 3445: my $newfolderb;
1.342 ehlerst 3446:
1.451 www 3447: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3448:
1.329 droeschl 3449: my $newpageform=(<<NPFORM);
3450: <form action="/adm/coursedocs" method="post" name="newpage">
3451: <input type="hidden" name="folderpath" value="$path" />
3452: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3453: <input type="hidden" name="active" value="cc" />
1.423 onken 3454: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 3455: $help{'Adding_Pages'}
1.329 droeschl 3456: </form>
3457: NPFORM
1.390 tempelho 3458:
3459:
1.351 ehlerst 3460: $newfolderform=(<<NFFORM);
1.329 droeschl 3461: <form action="/adm/coursedocs" method="post" name="newfolder">
3462: <input type="hidden" name="folderpath" value="$path" />
3463: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3464: <input type="hidden" name="active" value="aa" />
1.422 onken 3465: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3466: </form>
3467: NFFORM
3468:
3469: my $newsylform=(<<NSYLFORM);
3470: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3471: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3472: $uploadtag
3473: <input type="hidden" name="importdetail"
3474: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3475: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3476: $help{'Syllabus'}
1.383 tempelho 3477:
1.329 droeschl 3478: </form>
3479: NSYLFORM
1.364 bisitz 3480:
1.329 droeschl 3481: my $newgroupfileform=(<<NGFFORM);
3482: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3483: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3484: $uploadtag
3485: <input type="hidden" name="importdetail"
3486: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 3487: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3488: $help{'Group Portfolio'}
1.329 droeschl 3489: </form>
3490: NGFFORM
1.383 tempelho 3491: @specialdocumentsforma=(
1.421 onken 3492: {'<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 3493: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 3494: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3495: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3496: );
3497: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
3498:
1.434 raeburn 3499:
3500: my @importdoc = (
3501: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
3502: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
1.459 raeburn 3503: $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 3504:
1.451 www 3505: @gradingforma=(
3506: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3507: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3508: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3509:
3510: );
3511: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
3512:
3513: @communityforma=(
3514: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3515: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3516: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3517: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
3518: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
3519: );
3520: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 3521:
1.329 droeschl 3522:
1.331 muellerd 3523:
1.383 tempelho 3524: my @tools = (
1.417 droeschl 3525: # {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" />'=>$extresourcesform},
3526: # {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" />'=>$imspform},
1.436 wenzelju 3527: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/recover.png" alt="'.$lt{reco}.'" onclick="javascript:groupopen(\''.$readfile.'\',1)" />'=>$recoverform},
1.383 tempelho 3528: );
3529:
1.330 tempelho 3530: my %orderhash = (
1.417 droeschl 3531: 'aa' => ['Import Documents',$fileuploadform],
1.377 bisitz 3532: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.451 www 3533: 'cc' => ['Grading Resources',$gradingform],
3534: 'ff' => ['Tools', &create_form_ul(&create_list_elements(@tools)).&generate_admin_options(\%help,\%env)],
1.330 tempelho 3535: );
1.451 www 3536: unless ($env{'form.pagepath'}) {
1.434 raeburn 3537: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.451 www 3538: $orderhash{'dd'} = ['Community Resources',$communityform];
3539: $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434 raeburn 3540: }
3541:
1.341 ehlerst 3542: $hadchanges=0;
1.443 www 3543: unless ($supplementalflag) {
1.458 raeburn 3544: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 3545: $supplementalflag,\%orderhash,$iconpath);
1.443 www 3546: if ($error) {
3547: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3548: }
3549: if ($hadchanges) {
3550: &mark_hash_old();
3551: }
1.341 ehlerst 3552:
1.443 www 3553: &changewarning($r,'');
3554: }
1.458 raeburn 3555: }
1.442 www 3556:
1.443 www 3557: # Supplemental documents start here
3558:
1.329 droeschl 3559: my $folder=$env{'form.folder'};
1.443 www 3560: unless ($supplementalflag) {
1.329 droeschl 3561: $folder='supplemental';
3562: }
3563: if ($folder =~ /^supplemental$/ &&
3564: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 3565: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 3566: } elsif ($allowed) {
1.356 tempelho 3567: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3568: }
1.362 ehlerst 3569: $env{'form.pagepath'} = '';
1.329 droeschl 3570: if ($allowed) {
3571: my $folderseq=
3572: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3573: '.sequence';
3574:
3575: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3576:
1.400 droeschl 3577: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329 droeschl 3578: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 3579: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 3580: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3581: $fileupload
3582: <br />
3583: <br />
3584: <span class="LC_nobreak">
3585: $checkbox
3586: </span>
3587: <br /><br />
3588: $lt{'comment'}:<br />
1.383 tempelho 3589: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3590: <br />
3591: <input type="hidden" name="folderpath" value="$path" />
3592: <input type="hidden" name="cmd" value="upload_supplemental" />
3593: SUPDOCFORM
1.443 www 3594: $supupdocform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329 droeschl 3595:
3596: my $supnewfolderform=(<<SNFFORM);
3597: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3598: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3599: <input type="hidden" name="folderpath" value="$path" />
3600: <input type="hidden" name="importdetail" value="" />
1.423 onken 3601: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 3602: $help{'Adding_Folders'}
1.329 droeschl 3603: </form>
3604: SNFFORM
1.383 tempelho 3605:
1.329 droeschl 3606:
3607: my $supnewextform=(<<SNEFORM);
3608: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 3609: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3610: <input type="hidden" name="folderpath" value="$path" />
3611: <input type="hidden" name="importdetail" value="" />
1.423 onken 3612: <a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 3613: </form>
3614: SNEFORM
3615:
3616: my $supnewsylform=(<<SNSFORM);
3617: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 3618: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3619: <input type="hidden" name="folderpath" value="$path" />
3620: <input type="hidden" name="importdetail"
3621: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3622: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3623: $help{'Syllabus'}
3624: </form>
3625: SNSFORM
3626:
3627: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 3628: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 3629: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3630: <input type="hidden" name="folderpath" value="$path" />
3631: <input type="hidden" name="importdetail"
3632: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3633: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3634: $help{'My Personal Information Page'}
1.329 droeschl 3635: </form>
3636: SNAMFORM
3637:
1.333 muellerd 3638:
1.383 tempelho 3639: my @specialdocs = (
1.417 droeschl 3640: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
3641: =>$supnewsylform},
3642: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
3643: =>$supnewaboutmeform},
1.383 tempelho 3644: );
1.417 droeschl 3645: my @supimportdoc = (
3646: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
3647: =>$supnewextform},
3648: );
1.459 raeburn 3649: $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 3650: my %suporderhash = (
1.390 tempelho 3651: '00' => ['Supnewfolder', $supnewfolderform],
1.417 droeschl 3652: 'ee' => ['Import Documents',$supupdocform],
1.443 www 3653: 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 3654: );
1.443 www 3655: if ($supplementalflag) {
1.458 raeburn 3656: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 3657: $supplementalflag,\%suporderhash,$iconpath);
1.443 www 3658: if ($error) {
3659: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3660: }
1.393 raeburn 3661: }
1.443 www 3662: } elsif ($supplementalflag) {
1.458 raeburn 3663: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 3664: $supplementalflag,'',$iconpath);
1.393 raeburn 3665: if ($error) {
3666: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3667: }
1.393 raeburn 3668: }
1.389 tempelho 3669:
1.442 www 3670: &endContentScreen($r);
1.383 tempelho 3671:
1.329 droeschl 3672: if ($allowed) {
3673: $r->print('
3674: <form method="post" name="extimport" action="/adm/coursedocs">
3675: <input type="hidden" name="title" />
3676: <input type="hidden" name="url" />
3677: <input type="hidden" name="useform" />
3678: <input type="hidden" name="residx" />
3679: </form>');
3680: }
3681: } else {
1.440 raeburn 3682: unless ($uploadphase) {
1.329 droeschl 3683: # -------------------------------------------------------- This is showdoc mode
3684: $r->print("<h1>".&mt('Uploaded Document').' - '.
3685: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3686: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3687: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3688: }
3689: }
3690: }
3691: $r->print(&Apache::loncommon::end_page());
3692: return OK;
1.364 bisitz 3693: }
1.329 droeschl 3694:
1.440 raeburn 3695: sub embedded_form_elems {
3696: my ($phase,$primaryurl,$newidx) = @_;
3697: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3698: return <<STATE;
3699: <input type="hidden" name="folderpath" value="$folderpath" />
3700: <input type="hidden" name="cmd" value="upload_embedded" />
3701: <input type="hidden" name="newidx" value="$newidx" />
3702: <input type="hidden" name="phase" value="$phase" />
3703: <input type="hidden" name="primaryurl" value="$primaryurl" />
3704: STATE
3705: }
3706:
3707: sub embedded_destination {
3708: my $folder=$env{'form.folder'};
3709: my $destination = 'docs/';
3710: if ($folder =~ /^supplemental/) {
3711: $destination = 'supplemental/';
3712: }
3713: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3714: $destination .= 'default/';
3715: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3716: $destination .= $2.'/';
3717: }
3718: $destination .= $env{'form.newidx'};
3719: my $dir_root = '/userfiles';
3720: return ($destination,$dir_root);
3721: }
3722:
3723: sub return_to_editor {
3724: my $actionurl = '/adm/coursedocs';
3725: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
3726: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
3727: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
3728: '</a></p>';
3729: }
3730:
1.329 droeschl 3731: sub generate_admin_options {
1.434 raeburn 3732: my ($help_ref,$env_ref) = @_;
3733: my %lt=&Apache::lonlocal::texthash(
1.337 ehlerst 3734: 'vc' => 'Verify Content',
3735: 'cv' => 'Check/Set Resource Versions',
3736: 'ls' => 'List Symbs',
1.412 wenzelju 3737: 'sl' => 'Show Log',
3738: 'imse' => 'IMS Export',
1.419 bisitz 3739: 'dcd' => 'Dump Course Documents to Construction Space: available on other servers'
1.337 ehlerst 3740: );
1.329 droeschl 3741: my %help = %{$help_ref};
3742: my %env = %{$env_ref};
3743: my $dumpbut=&dumpbutton();
3744: my $exportbut=&exportbutton();
1.383 tempelho 3745: my @list = (
1.417 droeschl 3746: {'<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 3747: => "<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
1.417 droeschl 3748: {'<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 3749: =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
1.383 tempelho 3750: );
3751: if($dumpbut ne ''){
1.417 droeschl 3752: push @list, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dump.png" alt="'.$lt{dcd}.'" />'=>$dumpbut};
1.383 tempelho 3753: }
1.431 raeburn 3754: 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 3755: =>$exportbut},
3756: {'<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 3757: =>"<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 3758: {'<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 3759: =>"<a class='LC_menubuttons_link' href='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
1.383 tempelho 3760: );
1.443 www 3761: 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 3762:
1.329 droeschl 3763: }
3764:
1.330 tempelho 3765:
1.329 droeschl 3766: sub generate_edit_table {
1.472 raeburn 3767: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto) = @_;
1.406 raeburn 3768: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 3769: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3770: my $form;
1.371 tempelho 3771: my $activetab;
3772: my $active;
3773: if($env{'form.active'} ne ''){
3774: $activetab = $env{'form.active'};
3775: }
1.472 raeburn 3776: my $backicon = $iconpath.'clickhere.gif';
3777: my $backtext = &mt('Back to Overview');
1.458 raeburn 3778: $form = '<div class="LC_Box" style="margin:0;">'.
1.472 raeburn 3779: '<ul id="navigation'.$tid.'" class="LC_TabContent">'.
3780: '<li class="goback">'.
3781: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.473 raeburn 3782: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
3783: ' alt="'.$backtext.'" />'.$backtext.'</a></li>';
1.458 raeburn 3784: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 3785: if($name ne '00'){
1.371 tempelho 3786: if($activetab eq '' || $activetab ne $name){
3787: $active = '';
3788: }elsif($activetab eq $name){
3789: $active = 'class="active"';
3790: }
1.458 raeburn 3791: $form .= '<li style="float:right" '.$active
1.429 droeschl 3792: .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
3793: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>';
1.390 tempelho 3794: } else {
1.458 raeburn 3795: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>';
1.390 tempelho 3796:
3797: }
1.329 droeschl 3798: }
1.339 ehlerst 3799: $form .= '</ul>';
1.458 raeburn 3800: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">';
3801:
3802: if ($to_show ne '') {
3803: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>';
3804: }
1.363 ehlerst 3805: foreach my $field (keys(%orderhash)){
1.390 tempelho 3806: if($field ne '00'){
1.422 onken 3807: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 3808: $active = 'style="display: none;float:left"';
1.422 onken 3809: }elsif($activetab eq $field){
1.458 raeburn 3810: $active = 'style="display:block;float:left"';
1.422 onken 3811: }
3812: $form .= '<div id="'.$field.$tid.'"'
3813: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3814: .'</div>';
1.363 ehlerst 3815: }
3816: }
1.330 tempelho 3817: $form .= '</div></div>';
1.364 bisitz 3818:
1.329 droeschl 3819: return $form;
3820: }
3821:
3822: sub editing_js {
1.472 raeburn 3823: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 3824: my $now = time();
3825: my %lt = &Apache::lonlocal::texthash(
3826: p_mnf => 'Name of New Folder',
3827: t_mnf => 'New Folder',
3828: p_mnp => 'Name of New Page',
3829: t_mnp => 'New Page',
1.451 www 3830: p_mxu => 'Title for the External Score',
1.349 biermanm 3831: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3832: p_msb => 'Title for the Problem',
3833: p_mdb => 'Title for the Drop Box',
1.336 schafran 3834: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3835: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3836: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3837: p_mab_alrt1 => 'Not a valid user:domain',
3838: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3839: p_chn => 'New Title',
3840: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3841: p_rmr2a => 'Remove[_99]',
3842: p_rmr2b => '?[_99]',
3843: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3844: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3845: p_ctr2a => 'Cut[_98]',
3846: p_ctr2b => '?[_98]'
3847: );
3848:
1.433 raeburn 3849: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 3850: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
3851: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
3852: my $main_container_page;
3853: if ($docs_folderpath eq '') {
3854: if ($docs_pagepath ne '') {
3855: $main_container_page = 1;
3856: }
3857: }
1.433 raeburn 3858: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446 www 3859: my $toplevelsupp = &supplemental_base();
1.433 raeburn 3860:
1.472 raeburn 3861: my $backtourl = '/adm/navmaps';
3862: if ($supplementalflag) {
3863: $backtourl = '/adm/supplemental';
3864: }
3865:
1.329 droeschl 3866: return <<ENDNEWSCRIPT;
3867: function makenewfolder(targetform,folderseq) {
3868: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3869: if (foldername) {
3870: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3871: targetform.submit();
3872: }
3873: }
3874:
3875: function makenewpage(targetform,folderseq) {
3876: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3877: if (pagename) {
3878: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3879: targetform.submit();
3880: }
3881: }
3882:
3883: function makenewext(targetname) {
3884: this.document.forms.extimport.useform.value=targetname;
3885: this.document.forms.extimport.title.value='';
3886: this.document.forms.extimport.url.value='';
3887: this.document.forms.extimport.residx.value='';
3888: window.open('/adm/rat/extpickframe.html');
3889: }
3890:
3891: function edittext(targetname,residx,title,url) {
3892: this.document.forms.extimport.useform.value=targetname;
3893: this.document.forms.extimport.residx.value=residx;
3894: this.document.forms.extimport.url.value=url;
3895: this.document.forms.extimport.title.value=title;
3896: window.open('/adm/rat/extpickframe.html');
3897: }
3898:
3899: function makeexamupload() {
3900: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3901: if (title) {
1.329 droeschl 3902: this.document.forms.newexamupload.importdetail.value=
3903: escape(title)+'=/res/lib/templates/examupload.problem';
3904: this.document.forms.newexamupload.submit();
3905: }
3906: }
3907:
3908: function makesmppage() {
3909: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3910: if (title) {
1.329 droeschl 3911: this.document.forms.newsmppg.importdetail.value=
3912: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3913: this.document.forms.newsmppg.submit();
3914: }
3915: }
3916:
3917: function makesmpproblem() {
3918: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3919: if (title) {
1.329 droeschl 3920: this.document.forms.newsmpproblem.importdetail.value=
3921: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3922: this.document.forms.newsmpproblem.submit();
3923: }
3924: }
3925:
3926: function makedropbox() {
3927: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3928: if (title) {
1.329 droeschl 3929: this.document.forms.newdropbox.importdetail.value=
3930: escape(title)+'=/res/lib/templates/DropBox.problem';
3931: this.document.forms.newdropbox.submit();
3932: }
3933: }
3934:
3935: function makebulboard() {
3936: var title=prompt('$lt{"p_mbb"}');
3937: if (title) {
3938: this.document.forms.newbul.importdetail.value=
3939: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3940: this.document.forms.newbul.submit();
3941: }
3942: }
3943:
3944: function makeabout() {
3945: var user=prompt("$lt{'p_mab'}");
3946: if (user) {
3947: var comp=new Array();
3948: comp=user.split(':');
3949: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3950: if ((comp[0]) && (comp[1])) {
3951: this.document.forms.newaboutsomeone.importdetail.value=
3952: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3953: this.document.forms.newaboutsomeone.submit();
3954: } else {
3955: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3956: }
1.335 ehlerst 3957: } else {
3958: alert("$lt{'p_mab_alrt2'}");
3959: }
3960: }
1.329 droeschl 3961: }
3962:
3963: function makeims() {
1.335 ehlerst 3964: var caller = document.forms.ims.folder.value;
3965: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3966: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3967: newWindow.location.href = newlocation;
1.329 droeschl 3968: }
3969:
3970:
3971: function finishpick() {
1.335 ehlerst 3972: var title=this.document.forms.extimport.title.value;
3973: var url=this.document.forms.extimport.url.value;
3974: var form=this.document.forms.extimport.useform.value;
3975: var residx=this.document.forms.extimport.residx.value;
3976: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3977: }
3978:
3979: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3980: var title=prompt('$lt{"p_chn"}',oldtitle);
3981: if (title) {
3982: this.document.forms.renameform.markcopy.value=-1;
3983: this.document.forms.renameform.title.value=title;
3984: this.document.forms.renameform.cmd.value='rename_'+index;
3985: if (container == 'sequence') {
3986: this.document.forms.renameform.folderpath.value=folderpath;
3987: }
3988: if (container == 'page') {
3989: this.document.forms.renameform.pagepath.value=folderpath;
3990: this.document.forms.renameform.pagesymb.value=pagesymb;
3991: }
3992: this.document.forms.renameform.submit();
3993: }
1.329 droeschl 3994: }
3995:
3996: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3997: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3998: this.document.forms.renameform.markcopy.value=-1;
3999: this.document.forms.renameform.cmd.value='del_'+index;
4000: if (container == 'sequence') {
4001: this.document.forms.renameform.folderpath.value=folderpath;
4002: }
4003: if (container == 'page') {
4004: this.document.forms.renameform.pagepath.value=folderpath;
4005: this.document.forms.renameform.pagesymb.value=pagesymb;
4006: }
4007: this.document.forms.renameform.submit();
4008: }
1.329 droeschl 4009: }
4010:
4011: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 4012: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
4013: this.document.forms.renameform.cmd.value='cut_'+index;
4014: this.document.forms.renameform.markcopy.value=index;
4015: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4016: if (container == 'sequence') {
4017: this.document.forms.renameform.folderpath.value=folderpath;
4018: }
4019: if (container == 'page') {
4020: this.document.forms.renameform.pagepath.value=folderpath;
4021: this.document.forms.renameform.pagesymb.value=pagesymb;
4022: }
4023: this.document.forms.renameform.submit();
4024: }
1.329 droeschl 4025: }
4026:
4027: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 4028: this.document.forms.renameform.markcopy.value=index;
4029: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4030: if (container == 'sequence') {
4031: this.document.forms.renameform.folderpath.value=folderpath;
4032: }
4033: if (container == 'page') {
4034: this.document.forms.renameform.pagepath.value=folderpath;
4035: this.document.forms.renameform.pagesymb.value=pagesymb;
4036: }
4037: this.document.forms.renameform.submit();
1.329 droeschl 4038: }
4039:
1.334 muellerd 4040: function unselectInactive(nav) {
1.335 ehlerst 4041: currentNav = document.getElementById(nav);
4042: currentLis = currentNav.getElementsByTagName('LI');
4043: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 4044: if (currentLis[i].className == 'goback') {
4045: currentLis[i].className = 'goback';
4046: } else {
4047: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 4048: currentLis[i].className = 'right';
1.472 raeburn 4049: } else {
1.374 tempelho 4050: currentLis[i].className = 'i';
1.472 raeburn 4051: }
4052: }
1.335 ehlerst 4053: }
1.332 tempelho 4054: }
4055:
1.334 muellerd 4056: function hideAll(current, nav, data) {
1.335 ehlerst 4057: unselectInactive(nav);
1.374 tempelho 4058: if(current.className == 'right'){
4059: current.className = 'right active'
4060: }else{
4061: current.className = 'active';
4062: }
1.335 ehlerst 4063: currentData = document.getElementById(data);
4064: currentDivs = currentData.getElementsByTagName('DIV');
4065: for (i = 0; i < currentDivs.length; i++) {
4066: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 4067: currentDivs[i].style.display = 'none';
1.330 tempelho 4068: }
4069: }
1.335 ehlerst 4070: }
1.330 tempelho 4071:
1.374 tempelho 4072: function openTabs(pageId) {
4073: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 4074: if(tabnav.length > 2 ){
1.389 tempelho 4075: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 4076: currentLis = currentNav.getElementsByTagName('LI');
4077: for(i = 0; i< currentLis.length; i++){
4078: if(currentLis[i].className == 'active') {
1.375 tempelho 4079: funcString = currentLis[i].onclick.toString();
4080: tab = funcString.split('"');
1.420 onken 4081: if(tab.length < 2) {
4082: tab = funcString.split("'");
4083: }
1.375 tempelho 4084: currentData = document.getElementById(tab[1]);
4085: currentData.style.display = 'block';
1.374 tempelho 4086: }
4087: }
4088: }
4089: }
4090:
1.334 muellerd 4091: function showPage(current, pageId, nav, data) {
4092: hideAll(current, nav, data);
1.375 tempelho 4093: openTabs(pageId);
1.334 muellerd 4094: unselectInactive(nav);
1.330 tempelho 4095: current.className = 'active';
4096: currentData = document.getElementById(pageId);
4097: currentData.style.display = 'block';
1.458 raeburn 4098: activeTab = pageId;
1.433 raeburn 4099: if (nav == 'mainnav') {
4100: var storedpath = "$docs_folderpath";
4101: if (storedpath == '') {
4102: storedpath = "$docs_pagepath";
4103: }
1.434 raeburn 4104: var storedpage = "$main_container_page";
1.433 raeburn 4105: var reg = new RegExp("^supplemental");
4106: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 4107: if (storedpage == 1) {
4108: document.simpleedit.folderpath.value = '';
4109: document.uploaddocument.folderpath.value = '';
4110: } else {
4111: if (reg.test(storedpath)) {
4112: document.simpleedit.folderpath.value = '$toplevelmain';
4113: document.uploaddocument.folderpath.value = '$toplevelmain';
4114: document.newext.folderpath.value = '$toplevelmain';
4115: } else {
4116: document.simpleedit.folderpath.value = storedpath;
4117: document.uploaddocument.folderpath.value = storedpath;
4118: document.newext.folderpath.value = storedpath;
4119: }
1.433 raeburn 4120: }
4121: } else {
1.434 raeburn 4122: if (reg.test(storedpath)) {
4123: document.simpleedit.folderpath.value = storedpath;
4124: document.supuploaddocument.folderpath.value = storedpath;
4125: document.supnewext.folderpath.value = storedpath;
4126: } else {
1.433 raeburn 4127: document.simpleedit.folderpath.value = '$toplevelsupp';
4128: document.supuploaddocument.folderpath.value = '$toplevelsupp';
4129: document.supnewext.folderpath.value = '$toplevelsupp';
4130: }
4131: }
4132: }
1.458 raeburn 4133: resize_contentdiv('contentscroll','1','0');
1.330 tempelho 4134: return false;
4135: }
1.329 droeschl 4136:
1.383 tempelho 4137: function injectData(current, hiddenField, name, value) {
4138: currentElement = document.getElementById(hiddenField);
4139: currentElement.name = name;
4140: currentElement.value = value;
4141: current.submit();
4142: }
4143:
1.472 raeburn 4144: function toContents(jumpto) {
4145: var newurl = '$backtourl';
4146: if (jumpto != '') {
4147: newurl = newurl+'?postdata='+jumpto;
4148: ;
4149: }
4150: location.href=newurl;
4151: }
4152:
1.329 droeschl 4153: ENDNEWSCRIPT
4154: }
1.457 raeburn 4155:
4156: sub resize_contentdiv_js {
1.458 raeburn 4157: my ($tabidstr) = @_;
1.457 raeburn 4158: my $viewport_js = &Apache::loncommon::viewport_geometry_js();
4159: return <<ENDRESIZESCRIPT;
4160:
1.458 raeburn 4161: window.onresize=resizeContentEditor;
4162:
4163: var activeTab;
4164:
1.457 raeburn 4165: $viewport_js
4166:
1.458 raeburn 4167: function resize_contentdiv(scrollboxname,chkw,chkh) {
4168: var scrollboxid = 'div_'+scrollboxname;
4169: var scrolltableid = 'table_'+scrollboxname;
4170: var scrollbox;
4171: var scrolltable;
4172:
1.457 raeburn 4173: if (document.getElementById("contenteditor") == null) {
4174: return;
4175: }
1.458 raeburn 4176:
4177: if (document.getElementById(scrollboxid) == null) {
4178: return;
4179: } else {
4180: scrollbox = document.getElementById(scrollboxid);
4181: }
4182:
4183: if (document.getElementById(scrolltableid) == null) {
4184: return;
4185: } else {
4186: scrolltable = document.getElementById(scrolltableid);
4187: }
4188:
1.457 raeburn 4189: init_geometry();
4190: var vph = Geometry.getViewportHeight();
1.458 raeburn 4191: var vpw = Geometry.getViewportWidth();
4192:
4193: var alltabs = ['$tabidstr'];
4194: var listwchange;
4195: if (chkw == 1) {
4196: var contenteditorw = document.getElementById("contenteditor").offsetWidth;
4197: var contentlistw;
4198: var contentlistid = document.getElementById("contentlist");
4199: if (contentlistid != null) {
4200: contentlistw = document.getElementById("contentlist").offsetWidth;
4201: }
4202: var contentlistwstart = contentlistw;
4203:
4204: var scrollboxw = scrollbox.offsetWidth;
4205: var scrollboxscrollw = scrollbox.scrollWidth;
4206:
4207: var offsetw = parseInt(vpw * 0.015);
4208: var paddingw = parseInt(vpw * 0.09);
4209:
4210: var minscrollboxw = 250;
4211:
4212: var maxtabw = 0;
1.459 raeburn 4213: var actabw = 0;
1.458 raeburn 4214: for (var i=0; i<alltabs.length; i++) {
4215: if (activeTab == alltabs[i]) {
1.459 raeburn 4216: actabw = document.getElementById(alltabs[i]).offsetWidth;
4217: if (actabw > maxtabw) {
4218: maxtabw = actabw;
1.458 raeburn 4219: }
4220: } else {
4221: if (document.getElementById(alltabs[i]) != null) {
4222: var thistab = document.getElementById(alltabs[i]);
4223: thistab.style.visibility = 'hidden';
4224: thistab.style.display = 'block';
4225: var tabw = document.getElementById(alltabs[i]).offsetWidth;
4226: thistab.style.display = 'none';
4227: thistab.style.visibility = '';
4228: if (tabw > maxtabw) {
4229: maxtabw = tabw;
4230: }
4231: }
4232: }
4233: }
1.457 raeburn 4234:
1.458 raeburn 4235: if (maxtabw > 0) {
4236: var newscrollboxw;
4237: if (maxtabw+paddingw+scrollboxscrollw<contenteditorw) {
4238: newscrollboxw = contenteditorw-paddingw-maxtabw;
4239: if (newscrollboxw < minscrollboxw) {
4240: newscrollboxw = minscrollboxw;
4241: }
4242: scrollbox.style.width = newscrollboxw+"px";
4243: if (newscrollboxw != scrollboxw) {
4244: var newcontentlistw = newscrollboxw-offsetw;
4245: contentlistid.style.width = newcontentlistw+"px";
4246: }
4247: } else {
4248: newscrollboxw = contenteditorw-paddingw-maxtabw;
4249: if (newscrollboxw < minscrollboxw) {
4250: newscrollboxw = minscrollboxw;
4251: }
4252: scrollbox.style.width = newscrollboxw+"px";
4253: if (newscrollboxw != scrollboxw) {
4254: var newcontentlistw = newscrollboxw-offsetw;
4255: contentlistid.style.width = newcontentlistw+"px";
4256: }
4257: }
4258:
4259: if (newscrollboxw != scrollboxw) {
4260: var newscrolltablew = newscrollboxw+offsetw;
4261: scrolltable.style.width = newscrolltablew+"px";
4262: }
4263: }
4264:
4265: if (contentlistid.offsetWidth != contentlistwstart) {
4266: listwchange = 1;
4267: }
4268:
1.459 raeburn 4269: if (activeTab == 'cc1') {
4270: if (document.getElementById('cc_hrule') != null) {
4271: document.getElementById('cc_hrule').style.width=actabw+"px";
4272: }
4273: } else {
4274: if (activeTab == 'bb1') {
4275: if (document.getElementById('bb_hrule') != null) {
4276: document.getElementById('bb_hrule').style.width=actabw+"px";
4277: }
4278: } else {
4279: if (activeTab == 'ee2') {
4280: if (document.getElementById('ee_hrule') != null) {
4281: document.getElementById('ee_hrule').style.width=actabw+"px";
4282: }
4283: }
4284: }
4285: }
1.458 raeburn 4286: }
4287: if ((chkh == 1) || (listwchange)) {
4288: var primaryheight = document.getElementById("LC_nav_bar").offsetHeight;
4289: var secondaryheight = document.getElementById("LC_secondary_menu").offsetHeight;
4290: var crumbsheight = document.getElementById("LC_breadcrumbs").offsetHeight;
4291: var dccidheight = document.getElementById("dccid").offsetHeight;
4292:
4293: var uploadresultheight = 0;
4294: if (document.getElementById("uploadfileresult") != null) {
4295: uploadresultheight = document.getElementById("uploadfileresult").offsetHeight;
4296: }
4297: var tabbedheight = document.getElementById("tabbededitor").offsetHeight;
4298: var contenteditorheight = document.getElementById("contenteditor").offsetHeight;
1.457 raeburn 4299: var scrollboxheight = scrollbox.offsetHeight;
4300: var scrollboxscrollheight = scrollbox.scrollHeight;
1.458 raeburn 4301: var freevspace = vph-(primaryheight+secondaryheight+crumbsheight+dccidheight+uploadresultheight+tabbedheight+contenteditorheight);
1.457 raeburn 4302:
1.458 raeburn 4303: var minvscrollbox = 200;
4304: var offsetv = 20;
1.457 raeburn 4305: var newscrollboxheight;
1.458 raeburn 4306: if (freevspace < 0) {
4307: newscrollboxheight = scrollboxheight+freevspace-offsetv;
4308: if (newscrollboxheight < minvscrollbox) {
4309: newscrollboxheight = minvscrollbox;
1.457 raeburn 4310: }
4311: scrollbox.style.height = newscrollboxheight + "px";
4312: } else {
4313: if (scrollboxscrollheight > scrollboxheight) {
1.458 raeburn 4314: if (freevspace > offsetv) {
4315: newscrollboxheight = scrollboxheight+freevspace-offsetv;
4316: if (newscrollboxheight < minvscrollbox) {
4317: newscrollboxheight = minvscrollbox;
1.457 raeburn 4318: }
4319: scrollbox.style.height = newscrollboxheight+"px";
4320: }
4321: }
4322: }
4323: scrollboxheight = scrollbox.offsetHeight;
1.458 raeburn 4324: var contentlistheight = document.getElementById("contentlist").offsetHeight;
1.457 raeburn 4325:
4326: if (scrollboxscrollheight <= scrollboxheight) {
1.458 raeburn 4327: if ((contentlistheight+offsetv)<scrollboxheight) {
4328: newscrollheight = contentlistheight+offsetv;
1.457 raeburn 4329: scrollbox.style.height = newscrollheight+"px";
4330: }
4331: }
4332: }
1.458 raeburn 4333: return;
4334: }
4335:
4336: function resizeContentEditor() {
4337: var timer;
4338: clearTimeout(timer)
4339: timer=setTimeout('resize_contentdiv("contentscroll","1","1")',500);
1.457 raeburn 4340: }
4341:
4342: ENDRESIZESCRIPT
4343: return;
4344: }
4345:
1.329 droeschl 4346: 1;
4347: __END__
4348:
4349:
4350: =head1 NAME
4351:
4352: Apache::londocs.pm
4353:
4354: =head1 SYNOPSIS
4355:
4356: This is part of the LearningOnline Network with CAPA project
4357: described at http://www.lon-capa.org.
4358:
4359: =head1 SUBROUTINES
4360:
4361: =over
4362:
4363: =item %help=()
4364:
4365: Available help topics
4366:
4367: =item mapread()
4368:
1.344 bisitz 4369: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 4370: @order and @resources, determines status
4371: sets @order - pointer to resources in right order
4372: sets @resources - array with the resources with correct idx
4373:
4374: =item authorhosts()
4375:
4376: Return hash with valid author names
4377:
4378: =item dumpbutton()
4379:
4380: Generate "dump" button
4381:
4382: =item clean()
4383:
4384: =item dumpcourse()
4385:
4386: Actually dump course
4387:
4388:
4389: =item exportbutton()
4390:
4391: Generate "export" button
4392:
4393: =item exportcourse()
4394:
4395: =item create_ims_store()
4396:
4397: =item build_package()
4398:
4399: =item get_dependencies()
4400:
4401: =item process_content()
4402:
4403: =item replicate_content()
4404:
4405: =item extract_media()
4406:
4407: =item store_template()
4408:
4409: =item group_import()
4410:
4411: Imports the given (name, url) resources into the course
4412: coursenum, coursedom, and folder must precede the list
4413:
4414: =item breadcrumbs()
4415:
4416: =item log_docs()
4417:
4418: =item docs_change_log()
4419:
4420: =item update_paste_buffer()
4421:
4422: =item print_paste_buffer()
4423:
4424: =item do_paste_from_buffer()
4425:
4426: =item update_parameter()
4427:
4428: =item handle_edit_cmd()
4429:
4430: =item editor()
4431:
4432: =item process_file_upload()
4433:
4434: =item process_secondary_uploads()
4435:
4436: =item is_supplemental_title()
4437:
4438: =item parse_supplemental_title()
4439:
4440: =item entryline()
4441:
4442: =item tiehash()
4443:
4444: =item untiehash()
4445:
4446: =item checkonthis()
4447:
4448: check on this
4449:
4450: =item verifycontent()
4451:
4452: Verify Content
4453:
4454: =item devalidateversioncache() & checkversions()
4455:
4456: Check Versions
4457:
4458: =item mark_hash_old()
4459:
4460: =item is_hash_old()
4461:
4462: =item changewarning()
4463:
4464: =item init_breadcrumbs()
4465:
4466: Breadcrumbs for special functions
4467:
4468: =back
4469:
4470: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>