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