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