Annotation of loncom/imspackages/imsimportdocs.pm, revision 1.15
1.7 raeburn 1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23:
1.1 raeburn 24: package Apache::imsimportdocs;
25:
1.2 raeburn 26: use Apache::Constants qw(:common :http :methods);
1.1 raeburn 27: use Apache::lonnet;
1.2 raeburn 28: use Apache::londocs;
1.1 raeburn 29: use Apache::loncommon;
30: use Apache::lonlocal;
31: use Apache::imsprocessor;
32: use LONCAPA::Configuration;
1.2 raeburn 33: use strict;
1.1 raeburn 34:
35: sub jscript_one {
36: my $javascript = shift;
37: $$javascript = qq#
38: function verify() {
39: if ((document.forms.pickcms.uploadname.value == '') || (!document.forms.pickcms.uploadname.value)) {
40: alert("You must provide the name of the IMS package to be imported")
41: return false
42: }
43: if (document.forms.pickcms.source.selectedIndex == 0) {
44: alert("You must choose the Course Management System from which the IMS package was exported");
45: return false
46: }
47: return true
48: }
49:
50: function nextPage() {
51: if (verify()) {
52: document.forms.pickcms.submit()
53: }
54: }
55: #;
56:
57: }
58:
59: sub jscript_two {
60: my $javascript = shift;
61: $$javascript = qq#
62: function setOptions(caller,itemnum) {
63: var opForm = document.forms.pickoptions
64: var menu = 1 + itemnum*2
65: opForm.elements[menu].length = 0
66: if (opForm.elements[itemnum*2].checked == true) {
67: if (caller == "board") {
68: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
69: opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
1.4 raeburn 70: opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
71: opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
1.1 raeburn 72: }
73: else {
74: if (caller == "users") {
75: opForm.elements[menu].length = 0
76: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
77: opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
78: opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
79: }
80: }
81: }
82: else {
83: opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
84: }
85: opForm.elements[menu].selectedIndex = 0
86: }
87:
88: function verify(caller) {
89: var opForm = document.forms.pickoptions
90: var totcheck = 0;
91: for (var i=0; i<caller; i++) {
92: if (opForm.elements[2*i].checked == true) {
93: totcheck ++
94: if (opForm.elements[2*i].name == "board") {
95: if (opForm.elements[2*i+1].selectedIndex == 0) {
96: alert("You must select one of the additional options when importing Discussion Boards ")
97: return false
98: }
99: }
100: if (opForm.elements[2*i].name == "users") {
101: if (opForm.elements[2*i+1].selectedIndex == 0) {
102: alert("You must select one of the additional options when importing Enrollment")
103: return false
104: }
105: }
106: }
107: }
108: if (totcheck == 0) {
109: alert("You must check the Checkbox for at least one Content Type");
110: return false
111: }
112: return true
113: }
114:
115: function nextPage(caller) {
116: if (verify(caller)) {
117: document.forms.pickoptions.submit()
118: }
119: }
120: #;
121: }
122:
1.2 raeburn 123: sub jscript_three {
124: my $javascript = shift;
125: $$javascript = qq|
126: function init(tf) {
127: setTimeout("self.close()",3000)
128: tf.submit();
129: }
130: |;
131: }
132:
1.1 raeburn 133: sub handler {
134: my $r = shift;
135: my $javascript = '';
136: &Apache::loncommon::content_type($r,'text/html');
137: $r->send_http_header;
138: return OK if $r->header_only;
139:
1.3 raeburn 140: my @areas = ();
1.1 raeburn 141: my %cmsmap = ();
1.3 raeburn 142: my %areaname = ();
143: &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
1.1 raeburn 144:
145: # get course data
1.12 albertel 146: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
147: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.1 raeburn 148:
149: # get personal data
150:
1.12 albertel 151: my $uname=$env{'user.name'};
152: my $udom=$env{'user.domain'};
1.1 raeburn 153: my $plainname=&Apache::lonnet::escape(
154: &Apache::loncommon::plainname($uname,$udom));
155:
156: # does this user have privileges to post, etc?
1.12 albertel 157: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.1 raeburn 158: unless ($allowed) {
1.15 ! albertel 159: $r->print(&Apache::loncommon::start_page('Import IMS package',undef,
! 160: {'only_body' => 1,}));
! 161: $r->print('<h3>'.&mt('Modification of Course Contents Disallowed').'</h3>'.&mt('Your current role does not grant you the right to modify course content in this course.').
! 162: &Apache::loncommon::end_page());
1.1 raeburn 163: return OK;
164: }
165:
166: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
167: ['phase']);
168:
1.12 albertel 169: if ($env{'form.phase'} eq 'one') {
1.1 raeburn 170: &jscript_one(\$javascript);
1.12 albertel 171: } elsif ($env{'form.phase'} eq 'two') {
1.1 raeburn 172: &jscript_two(\$javascript);
1.12 albertel 173: } elsif ($env{'form.phase'} eq 'three') {
1.2 raeburn 174: &jscript_three(\$javascript);
1.1 raeburn 175: }
176:
1.15 ! albertel 177: $javascript =
! 178: "<script type=\"text/javascript\">\n".
! 179: "//<!--\n$javascript\n// --></script>\n";
! 180: my $start_page = &Apache::loncommon::start_page('Import IMS package',
! 181: $javascript,
! 182: {'only_body' => 1,});
1.1 raeburn 183: # print screen
1.15 ! albertel 184: $r->print($start_page);
! 185:
1.12 albertel 186: if ($env{'form.phase'} eq 'one') {
1.1 raeburn 187: &display_one($r);
1.12 albertel 188: } elsif ($env{'form.phase'} eq 'two') {
1.3 raeburn 189: &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap);
1.12 albertel 190: } elsif ($env{'form.phase'} eq 'three') {
1.14 raeburn 191: &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap);
1.1 raeburn 192: }
1.15 ! albertel 193: $r->print(&Apache::loncommon::end_page());
1.2 raeburn 194: return OK;
1.1 raeburn 195: }
196:
197:
198: sub display_one {
1.2 raeburn 199: my ($r) = @_;
1.1 raeburn 200: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);
201:
202: $r->print(<<ENDBLOCK);
203: <form action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" name="pickcms">
204: <table border='0' bgcolor='#F6F6F6' cellspacing='0' cellpadding ='0' width='100%'>
205: <tr>
206: <td colspan='2'>
207: <table border='0' cellspacing='0' cellpadding='0'>
208: <tr>
209: <td colspan='2' align='left'>
210: </td>
211: </tr>
212: <tr bgcolor='#CCCCFF'>
213: <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>
214: </td>
215: <td width='100%' align='left'>
216: <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>
217: </font>
218: </td>
219: </tr>
220: <tr>
221: <td colspan='2'> </td>
222: </tr>
223: <tr>
224: <td> </td>
225: <td>
226: <font face='Arial,Helvetica,sans-serif'>
227: Please choose the CMS used to create your IMS content package.
228: <select name="source">
229: <option value='-1' selected="true">Please select
230: <option value='bb5'>Blackboard 5
1.7 raeburn 231: <option value='bb6'>Blackboard 6
1.1 raeburn 232: <option value='angel'>ANGEL
1.11 raeburn 233: <option value='webct4'>WebCT 4
1.1 raeburn 234: </select>
235: </font>
236: </td>
237: </tr>
238: <tr>
239: <td colspan='2'> </td>
240: </tr>
241: <tr>
242: <td colspan='2'> </td>
243: </tr>
244: <tr bgcolor='#CCCCFF'>
245: <td valign='middle'><img src='/res/adm/pages/bl_step2.gif'>
246: </td>
247: <td width='100%' align='left'>
248: <font face='arial,helvetica,sans-serif'><b>Locate the IMS content package you wish to upload.</b>
249: </font>
250: </td>
251: </tr>
252: <tr>
253: <td colspan='2'> </td>
254: </tr>
255: <tr>
256: <td colspan='2'>
1.12 albertel 257: <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1 raeburn 258: <input type="hidden" name="phase" value="two" />
259: <input type="file" name="uploadname" size="40" />
260: </td>
261: </tr>
262: <tr>
263: <td colspan='2'> </td>
264: </tr>
265: <tr>
266: <td> </td>
267: <td><font face='arial,helvetica,sans-serif'>If you have selected the CMS, and located the IMS package, you should click the 'Upload IMS package' button to upload the file to the server.</font></td>
268: </tr>
269: <tr>
270: <td colspan='2'> </td>
271: </tr>
272: <tr
273: <td colspan='2'>
274: <table border='0' cellspacing='0' cellpadding='0' width="100%">
275: <tr>
276: <td align='left'>
277: <input type="button" name="exitpage" value="Exit now" onClick="javascript:self.close()">
278: </td>
279: <td align='right'>
280: <input type="button" name="nextpage" value="Upload IMS package" onClick="javascript:nextPage()">
281: </td>
282: </tr>
283: </table>
284: </td>
285: </tr>
286: </table>
287: </td>
288: </tr>
289: </table>
290: </form>
291: ENDBLOCK
292: }
293:
294:
295: sub display_two {
1.3 raeburn 296: my ($r,$crs,$areasref,$areaname,%cmsmap) = @_;
1.1 raeburn 297: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
1.12 albertel 298: my $cms = $env{'form.source'};
1.2 raeburn 299: my $timenow = time;
300: my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow);
1.3 raeburn 301: my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir);
1.1 raeburn 302: my $unzip_result = '';
303: my $manifest_result = '';
304: unless ($tempdir eq '') {
305: $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
306: }
307: my %resources = ();
1.9 raeburn 308: my %includedres = ();
309: my %includeditems = ();
1.1 raeburn 310: my %items = ();
311: my %hrefs = ();
1.2 raeburn 312: my %resinfo = ();
1.1 raeburn 313: my %count = ();
314: my @bgcolors = ("#eeeeee","#dddddd");
315:
316: my $counter = 0;
317: my $iter = 0;
318: my %count = (
319: announce => 0,
320: board => 0,
321: doc => 0,
322: extlink => 0,
323: msg => 0,
324: pool => 0,
325: quiz => 0,
326: staff => 0,
327: survey => 0,
328: users => 0,
329: );
330:
331: if ($unzip_result eq 'ok') {
1.9 raeburn 332: $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
1.1 raeburn 333: if ($manifest_result eq 'ok') {
334: foreach my $res (sort keys %resources) {
1.11 raeburn 335: if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
1.1 raeburn 336: foreach my $area (keys %{$cmsmap{$cms}}) {
337: if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
338: $count{$area} ++;
339: }
340: }
341: } elsif ($cms eq 'angel') {
342: foreach my $area (keys %{$cmsmap{$cms}}) {
343: if ($area eq 'doc') {
344: if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
345: $count{$area} ++;
346: }
347: } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
348: $count{$area} ++;
349: }
350: }
351: }
352: }
353: $r->print(<<ENDBLOCK);
354: <form name="pickoptions" method="post">
355: <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
356: <tr>
357: <td colspan='2'>
358: <table border='0' cellspacing='0' cellpadding='0'>
359: <tr>
360: <td colspan='2' align='left'>
361: </td>
362: </tr>
363: <tr bgcolor='#CCCCFF'>
364: <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>
365: </td>
366: <td width='100%' align='left'>
367: <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
368: </td>
369: </tr>
370: <tr>
371: <td colspan='2'> </td>
372: </tr>
373: <tr>
374: <td> </td>
375: <td>
376: <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
377: <tr>
378: <td>
379: <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
380: <tr>
381: <td>
382: <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
383: <tr bgcolor='#CCCCFF'>
384: <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>
385: <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
386: <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
387: </tr>
388: ENDBLOCK
389: foreach my $area (@{$areasref}) {
390: if ($count{$area} > 0) {
391: my $count_tag = 'flag_'.$counter;
392: $r->print(" <tr bgcolor='@bgcolors[$iter]'>
393: <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
394: if ($area eq 'board' || $area eq 'users') {
395: $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
396: }
397: $r->print("/></font></td>
1.3 raeburn 398: <td align='left'><font face='arial,helvetica,sans-serif'> $$areaname{$area} - $count{$area} item(s)</font></td>");
1.1 raeburn 399: if ($area eq 'board') {
400: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
1.2 raeburn 401: <select name='db_handling'>
1.1 raeburn 402: <option value='-2'><-- Check Import first
403: </select></font>
404: </td>");
405: } elsif ($area eq 'users') {
406: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
407: <select name='user_handling'>
408: <option value='-2'><-- Check Import first
409: </select>
410: </font>
411: </td>");
412: } else {
413: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'> None<input type='hidden' name='$count_tag' /></font></td>");
414: }
415: $counter ++;
416: $iter = $counter%2;
417: }
418: }
419: $r->print(<<ENDDOCUMENT);
420: </tr>
421: </table>
422: </td>
423: </tr>
424: </table>
425: </td>
426: </tr>
427: </table>
428: </td>
429: </tr>
430: <tr>
431: <td colspan='2'> <br /><br /></td>
432: </tr>
1.2 raeburn 433: <tr bgcolor='#CCCCFF'>
434: <td valign='middle'><img src='/res/adm/pages/bl_step4.gif'>
435: </td>
436: <td width='100%' align='left'>
437: <font face='arial,helvetica,sans-serif'><b>Choose display options for listing of contents of top level of package.</b></font>
438: </td>
439: </tr>
440: <tr>
441: <td colspan='2'> </td>
442: </tr>
1.1 raeburn 443: <tr>
444: <td> </td>
1.2 raeburn 445: <td>
446: <table border='0'>
447: <tr>
448: <td><font face='arial,helvetica,sans-serif'><input type="radio" name="toplevel" value="newfolder" />Display listing of contents in a new folder, with folder name: <input type="text" name="foldername" size="15" value="Type Name Here" /></font></td>
449: </tr>
450: <tr>
451: <td><font face='arial,helvetica,sans-serif'><input type="radio" name="toplevel" value="oldfolder" />Append listing of contents of top level of package to contents list for the current folder.</font></td>
452: </tr>
453: </table>
454: </td>
455: </tr>
456: <tr>
457: <td colspan='2'> </td>
458: </tr>
459: <tr>
460: <td> </td>
461: <td><font face='arial,helvetica,sans-serif'>Once you have checked the checkboxes for all areas you wish to import from the IMS package, selected options (if available), and selected a display option for the package contents you should click the 'Complete Import' button.</font></td>
1.1 raeburn 462: </tr>
463: <tr>
464: <td colspan='2'>
1.12 albertel 465: <input type="hidden" name="folder" value="$env{'form.folder'}" />
1.1 raeburn 466: <input type="hidden" name="source" value="$cms" />
467: <input type="hidden" name="tempdir" value="$tempdir" />
468: <input type="hidden" name="phase" value="three" />
469: </td>
470: </tr>
471: <tr>
472: <td colspan='2'>
473: <table border='0' cellspacing='0' cellpadding='0' width="100%">
474: <tr>
475: <td align='left'>
476: <input type='button' name='exitpage' value='Exit now' onClick="javascript:self.close()">
477: </td>
478: <td align='right'>
479: <input type="button" name="nextpage" value="Complete Import" onClick="javascript:nextPage($counter)">
480: </td>
481: </tr>
482: </table>
483: </td>
484: </tr>
485: </table>
486: </td>
487: </tr>
488: </table>
489: ENDDOCUMENT
490: } else {
491: $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");
492: }
493: } else {
494: $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");
495: }
496: }
497:
498:
499: sub display_three {
1.14 raeburn 500: my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_;
1.12 albertel 501: my $folder = $env{'form.folder'};
502: my $cms = $env{'form.source'};
503: my $tempdir = $env{'form.tempdir'};
1.2 raeburn 504: my $longcrs = '';
505: if ($crs =~ m/^(\d)(\d)(\d)/) {
506: $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
507: }
1.9 raeburn 508: my %importareas = ();
509: my %includedres = ();
510: my %includeditems = ();
1.2 raeburn 511: my @targets = ();
512: my %resources = ();
513: my %items = ();
514: my %hrefs = ();
515: my %urls = ();
516: my %resinfo = ();
517: my %total = (
518: page => 0,
519: prob => 0,
520: seq => 0,
521: board => 0,
522: quiz => 0,
523: surv => 0,
524: );
525: my @pages = ();
526: my @sequences = ();
527: my @resrcfiles = ();
528:
529: my $timenow = time;
530:
531: my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow;
532: my $seqstem = "/uploaded/$cdom/$crs/$timenow";
533: my $db_handling = '';
534: my $user_handling = '';
535:
536: my $toplevel = '';
537: my $foldername = '';
538: my %topitems = ();
1.12 albertel 539: if (defined($env{'form.toplevel'}) ) {
540: $toplevel = $env{'form.toplevel'};
1.2 raeburn 541: }
1.12 albertel 542: if (defined($env{'form.foldername'}) ) {
543: $foldername = $env{'form.foldername'};
1.2 raeburn 544: }
1.8 raeburn 545:
1.2 raeburn 546: foreach my $area (@{$areas}) {
1.12 albertel 547: if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) {
1.2 raeburn 548: if ($cms eq 'angel' && $area eq 'doc') {
549: foreach (@{$cmsmap{$cms}{$area}}) {
1.9 raeburn 550: $importareas{$_} = 1;
1.2 raeburn 551: }
552: } else {
1.9 raeburn 553: $importareas{$cmsmap{$cms}{$area}} = 1;
1.2 raeburn 554: }
555: if ($area eq 'board') {
1.12 albertel 556: $db_handling = $env{'form.db_handling'};
1.2 raeburn 557: } elsif ($area eq 'users') {
1.12 albertel 558: $user_handling = $env{'form.user_handling'};
1.2 raeburn 559: }
560: }
561: }
1.9 raeburn 562:
563: my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
1.2 raeburn 564: if ($manifest_result eq 'ok') {
1.9 raeburn 565: foreach my $res (sort keys %resources) {
566: if ($importareas{$resources{$res}{type}}) {
567: $includedres{$res} = 1;
568: }
569: }
570: foreach my $itm (sort keys %items) {
571: &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
572: }
573: }
574: foreach my $itm (sort keys %includeditems) {
575: &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
576: }
577:
578: $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
579: if ($manifest_result eq 'ok') {
580:
1.5 raeburn 581: my @path = ($cdom,$crs,$timenow);
582: my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
583: foreach my $item (@path) {
584: $fullpath .= '/'.$item;
585: if (!-e "$fullpath") {
586: mkdir("$fullpath",0770);
587: }
588: }
589: my @namedirs = ("resfiles","sequences","pages","problems");
590: foreach my $name (@namedirs) {
591: if (!-e "$fullpath/$name") {
592: mkdir("$fullpath/$name",0770);
593: }
594: }
1.9 raeburn 595: &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
1.2 raeburn 596:
597: my @boards = ();
598: my @announcements = ();
599: my @quizzes = ();
600: my @surveys = ();
1.9 raeburn 601: my @pools = ();
1.2 raeburn 602: my @groups = ();
603: my %messages = ();
604: my @timestamp = ();
605: my %boardnum = ();
606: my @topurls = ();
607: my @topnames = ();
1.7 raeburn 608: my @packages = ();
1.2 raeburn 609:
1.9 raeburn 610: &Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
1.7 raeburn 611:
1.14 raeburn 612: my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas);
1.2 raeburn 613:
1.9 raeburn 614: &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems);
1.11 raeburn 615:
1.2 raeburn 616: foreach my $item (@pages) {
1.3 raeburn 617: my $filename = $timenow.'/pages/'.$item;
1.13 raeburn 618: my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2 raeburn 619: }
620: foreach my $item (@sequences) {
621: unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') {
1.3 raeburn 622: my $filename = $timenow.'/sequences/'.$item;
1.13 raeburn 623: my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2 raeburn 624: }
625: }
626: foreach my $item (@resrcfiles) {
1.3 raeburn 627: my $filename = $timenow.'/resfiles/'.$item;
1.13 raeburn 628: my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,'');
1.2 raeburn 629: }
630:
631: my @imports = ();
632: if ($toplevel eq 'oldfolder') {
633: for (my $i=0; $i<@topurls; $i++) {
634: my $url = &Apache::lonnet::unescape($topurls[$i]);
635: my $name = &Apache::lonnet::unescape($topnames[$i]);
636: push @imports, $name, $url;
637: }
638: } elsif ($toplevel eq 'newfolder') {
639: my $url = &Apache::lonnet::unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence");
1.12 albertel 640: my $name = &Apache::lonnet::unescape("$env{'form.foldername'}");
1.2 raeburn 641: push @imports, $name, $url;
642: }
643: my $errtext='';
644: my $fatal=0;
645: ($errtext,$fatal)= &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence');
646: if ($#Apache::lonratedt::order<1) {
647: $Apache::lonratedt::order[0]=1;
648: $Apache::lonratedt::resources[1]='';
649: }
1.8 raeburn 650: my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports);
1.2 raeburn 651: if ($fatal) {
652: print STDERR "Fatal error during group_import\n";
653: }
654: }
1.3 raeburn 655: if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) {
656: system("rm -r -f $tempdir");
657: }
1.2 raeburn 658: $r->print(<<ENDBLOCK);
659: <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
660: <tr>
661: <td colspan='2'>
662: <table border='0' cellspacing='0' cellpadding='0'>
663: <tr>
664: <td colspan='2' align='left'>
665: </td>
666: </tr>
667: <tr bgcolor='#CCCCFF'>
668: <td valign='middle'><img src='/res/adm/pages/bl_step5.gif'>
669: </td>
670: <td width='100%' align='left'>
671: <font face='arial,helvetica,sans-serif'><b>Your import is complete</b></font>
672: </td>
673: </tr>
674: <tr>
675: <td colspan='2'> </td>
676: </tr>
677: <tr>
678: <td> </td>
679: <td>
680: ENDBLOCK
681: my $initblock = qq|
682: <form method="post" action="/adm/roles" target="loncapaclient" name="importDone">
683: <input type="hidden" name="orgurl" value="/adm/coursedocs" />
684: <input type="hidden" name="selectrole" value="1" />
685: <h3><font color="red">Changes will become active for your current session after
1.12 albertel 686: <input type="hidden" name="$env{'request.role'}" value="1" />
1.2 raeburn 687: <input type="button" value="|;
688: $initblock .= &mt('re-initializing course');
689: $initblock .= qq|" onClick="javascript:init(this.form)"/>|;
1.8 raeburn 690: $initblock .= ', '.&mt('or the next time you log in.');
1.2 raeburn 691: $initblock .= qq|</font></h3></form>|;
692: $r->print($initblock);
693: $r->print(<<ENDBLOCKTWO);
694: </table>
695: </td>
696: </tr>
697: </table>
698: ENDBLOCKTWO
1.1 raeburn 699: }
700:
701: 1;
702: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>