Annotation of loncom/imspackages/imsimport.pm, revision 1.8
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.7 raeburn 296: <option value='bb6'>Blackboard 6
1.2 raeburn 297: <option value='bb5'>Blackboard 5
298: <option value='angel'>ANGEL
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']);
367: my $cms = $ENV{'form.source'};
368: my $dirname = $ENV{'form.newdir'};
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 = ();
377: my %items = ();
378: my %hrefs = ();
379: my %resinfo = ();
380: my %count = ();
381: my @bgcolors = ("#eeeeee","#dddddd");
382:
383: my $counter = 0;
384: my $iter = 0;
385: my %count = (
386: announce => 0,
387: board => 0,
388: doc => 0,
389: extlink => 0,
390: msg => 0,
391: pool => 0,
392: quiz => 0,
393: staff => 0,
394: survey => 0,
395: users => 0,
396: );
397: my $conditions;
398:
399: if ($unzip_result eq 'ok') {
400: $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
401: if ($manifest_result eq 'ok') {
402: foreach my $res (sort keys %resources) {
1.7 raeburn 403: if ($cms eq 'bb5' || $cms eq 'bb6') {
1.5 raeburn 404: foreach my $area (keys %{$$cmsmap{$cms}}) {
405: if ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
406: $count{$area} ++;
407: }
408: }
409: } elsif ($cms eq 'angel') {
410: foreach my $area (keys %{$$cmsmap{$cms}}) {
411: if ($area eq 'doc') {
412: if (grep/^$resources{$res}{type}$/,@{$$cmsmap{$cms}{doc}}) {
413: $count{$area} ++;
414: }
415: } elsif ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
416: $count{$area} ++;
417: }
418: }
419: }
420: }
421: if ($count{board} > 0) {
422: if ($count{users} > 0) {
423: $conditions = 'both';
424: } else {
425: $conditions = 'board';
426: }
427: } elsif ($count{users} > 0) {
428: $conditions = 'users';
429: } else {
430: $conditions = 'none';
431: }
432:
433: $r->print(<<ENDBLOCK);
434: <form name="pickoptions" method="post">
435: <table border='0' cellspacing='0' cellpadding ='0' width='100%'>
436: <tr>
437: <td colspan='2'>
438: <table border='0' cellspacing='0' cellpadding='0'>
439: <tr>
440: <td colspan='2' align='left'>
441: </td>
442: </tr>
1.1 raeburn 443: <tr bgcolor='#ccddaa'>
1.2 raeburn 444: <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>
1.1 raeburn 445: </td>
446: <td width='100%' align='left'>
1.5 raeburn 447: <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
1.1 raeburn 448: </td>
449: </tr>
450: <tr>
451: <td colspan='2'> </td>
452: </tr>
453: <tr>
454: <td> </td>
455: <td>
1.2 raeburn 456: <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
457: <tr>
458: <td>
459: <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
460: <tr>
461: <td>
1.5 raeburn 462: <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
1.2 raeburn 463: <tr bgcolor='#ccddaa'>
1.5 raeburn 464: <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>
465: <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
466: <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
1.2 raeburn 467: </tr>
1.5 raeburn 468: ENDBLOCK
469: foreach my $area (@{$areas}) {
470: if ($count{$area} > 0) {
471: my $count_tag = 'flag_'.$counter;
472: $r->print(" <tr bgcolor='@bgcolors[$iter]'>
473: <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
474: if ($area eq 'board' || $area eq 'users') {
475: $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
476: }
477: $r->print("/></font></td>
478: <td align='left'><font face='arial,helvetica,sans-serif'> $$areaname{$area} - $count{$area} item(s)</font></td>");
479: if ($area eq 'board') {
480: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
481: <select name='db_handling'>
482: <option value='-2'><-- Check Import first
483: </select></font>
484: </td>");
485: } elsif ($area eq 'users') {
486: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'>
487: <select name='user_handling'>
488: <option value='-2'><-- Check Import first
1.2 raeburn 489: </select>
1.5 raeburn 490: </font>
491: </td>");
492: } else {
493: $r->print(" <td align='left'><font face='arial,helvetica,sans-serif'> None<input type='hidden' name='$count_tag' /></font></td>");
494: }
495: $counter ++;
496: $iter = $counter%2;
497: }
498: }
499: $r->print(<<ENDBLOCKTWO);
1.2 raeburn 500: </tr>
501: </table>
502: </td>
503: </tr>
504: </table>
505: </td>
506: </tr>
507: </table>
1.1 raeburn 508: </td>
509: </tr>
510: <tr>
1.5 raeburn 511: <td colspan='2' align='left'>
512: </td>
513: </tr>
514: ENDBLOCKTWO
515: if ($count{board} + $count{users} > 0) {
516: $r->print("
517: <tr bgcolor='#ccddaa'>
518: <td valign='middle'><img src='/res/adm/pages/bl_step4.gif'>
519: </td>
520: <td width='100%' align='left'>
521: <font face='arial,helvetica,sans-serif'><b>Choose a course to receive bulletin boards and user enrollment.</b></font>
522: </td>
523: </tr>
524: <tr>
525: <td colspan='2'> </td>
526: </tr>
527: ");
528: if ($$numcrs > 0) {
529: $r->print(" <tr>
530: <td> </td>
531: <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.
532: <br /><br />
533: Choose course:
534: <select name='targetcourse'>
535: <option value='-1'>Not required
536: </select></font>
537: </td>
538: </tr>
539: ");
540: } else {
541: $r->print(" <tr>
542: <td> </td>
543: <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>
544: ");
545: }
546: }
547: $r->print(<<ENDBLOCK);
548: <tr>
1.2 raeburn 549: <td colspan='2'> <br /><br /></td>
1.1 raeburn 550: </tr>
551: <tr>
552: <td> </td>
1.5 raeburn 553: <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 554: </tr>
555: <tr>
1.5 raeburn 556: <td colspan='2'>
557: <input type="hidden" name="newdir" value="$ENV{'form.newdir'}" />
558: <input type="hidden" name="conditions" value="$conditions" />
559: <input type="hidden" name="source" value="$cms" />
560: <input type="hidden" name="tempdir" value="$tempdir" />
1.1 raeburn 561: <input type="hidden" name="uploaduname" value="$uname">
1.5 raeburn 562: <input type="hidden" name="filename" value="$fname">
563: <input type="hidden" name="phase" value="four" />
564: ENDBLOCK
565: if ($count{board} == 0) {
566: $r->print(' <input type="hidden" name="board" value="" />'."\n");
567: }
568: if ($count{users} == 0) {
569: $r->print(' <input type="hidden" name="users" value="" />'."\n");
570: }
571: $r->print(<<ENDDOCUMENT);
1.1 raeburn 572: </td>
573: </tr>
574: <tr>
575: <td colspan='2'>
576: <table border='0' cellspacing='0' cellpadding='0' width="100%">
577: <tr>
1.2 raeburn 578: <td align='left'>
579: <input type='button' name='exitpage' value='Exit now' onClick="javascript:location.href='$fullpath'">
1.1 raeburn 580: </td>
581: <td align='right'>
1.5 raeburn 582: <input type="button" name="nextpage" value="Import package" onClick="javascript:nextPage($counter)">
1.1 raeburn 583: </td>
584: </tr>
585: </table>
586: </td>
587: </tr>
588: </table>
589: </td>
590: </tr>
591: </table>
1.5 raeburn 592: ENDDOCUMENT
593: } else {
594: $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");
1.2 raeburn 595: }
1.4 raeburn 596: } else {
1.5 raeburn 597: $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");
598: }
599: }
1.1 raeburn 600:
1.5 raeburn 601: # ---------------------------------------------------------------- Display Three
602: sub display_three {
603: my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$newdir) = @_;
604: my $crs = '';
605: my $cdom = '';
606: my $chome = '';
607: my $db_handling = '';
608: my $timenow = time;
609: my $announce_handling = 'ok';
610: my $cms = $ENV{'form.source'};
611: if ( defined($ENV{'form.bb_crs'}) ) {
612: ($cdom,$crs) = split/\//,$ENV{'form.bb_crs'};
613: $chome = &Apache::lonnet::homeserver($crs,$cdom);
1.4 raeburn 614: }
1.5 raeburn 615: if ( defined($ENV{'form.bb_handling'}) ) {
616: $db_handling = $ENV{'form.bb_handling'};
617: }
618: my $user_crs = '';
619: my $user_cdom = '';
620: my $user_handling = '';
621: if ( defined($ENV{'form.user_crs'}) ) {
622: ($user_cdom,$user_crs) = split/\//,$ENV{'form.user_crs'};
623: }
624: if ( defined($ENV{'form.user_handling'}) ) {
625: $user_handling = $ENV{'form.user_handling'};
626: }
627: my $seqstem = "/res/$udom/$uname/$newdir";
628: my %imports = ();
629: my @targets = ();
630: my %resources = ();
631: my %items = ();
632: my %hrefs = ();
633: my %urls = ();
634: my %resinfo = ();
635: my %total = (
636: page => 0,
637: prob => 0,
638: seq => 0,
639: board => 0,
640: quiz => 0,
641: surv => 0,
642: );
643:
644: my @pages = ();
645: my @sequences = ();
646: my @resrcfiles = ();
647:
648: my $tempdir = $ENV{'form.tempdir'};
649:
650: foreach my $area (@{$areas}) {
651: if (defined($ENV{"form.$area"}) ) {
652: if ($cms eq 'angel' && $area eq 'doc') {
653: foreach (@{$$cmsmap{$cms}{$area}}) {
654: $imports{$_} = 1;
1.1 raeburn 655: }
1.5 raeburn 656: } else {
657: $imports{$$cmsmap{$cms}{$area}} = 1;
1.2 raeburn 658: }
1.5 raeburn 659: if ($area eq 'board') {
660: $db_handling = $ENV{'form.db_handling'};
661: } elsif ($area eq 'users') {
662: $user_handling = $ENV{'form.user_handling'};
1.4 raeburn 663: }
1.1 raeburn 664: }
665: }
1.5 raeburn 666: my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
667: if ($manifest_result eq 'ok') {
668: &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
669:
670: my @boards = ();
671: my @announcements = ();
672: my @quizzes = ();
673: my @surveys = ();
674: my @groups = ();
675: my %messages = ();
676: my @timestamp = ();
677: my %boardnum = ();
678: my @topurls = ();
679: my @topnames = ();
1.7 raeburn 680: my @packages = ();
1.5 raeburn 681:
1.8 ! raeburn 682: &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$newdir,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
1.7 raeburn 683:
684: my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow);
1.5 raeburn 685:
1.7 raeburn 686: &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages);
1.5 raeburn 687:
688: $r->print("<h3>Step 3: Publish your new LON-CAPA materials</h3>");
689:
690: if ($cms eq 'bb5') {
691: $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");
692: } elsif ($cms eq 'angel') {
693: $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");
694: }
695: # system (" rm -r -f $destdir/temp");
696: } elsif ($manifest_result eq 'nomanifest') {
697: $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 .");
1.4 raeburn 698: }
1.5 raeburn 699: }
700:
701: # ---------------------------------------------------------------- Get LON-CAPA Course Coordinator roles for this user
702: sub get_ccroles {
703: my ($user,$dom,$crsentry,$crslist) = @_;
704: my %roles = ();
705: unless ($user eq '') {
706: %roles = &Apache::lonnet::dump('roles',$dom,$user);
1.4 raeburn 707: }
1.5 raeburn 708: my $iter = 0;
709: my @codes = ();
710: my %courses = ();
711: my @crslist = ();
712: my %descrip =();
713: foreach my $key (keys %roles ) {
714: if ($key =~ m/^\/(\w+)\/(\w+)_cc$/) {
715: my $cdom = $1;
716: my $crs = $2;
717: my $role_end = 0;
718: my $role_start = 0;
719: my $active_chk = 1;
720: if ( $roles{$key} =~ m/^cc_(\d+)/ ) {
721: $role_end = $1;
722: if ( $roles{$key} =~ m/^cc_($role_end)_(\d+)$/ )
723: {
724: $role_start = $2;
725: }
726: }
727: if ($role_start > 0) {
728: if (time < $role_start) {
729: $active_chk = 0;
1.1 raeburn 730: }
1.5 raeburn 731: }
732: if ($role_end > 0) {
733: if (time > $role_end) {
734: $active_chk = 0;
1.1 raeburn 735: }
736: }
1.5 raeburn 737: if ($active_chk) {
738: my $currcode = '';
739: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','description'],$cdom,$crs);
740: if (defined($settings{'description'}) ) {
741: $descrip{$crs} = $settings{'description'};
1.1 raeburn 742: } else {
1.5 raeburn 743: $descrip{$crs} = 'Unknown';
1.1 raeburn 744: }
1.5 raeburn 745: if (defined($settings{'internal.coursecode'}) ) {
746: $currcode = $settings{'internal.coursecode'};
747: if ($currcode eq '') {
748: $currcode = "____".$iter;
749: $iter ++;
1.1 raeburn 750: }
751: } else {
1.5 raeburn 752: $currcode = "____".$iter;
753: $iter ++;
754: }
755: unless (grep/^$currcode$/,@codes) {
756: push @codes,$currcode;
757: @{$courses{$currcode}} = ();
1.1 raeburn 758: }
1.5 raeburn 759: push @{$courses{$currcode}}, $cdom.'/'.$crs;
1.1 raeburn 760: }
1.5 raeburn 761: }
762: }
763: foreach my $code (sort @codes) {
764: foreach my $crsdom (@{$courses{$code}}) {
1.2 raeburn 765: my ($cdom,$crs) = split/\//,$crsdom;
766: my $showcode = '';
767: unless ($code =~m/^____\d+$/) { $showcode = $code; }
768: $$crsentry{$crsdom} = $showcode.':'.$descrip{$crs};
1.5 raeburn 769: push @{$crslist}, $crsdom;
1.2 raeburn 770: }
771: }
1.5 raeburn 772: return;
1.2 raeburn 773: }
1.1 raeburn 774:
775: # ---------------------------------------------------------------- Main Handler
776: sub handler {
777: my $r=shift;
778: my $uname;
779: my $udom;
780: my $javascript = '';
781: my $page_name = '';
782: my $current_page = '';
783: my $loadentries = '';
784: my $qcount = '';
1.5 raeburn 785:
786: # get personal information for this user
787: my $user=$ENV{'user.name'};
788: my $dom=$ENV{'user.domain'};
789:
1.1 raeburn 790: #
1.5 raeburn 791: # re-attach user
1.1 raeburn 792: #
793: if ($ENV{'form.uploaduname'}) {
794: $ENV{'form.filename'}='/priv/'.$ENV{'form.uploaduname'}.'/'.
795: $ENV{'form.filename'};
796: }
797: ($uname,$udom)=
798: &Apache::loncacc::constructaccess($ENV{'form.filename'},
799: $r->dir_config('lonDefDomain'));
800: unless (($uname) && ($udom)) {
801: $r->log_reason($uname.' at '.$udom.
802: ' trying to publish file '.$ENV{'form.filename'}.
803: ' - not authorized',
804: $r->filename);
805: return HTTP_NOT_ACCEPTABLE;
806: }
807:
808: my $fn;
809: if ($ENV{'form.filename'}) {
810: $fn=$ENV{'form.filename'};
811: $fn=~s/^http\:\/\/[^\/]+\///;
812: $fn=~s/^\///;
813: $fn=~s/(\~|priv\/)(\w+)//;
814: $fn=~s/\/+/\//g;
815: } else {
816: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
817: ' unspecified filename for upload', $r->filename);
818: return HTTP_NOT_FOUND;
819: }
1.5 raeburn 820: my $zipupload = '/home/'.$uname.'/public_html'.$fn;
1.1 raeburn 821: my $pathname = &File::Basename::dirname($fn);
822: my $fullpath = '/priv/'.$uname.$pathname;
823: unless ($pathname eq '/') {
824: $fullpath .= '/';
825: }
826: my $loadentries = '';
1.5 raeburn 827:
828: my @areas = ();
829: my %cmsmap = ();
830: my %areaname = ();
831: my $numcrs = 0;
832:
833: &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
1.1 raeburn 834: # ----------------------------------------------------------- Start page output
835: &Apache::loncommon::content_type($r,'text/html');
836: $r->send_http_header;
1.5 raeburn 837:
838: if ($ENV{'form.phase'} eq 'two') {
839: &jscript_one($fullpath,\$javascript,$uname,$udom);
840: } elsif ($ENV{'form.phase'} eq 'three') {
841: &jscript_two(\$javascript,$user,$dom,\$numcrs);
842: } elsif ($ENV{'form.phase'} eq 'four') {
843: &jscript_three(\$javascript);
1.1 raeburn 844: }
845: $r->print("<html><head><title>LON-CAPA Construction Space</title><script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n</head>");
846:
847: $r->print(&Apache::loncommon::bodytag('Upload IMS package to Construction Space',undef,$loadentries));
848:
849: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
850: $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
851: &mt(' at ').$udom.'</font></h3>');
1.5 raeburn 852: }
853: if ($ENV{'form.phase'} eq 'two') {
1.1 raeburn 854: my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport');
855: if ($flag eq 'ok') {
1.5 raeburn 856: &display_one($r,$uname,$fn,$fullpath);
857: }
858: } elsif ( ($ENV{'form.phase'} eq 'three') || ($ENV{'form.phase'} eq 'four') ) {
859: my $docroot = $ENV{'form.newdir'};
860: my $newdir = '';
861: if ($docroot =~ m|public_html/(.+)$|) {
862: $newdir = $1;
863: }
864: if ($ENV{'form.phase'} eq 'three') {
865: &display_two ($r,$zipupload,\@areas,\%areaname,\%cmsmap,$uname,$newdir,\$numcrs,$fullpath);
866: } elsif ($ENV{'form.phase'} eq 'four') {
867: &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir);
1.1 raeburn 868: }
869: } else {
870: &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'imsimport');
871: }
872: $r->print('</body></html>');
873: return OK;
874: }
875: 1;
876: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>