public function post_create_client($POST) { $ignoreCaps = array("password"); foreach ($POST as $POST_KEY => $POST_VALUE) { if (!in_array($POST_KEY, $ignoreCaps)) { $POST[$POST_KEY] = strtoupper($POST_VALUE); } } $POST['billingPhone'] = preg_replace("/[^0-9]/", "", $POST['billingPhone']); if (strlen($POST['billingPhone']) === 10) { $POST['billingPhone'] = "(" . substr($POST['billingPhone'], 0, 3) . ")" . substr($POST['billingPhone'], 3, 3) . "-" . substr($POST['billingPhone'], -4); } $error = ""; $Database = new Database($this->environment, $this->connection, $this->security); $Agent = new Agents($this->environment, $this->connection, $this->security); $User = new Users($this->environment, $this->connection, $this->security); $Company = new Company($this->environment, $this->connection, $this->security); $Provider = new Provider($this->environment, $this->connection, $this->security); if (!isset($POST['clientid'])) { $return_trans = $this->post_recurring_profile_details($POST); if ($return_trans['result']) { $type = "create"; $return_client = $Company->post_automated_register_new_client($POST); } else { $error = "Failed to insert the transaction record. Reason: " . $return_trans['response']; } } else { $type = "update"; $return_client = $Company->get_automated_register_client_info($POST); $nameSplit = explode(" ", $return_client['response']['contact']); $POST['name'] = $nameSplit[0]; $POST['lname'] = $nameSplit[1]; $POST['title'] = "ADMINISTRATOR"; $POST['email'] = $return_client['response']['email']; $POST['billingPhone'] = $return_client['response']['phone1']; $POST['addonBox'] = $return_client['response']['clienttype']; $POST['agency'] = $return_client['response']['cotype']; $POST['licenseNum'] = $return_client['response']['userlicensenum']; } if (empty($error)) { if ($return_client['result']) { $POST['clientid'] = isset($return_client['clientid']) ? $return_client['clientid'] : $return_client['response']['id']; $return_database = $Database->post_automated_register_new_database($POST); if ($return_database['result']) { $POST['qdatabase'] = $return_database['qdatabase']; $return_provider = $Provider->post_automated_register_new_provider($POST); if ($return_provider['result']) { $return_agent = $Agent->post_automated_register_new_agent($POST); if ($return_agent['result']) { $POST['agentid'] = $return_agent['agentid']; $return_user = $User->post_automated_register_new_user($POST); if ($return_user['result']) { $POST['userid'] = $return_user['userid']; $return_company = $Company->post_automated_register_new_company($POST); if ($return_company['result']) { $return_client = $Company->post_automated_register_activate_client($POST); $this->post_send_confirmation_email($POST); //send confirmation email if (!$return_user['result']) { $error = "Failed to activate the client. Reason: " . $return_client['response']; } } else { $error = "Failed to update company information. Reason: " . $return_company['response']; } } else { $error = "Failed to create the user record. Reason: " . $return_user['userid']; } } else { $error = "Failed to create the agent record. Reason: " . $return_agent['agentid']; } } else { $error = "Failed to create the provider record. Reason: " . $return_provider['provid']; } } else { $error = $return_database['error']; } } else { $error = "Failed to {$type} the client record. Reason: " . $return_client['clientid']; } } if (!empty($error)) { $Database->post_automated_register_remove_database($POST); $User->post_automated_register_remove_user($POST); // we don't want to remove the client database reference because that one will hold the transaction express client id...since they have already paid at this point, we don't want to lose that. } return array("result" => empty($error), "error" => $error); }