Annotation of loncom/imspackages/imsimport.pm, revision 1.19
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::imsimport;
25:
1.4 raeburn 26: use strict;
27: use Apache::Constants qw(:common :http :methods);
28: use Apache::loncacc;
29: use Apache::loncommon();
30: use Apache::lonnet;
1.5 raeburn 31: use Apache::imsprocessor;
1.4 raeburn 32: use HTML::Parser;
33: use HTML::Entities();
34: use Apache::lonlocal;
35: use Apache::lonupload;
1.5 raeburn 36: use File::Basename();
37:
38: # ---------------------------------------------------------------- Jscript One
39: sub jscript_one {
40: my ($fullpath,$jsref) = @_;
1.14 albertel 41:
42: my $start_page =
43: &Apache::loncommon::start_page('Create IMS import directory',undef,
44: {'only_body' => 1,
45: 'add_entries' => "topmargin='0' leftmargin='0' marginheight='0'marginwidth='0' rightmargin='0'",
46: 'js_ready' => 1,});
47: my $end_page =
48: &Apache::loncommon::end_page({'js_ready' => 1,});
49:
1.1 raeburn 50: $$jsref = <<"END_OF_ONE";
51: function verify() {
52: if ((document.forms.dataForm.newdir.value == '') || (!document.forms.dataForm.newdir.value)) {
53: alert("You must choose a destination directory for the import")
54: return false
55: }
56: if (document.forms.dataForm.source.selectedIndex == 0) {
57: alert("You must choose the Course Management System from which the IMS package was exported");
58: return false
1.2 raeburn 59: }
1.1 raeburn 60: return true
61: }
1.2 raeburn 62:
1.1 raeburn 63: function nextPage() {
1.5 raeburn 64: if (verify()) {
65: document.forms.dataForm.submit()
66: }
1.1 raeburn 67: }
68:
69: function createWin() {
70: document.dataForm.newdir.value = "";
71: newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
72: newWindow.document.open()
1.14 albertel 73: newWindow.document.write('$start_page')
74: newWindow.document.write("\\n<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")
1.1 raeburn 75: newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='600' bgcolor='#CCFFDD'>\\n")
76: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
77: newWindow.document.write("<td><h3>Location: <tt>$fullpath</tt></h3><h3>New Directory</h3></td></tr>\\n")
78: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
79: newWindow.document.write("<td><form name='fileaction' action='/adm/cfile' method='post'>\\n")
80: newWindow.document.write("<font face='arial,helvetica,sans-serif'>Enter the name of the new directory where you will store the contents of your IMS package.<br /><br />")
1.15 albertel 81: newWindow.document.write("<input type='hidden' name='filename' value='$fullpath' />")
82: newWindow.document.write("<input type='hidden' name='action' value='newdir' />")
83: newWindow.document.write("<input type='hidden' name='callingmode' value='imsimport' />")
84: newWindow.document.write("$fullpath<input type='text' name='newfilename' value='' />")
1.1 raeburn 85: newWindow.document.write("<input type='button' value='Go' onClick='document.fileaction.submit();' />")
86: newWindow.document.write("</td></tr>\\n")
1.14 albertel 87: newWindow.document.write("</table>")
88: newWindow.document.write('$end_page')
1.1 raeburn 89: newWindow.document.close()
90: newWindow.focus()
91: }
1.2 raeburn 92:
1.5 raeburn 93: END_OF_ONE
94:
95: }
96:
97: # ---------------------------------------------------------------- Jscript Two
98: sub jscript_two {
99: my ($javascript,$user,$dom,$numcrs) = @_;
100: my %crsentry = ();
101: my $course_list;
102: my $title_list;
103: my @crslist = ();
104: &get_ccroles($user,$dom,\%crsentry,\@crslist);
105: if (@crslist > 0) {
106: $crsentry{$crslist[0]} =~ s/("|,)//g;
107: $title_list = '"'.$crsentry{$crslist[0]}.'"';
108: if (@crslist > 1) {
109: for (my $i=1; $i<@crslist; $i++) {
110: $crsentry{$crslist[$i]} =~ s/("|,)//g;
111: $title_list .= ',"'.$crsentry{$crslist[$i]}.'"';
112: }
113: }
114: }
115: $course_list = '"'.join('","',@crslist).'"';
116: $$numcrs = @crslist;
117:
118: $$javascript = qq#
119:
120: function checkCourse() {
121: courseID_array = new Array($course_list)
122: courseTitle_array = new Array($title_list)
123: var step2Form = document.forms.pickoptions
124: var conditionType = step2Form.conditions.value
125: var curVal = step2Form.targetcourse.options[step2Form.targetcourse.selectedIndex].value
126: if (curVal == -1) {
127: if ( conditionType == 'both' ) {
128: if ( step2Form.board.checked == true || step2Form.users.checked == true ) {
129: setCourse(step2Form,'add')
130: }
131: }
132: if ( conditionType == 'users' ) {
133: if ( step2Form.users.checked == true ) {
134: setCourse(step2Form,'add')
135: }
136: }
137: if ( conditionType == 'board' ) {
138: if ( step2Form.board.checked == true ) {
139: setCourse(step2Form,'add')
140: }
141: }
142: }
143: else {
144: if ( conditionType == 'both' ) {
145: if ( step2Form.board.checked == false && step2Form.users.checked == false ) {
146: setCourse(step2Form,'clear')
147: }
148: }
149: if ( conditionType == 'users' ) {
150: if ( step2Form.users.checked == false ) {
151: setCourse(step2Form,'clear')
152: }
153: }
154: if ( conditionType == 'board' ) {
155: if ( step2Form.board.checked == false ) {
156: setCourse(step2Form,'clear')
157: }
158: }
159: }
160: }
161:
162: function setCourse(step2Form,call) {
163: step2Form.targetcourse.length = 0
164: if (call == 'add') {
165: step2Form.targetcourse.length = 0
166: step2Form.targetcourse.options[0] = new Option("Please Select","0",true,true)
167: for (var i=0; i<courseID_array.length; i++) {
168: step2Form.targetcourse.options[i+1] = new Option(courseTitle_array[i],courseID_array[i],false,false)
169: }
170: step2Form.targetcourse.selectedIndex = 0
171: }
172: else {
173: step2Form.targetcourse.options[0] = new Option("Not required","-1",true,true)
174: step2Form.targetcourse.selectedIndex = 0
175: }
176: }
177:
178:
179: function setOptions(caller,itemnum) {
180: var numCrs = $$numcrs
181: var opForm = document.forms.pickoptions
182: var menu = 1 + itemnum*2
183: opForm.elements[menu].length = 0
184: if (opForm.elements[itemnum*2].checked == true) {
185: if (caller == "board") {
186: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
187: opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
188: opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
189: opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
190: }
191: else {
192: if (caller == "users") {
193: opForm.elements[menu].length = 0
194: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
195: opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
196: opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
197: }
198: }
199: }
200: else {
201: opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
202: }
203: opForm.elements[menu].selectedIndex = 0
204: if (numCrs > 0) {
205: checkCourse()
206: }
207: }
208:
209: function verify(caller) {
210: var numCrs = $$numcrs
211: var opForm = document.forms.pickoptions
212: var totcheck = 0;
213: var totchg = 0;
214: for (var i=0; i<caller; i++) {
215: if (opForm.elements[2*i].checked == true) {
216: totcheck ++
217: if (opForm.elements[2*i].name == "board") {
218: if (opForm.elements[2*i+1].selectedIndex == 0) {
219: alert("You must select one of the additional options when importing Discussion Boards ")
220: return false
221: }
222: if (numCrs == 0) {
223: opForm.elements[2*i].checked = false
224: totchg ++
225: }
226: else {
227: if (opForm.targetcourse.selectedIndex == 0) {
228: alert("You must select a target course when importing Discussion Boards")
229: return false
230: }
231: }
232: }
233: if (opForm.elements[2*i].name == "users") {
234: if (opForm.elements[2*i+1].selectedIndex == 0) {
235: alert("You must select one of the additional options when importing Enrollment")
236: return false
237: }
238: if (numCrs == 0) {
239: opForm.elements[2*i].checked = false
240: totchg ++
241: }
242: else {
243: if (opForm.targetcourse.selectedIndex == 0) {
244: alert("You must select a target course when importing enrollment information")
245: return false
246: }
247: }
248: }
249: }
250: }
251: if (totcheck == 0) {
252: alert("You must check the Checkbox for at least one Content Type");
253: return false
254: }
255: return true
256: }
257:
258: function nextPage(caller) {
259: if (verify(caller)) {
260: document.forms.pickoptions.submit()
261: }
1.2 raeburn 262: }
263:
1.5 raeburn 264: #;
265:
266: }
1.1 raeburn 267:
1.5 raeburn 268: # ---------------------------------------------------------------- Jscript Three
269: sub jscript_three {
270: my $javascript = shift;
1.1 raeburn 271: }
272:
1.5 raeburn 273: # ---------------------------------------------------------------- Display One
274: sub display_one {
275: my ($r,$uname,$fn,$fullpath) = @_;
1.1 raeburn 276: $r->print(<<"END_OF_ONE");
277: <form name="dataForm" method="post">
278: <table border='0' bgcolor='#CCFFDD' cellspacing='0' cellpadding ='0' width='100%'>
279: <tr>
280: <td colspan='2'>
281: <table border='0' cellspacing='0' cellpadding='0'>
282: <tr>
283: <td colspan='2' align='left'>
284: </td>
285: </tr>
286: <tr bgcolor='#ccddaa'>
1.2 raeburn 287: <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>
1.1 raeburn 288: </td>
289: <td width='100%' align='left'>
1.2 raeburn 290: <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>
291: </font>
1.1 raeburn 292: </td>
293: </tr>
294: <tr>
295: <td colspan='2'> </td>
296: </tr>
297: <tr>
298: <td> </td>
299: <td>
300: <font face='Arial,Helvetica,sans-serif'>
1.2 raeburn 301: Please choose the CMS used to create your IMS content package.
302: <select name="source">
1.15 albertel 303: <option value='-1' selected="true">Please select</option>
304: <option value='bb5'>Blackboard 5</option>
305: <option value='bb6'>Blackboard 6</option>
306: <option value='angel'>ANGEL</option>
1.16 raeburn 307: <option value='webctce4'>WebCT 4 Campus Edition</option>
1.19 ! raeburn 308: <option value='webctvista4'>WebCT Vista 4</option>
1.2 raeburn 309: </select>
310: </font>
1.1 raeburn 311: </td>
312: </tr>
313: <tr>
314: <td colspan='2'> </td>
315: </tr>
316: <tr>
1.2 raeburn 317: <td colspan='2'> </td>
318: </tr>
319: <tr bgcolor='#ccddaa'>
320: <td valign='middle'><img src='/res/adm/pages/bl_step2.gif'>
321: </td>
322: <td width='100%' align='left'>
323: <font face='arial,helvetica,sans-serif'><b>Create a directory where you will unpack your IMS package.</b> </font></td>
324: </tr>
1.1 raeburn 325: <tr>
1.2 raeburn 326: <td colspan='2'> </td>
327: </tr>
1.1 raeburn 328: <td> </td>
329: <td>
330: <font face='Arial,Helvetica,sans-serif'>
1.15 albertel 331: Please choose a destination LON-CAPA directory in which to store the contents of the IMS package file. <input type="button" name="createdir" value="Create Directory" onClick="javascript:createWin()" /><input type="hidden" name="newdir" value="" /></font>
1.1 raeburn 332: </td>
333: </tr>
334: <tr>
1.2 raeburn 335: <td colspan='2'> <br /><br /></td>
1.1 raeburn 336: </tr>
1.5 raeburn 337: <tr>
338: <td> </td>
339: <td><font face='arial,helvetica,sans-serif'>If you have selected the CMS used to create the IMS package, and have created a destination directory, click the 'Proceed' button to continue the IMS package upload process.</font></td>
340: </tr>
341: <tr>
342: <td colspan='2'>
1.15 albertel 343: <input type="hidden" name="uploaduname" value="$uname" />
344: <input type="hidden" name="filename" value="$fn" />
345: <input type="hidden" name="phase" value="three" />
1.5 raeburn 346: </td>
347: </tr>
348: <tr>
349: <td colspan='2'> </td>
350: </tr>
351: <tr>
352: <td colspan='2'>
353: <table border='0' cellspacing='0' cellpadding='0' width="100%">
354: <tr>
355: <td align='left'>
1.15 albertel 356: <input type='button' name='exitpage' value='Exit now' onClick="javascript:location.href='$fullpath'" />
1.5 raeburn 357: </td>
358: <td align='right'>
1.15 albertel 359: <input type="button" name="nextpage" value="Proceed" onClick="javascript:nextPage()" />
1.5 raeburn 360: </td>
361: </tr>
362: </table>
363: </td>
364: </tr>
365: </table>
366: </td>
367: </tr>
368: </table>
369: </form>
370: END_OF_ONE
371: }
372:
373: # ---------------------------------------------------------------- Display Two
374: sub display_two {
375: my ($r,$zipupload,$areas,$areaname,$cmsmap,$uname,$newdir,$numcrs,$fullpath) = @_;
376: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
1.11 albertel 377: my $cms = $env{'form.source'};
378: my $dirname = $env{'form.newdir'};
1.5 raeburn 379: my $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$dirname,'');
380: my $fname = &Apache::imsprocessor::uploadzip('CSTR',$tempdir,$zipupload);
381: my $unzip_result = '';
382: my $manifest_result = '';
383: unless ($tempdir eq '') {
384: $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
385: }
386: my %resources = ();
1.9 raeburn 387: my %includedres = ();
388: my %includeditems = ();
1.5 raeburn 389: my %items = ();
390: my %hrefs = ();
391: my %resinfo = ();
392: my %count = ();
393: my @bgcolors = ("#eeeeee","#dddddd");
394:
395: my $counter = 0;
396: my $iter = 0;
397: my %count = (
398: announce => 0,
399: board => 0,
400: doc => 0,
401: extlink => 0,
402: msg => 0,
403: pool => 0,
404: quiz => 0,
405: staff => 0,
406: survey => 0,
407: users => 0,
408: );
409: my $conditions;
410:
411: if ($unzip_result eq 'ok') {
1.19 ! raeburn 412: $manifest_result = &Apache::imsprocessor::process_manifest($cms,
! 413: $tempdir,\%resources,\%items,\%hrefs,\%resinfo,
! 414: 'choose',\%includedres,\%includeditems);
1.5 raeburn 415: if ($manifest_result eq 'ok') {
416: foreach my $res (sort keys %resources) {
1.19 ! raeburn 417: if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4'
! 418: || $cms eq 'webctvista4') {
1.5 raeburn 419: foreach my $area (keys %{$$cmsmap{$cms}}) {
420: if ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
421: $count{$area} ++;
422: }
423: }
424: } elsif ($cms eq 'angel') {
425: foreach my $area (keys %{$$cmsmap{$cms}}) {
426: if ($area eq 'doc') {
427: if (grep/^$resources{$res}{type}$/,@{$$cmsmap{$cms}{doc}}) {
428: $count{$area} ++;
429: }
430: } elsif ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
431: $count{$area} ++;
432: }
433: }
434: }
435: }
436: if ($count{board} > 0) {
437: if ($count{users} > 0) {
438: $conditions = 'both';
439: } else {
440: $conditions = 'board';
441: }
442: } elsif ($count{users} > 0) {
443: $conditions = 'users';
444: } else {
445: $conditions = 'none';
446: }
447:
448: $r->print(<<ENDBLOCK);
449: <form name="pickoptions" method="post">
450: <table border='0' cellspacing='0' cellpadding ='0' width='100%'>
451: <tr>
452: <td colspan='2'>
453: <table border='0' cellspacing='0' cellpadding='0'>
454: <tr>
455: <td colspan='2' align='left'>
456: </td>
457: </tr>
1.1 raeburn 458: <tr bgcolor='#ccddaa'>
1.2 raeburn 459: <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>
1.1 raeburn 460: </td>
461: <td width='100%' align='left'>
1.5 raeburn 462: <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
1.1 raeburn 463: </td>
464: </tr>
465: <tr>
466: <td colspan='2'> </td>
467: </tr>
468: <tr>
469: <td> </td>
470: <td>
1.2 raeburn 471: <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
472: <tr>
473: <td>
474: <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
475: <tr>
476: <td>
1.5 raeburn 477: <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
1.2 raeburn 478: <tr bgcolor='#ccddaa'>
1.5 raeburn 479: <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>
480: <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
481: <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
1.2 raeburn 482: </tr>
1.5 raeburn 483: ENDBLOCK
484: foreach my $area (@{$areas}) {
485: if ($count{$area} > 0) {
486: my $count_tag = 'flag_'.$counter;
487: $r->print(" <tr bgcolor='@bgcolors[$iter]'>
488: <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
489: if ($area eq 'board' || $area eq 'users') {
490: $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
491: }
492: $r->print("/></font></td>
493: <td align='left'><font face='arial,helvetica,sans-serif'> $$areaname{$area} - $count{$area} item(s)</font></td>");
494: if ($area eq 'board') {
495: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
496: <select name='db_handling'>
1.15 albertel 497: <option value='-2'><-- Check Import first</option>
1.5 raeburn 498: </select></font>
499: </td>");
500: } elsif ($area eq 'users') {
501: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
502: <select name='user_handling'>
1.15 albertel 503: <option value='-2'><-- Check Import first</option>
1.2 raeburn 504: </select>
1.5 raeburn 505: </font>
506: </td>");
507: } else {
508: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'> None<input type='hidden' name='$count_tag' /></font></td>");
509: }
510: $counter ++;
511: $iter = $counter%2;
512: }
513: }
514: $r->print(<<ENDBLOCKTWO);
1.2 raeburn 515: </tr>
516: </table>
517: </td>
518: </tr>
519: </table>
520: </td>
521: </tr>
522: </table>
1.1 raeburn 523: </td>
524: </tr>
525: <tr>
1.5 raeburn 526: <td colspan='2' align='left'>
527: </td>
528: </tr>
529: ENDBLOCKTWO
530: if ($count{board} + $count{users} > 0) {
531: $r->print("
532: <tr bgcolor='#ccddaa'>
533: <td valign='middle'><img src='/res/adm/pages/bl_step4.gif'>
534: </td>
535: <td width='100%' align='left'>
536: <font face='arial,helvetica,sans-serif'><b>Choose a course to receive bulletin boards and user enrollment.</b></font>
537: </td>
538: </tr>
539: <tr>
540: <td colspan='2'> </td>
541: </tr>
542: ");
543: if ($$numcrs > 0) {
544: $r->print(" <tr>
545: <td> </td>
546: <td><font face='arial,helvetica,sans-serif'>A listing of possible course targets will be displayed if import of bulletin boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course.
547: <br /><br />
548: Choose course:
549: <select name='targetcourse'>
1.15 albertel 550: <option value='-1'>Not required</option>
1.5 raeburn 551: </select></font>
552: </td>
553: </tr>
554: ");
555: } else {
556: $r->print(" <tr>
557: <td> </td>
558: <td><font face='arial,helvetica,sans-serif'>You do not have active course coordinator status in any LON-CAPA courses currently, so bulletin boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3). If you wish to import bulletin boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload bulletin boards and/or enroll users.</font>
559: ");
560: }
561: }
562: $r->print(<<ENDBLOCK);
563: <tr>
1.2 raeburn 564: <td colspan='2'> <br /><br /></td>
1.1 raeburn 565: </tr>
566: <tr>
567: <td> </td>
1.5 raeburn 568: <td><font face='arial,helvetica,sans-serif'>Once you have checked the checkboxes for all areas you wish to import from the IMS package, and selected additional options (if available) you should click the 'Import package' button.</font></td>
1.1 raeburn 569: </tr>
570: <tr>
1.5 raeburn 571: <td colspan='2'>
1.11 albertel 572: <input type="hidden" name="newdir" value="$env{'form.newdir'}" />
1.5 raeburn 573: <input type="hidden" name="conditions" value="$conditions" />
574: <input type="hidden" name="source" value="$cms" />
575: <input type="hidden" name="tempdir" value="$tempdir" />
1.1 raeburn 576: <input type="hidden" name="uploaduname" value="$uname">
1.5 raeburn 577: <input type="hidden" name="filename" value="$fname">
578: <input type="hidden" name="phase" value="four" />
579: ENDBLOCK
580: if ($count{board} == 0) {
581: $r->print(' <input type="hidden" name="board" value="" />'."\n");
582: }
583: if ($count{users} == 0) {
584: $r->print(' <input type="hidden" name="users" value="" />'."\n");
585: }
586: $r->print(<<ENDDOCUMENT);
1.1 raeburn 587: </td>
588: </tr>
589: <tr>
590: <td colspan='2'>
591: <table border='0' cellspacing='0' cellpadding='0' width="100%">
592: <tr>
1.2 raeburn 593: <td align='left'>
1.15 albertel 594: <input type='button' name='exitpage' value='Exit now' onClick="javascript:location.href='$fullpath'" />
1.1 raeburn 595: </td>
596: <td align='right'>
1.15 albertel 597: <input type="button" name="nextpage" value="Import package" onClick="javascript:nextPage($counter)" />
1.1 raeburn 598: </td>
599: </tr>
600: </table>
601: </td>
602: </tr>
603: </table>
604: </td>
605: </tr>
606: </table>
1.5 raeburn 607: ENDDOCUMENT
608: } else {
609: $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");
1.2 raeburn 610: }
1.4 raeburn 611: } else {
1.5 raeburn 612: $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");
613: }
614: }
1.1 raeburn 615:
1.5 raeburn 616: # ---------------------------------------------------------------- Display Three
617: sub display_three {
618: my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$newdir) = @_;
619: my $crs = '';
620: my $cdom = '';
621: my $db_handling = '';
622: my $timenow = time;
623: my $announce_handling = 'ok';
1.11 albertel 624: my $cms = $env{'form.source'};
625: if ( defined($env{'form.bb_crs'}) ) {
626: ($cdom,$crs) = split/\//,$env{'form.bb_crs'};
1.4 raeburn 627: }
1.5 raeburn 628: my $user_crs = '';
629: my $user_cdom = '';
630: my $user_handling = '';
1.11 albertel 631: if ( defined($env{'form.user_crs'}) ) {
632: ($user_cdom,$user_crs) = split/\//,$env{'form.user_crs'};
1.5 raeburn 633: }
634: my $seqstem = "/res/$udom/$uname/$newdir";
1.9 raeburn 635: my %importareas = ();
636: my %includedres = ();
637: my %includeditems = ();
1.10 raeburn 638: my %randompicks = ();
1.5 raeburn 639: my @targets = ();
640: my %resources = ();
641: my %items = ();
642: my %hrefs = ();
643: my %urls = ();
644: my %resinfo = ();
645: my %total = (
646: page => 0,
647: prob => 0,
648: seq => 0,
649: board => 0,
650: quiz => 0,
651: surv => 0,
652: );
653:
654: my @pages = ();
655: my @sequences = ();
656: my @resrcfiles = ();
1.19 ! raeburn 657: my @assessmentfiles = ();
1.5 raeburn 658:
1.11 albertel 659: my $tempdir = $env{'form.tempdir'};
1.5 raeburn 660:
661: foreach my $area (@{$areas}) {
1.11 albertel 662: if (defined($env{"form.$area"}) ) {
1.5 raeburn 663: if ($cms eq 'angel' && $area eq 'doc') {
664: foreach (@{$$cmsmap{$cms}{$area}}) {
1.9 raeburn 665: $importareas{$_} = 1;
1.1 raeburn 666: }
1.5 raeburn 667: } else {
1.9 raeburn 668: $importareas{$$cmsmap{$cms}{$area}} = 1;
1.2 raeburn 669: }
1.5 raeburn 670: if ($area eq 'board') {
1.11 albertel 671: $db_handling = $env{'form.db_handling'};
1.5 raeburn 672: } elsif ($area eq 'users') {
1.11 albertel 673: $user_handling = $env{'form.user_handling'};
1.4 raeburn 674: }
1.1 raeburn 675: }
676: }
1.9 raeburn 677:
1.19 ! raeburn 678: my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
! 679: \%resources,\%items,\%hrefs,\%resinfo,'prepare',
! 680: \%includedres);
1.9 raeburn 681: if ($manifest_result eq 'ok') {
682: foreach my $res (sort keys %resources) {
683: if ($importareas{$resources{$res}{type}}) {
684: $includedres{$res} = 1;
1.19 ! raeburn 685: if ($resources{$res}{type} eq 'webct.manifest' ||
! 686: $resources{$res}{type} eq 'webct.assessment' ||
! 687: $resources{$res}{type} eq 'webct.question') {
! 688: push(@assessmentfiles,$res);
! 689: }
1.9 raeburn 690: }
691: }
692: foreach my $itm (sort keys %items) {
693: &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
694: }
695: }
696:
697: foreach my $itm (sort keys %includeditems) {
698: &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
699: }
700:
1.19 ! raeburn 701: $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
! 702: \%resources,\%items,\%hrefs,\%resinfo,'build',
! 703: \%includedres,\%includeditems);
1.5 raeburn 704: if ($manifest_result eq 'ok') {
1.9 raeburn 705: &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
1.5 raeburn 706:
707: my @boards = ();
708: my @announcements = ();
709: my @quizzes = ();
710: my @surveys = ();
1.9 raeburn 711: my @pools = ();
1.5 raeburn 712: my @groups = ();
713: my %messages = ();
714: my @timestamp = ();
715: my %boardnum = ();
716: my @topurls = ();
717: my @topnames = ();
1.7 raeburn 718: my @packages = ();
1.5 raeburn 719:
1.10 raeburn 720: &Apache::imsprocessor::process_resinfo($cms,'CSTR',$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,\%randompicks);
1.7 raeburn 721:
1.19 ! raeburn 722: my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas,\@assessmentfiles);
1.5 raeburn 723:
1.10 raeburn 724: &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks);
1.5 raeburn 725:
1.9 raeburn 726: $r->print("<h3>IMS import completed</h3>");
1.5 raeburn 727:
728: if ($cms eq 'bb5') {
729: $r->print("<font face='arial,helvetica,sans-serif'>Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, $total{board} bulletin boards, $total{quiz} quizzes, $total{surv} surveys and $total{prob} problems have been created.<br /><br />\n");
730: } elsif ($cms eq 'angel') {
731: $r->print("<font face='arial,helvetica,sans-serif'>Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, and $total{board} bulletin boards have been created.<br /><br />\n");
732: }
1.10 raeburn 733: $r->print("Please view the imported items and use the LON-CAPA editing tools to make changes. The sequences directory contains a file named 'Top.sequence' which includes links to the items found at the top level of your IMS package. From there you can follow links to display all the imported items. Alternatively, you can browse the pages, sequences, problems and resfiles directories directly. Note if you rename a file, you will need to modify any .sequence files or .page files which include a reference to the renamed file.<br /><br />The final step in the IMS import process is to publish the materials you have imported into your Construction Space so that you can use them in a course. Once your file are published, subsequent re-publication will result in the storage of information about changes between the different versions.<br /><br /><a href='/priv/".$uname."/".$newdir."'>Display new directory</a></font>");
1.9 raeburn 734: if ($destdir =~ m-^/home/$uname/public_html/-) {
735: system (" rm -r -f $destdir/temp");
736: }
1.5 raeburn 737: } elsif ($manifest_result eq 'nomanifest') {
1.9 raeburn 738: $r->print("<font face='arial,helvetica,sans-serif'>Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file.</font>");
1.4 raeburn 739: }
1.5 raeburn 740: }
741:
742: # ---------------------------------------------------------------- Get LON-CAPA Course Coordinator roles for this user
743: sub get_ccroles {
744: my ($user,$dom,$crsentry,$crslist) = @_;
745: my %roles = ();
746: unless ($user eq '') {
747: %roles = &Apache::lonnet::dump('roles',$dom,$user);
1.4 raeburn 748: }
1.5 raeburn 749: my $iter = 0;
750: my @codes = ();
751: my %courses = ();
752: my @crslist = ();
753: my %descrip =();
754: foreach my $key (keys %roles ) {
755: if ($key =~ m/^\/(\w+)\/(\w+)_cc$/) {
756: my $cdom = $1;
757: my $crs = $2;
758: my $role_end = 0;
759: my $role_start = 0;
760: my $active_chk = 1;
761: if ( $roles{$key} =~ m/^cc_(\d+)/ ) {
762: $role_end = $1;
763: if ( $roles{$key} =~ m/^cc_($role_end)_(\d+)$/ )
764: {
765: $role_start = $2;
766: }
767: }
768: if ($role_start > 0) {
769: if (time < $role_start) {
770: $active_chk = 0;
1.1 raeburn 771: }
1.5 raeburn 772: }
773: if ($role_end > 0) {
774: if (time > $role_end) {
775: $active_chk = 0;
1.1 raeburn 776: }
777: }
1.5 raeburn 778: if ($active_chk) {
779: my $currcode = '';
780: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','description'],$cdom,$crs);
781: if (defined($settings{'description'}) ) {
782: $descrip{$crs} = $settings{'description'};
1.1 raeburn 783: } else {
1.5 raeburn 784: $descrip{$crs} = 'Unknown';
1.1 raeburn 785: }
1.5 raeburn 786: if (defined($settings{'internal.coursecode'}) ) {
787: $currcode = $settings{'internal.coursecode'};
788: if ($currcode eq '') {
789: $currcode = "____".$iter;
790: $iter ++;
1.1 raeburn 791: }
792: } else {
1.5 raeburn 793: $currcode = "____".$iter;
794: $iter ++;
795: }
796: unless (grep/^$currcode$/,@codes) {
797: push @codes,$currcode;
798: @{$courses{$currcode}} = ();
1.1 raeburn 799: }
1.5 raeburn 800: push @{$courses{$currcode}}, $cdom.'/'.$crs;
1.1 raeburn 801: }
1.5 raeburn 802: }
803: }
804: foreach my $code (sort @codes) {
805: foreach my $crsdom (@{$courses{$code}}) {
1.2 raeburn 806: my ($cdom,$crs) = split/\//,$crsdom;
807: my $showcode = '';
808: unless ($code =~m/^____\d+$/) { $showcode = $code; }
809: $$crsentry{$crsdom} = $showcode.':'.$descrip{$crs};
1.5 raeburn 810: push @{$crslist}, $crsdom;
1.2 raeburn 811: }
812: }
1.5 raeburn 813: return;
1.2 raeburn 814: }
1.1 raeburn 815:
816: # ---------------------------------------------------------------- Main Handler
817: sub handler {
818: my $r=shift;
819: my $uname;
820: my $udom;
821: my $javascript = '';
822: my $page_name = '';
823: my $current_page = '';
824: my $loadentries = '';
825: my $qcount = '';
1.5 raeburn 826:
827: # get personal information for this user
1.11 albertel 828: my $user=$env{'user.name'};
829: my $dom=$env{'user.domain'};
1.5 raeburn 830:
1.1 raeburn 831: #
1.5 raeburn 832: # re-attach user
1.1 raeburn 833: #
1.11 albertel 834: if ($env{'form.uploaduname'}) {
835: $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
836: $env{'form.filename'};
1.1 raeburn 837: }
838: ($uname,$udom)=
1.11 albertel 839: &Apache::loncacc::constructaccess($env{'form.filename'},
1.1 raeburn 840: $r->dir_config('lonDefDomain'));
841: unless (($uname) && ($udom)) {
842: $r->log_reason($uname.' at '.$udom.
1.11 albertel 843: ' trying to publish file '.$env{'form.filename'}.
1.1 raeburn 844: ' - not authorized',
845: $r->filename);
846: return HTTP_NOT_ACCEPTABLE;
847: }
848:
849: my $fn;
1.11 albertel 850: if ($env{'form.filename'}) {
851: $fn=$env{'form.filename'};
1.1 raeburn 852: $fn=~s/^http\:\/\/[^\/]+\///;
853: $fn=~s/^\///;
854: $fn=~s/(\~|priv\/)(\w+)//;
855: $fn=~s/\/+/\//g;
856: } else {
1.11 albertel 857: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.1 raeburn 858: ' unspecified filename for upload', $r->filename);
859: return HTTP_NOT_FOUND;
860: }
1.5 raeburn 861: my $zipupload = '/home/'.$uname.'/public_html'.$fn;
1.1 raeburn 862: my $pathname = &File::Basename::dirname($fn);
863: my $fullpath = '/priv/'.$uname.$pathname;
864: unless ($pathname eq '/') {
865: $fullpath .= '/';
866: }
867: my $loadentries = '';
1.5 raeburn 868:
869: my @areas = ();
870: my %cmsmap = ();
871: my %areaname = ();
872: my $numcrs = 0;
873:
874: &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
1.1 raeburn 875: # ----------------------------------------------------------- Start page output
876: &Apache::loncommon::content_type($r,'text/html');
877: $r->send_http_header;
1.5 raeburn 878:
1.11 albertel 879: if ($env{'form.phase'} eq 'two') {
1.5 raeburn 880: &jscript_one($fullpath,\$javascript,$uname,$udom);
1.11 albertel 881: } elsif ($env{'form.phase'} eq 'three') {
1.5 raeburn 882: &jscript_two(\$javascript,$user,$dom,\$numcrs);
1.11 albertel 883: } elsif ($env{'form.phase'} eq 'four') {
1.5 raeburn 884: &jscript_three(\$javascript);
1.1 raeburn 885: }
1.14 albertel 886: $javascript = "<script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n";
887:
888: my $title = 'Upload IMS package to Construction Space';
889: $r->print(&Apache::loncommon::start_page($title, $javascript,
890: {'add_entries' =>
891: $loadentries,}));
892:
1.11 albertel 893: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1 raeburn 894: $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
895: &mt(' at ').$udom.'</font></h3>');
1.5 raeburn 896: }
1.11 albertel 897: if ($env{'form.phase'} eq 'two') {
1.1 raeburn 898: my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport');
899: if ($flag eq 'ok') {
1.5 raeburn 900: &display_one($r,$uname,$fn,$fullpath);
901: }
1.11 albertel 902: } elsif ( ($env{'form.phase'} eq 'three') || ($env{'form.phase'} eq 'four') ) {
903: my $docroot = $env{'form.newdir'};
1.5 raeburn 904: my $newdir = '';
905: if ($docroot =~ m|public_html/(.+)$|) {
906: $newdir = $1;
907: }
1.11 albertel 908: if ($env{'form.phase'} eq 'three') {
1.5 raeburn 909: &display_two ($r,$zipupload,\@areas,\%areaname,\%cmsmap,$uname,$newdir,\$numcrs,$fullpath);
1.11 albertel 910: } elsif ($env{'form.phase'} eq 'four') {
1.5 raeburn 911: &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir);
1.1 raeburn 912: }
913: } else {
914: &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'imsimport');
915: }
1.14 albertel 916: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 917: return OK;
918: }
919: 1;
920: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>