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