Annotation of loncom/interface/londocs.pm, revision 1.411.2.7
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.411.2.7! raeburn 4: # $Id: londocs.pm,v 1.411.2.6 2010/11/08 19:47:04 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'};
1.411.2.7! raeburn 2623: if ($coursedom =~ /^\w+citest$/) {
1.411.2.3 raeburn 2624: my $coursenum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.411.2.1 raeburn 2625: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2626: if ($allowed) {
1.411.2.3 raeburn 2627: &concept_test_builder($r,$coursedom,$coursenum);
1.411.2.1 raeburn 2628: return OK;
2629: }
2630: }
1.329 droeschl 2631:
2632: # --------------------------------------------- Initialize help topics for this
2633: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2634: 'Adding_External_Resource','Navigate_Content',
2635: 'Adding_Folders','Docs_Overview', 'Load_Map',
2636: 'Supplemental','Score_Upload_Form','Adding_Pages',
2637: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2638: 'Check_Resource_Versions','Verify_Content') {
2639: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2640: }
2641: # Composite help files
2642: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2643: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2644: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2645: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2646: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2647: 'Option_Response_Simple');
2648: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2649: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2650: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2651: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2652: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2653: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2654:
2655: # does this user have privileges to modify docs
2656: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2657: if ($allowed && $env{'form.verify'}) {
2658: &init_breadcrumbs('verify','Verify Content');
2659: &verifycontent($r);
2660: } elsif ($allowed && $env{'form.listsymbs'}) {
2661: &init_breadcrumbs('listsymbs','List Symbs');
2662: &list_symbs($r);
2663: } elsif ($allowed && $env{'form.docslog'}) {
2664: &init_breadcrumbs('docslog','Show Log');
2665: &docs_change_log($r);
2666: } elsif ($allowed && $env{'form.versions'}) {
2667: &init_breadcrumbs('versions','Check/Set Resource Versions');
2668: &checkversions($r);
2669: } elsif ($allowed && $env{'form.dumpcourse'}) {
2670: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2671: &dumpcourse($r);
2672: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2673: &init_breadcrumbs('exportcourse','IMS Export');
1.329 droeschl 2674: &exportcourse($r);
2675: } else {
2676: # is this a standard course?
2677:
2678: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2679: my $forcestandard = 0;
2680: my $forcesupplement;
2681: my $script='';
2682: my $showdoc=0;
2683: my $containertag;
2684: my $uploadtag;
2685:
2686:
2687: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2688: ['folderpath','pagepath',
2689: 'pagesymb']);
2690: # No folderpath, no pagepath, see if we have something stored
2691: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2692: &Apache::loncommon::restore_course_settings('docs_folderpath',
2693: {'folderpath' => 'scalar'});
2694: }
1.409 raeburn 2695: if (!$allowed) {
2696: unless($env{'form.folderpath'} =~ /^supplemental/) {
2697: $env{'form.folderpath'} = '';
2698: }
2699: }
2700: if (!$env{'form.folderpath'} && $allowed) {
1.329 droeschl 2701: &Apache::loncommon::restore_course_settings('docs_folderpath',
2702: {'pagepath' => 'scalar'});
2703: }
2704: if ($env{'form.pagepath'}) {
2705: $env{'form.folderpath'}='';
2706: }
2707: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2708: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 2709: &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
1.329 droeschl 2710: $env{'form.folderpath'};
2711: }
2712: &Apache::loncommon::store_course_settings('docs_folderpath',
2713: {'pagepath' => 'scalar',
2714: 'folderpath' => 'scalar'});
2715: if ($env{'form.folderpath'}) {
2716: my (@folderpath)=split('&',$env{'form.folderpath'});
2717: $env{'form.foldername'}=&unescape(pop(@folderpath));
2718: $env{'form.folder'}=pop(@folderpath);
2719: }
2720: if ($env{'form.pagepath'}) {
2721: my (@pagepath)=split('&',$env{'form.pagepath'});
2722: $env{'form.pagename'}=&unescape(pop(@pagepath));
2723: $env{'form.folder'}=pop(@pagepath);
2724: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2725: '<input type="hidden" name="pagesymb" value="" />';
2726: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2727: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2728: }
2729: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2730: $showdoc='/'.$1;
2731: }
1.402 raeburn 2732: if ($showdoc) { # got called in sequence from course
2733: $allowed=0;
2734: } else {
1.344 bisitz 2735: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.329 droeschl 2736: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2737: $forcestandard = 1;
1.364 bisitz 2738: }
1.329 droeschl 2739: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2740:
1.344 bisitz 2741: if ($allowed) {
1.329 droeschl 2742: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344 bisitz 2743: $script=&Apache::lonratedt::editscript('simple');
1.329 droeschl 2744: }
2745: }
2746:
1.383 tempelho 2747: # subroutine to list form elements
2748: sub create_list_elements {
2749: my @formarr = @_;
2750: my $list = '';
2751: for my $button (@formarr){
2752: for my $picture(keys %$button) {
2753: #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
2754: $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2755: }
2756: }
2757: return $list;
2758: }
2759:
2760: # subroutine to create ul from list elements
2761: sub create_form_ul {
2762: my $list = shift;
2763: my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2764: return $ul;
2765: }
2766:
1.329 droeschl 2767: # get course data
2768: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2769: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2770:
1.344 bisitz 2771: # get personal data
1.329 droeschl 2772: my $uname=$env{'user.name'};
2773: my $udom=$env{'user.domain'};
2774: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2775:
2776: # graphics settings
2777:
2778: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2779:
2780: if ($allowed) {
2781: $script .= &editing_js($udom,$uname);
2782: }
2783: # -------------------------------------------------------------------- Body tag
1.369 bisitz 2784: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 2785: .'// <![CDATA['."\n"
2786: .$script."\n"
2787: .'// ]]>'."\n"
2788: .'</script>'."\n";
1.385 bisitz 2789:
2790: # Breadcrumbs
2791: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.392 raeburn 2792: if ($allowed) {
2793: &Apache::lonhtmlcommon::add_breadcrumb({
1.408 raeburn 2794: href=>"/adm/coursedocs",text=>"$crstype Editor"});
1.392 raeburn 2795:
1.408 raeburn 2796: $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
1.392 raeburn 2797: {'force_register' => $showdoc,})
2798: .&Apache::loncommon::help_open_menu('','',273,'RAT')
2799: .&Apache::lonhtmlcommon::breadcrumbs(
1.408 raeburn 2800: 'Editing the Table of Contents for your '.$crstype,
1.392 raeburn 2801: 'Docs_Adding_Course_Doc')
2802: );
1.402 raeburn 2803: } elsif ($showdoc) {
1.408 raeburn 2804: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 2805: {'force_register' => $showdoc,}));
1.392 raeburn 2806: } else {
1.395 raeburn 2807: my $folder=$env{'form.folder'};
2808: if ($folder eq '' || $folder eq 'supplemental') {
2809: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 2810: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.395 raeburn 2811: }
1.408 raeburn 2812: my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
1.392 raeburn 2813: $r->print(&Apache::loncommon::start_page("Supplemental documents").
1.395 raeburn 2814: $breadcrumbtrail);
1.392 raeburn 2815: }
1.364 bisitz 2816:
1.329 droeschl 2817: my %allfiles = ();
2818: my %codebase = ();
2819: my ($upload_result,$upload_output);
2820: if ($allowed) {
2821: if (($env{'form.uploaddoc.filename'}) &&
2822: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.344 bisitz 2823: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 2824: undef($hadchanges);
2825: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2826: $coursedom,\%allfiles,
2827: \%codebase,$1);
2828: if ($hadchanges) {
2829: &mark_hash_old();
2830: }
2831: if ($upload_result eq 'phasetwo') {
2832: $r->print($upload_output);
2833: }
2834: } elsif ($env{'form.phasetwo'}) {
2835: my %newname = ();
2836: my %origname = ();
2837: my %attribs = ();
2838: my $updateflag = 0;
2839: my $residx = $env{'form.newidx'};
2840: my $primary_url = &unescape($env{'form.primaryurl'});
2841: # Process file upload - phase two - gather secondary files.
2842: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2843: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2844: my $javacodebase;
2845: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2846: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2847: if (exists($env{'form.embedded_codebase_'.$i})) {
1.344 bisitz 2848: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2849: $origname{$i} =~ s#^\Q$javacodebase\E/##;
1.329 droeschl 2850: }
2851: my @attributes = ();
2852: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2853: @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
2854: } else {
2855: @attributes = ($env{'form.embedded_attrib_'.$i});
2856: }
2857: foreach my $attr (@attributes) {
2858: push(@{$attribs{$i}},&unescape($attr));
2859: }
2860: if ($javacodebase) {
2861: $codebase{$i} = $javacodebase;
2862: $codebase{$i} =~ s#/$##;
2863: $updateflag = 1;
2864: }
2865: }
2866: unless ($newname{$i} eq $origname{$i}) {
2867: $updateflag = 1;
2868: }
2869: }
2870: # Process file upload - phase three - modify primary file
2871: if ($updateflag) {
2872: my ($content,$rtncode);
2873: my $updateflag = 0;
2874: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2875: if ($getstatus eq 'ok') {
2876: foreach my $item (keys(%newname)) {
2877: if ($newname{$item} ne $origname{$item}) {
2878: my $attrib_regexp = '';
2879: if (@{$attribs{$item}} > 1) {
2880: $attrib_regexp = join('|',@{$attribs{$item}});
2881: } else {
2882: $attrib_regexp = $attribs{$item}[0];
2883: }
2884: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
1.364 bisitz 2885: }
1.344 bisitz 2886: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
1.329 droeschl 2887: }
2888: if (exists($codebase{$item})) {
2889: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2890: }
2891: }
2892: # Save edited file.
2893: my $saveresult;
2894: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2895: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2896: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2897: } else {
1.344 bisitz 2898: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
1.329 droeschl 2899: }
2900: }
2901: }
2902: }
2903:
2904: unless ($showdoc || $upload_result eq 'phasetwo') {
2905: # -----------------------------------------------------------------------------
2906: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 2907: 'uplm' => 'Upload a new main '.lc($crstype).' document',
2908: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 2909: 'impp' => 'Import a document',
2910: 'copm' => 'All documents out of a published map into this folder',
2911: 'upld' => 'Upload Document',
2912: 'srch' => 'Search',
2913: 'impo' => 'Import',
2914: 'book' => 'Import Bookmarks',
2915: 'selm' => 'Select Map',
2916: 'load' => 'Load Map',
2917: 'reco' => 'Recover Deleted Resources',
2918: 'newf' => 'New Folder',
2919: 'newp' => 'New Composite Page',
2920: 'extr' => 'External Resource',
2921: 'syll' => 'Syllabus',
2922: 'navc' => 'Navigate Contents',
1.343 biermanm 2923: 'sipa' => 'Simple Course Page',
1.329 droeschl 2924: 'sipr' => 'Simple Problem',
2925: 'drbx' => 'Drop Box',
2926: 'scuf' => 'Score Upload Form',
1.336 schafran 2927: 'bull' => 'Discussion Board',
1.347 weissno 2928: 'mypi' => 'My Personal Information Page',
1.353 weissno 2929: 'grpo' => 'Group Portfolio',
1.329 droeschl 2930: 'rost' => 'Course Roster',
1.348 weissno 2931: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 2932: 'imsf' => 'IMS Import',
2933: 'imsl' => 'Import IMS package',
1.329 droeschl 2934: 'file' => 'File',
2935: 'title' => 'Title',
2936: 'comment' => 'Comment',
1.403 raeburn 2937: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 2938: 'nd' => 'Upload Document',
1.329 droeschl 2939: 'pm' => 'Published Map',
2940: 'sd' => 'Special Document',
2941: 'mo' => 'More Options',
2942: );
2943: # -----------------------------------------------------------------------------
2944: my $fileupload=(<<FIUP);
2945: $lt{'file'}:<br />
2946: <input type="file" name="uploaddoc" size="40" />
2947: FIUP
2948:
2949: my $checkbox=(<<CHBO);
2950: <!-- <label>$lt{'parse'}?
2951: <input type="checkbox" name="parserflag" />
2952: </label> -->
2953: <label>
2954: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2955: </label>
2956: CHBO
2957:
1.394 droeschl 2958: my $fileuploada = "<input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329 droeschl 2959: my $fileuploadform=(<<FUFORM);
2960: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 2961: <input type="hidden" name="active" value="aa" />
1.329 droeschl 2962: $fileupload
2963: <br />
2964: $lt{'title'}:<br />
2965: <input type="text" size="50" name="comment" />
2966: $uploadtag
2967: <input type="hidden" name="cmd" value="upload_default" />
2968: <br />
2969: <span class="LC_nobreak">
2970: $checkbox
2971: </span>
1.383 tempelho 2972: FUFORM
1.394 droeschl 2973: #$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2974: #$fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
2975: $fileuploadform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'}));
1.383 tempelho 2976: $fileuploadform .= (<<FUFORM);
1.329 droeschl 2977: </form>
2978: FUFORM
2979:
2980: my $simpleeditdefaultform=(<<SEDFFORM);
2981: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 2982: <input type="hidden" name="active" value="bb" />
1.383 tempelho 2983: SEDFFORM
2984: my @simpleeditdefaultforma = (
1.410 wenzelju 2985: { '<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>" },
2986: { '<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'}" },
2987: { '<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 2988: );
2989: $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
2990: $simpleeditdefaultform .=(<<SEDFFORM);
1.329 droeschl 2991: <hr />
2992: <p>
2993: $lt{'copm'}<br />
2994: <input type="text" size="40" name="importmap" /><br />
1.344 bisitz 2995: <span class="LC_nobreak"><input type="button"
1.369 bisitz 2996: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 2997: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2998: $help{'Load_Map'}</span>
2999: </p>
3000: </form>
3001: SEDFFORM
3002:
3003: my $extresourcesform=(<<ERFORM);
3004: <form action="/adm/coursedocs" method="post" name="newext">
3005: $uploadtag
3006: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3007: <a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.329 droeschl 3008: </form>
3009: ERFORM
3010:
3011: if ($allowed) {
3012: &update_paste_buffer($coursenum,$coursedom);
3013: my %lt=&Apache::lonlocal::texthash(
3014: 'vc' => 'Verify Content',
3015: 'cv' => 'Check/Set Resource Versions',
3016: 'ls' => 'List Symbs',
3017: 'sl' => 'Show Log'
3018: );
3019:
3020: my $folderpath=$env{'form.folderpath'};
3021: if (!$folderpath) {
3022: if ($env{'form.folder'} eq '' ||
3023: $env{'form.folder'} eq 'supplemental') {
3024: $folderpath='default&'.
1.408 raeburn 3025: &escape(&mt('Main '.$crstype.' Documents'));
1.329 droeschl 3026: }
3027: }
3028: unless ($env{'form.pagepath'}) {
3029: $containertag = '<input type="hidden" name="folderpath" value="" />';
3030: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
3031: }
1.337 ehlerst 3032: $r->print(<<HIDDENFORM);
3033: <form name="renameform" method="post" action="/adm/coursedocs">
3034: <input type="hidden" name="title" />
3035: <input type="hidden" name="cmd" />
3036: <input type="hidden" name="markcopy" />
3037: <input type="hidden" name="copyfolder" />
3038: $containertag
3039: </form>
3040: <form name="simpleedit" method="post" action="/adm/coursedocs">
3041: <input type="hidden" name="importdetail" value="" />
3042: $uploadtag
3043: </form>
3044: HIDDENFORM
1.329 droeschl 3045: }
1.335 ehlerst 3046: # --------------------------------------------------------- Main tab structure
1.395 raeburn 3047:
1.335 ehlerst 3048: my $activeClass = 1;
1.355 ehlerst 3049: my $active = '';
1.407 raeburn 3050: my %tabtitles = (
3051: main => {
3052: Course => &mt('Main Course Documents'),
3053: Community => &mt('Main Community Documents'),
3054: },
3055: supplemental => {
3056: Course => &mt('Supplemental Course Documents'),
3057: Community => &mt('Supplemental Community Documents'),
3058: },
3059: );
1.395 raeburn 3060: if ($allowed) {
3061: $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
3062: if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
3063: if($activeClass == 1){
3064: $active = 'class="active"';
3065: $activeClass = 0;
3066: }
3067: }
1.408 raeburn 3068: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'main'}{$crstype}.'</b></a></li>');
1.395 raeburn 3069: $active = '';
3070: if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
3071: if($activeClass == 1){
3072: $active = 'class="active"';
3073: }
1.335 ehlerst 3074: }
1.408 raeburn 3075: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'supplemental'}{$crstype}.'</b></a></li>');
1.395 raeburn 3076: $r->print('</ul>');
3077: } else {
3078: $r->print('<br />');
1.335 ehlerst 3079: }
1.395 raeburn 3080: $r->print('<div class="LC_Box" style="clear:both;margin:0;">'
1.376 bisitz 3081: .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
1.329 droeschl 3082: # --------------------------------------------------------- Standard documents
1.356 tempelho 3083: my $savefolderpath;
1.395 raeburn 3084: $active = 'style="display: none;"';
1.335 ehlerst 3085: if($activeClass == 0){
3086: $active = 'style="display: block;"';
3087: }
1.393 raeburn 3088: if ($allowed) {
1.359 tempelho 3089: $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
1.329 droeschl 3090: my $folder=$env{'form.folder'};
1.356 tempelho 3091: if ($folder eq '' || $folder=~/^supplemental/) {
1.329 droeschl 3092: $folder='default';
1.356 tempelho 3093: $savefolderpath = $env{'form.folderpath'};
1.408 raeburn 3094: $env{'form.folderpath'}='default&'.&escape($tabtitles{'main'}{$crstype});
1.329 droeschl 3095: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3096: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3097: }
3098: my $postexec='';
3099: if ($folder eq 'default') {
1.372 bisitz 3100: $r->print('<script type="text/javascript">'."\n"
3101: .'// <![CDATA['."\n"
3102: .'this.window.name="loncapaclient";'."\n"
3103: .'// ]]>'."\n"
3104: .'</script>'."\n"
1.369 bisitz 3105: );
1.329 droeschl 3106: } else {
3107: #$postexec='self.close();';
3108: }
3109: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3110: '.sequence';
3111: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3112: '.page';
3113: my $container='sequence';
3114: if ($env{'form.pagepath'}) {
3115: $container='page';
3116: }
3117: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3118:
3119:
3120:
3121: my $recoverform=(<<RFORM);
3122: <form action="/adm/groupsort" method="post" name="recover">
1.383 tempelho 3123: <a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
1.329 droeschl 3124: </form>
3125: RFORM
3126:
3127: my $imspform=(<<IMSPFORM);
3128: <form action="/adm/imsimportdocs" method="post" name="ims">
3129: <input type="hidden" name="folder" value="$folder" />
1.383 tempelho 3130: <a onclick="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 3131: </form>
3132: IMSPFORM
3133:
3134: my $newnavform=(<<NNFORM);
3135: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3136: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3137: $uploadtag
3138: <input type="hidden" name="importdetail"
3139: value="$lt{'navc'}=/adm/navmaps" />
1.383 tempelho 3140: <a onclick="document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3141: $help{'Navigate_Content'}
3142: </form>
3143: NNFORM
3144: my $newsmppageform=(<<NSPFORM);
3145: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3146: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3147: $uploadtag
3148: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3149: <a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
3150: $help{'Simple Page'}
1.329 droeschl 3151: </form>
3152: NSPFORM
3153:
3154: my $newsmpproblemform=(<<NSPROBFORM);
3155: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3156: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3157: $uploadtag
3158: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3159: <a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
3160: $help{'Simple Problem'}
1.329 droeschl 3161: </form>
3162:
3163: NSPROBFORM
3164:
3165: my $newdropboxform=(<<NDBFORM);
3166: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3167: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3168: $uploadtag
1.329 droeschl 3169: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3170: <a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3171: </form>
1.329 droeschl 3172: NDBFORM
3173:
3174: my $newexuploadform=(<<NEXUFORM);
3175: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3176: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3177: $uploadtag
3178: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3179: <a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3180: $help{'Score_Upload_Form'}
3181: </form>
3182: NEXUFORM
3183:
3184: my $newbulform=(<<NBFORM);
3185: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3186: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3187: $uploadtag
3188: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3189: <a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3190: $help{'Bulletin Board'}
3191: </form>
3192: NBFORM
3193:
3194: my $newaboutmeform=(<<NAMFORM);
3195: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3196: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3197: $uploadtag
3198: <input type="hidden" name="importdetail"
3199: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3200: <a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3201: $help{'My Personal Information Page'}
1.329 droeschl 3202: </form>
3203: NAMFORM
3204:
3205: my $newaboutsomeoneform=(<<NASOFORM);
3206: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3207: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3208: $uploadtag
3209: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3210: <a onclick="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3211: </form>
3212: NASOFORM
3213:
3214:
3215: my $newrosterform=(<<NROSTFORM);
3216: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3217: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3218: $uploadtag
3219: <input type="hidden" name="importdetail"
3220: value="$lt{'rost'}=/adm/viewclasslist" />
1.383 tempelho 3221: <a onclick="document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3222: $help{'Course Roster'}
3223: </form>
3224: NROSTFORM
3225:
1.342 ehlerst 3226: my $specialdocumentsform;
1.383 tempelho 3227: my @specialdocumentsforma;
1.351 ehlerst 3228: my $newfolderform;
1.390 tempelho 3229: my $newfolderb;
1.342 ehlerst 3230:
1.329 droeschl 3231: unless ($env{'form.pagepath'}) {
3232: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3233:
1.329 droeschl 3234: my $newpageform=(<<NPFORM);
3235: <form action="/adm/coursedocs" method="post" name="newpage">
3236: <input type="hidden" name="folderpath" value="$path" />
3237: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3238: <input type="hidden" name="active" value="cc" />
1.383 tempelho 3239: <a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
3240: $help{'Adding_Pages'}
1.329 droeschl 3241: </form>
3242: NPFORM
1.390 tempelho 3243:
3244:
1.351 ehlerst 3245: $newfolderform=(<<NFFORM);
1.329 droeschl 3246: <form action="/adm/coursedocs" method="post" name="newfolder">
3247: <input type="hidden" name="folderpath" value="$path" />
3248: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3249: <input type="hidden" name="active" value="aa" />
1.383 tempelho 3250: <a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3251: </form>
3252: NFFORM
3253:
3254: my $newsylform=(<<NSYLFORM);
3255: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3256: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3257: $uploadtag
3258: <input type="hidden" name="importdetail"
3259: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3260: <a onclick="document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3261: $help{'Syllabus'}
1.383 tempelho 3262:
1.329 droeschl 3263: </form>
3264: NSYLFORM
1.364 bisitz 3265:
1.329 droeschl 3266: my $newgroupfileform=(<<NGFFORM);
3267: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3268: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3269: $uploadtag
3270: <input type="hidden" name="importdetail"
3271: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.383 tempelho 3272: <a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3273: $help{'Group Portfolio'}
1.329 droeschl 3274: </form>
3275: NGFFORM
1.383 tempelho 3276: @specialdocumentsforma=(
1.410 wenzelju 3277: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/page.png" alt="'.&mt('New Composite Page').'" />'=>$newpageform},
3278: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/syllabus.png" alt="'.&mt('Syllabus').'" />'=>$newsylform},
3279: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/groupportfolio.png" alt="'.&mt('Group Portfolio').'" />'=>$newgroupfileform},
1.383 tempelho 3280: );
3281:
3282: }
1.410 wenzelju 3283: push @specialdocumentsforma, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/navigation.png" alt="'.&mt('Navigate Contents').'" />'=>$newnavform},
3284: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simple.png" alt="'.&mt('Simple Course Page').'" />'=>$newsmppageform},
3285: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simpprob.png" alt="'.&mt('Simple Problem').'" />'=>$newsmpproblemform},
3286: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/dropbox.png" alt="'.&mt('Drop Box').'" />'=>$newdropboxform},
3287: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/scoreupfrm.png" alt="'.&mt('Score Upload Form').'" />'=>$newexuploadform},
3288: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/bchat.png" alt="'.&mt('Discussion Board').'" />'=>$newbulform},
3289: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/myaboutme.png" alt="'.&mt('My Personal Information Page').'" />'=>$newaboutmeform},
3290: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/aboutme.png" alt="'.&mt('Personal Information Page for a User').'" />'=>$newaboutsomeoneform},
3291: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/chrt.png" alt="'.&mt('Course Roster').'" />'=>$newrosterform},);
1.383 tempelho 3292:
3293: $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
1.329 droeschl 3294:
1.342 ehlerst 3295: if($env{'form.pagepath'}) {
1.383 tempelho 3296:
3297: @specialdocumentsforma=(
1.410 wenzelju 3298: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/simpprob.png" alt="'.&mt('Simple Problem').'" />'=>$newsmpproblemform},
3299: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/scoreupfrm.png" alt="'.&mt('Score Upload Form').'" />'=>$newexuploadform}
1.383 tempelho 3300: );
3301: $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
1.342 ehlerst 3302: }
1.331 muellerd 3303:
1.383 tempelho 3304: my @tools = (
1.410 wenzelju 3305: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.&mt('External Resource').'" />'=>$extresourcesform},
3306: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="'.&mt('IMS Import').'" />'=>$imspform},
3307: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/recover.png" alt="'.&mt('Recover Deleted Resources').'" />'=>$recoverform},
1.383 tempelho 3308: );
3309:
1.330 tempelho 3310: my %orderhash = (
1.390 tempelho 3311: '00' => ['Newfolder',$newfolderform],
3312: 'aa' => ['Upload Document',$fileuploadform],
1.377 bisitz 3313: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.363 ehlerst 3314: 'cc' => ['Special Documents',$specialdocumentsform],
1.383 tempelho 3315: 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
1.330 tempelho 3316: );
1.334 muellerd 3317: my $tid='1';
1.341 ehlerst 3318: $hadchanges=0;
1.408 raeburn 3319: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.335 ehlerst 3320: if ($error) {
3321: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3322: }
1.341 ehlerst 3323: if ($hadchanges) {
3324: &mark_hash_old();
3325: }
3326:
3327: &changewarning($r,'');
1.406 raeburn 3328: $r->print(&generate_edit_table($tid,\%orderhash));
1.389 tempelho 3329:
1.335 ehlerst 3330: $r->print('</div>');
1.383 tempelho 3331: }
1.329 droeschl 3332: if ($env{'form.pagepath'}) {
3333: }
3334: # ----------------------------------------------------- Supplemental documents
1.395 raeburn 3335: $active = 'style="display: none;"';
1.335 ehlerst 3336: if($activeClass == 1){
3337: $active = 'style="display: block;"';
3338: }
1.373 bisitz 3339: $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
1.329 droeschl 3340: my $folder=$env{'form.folder'};
3341: unless ($folder=~/^supplemental/) {
3342: $folder='supplemental';
3343: }
3344: if ($folder =~ /^supplemental$/ &&
3345: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3346: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 3347: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.393 raeburn 3348: } elsif ($allowed) {
1.356 tempelho 3349: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3350: }
1.362 ehlerst 3351: $env{'form.pagepath'} = '';
1.329 droeschl 3352: if ($allowed) {
3353: my $folderseq=
3354: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3355: '.sequence';
3356:
3357: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3358:
1.400 droeschl 3359: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329 droeschl 3360: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 3361: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 3362: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3363: $fileupload
3364: <br />
3365: <br />
3366: <span class="LC_nobreak">
3367: $checkbox
3368: </span>
3369: <br /><br />
3370: $lt{'comment'}:<br />
1.383 tempelho 3371: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3372: <br />
3373: <input type="hidden" name="folderpath" value="$path" />
3374: <input type="hidden" name="cmd" value="upload_supplemental" />
3375: SUPDOCFORM
1.400 droeschl 3376: $supupdocform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329 droeschl 3377:
3378: my $supnewfolderform=(<<SNFFORM);
3379: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3380: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3381: <input type="hidden" name="folderpath" value="$path" />
3382: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3383: <a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
3384: $help{'Adding_Folders'}
1.329 droeschl 3385: </form>
3386: SNFFORM
1.383 tempelho 3387:
1.329 droeschl 3388:
3389: my $supnewextform=(<<SNEFORM);
3390: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 3391: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3392: <input type="hidden" name="folderpath" value="$path" />
3393: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3394: <a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 3395: </form>
3396: SNEFORM
3397:
3398: my $supnewsylform=(<<SNSFORM);
3399: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 3400: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3401: <input type="hidden" name="folderpath" value="$path" />
3402: <input type="hidden" name="importdetail"
3403: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3404: <a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3405: $help{'Syllabus'}
3406: </form>
3407: SNSFORM
3408:
3409: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 3410: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 3411: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3412: <input type="hidden" name="folderpath" value="$path" />
3413: <input type="hidden" name="importdetail"
3414: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3415: <a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3416: $help{'My Personal Information Page'}
1.329 droeschl 3417: </form>
3418: SNAMFORM
3419:
1.333 muellerd 3420:
1.383 tempelho 3421: my @specialdocs = (
1.410 wenzelju 3422: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.&mt('External Resource').'" />'=>$supnewextform},
3423: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/syllabus.png" alt="'.&mt('Syllabus').'" />'=>$supnewsylform},
3424: {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/myaboutme.png" alt="'.&mt('My Personal Information Page').'" />'=>$supnewaboutmeform},
1.383 tempelho 3425: );
1.333 muellerd 3426: my %suporderhash = (
1.390 tempelho 3427: '00' => ['Supnewfolder', $supnewfolderform],
3428: 'ee' => ['Upload Document',$supupdocform],
3429: 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))]
1.333 muellerd 3430: );
1.334 muellerd 3431:
1.408 raeburn 3432: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3433: if ($error) {
3434: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3435: }
3436: my $tid='2';
1.406 raeburn 3437: $r->print(&generate_edit_table($tid,\%suporderhash));
1.393 raeburn 3438: } else {
1.408 raeburn 3439: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3440: if ($error) {
3441: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3442: }
1.393 raeburn 3443: }
1.389 tempelho 3444:
3445:
1.335 ehlerst 3446: $r->print('</div>');
1.383 tempelho 3447: $r->print('</div></div>');
3448:
3449:
1.329 droeschl 3450: if ($allowed) {
3451: $r->print('
3452: <form method="post" name="extimport" action="/adm/coursedocs">
3453: <input type="hidden" name="title" />
3454: <input type="hidden" name="url" />
3455: <input type="hidden" name="useform" />
3456: <input type="hidden" name="residx" />
3457: </form>');
3458: }
3459: } else {
3460: unless ($upload_result eq 'phasetwo') {
3461: # -------------------------------------------------------- This is showdoc mode
3462: $r->print("<h1>".&mt('Uploaded Document').' - '.
3463: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3464: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3465: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3466: }
3467: }
3468: }
3469: $r->print(&Apache::loncommon::end_page());
3470: return OK;
1.364 bisitz 3471: }
1.329 droeschl 3472:
3473: sub generate_admin_options {
1.337 ehlerst 3474: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3475: my %lt=&Apache::lonlocal::texthash(
3476: 'vc' => 'Verify Content',
3477: 'cv' => 'Check/Set Resource Versions',
3478: 'ls' => 'List Symbs',
3479: 'sl' => 'Show Log'
3480: );
1.329 droeschl 3481: my %help = %{$help_ref};
3482: my %env = %{$env_ref};
3483: my $dumpbut=&dumpbutton();
3484: my $exportbut=&exportbutton();
1.383 tempelho 3485: my @list = (
1.410 wenzelju 3486: {'<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'}"},
3487: {'<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 3488: );
3489: if($dumpbut ne ''){
1.410 wenzelju 3490: 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 3491: }
1.410 wenzelju 3492: push @list, ({'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/imsexport.png" alt="'.&mt('IMS Export').'" />'=>$exportbut},
3493: {'<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'}' />"},
3494: {'<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 3495: );
3496: 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 3497:
1.329 droeschl 3498: }
3499:
1.330 tempelho 3500:
1.329 droeschl 3501: sub generate_edit_table {
1.406 raeburn 3502: my ($tid,$orderhash_ref) = @_;
3503: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 3504: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3505: my $form;
1.371 tempelho 3506: my $activetab;
3507: my $active;
3508: if($env{'form.active'} ne ''){
3509: $activetab = $env{'form.active'};
3510: }
1.382 tempelho 3511: $form = '<div class="LC_Box">';
1.359 tempelho 3512: $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
1.329 droeschl 3513: foreach my $name (sort(keys(%orderhash))){
1.390 tempelho 3514: if($name ne '00'){
1.371 tempelho 3515: if($activetab eq '' || $activetab ne $name){
3516: $active = '';
3517: }elsif($activetab eq $name){
3518: $active = 'class="active"';
3519: }
1.374 tempelho 3520: $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
1.390 tempelho 3521: } else {
3522: $form .= '<li '.$active.'>'.${$orderhash{$name}}[1].'</li>';
3523:
3524: }
1.329 droeschl 3525: }
1.339 ehlerst 3526: $form .= '</ul>';
1.398 bisitz 3527: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; clear: both;">';
1.363 ehlerst 3528: foreach my $field (keys(%orderhash)){
1.390 tempelho 3529: if($field ne '00'){
1.371 tempelho 3530: if($activetab eq '' || $activetab ne $field){
3531: $active = 'style="display: none;"';
3532: }elsif($activetab eq $field){
3533: $active = 'style="display:block;"';
3534: }
1.374 tempelho 3535: $form .= '<div id="'.$field.$tid.'"'
1.373 bisitz 3536: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3537: .'</div>';
1.363 ehlerst 3538: }
3539: }
1.330 tempelho 3540: $form .= '</div></div>';
1.364 bisitz 3541:
1.329 droeschl 3542: return $form;
3543: }
3544:
1.411.2.1 raeburn 3545: sub concept_test_builder {
1.411.2.3 raeburn 3546: my ($r,$cdom,$cnum) = @_;
1.411.2.7! raeburn 3547: &Apache::londocsgci::setdefaults($cdom);
1.411.2.6 raeburn 3548: if ($env{'form.context'} eq 'requestcrs') {
3549: if ($env{'form.phase'} eq 'storemap') {
3550: &Apache::londocsgci::evaluate();
3551: my $error = &Apache::londocsgci::store('requestcrs',$cdom,$cnum);
3552: my $output = '<p>';
3553: if ($error) {
3554: $output .= '<span class="LC_error">'.
3555: &mt('An error occurred saving your concept test: [_1].',$error).
3556: '</span>';
3557: } else {
3558: &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
3559: $output .= &mt('Your concept test has been saved.');
3560: }
3561: $output .= '</p>';
3562: if (&Apache::lonrequestcourse::generate_page($r,'new','chooseitems')) {
3563: my $formname = 'requestcrs';
3564: $r->print('<br /><form name="'.$formname.'" method="post" action="/adm/requestcourse">');
3565: my $title = &mt('Concept Test Created');
3566: &Apache::lonrequestcourse::roster_upload_form($r,$output,$formname,$title);
3567: }
3568: $r->print(&Apache::loncommon::end_page());
3569: return;
3570: }
3571: }
1.411.2.3 raeburn 3572: my $js = '
3573: <script type="text/javascript">
3574: // <![CDATA[
3575: '.
1.411.2.7! raeburn 3576: &Apache::londocsgci::builder_javascript($cdom).
1.411.2.3 raeburn 3577: '
3578: // ]]>
3579: </script>
3580: ';
1.411.2.5 raeburn 3581: $r->print(&Apache::loncommon::start_page('Assemble Test',$js));
1.411.2.3 raeburn 3582: &Apache::lonhtmlcommon::clear_breadcrumbs();
3583: &Apache::lonhtmlcommon::add_breadcrumb
3584: ({href=>'/adm/coursedocs',
3585: text=>"Assemble Test"});
1.411.2.1 raeburn 3586: if ($env{'form.phase'} eq 'storemap') {
1.411.2.3 raeburn 3587: &Apache::lonhtmlcommon::add_breadcrumb
3588: ({href=>'/adm/coursedocs?phase=storemap',
3589: text=>"Validate Test"});
3590: &Apache::londocsgci::evaluate();
3591: $r->print(&Apache::lonhtmlcommon::breadcrumbs
3592: ('Build Concept Test','Concept_Test_Assembly'));
3593: $r->print(&Apache::londocsgci::store('edit',$cdom,$cnum));
3594: } elsif ($env{'form.phase'} eq 'storeparms') {
3595: &Apache::lonhtmlcommon::add_breadcrumb
3596: ({href=>'/adm/coursedocs?phase=storeparms',
3597: text=>"Set Availability"});
3598: $r->print(&Apache::lonhtmlcommon::breadcrumbs
3599: ('Build Concept Test','Concept_Test_Assembly'));
3600: $r->print(&Apache::londocsgci::store_dates_parms($cdom,$cnum));
3601: $r->print(&Apache::loncommon::end_page());
3602: return;
3603: } else {
3604: $r->print(&Apache::lonhtmlcommon::breadcrumbs
3605: ('Build Concept Test','Concept_Test_Assembly'));
1.411.2.1 raeburn 3606: }
1.411.2.7! raeburn 3607: &Apache::londocsgci::load($cdom);
1.411.2.3 raeburn 3608: &Apache::londocsgci::listresources($r,'edit',$cdom,$cnum);
1.411.2.1 raeburn 3609: $r->print(&Apache::loncommon::end_page());
3610: return;
3611: }
3612:
1.329 droeschl 3613: sub editing_js {
3614: my ($udom,$uname) = @_;
3615: my $now = time();
3616: my %lt = &Apache::lonlocal::texthash(
3617: p_mnf => 'Name of New Folder',
3618: t_mnf => 'New Folder',
3619: p_mnp => 'Name of New Page',
3620: t_mnp => 'New Page',
3621: p_mxu => 'Title for the Uploaded Score',
1.349 biermanm 3622: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3623: p_msb => 'Title for the Problem',
3624: p_mdb => 'Title for the Drop Box',
1.336 schafran 3625: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3626: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3627: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3628: p_mab_alrt1 => 'Not a valid user:domain',
3629: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3630: p_chn => 'New Title',
3631: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3632: p_rmr2a => 'Remove[_99]',
3633: p_rmr2b => '?[_99]',
3634: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3635: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3636: p_ctr2a => 'Cut[_98]',
3637: p_ctr2b => '?[_98]'
3638: );
3639:
3640: return <<ENDNEWSCRIPT;
3641: function makenewfolder(targetform,folderseq) {
3642: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3643: if (foldername) {
3644: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3645: targetform.submit();
3646: }
3647: }
3648:
3649: function makenewpage(targetform,folderseq) {
3650: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3651: if (pagename) {
3652: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3653: targetform.submit();
3654: }
3655: }
3656:
3657: function makenewext(targetname) {
3658: this.document.forms.extimport.useform.value=targetname;
3659: this.document.forms.extimport.title.value='';
3660: this.document.forms.extimport.url.value='';
3661: this.document.forms.extimport.residx.value='';
3662: window.open('/adm/rat/extpickframe.html');
3663: }
3664:
3665: function edittext(targetname,residx,title,url) {
3666: this.document.forms.extimport.useform.value=targetname;
3667: this.document.forms.extimport.residx.value=residx;
3668: this.document.forms.extimport.url.value=url;
3669: this.document.forms.extimport.title.value=title;
3670: window.open('/adm/rat/extpickframe.html');
3671: }
3672:
3673: function makeexamupload() {
3674: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3675: if (title) {
1.329 droeschl 3676: this.document.forms.newexamupload.importdetail.value=
3677: escape(title)+'=/res/lib/templates/examupload.problem';
3678: this.document.forms.newexamupload.submit();
3679: }
3680: }
3681:
3682: function makesmppage() {
3683: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3684: if (title) {
1.329 droeschl 3685: this.document.forms.newsmppg.importdetail.value=
3686: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3687: this.document.forms.newsmppg.submit();
3688: }
3689: }
3690:
3691: function makesmpproblem() {
3692: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3693: if (title) {
1.329 droeschl 3694: this.document.forms.newsmpproblem.importdetail.value=
3695: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3696: this.document.forms.newsmpproblem.submit();
3697: }
3698: }
3699:
3700: function makedropbox() {
3701: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3702: if (title) {
1.329 droeschl 3703: this.document.forms.newdropbox.importdetail.value=
3704: escape(title)+'=/res/lib/templates/DropBox.problem';
3705: this.document.forms.newdropbox.submit();
3706: }
3707: }
3708:
3709: function makebulboard() {
3710: var title=prompt('$lt{"p_mbb"}');
3711: if (title) {
3712: this.document.forms.newbul.importdetail.value=
3713: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3714: this.document.forms.newbul.submit();
3715: }
3716: }
3717:
3718: function makeabout() {
3719: var user=prompt("$lt{'p_mab'}");
3720: if (user) {
3721: var comp=new Array();
3722: comp=user.split(':');
3723: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3724: if ((comp[0]) && (comp[1])) {
3725: this.document.forms.newaboutsomeone.importdetail.value=
3726: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3727: this.document.forms.newaboutsomeone.submit();
3728: } else {
3729: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3730: }
1.335 ehlerst 3731: } else {
3732: alert("$lt{'p_mab_alrt2'}");
3733: }
3734: }
1.329 droeschl 3735: }
3736:
3737: function makeims() {
1.335 ehlerst 3738: var caller = document.forms.ims.folder.value;
3739: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3740: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3741: newWindow.location.href = newlocation;
1.329 droeschl 3742: }
3743:
3744:
3745: function finishpick() {
1.335 ehlerst 3746: var title=this.document.forms.extimport.title.value;
3747: var url=this.document.forms.extimport.url.value;
3748: var form=this.document.forms.extimport.useform.value;
3749: var residx=this.document.forms.extimport.residx.value;
3750: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3751: }
3752:
3753: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3754: var title=prompt('$lt{"p_chn"}',oldtitle);
3755: if (title) {
3756: this.document.forms.renameform.markcopy.value=-1;
3757: this.document.forms.renameform.title.value=title;
3758: this.document.forms.renameform.cmd.value='rename_'+index;
3759: if (container == 'sequence') {
3760: this.document.forms.renameform.folderpath.value=folderpath;
3761: }
3762: if (container == 'page') {
3763: this.document.forms.renameform.pagepath.value=folderpath;
3764: this.document.forms.renameform.pagesymb.value=pagesymb;
3765: }
3766: this.document.forms.renameform.submit();
3767: }
1.329 droeschl 3768: }
3769:
3770: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3771: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3772: this.document.forms.renameform.markcopy.value=-1;
3773: this.document.forms.renameform.cmd.value='del_'+index;
3774: if (container == 'sequence') {
3775: this.document.forms.renameform.folderpath.value=folderpath;
3776: }
3777: if (container == 'page') {
3778: this.document.forms.renameform.pagepath.value=folderpath;
3779: this.document.forms.renameform.pagesymb.value=pagesymb;
3780: }
3781: this.document.forms.renameform.submit();
3782: }
1.329 droeschl 3783: }
3784:
3785: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3786: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3787: this.document.forms.renameform.cmd.value='cut_'+index;
3788: this.document.forms.renameform.markcopy.value=index;
3789: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3790: if (container == 'sequence') {
3791: this.document.forms.renameform.folderpath.value=folderpath;
3792: }
3793: if (container == 'page') {
3794: this.document.forms.renameform.pagepath.value=folderpath;
3795: this.document.forms.renameform.pagesymb.value=pagesymb;
3796: }
3797: this.document.forms.renameform.submit();
3798: }
1.329 droeschl 3799: }
3800:
3801: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3802: this.document.forms.renameform.markcopy.value=index;
3803: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3804: if (container == 'sequence') {
3805: this.document.forms.renameform.folderpath.value=folderpath;
3806: }
3807: if (container == 'page') {
3808: this.document.forms.renameform.pagepath.value=folderpath;
3809: this.document.forms.renameform.pagesymb.value=pagesymb;
3810: }
3811: this.document.forms.renameform.submit();
1.329 droeschl 3812: }
3813:
1.334 muellerd 3814: function unselectInactive(nav) {
1.335 ehlerst 3815: currentNav = document.getElementById(nav);
3816: currentLis = currentNav.getElementsByTagName('LI');
3817: for (i = 0; i < currentLis.length; i++) {
1.374 tempelho 3818: if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
3819: currentLis[i].className = 'right';
3820: }else{
3821: currentLis[i].className = 'i';
3822: }
1.335 ehlerst 3823: }
1.332 tempelho 3824: }
3825:
1.334 muellerd 3826: function hideAll(current, nav, data) {
1.335 ehlerst 3827: unselectInactive(nav);
1.374 tempelho 3828: if(current.className == 'right'){
3829: current.className = 'right active'
3830: }else{
3831: current.className = 'active';
3832: }
1.335 ehlerst 3833: currentData = document.getElementById(data);
3834: currentDivs = currentData.getElementsByTagName('DIV');
3835: for (i = 0; i < currentDivs.length; i++) {
3836: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3837: currentDivs[i].style.display = 'none';
1.330 tempelho 3838: }
3839: }
1.335 ehlerst 3840: }
1.330 tempelho 3841:
1.374 tempelho 3842: function openTabs(pageId) {
3843: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 3844: if(tabnav.length > 2 ){
1.389 tempelho 3845: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 3846: currentLis = currentNav.getElementsByTagName('LI');
3847: for(i = 0; i< currentLis.length; i++){
3848: if(currentLis[i].className == 'active') {
1.375 tempelho 3849: funcString = currentLis[i].onclick.toString();
3850: tab = funcString.split('"');
3851: currentData = document.getElementById(tab[1]);
3852: currentData.style.display = 'block';
1.374 tempelho 3853: }
3854: }
3855: }
3856: }
3857:
1.334 muellerd 3858: function showPage(current, pageId, nav, data) {
3859: hideAll(current, nav, data);
1.375 tempelho 3860: openTabs(pageId);
1.334 muellerd 3861: unselectInactive(nav);
1.330 tempelho 3862: current.className = 'active';
3863: currentData = document.getElementById(pageId);
3864: currentData.style.display = 'block';
3865: return false;
3866: }
1.329 droeschl 3867:
1.383 tempelho 3868: function injectData(current, hiddenField, name, value) {
3869: currentElement = document.getElementById(hiddenField);
3870: currentElement.name = name;
3871: currentElement.value = value;
3872: current.submit();
3873: }
3874:
1.329 droeschl 3875: ENDNEWSCRIPT
3876: }
3877: 1;
3878: __END__
3879:
3880:
3881: =head1 NAME
3882:
3883: Apache::londocs.pm
3884:
3885: =head1 SYNOPSIS
3886:
3887: This is part of the LearningOnline Network with CAPA project
3888: described at http://www.lon-capa.org.
3889:
3890: =head1 SUBROUTINES
3891:
3892: =over
3893:
3894: =item %help=()
3895:
3896: Available help topics
3897:
3898: =item mapread()
3899:
1.344 bisitz 3900: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 3901: @order and @resources, determines status
3902: sets @order - pointer to resources in right order
3903: sets @resources - array with the resources with correct idx
3904:
3905: =item authorhosts()
3906:
3907: Return hash with valid author names
3908:
3909: =item dumpbutton()
3910:
3911: Generate "dump" button
3912:
3913: =item clean()
3914:
3915: =item dumpcourse()
3916:
3917: Actually dump course
3918:
3919:
3920: =item exportbutton()
3921:
3922: Generate "export" button
3923:
3924: =item exportcourse()
3925:
3926: =item create_ims_store()
3927:
3928: =item build_package()
3929:
3930: =item get_dependencies()
3931:
3932: =item process_content()
3933:
3934: =item replicate_content()
3935:
3936: =item extract_media()
3937:
3938: =item store_template()
3939:
3940: =item group_import()
3941:
3942: Imports the given (name, url) resources into the course
3943: coursenum, coursedom, and folder must precede the list
3944:
3945: =item breadcrumbs()
3946:
3947: =item log_docs()
3948:
3949: =item docs_change_log()
3950:
3951: =item update_paste_buffer()
3952:
3953: =item print_paste_buffer()
3954:
3955: =item do_paste_from_buffer()
3956:
3957: =item update_parameter()
3958:
3959: =item handle_edit_cmd()
3960:
3961: =item editor()
3962:
3963: =item process_file_upload()
3964:
3965: =item process_secondary_uploads()
3966:
3967: =item is_supplemental_title()
3968:
3969: =item parse_supplemental_title()
3970:
3971: =item entryline()
3972:
3973: =item tiehash()
3974:
3975: =item untiehash()
3976:
3977: =item checkonthis()
3978:
3979: check on this
3980:
3981: =item verifycontent()
3982:
3983: Verify Content
3984:
3985: =item devalidateversioncache() & checkversions()
3986:
3987: Check Versions
3988:
3989: =item mark_hash_old()
3990:
3991: =item is_hash_old()
3992:
3993: =item changewarning()
3994:
3995: =item init_breadcrumbs()
3996:
3997: Breadcrumbs for special functions
3998:
3999: =back
4000:
4001: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>