Last active
August 29, 2015 14:07
-
-
Save dangtrinhnt/0ed782205e34ee72e8af to your computer and use it in GitHub Desktop.
Create parent account in PowerSchool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once("PSSSOSettings.php"); | |
| function mySSOErrorHandler($errno, $errstr, $errfile, $errline) | |
| { | |
| if (!(error_reporting() & $errno)) { | |
| // This error code is not included in error_reporting | |
| return; | |
| } | |
| $GLOBALS["ErrorMessage"] .= "Line ".$errline." in ".$errfile."\n"; | |
| $GLOBALS["ErrorMessage"] .= "(".$errno.") ".$errstr."\n\n"; | |
| /* Don't execute PHP internal error handler */ | |
| return false; | |
| } | |
| // fetch a list of parents accounts from external database then call this function to sync | |
| // with PowerSchool | |
| function SSOSync($Username, $Password, $LastName, $FirstName, $EmailAddress, $FamilyID, $Guardianship, $PSUsername, $PSPassword) { | |
| // Creates guardian accounts (if not already exist) | |
| date_default_timezone_set('Asia/Ho_Chi_Minh'); | |
| $old_error_handler = set_error_handler("mySSOErrorHandler"); | |
| $SyncCompleted = false; | |
| $ErrorMessage = ""; | |
| $Datadump = $FamilyID; | |
| global $NotificationEmail, $FromEmail, $PowerschoolErrorString, $PowerschoolErrorString1, $PowerschoolErrorString2, $PowerschoolConnectedString, $OracleListener, $OracleUsername, $OraclePassword, $PowerschoolDomainName; | |
| if ($FamilyID == "") { | |
| echo "SSOSync cURL error - ".$FamilyID . " - FamilyID not provided.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "FamilyID not provided.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return; | |
| } | |
| // check if the guardian account is already existed in the school parent db | |
| // Sheldon used Microsoft SQL Database here | |
| // this database's used to sync with LDAP | |
| // http://www.php.net/manual/en/function.sqlsrv-fetch-array.php | |
| // I don't need it for now | |
| //~ $mssqlstmt = "select * from parents where username = '" . $Username . "' and familyid = '" . $FamilyID . "'"; | |
| //~ while($mssqlrow = sqlsrv_fetch_array($mssqlstmt)) { | |
| //~ $Guardian = Array | |
| //~ ( | |
| //~ "USERNAME" => $Username, | |
| //~ "PASSWORD" => $Password, | |
| //~ "LASTNAME" => $LastName, | |
| //~ "FIRSTNAME" => $FirstName, | |
| //~ "EMAIL" => $EmailAddress | |
| //~ ); | |
| //~ } | |
| // create the guardian dictionary | |
| $Guardian = Array ( | |
| "USERNAME" => $Username, | |
| "PASSWORD" => $Password, | |
| "LASTNAME" => $LastName, | |
| "FIRSTNAME" => $FirstName, | |
| "EMAIL" => $EmailAddress | |
| ); | |
| echo "=> Trying to connect to the Oracle Database\n"; | |
| $conn = oci_connect($OracleUsername, $OraclePassword, $OracleListener); | |
| if (!$conn) { | |
| $e = oci_error(); | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot connect to Oracle.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot connect to Oracle.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR); | |
| } | |
| echo "=> See if SSO parent account already exists\n"; | |
| $sql = "select a.pcas_accounttoken | |
| from pcas_account a inner join pcas_emailcontact e on a.pcas_accountid = e.pcas_accountid | |
| where a.username = '".strtolower($Guardian["USERNAME"])."'"; | |
| $stmt = oci_parse($conn,$sql); | |
| oci_execute($stmt); | |
| $row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS); | |
| $Guardian["ParentID"] = $row["PCAS_ACCOUNTTOKEN"]; | |
| // ParentID is something like 'gkKTU+3aBg6b9MAcHnBgLg==' | |
| echo "=> Get already linked student list\n"; | |
| // and add those students to the remove list | |
| $sql = "select distinct gs.studentsdcid | |
| from guardian g inner join guardianstudent gs on g.guardianid = gs.guardianid | |
| where g.accountidentifier = '".$Guardian["ParentID"]."'"; | |
| $stmt = oci_parse($conn,$sql); | |
| oci_execute($stmt); | |
| $Students = ""; | |
| while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) { | |
| $Students[] = $row["STUDENTSDCID"]; | |
| } | |
| $Guardian["RemoveStudents"] = $Students; | |
| // Get current list of students to link | |
| //~ "10" > Father | |
| //~ "20" > Mother | |
| //~ "30" > Grandfather | |
| //~ "40" > Grandmother | |
| //~ "50" > Aunt | |
| //~ "60" > Uncle | |
| //~ "70" > Brother | |
| //~ "80" > Sister | |
| //~ "530" > Brother, half | |
| //~ "540" > Brother, step | |
| //~ "550" > Cousin | |
| //~ "560" > Daughter | |
| //~ "570" > Father, foster | |
| //~ "580" > Father, step | |
| //~ "590" selected="" > Friend | |
| //~ "610" > Husband | |
| //~ "620" > Mother, foster | |
| //~ "630" > Mother, step | |
| //~ "640" > Nephew | |
| //~ "650" > Niece | |
| //~ "660" > Significant other | |
| //~ "670" > Sister, half | |
| //~ "680" > Sister, step | |
| //~ "690" > Son | |
| //~ "700" > Ward | |
| //~ "710" > Wife | |
| //~ "1000" > Advisor | |
| //~ "1010" > Agency representative | |
| //~ "1020" > Brother-in-law | |
| //~ "1030" > Court appointed guardian | |
| //~ "1040" > Daughter-in-law | |
| //~ "1050" > Dependent | |
| //~ "1060" > Former husband | |
| //~ "1070" > Former wife | |
| //~ "1080" > Family member | |
| //~ "1090" > Father's significant other | |
| //~ "1100" > Father-in-law | |
| //~ "1110" > Fiance | |
| //~ "1120" > Foster daughter | |
| //~ "1130" > Foster parent | |
| //~ "1140" > Foster son | |
| //~ "1150" > Granddaughter | |
| //~ "1160" > Grandson | |
| //~ "1170" > Great aunt | |
| //~ "1180" > Great uncle | |
| //~ "1190" > Life partner | |
| //~ "1200" > Life partner of parent | |
| //~ "1210" > Minister or priest | |
| //~ "1220" > Mother's significant other | |
| //~ "1230" > Mother-in-law | |
| //~ "1240" > Partner | |
| //~ "1250" > Partner of parent | |
| //~ "1260" > Probation officer | |
| //~ "1270" > Sister-in-law | |
| //~ "1280" > Son-in-law | |
| //~ "1290" > Stepdaughter | |
| //~ "1300" > Stepson | |
| //~ "1310" > Other | |
| $Guardian["Relationship"] = "1310"; // Set Relationship to Student to "Other" | |
| if ($Guardianship != "") { | |
| if ($Guardianship == "father") { | |
| $Guardian["Relationship"] = "10"; // father | |
| } elseif ($Guardianship == "mother") { | |
| $Guardian["Relationship"] = "20"; // mother | |
| } | |
| } | |
| echo "=> Get all the students that have the same family_ident\n"; | |
| $sql = "select distinct | |
| nvl(rs.dcid,s.dcid) as dcid | |
| from students s | |
| left outer join relationship r on s.person_id = r.person_id | |
| left outer join students rs on r.relatedperson_id = rs.person_id | |
| where s.family_ident = '".$FamilyID."'"; | |
| $stmt = oci_parse($conn,$sql); | |
| oci_execute($stmt); | |
| $StudentRecords = ""; | |
| $StudentDCIDs = ""; | |
| $StudentRelationships = ""; | |
| $i = 0; | |
| while ($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) { | |
| $StudentRecords = $StudentRecords.$i.","; | |
| $StudentDCIDs = $StudentDCIDs.$row["DCID"].","; | |
| $StudentRelationships = $StudentRelationships.$Guardian["Relationship"].","; | |
| $i++; | |
| } | |
| $Guardian["StudentRecords"] = substr($StudentRecords,0,-1); | |
| $Guardian["StudentDCIDs"] = substr($StudentDCIDs,0,-1); | |
| $Guardian["StudentRelationships"] = substr($StudentRelationships,0,-1); | |
| oci_free_statement($stmt); | |
| oci_close($conn); | |
| $pslogin = $PSUsername; // Default school must be District Office | |
| $pspassword = $PSPassword; | |
| $domain = $PowerschoolDomainName; // No trailing slash | |
| $cookie = uniqid("sync") . '.txt'; // Cookie file, webserver must have r/w access | |
| $login1URL = $domain."/admin/pw.html"; // Authentication page | |
| $login2URL = $domain."/admin/home.html"; // Home page | |
| $newGuardian1URL = $domain."/admin/guardians/new_guardian_account.html"; // New guardian account load page | |
| $newGuardian2URL = $domain."/admin/guardians/home.html"; // New guardian account submit page | |
| $removeStudent1URL = $domain."/admin/students/guardian_delete_dialog.html"; // Remove student from guardian load page | |
| $removeStudent2URL = $domain."/admin/success.html"; // Remove student from guardian submit page | |
| $addStudentURL = $domain."/admin/guardians/student_add_dialog.html"; // Add student to guardian page | |
| $logoutURL = $domain."/admin/~loff"; // Logout | |
| try { | |
| echo "=> Load login page via cURL\n"; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $login1URL); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_POST, false); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
| $buffer = curl_exec($ch); | |
| // Scrape token and key from login page | |
| // Note - this will break if PS changes the layout of their login page | |
| // Not real classy (could have used regular expressions), but this works | |
| $lines = explode("\n", $buffer); | |
| foreach ($lines as $line) { | |
| if (strstr($line, '<input type="hidden" name="pstoken" value="') ){ | |
| $pstoken = str_replace('<input type="hidden" name="pstoken" value="', '', $line); | |
| $pstoken = str_replace('">', '', $pstoken); | |
| } | |
| if (strstr($line, 'var pskey = "')) { | |
| $pskey = str_replace('var pskey = "', '', $line); | |
| $pskey = str_replace('";', '', $pskey); | |
| } | |
| } | |
| if (!isset($pskey)) { | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot load login page.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot load login page.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return "Cannot load login page.\n"; | |
| } | |
| // First Hash password using md5 with raw binary output, then base64 encode | |
| // PS 8.x is still using this hash method | |
| $pspassword2 = base64_encode(md5($pspassword, TRUE)); | |
| // Then remove trailing "=" | |
| while (substr($pspassword2, -1, 1) == "=") | |
| $pspassword2 = substr($pspassword2, 0, -1); | |
| // Then hash again with md5, using supplied key on PS login page | |
| $hash = hash_hmac("md5", $pspassword2, $pskey); | |
| // Hash lower-case version of password (6.x) | |
| //$hash = hash_hmac("md5", strtolower($pspassword), $pskey); | |
| // Delete cookie from previous session | |
| if (is_file($cookie)) { | |
| unlink ($cookie); | |
| } | |
| echo "=> cURL the login authentication\n"; | |
| // The page is acutally called twice, hence the need for the -L. | |
| // The first time, it receives the session cookie. | |
| // The second time, it supplies the valid cookie and loads the page. | |
| // Add &ldappassword=$password to -d (POST values) string if logging on as ldap user | |
| $LoginData = array('username' => $pslogin, 'pstoken' => $pstoken, 'password' => $hash, 'ldappassword' => $pspassword, 'request_locale' => 'en_US'); | |
| curl_setopt($ch, CURLOPT_URL, $login2URL); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_HEADER, false); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $LoginData); | |
| $buffer = curl_exec($ch); | |
| if (strstr($buffer,$PowerschoolConnectedString) === false || strstr($buffer,$PowerschoolErrorString1) !== false || strstr($buffer,$PowerschoolErrorString2) !== false) { | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot login to Powerschool.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot login to Powerschool.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return "Cannot login to Powerschool.\n"; | |
| } | |
| echo "=> We are now logged in, and session cookie is stored in the $cookie file.\n"; | |
| if ($Guardian["ParentID"] == "" || is_null($Guardian["ParentID"])) { | |
| echo "=> New guardian account\n"; | |
| // new guardian data dictionary | |
| $NewGuardianData = array( | |
| "accountInfo.username" => strtolower($Guardian["USERNAME"]), | |
| "account.username" => strtolower($Guardian["USERNAME"]), | |
| "newGuardian.firstName" => $Guardian["FIRSTNAME"], | |
| "newGuardian.lastName" => $Guardian["LASTNAME"], | |
| "newGuardian.email" => $Guardian["EMAIL"], | |
| "searchParameters.email" => $Guardian["EMAIL"], | |
| "accountInfo.password" => $Guardian["PASSWORD"], | |
| "passwordConfirm" => $Guardian["PASSWORD"], | |
| "changesSaved" => "true", | |
| "ac" => "brij:admin-accountmanagement-pkg/submitAdminNoStudentsGuardianAccountForm", | |
| "doc" => "/admin/guardians/new_guardian_account.html", | |
| "render_in_java" => "true", | |
| "accountLocked" => "false", // PS internal field | |
| "__checkbox_accountLocked" => "false" // PS internal field | |
| ); | |
| echo "=> First, load the new guardian form\n"; | |
| curl_setopt($ch, CURLOPT_URL, $newGuardian1URL); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_POST, false); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| $buffer = curl_exec($ch); | |
| if (strstr($buffer,$PowerschoolConnectedString) === false || strstr($buffer,$PowerschoolErrorString) !== false) { | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot load the new guardian form.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot load the new guardian form.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return "Cannot load the new guardian form.\n"; | |
| } | |
| echo "=> Then, submit the new guardian form with data\n"; | |
| curl_setopt($ch, CURLOPT_URL, $newGuardian2URL); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $NewGuardianData); | |
| $buffer = curl_exec($ch); | |
| if (strstr($buffer,$PowerschoolConnectedString) === false || strstr($buffer,$PowerschoolErrorString) !== false) { | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot submit the new guardian form.\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot submit the new guardian form.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return "Cannot submit the new guardian form.\n"; | |
| } | |
| echo "=> Get ID of the created parent account\n"; | |
| $lines = explode("\n", $buffer); | |
| foreach ($lines as $line) { | |
| if (strstr($line, '<input type="hidden" id="guardian-edit-form-gai" name="gai" value="') ){ | |
| $ParentID = str_replace('<input type="hidden" id="guardian-edit-form-gai" name="gai" value="', '', $line); | |
| $ParentID = trim(str_replace('" />', '', $ParentID)); | |
| $Guardian["ParentID"] = $ParentID; | |
| } | |
| } | |
| // Add students to guardian | |
| $AddStudentData = array( | |
| "submitOperation" => "add", | |
| "selectedStudentRecords" => $Guardian["StudentRecords"], | |
| "selectedStudentDcids" => $Guardian["StudentDCIDs"], | |
| "selectedGuardianRelationshipsForStudents" => $Guardian["StudentRelationships"], | |
| "bypassStudentSearch" => "true", | |
| "gai" => $Guardian["ParentID"] | |
| ); | |
| echo "=> Call the add student form the first time. You can't skip this step.\n"; | |
| // $addStudentURL = $domain . '/admin/guardians/student_add_dialog.html'; | |
| curl_setopt($ch, CURLOPT_URL, $addStudentURL); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_POST, false); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| $buffer = curl_exec($ch); | |
| if (strstr($buffer,"<h2>Search for Students</h2>") === false) { | |
| echo "SSOSync cURL error - ".$FamilyID . " - Cannot call the add student form: ." . $addStudentURL . "\n\n".$Datadump; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot call the add student form.\n\n".$Datadump, "From: ".$FromEmail); | |
| } | |
| return "Cannot call the add student form.\n"; | |
| } | |
| echo "=> Call the add student form a second time, submitting the modified values\n"; | |
| curl_setopt($ch, CURLOPT_URL, $addStudentURL); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, true); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $AddStudentData); | |
| $buffer = curl_exec($ch); | |
| } else { | |
| echo "\n==> Parent account " . $Username . "(" . $EmailAddress . ") " . "already exists\n\n"; | |
| // update parent instead? | |
| // Fri, Aug 8 2014 - Trinh Nguyen | |
| //~ SSOUpdateGuardianAccount($Username, $Username, $Password, $LastName, $FirstName, $EmailAddress, false); | |
| } | |
| //~ echo "=> Remove students from guardian\n"; | |
| //~ if (is_array($Guardian["RemoveStudents"])) { | |
| //~ foreach ($Guardian["RemoveStudents"] as $key => $value) { | |
| //~ $DCID = $value; | |
| //~ $removeStudent1URL = $removeStudent1URL."?frn=001".$DCID."&gai=".$Guardian["ParentID"]."&guardianPortal=true"; | |
| //~ | |
| //~ $RemoveStudentData = array( | |
| //~ "frn" => "001".$DCID, | |
| //~ "studentId" => $DCID, | |
| //~ "guardianPortal" => "true", | |
| //~ "gai" => $Guardian["ParentID"], | |
| //~ "ac" => "brij:admin-accountmanagement-pkg/DeleteGuardianFromStudent", | |
| //~ "doc" => "/admin/students/guardian_delete_dialog.html", | |
| //~ "render_in_java" => "true" | |
| //~ ); | |
| //~ | |
| //~ echo "=> Call the remove student form the first time. You can't skip this step.\n"; | |
| //~ curl_setopt($ch, CURLOPT_URL, $removeStudent1URL); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_POST, false); | |
| //~ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| //~ $buffer = curl_exec($ch); | |
| //~ | |
| //~ if (strstr($buffer,"<h3>Remove Student</h3>") === false) { | |
| //~ echo "SSOSync cURL error - ".$FamilyID . " - Cannot load the remove student form.\n\n".$Datadump; | |
| //~ if ($NotificationEmail != "") { | |
| //~ mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot load the remove student form.\n\n".$Datadump, "From: ".$FromEmail); | |
| //~ } | |
| //~ return "Cannot load the remove student form.\n"; | |
| //~ } | |
| //~ | |
| //~ echo "=> Call the remove student form a second time, submitting the modified values\n"; | |
| //~ curl_setopt($ch, CURLOPT_URL, $removeStudent2URL); | |
| //~ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| //~ curl_setopt($ch, CURLOPT_POST, true); | |
| //~ curl_setopt($ch, CURLOPT_POSTFIELDS, $RemoveStudentData); | |
| //~ $buffer = curl_exec($ch); | |
| //~ | |
| //~ if (strstr($buffer,$PowerschoolErrorString) !== false) { | |
| //~ echo "SSOSync cURL error - ".$FamilyID . " - Cannot submit the remove student form.\n\n".$Datadump; | |
| //~ if ($NotificationEmail != "") { | |
| //~ mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot submit the remove student form.\n\n".$Datadump, "From: ".$FromEmail); | |
| //~ } | |
| //~ return "Cannot submit the remove student form.\n"; | |
| //~ } | |
| //~ } | |
| //~ } | |
| //~ // Add students to guardian | |
| //~ $AddStudentData = array( | |
| //~ "submitOperation" => "add", | |
| //~ "selectedStudentRecords" => $Guardian["StudentRecords"], | |
| //~ "selectedStudentDcids" => $Guardian["StudentDCIDs"], | |
| //~ "selectedGuardianRelationshipsForStudents" => $Guardian["StudentRelationships"], | |
| //~ "bypassStudentSearch" => "true", | |
| //~ "gai" => $Guardian["ParentID"] | |
| //~ ); | |
| //~ | |
| //~ echo "=> Call the add student form the first time. You can't skip this step.\n"; | |
| //~ // $addStudentURL = $domain . '/admin/guardians/student_add_dialog.html'; | |
| //~ curl_setopt($ch, CURLOPT_URL, $addStudentURL); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_POST, false); | |
| //~ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| //~ $buffer = curl_exec($ch); | |
| //~ | |
| //~ if (strstr($buffer,"<h2>Search for Students</h2>") === false) { | |
| //~ echo "SSOSync cURL error - ".$FamilyID . " - Cannot call the add student form: ." . $addStudentURL . "\n\n".$Datadump; | |
| //~ if ($NotificationEmail != "") { | |
| //~ mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, "Cannot call the add student form.\n\n".$Datadump, "From: ".$FromEmail); | |
| //~ } | |
| //~ return "Cannot call the add student form.\n"; | |
| //~ } | |
| //~ | |
| //~ echo "=> Call the add student form a second time, submitting the modified values\n"; | |
| //~ curl_setopt($ch, CURLOPT_URL, $addStudentURL); | |
| //~ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| //~ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| //~ curl_setopt($ch, CURLOPT_POST, true); | |
| //~ curl_setopt($ch, CURLOPT_POSTFIELDS, $AddStudentData); | |
| //~ $buffer = curl_exec($ch); | |
| echo "=> Logout\n"; | |
| curl_setopt($ch, CURLOPT_URL, $logoutURL); | |
| curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); | |
| curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); | |
| curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_POST, false); | |
| $buffer = curl_exec($ch); | |
| curl_close($ch); | |
| echo "=> Remove cookie file\n"; | |
| if (is_file($cookie)) { | |
| unlink ($cookie); | |
| } | |
| $SyncCompleted = true; | |
| } catch (Exception $e) { | |
| $ErrorMessage .= "Unknown error: ".$e->getMessage(); | |
| } | |
| restore_error_handler(); | |
| if ($ErrorMessage != "") { | |
| echo "SSOSync cURL error - ".$FamilyID . " - " . $ErrorMessage; | |
| if ($NotificationEmail != "") { | |
| mail($NotificationEmail, "SSOSync cURL error - ".$FamilyID, $ErrorMessage, "From: ".$FromEmail); | |
| } | |
| return $FamilyID." - ".$ErrorMessage."\n"; | |
| } else { | |
| return ""; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment