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