public function get_validate($apiKey = null) { $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey); if ($apiCheck === false) { $this->response(array('status' => 'FAIL', 'message' => 'Invalid API Key has been used, please contact your IT support!')); } else { $allFields = TRUE; $missingFields = array(); $surveyChoice = $apiCheck->survey; $surveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->where('required', '1')->get(); $allSurveyQuestions = \Model_Survey_Question::query()->where('survey_id', $surveyChoice)->get(); foreach ($surveyQuestions as $surveyRequired) { $requiredFields[] = 'form-q' . $surveyRequired->id; } foreach ($allSurveyQuestions as $surveyQuestions) { $questionFields[] = 'form-q' . $surveyQuestions->id; } // Check and make a list of any missing fields foreach ($requiredFields as $field) { if (is_null(Input::get($field, null)) || strlen(Input::get($field, null)) < 1 && !is_integer(Input::get($field, null)) || Input::get($field, null) == "-- Select") { $allFields = FALSE; $missingFields[] = $field; } } // If we have everything we need then we do our logic if ($allFields) { // Get the client type from the given questions $questionPassOn = array(); foreach ($questionFields as $singleQuestion) { $questionPassOn[$singleQuestion] = Input::get($singleQuestion, null); $questionPassOn[str_replace('form-q', 'form-e', $singleQuestion)] = Input::get(str_replace('form-q', 'form-e', $singleQuestion), null); } \log::write('PPI-DEBUG', \Format::forge($_GET)->to_json()); $clientType = \Crm\Portal\Portal_Check::choice($questionPassOn, $_GET, $apiKey); // If we can decide on a client type if (!is_null($clientType)) { $this->response(array('client_type' => $clientType)); } else { $this->response(array('status' => 'FAIL', 'message' => 'No client type could be decided. Please complete ALL the given questions.')); } } else { $this->response(array('status' => 'FAIL', 'code' => '101', 'message' => 'Not all required fields were submitted! Missing fields are ' . implode(", ", $missingFields), 'missing_fields' => $missingFields)); } } }
public function get_save($apiKey, $surveyID = 0) { // -- Check API Key // ---------------- $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey); if ($apiCheck === false) { $this->response(array('status' => 'FAIL', 'message' => 'Invalid API Key has been used, please contact your IT support!')); } else { if ((int) $surveyID == 0) { $this->response(array('status' => 'FAIL', 'message' => 'Invalid Survey ID, please contact your IT support!')); } else { // -- Save the Lead Details // ------------------------ $centerDetails = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one(); $Debtsolv = new Debtsolv(); $Debtsolv->data(\Input::get()); $Debtsolv->data(array('introducer_id' => $centerDetails->id)); $leadpoolID = 0; $leadpoolID = $Debtsolv->addNewLead(); if ((int) $leadpoolID > 0) { $responseLogID = 0; $responseLogID = ScriptForms::saveFormData($leadpoolID, 0, 0, 1, $surveyID, \Input::get('scriptForm')); $Survey = new ScriptForms($surveyID); // -- Save the Survey Results // -------------------------- #if(ScriptForms::saveFormData($leadpoolID, 0, 0, 0, $surveyID, \Input::get('scriptForm')) === true) // -- Save the Product Recommendations // ----------------------------------- $Survey->saveResponseProducts((int) $responseLogID); if ($responseLogID > 0) { // -- All Saved and Done. Now send an email // ---------------------------------------- $callCentre = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one(); $Email = \Email::forge(); $Email->from('*****@*****.**', 'Money Management Services'); $Email->to('*****@*****.**'); $Email->subject($leadpoolID . ' - New Survey Result'); $Email->html_body(\View::forge('email', array('leadDetails' => \Input::get(), 'leadpoolID' => $leadpoolID, 'recommendedProducts' => $Survey->getProductsRecomendations((int) $responseLogID), 'scriptForm' => ScriptForms::loadResponse($leadpoolID, 0, 1), 'centre' => $callCentre->title, 'agent' => \Input::get('agent'), 'pitchScript' => \Input::get('surveyName')))); $Email->send(); /* try { $Email->send(); } catch(\EmailSendingFailedException $e) { $this->response(array( 'status' => 'SUCCESS', 'message' => 'Survey Saved (Failed to send email)', 'results' => $Survey->getProductsRecomendations((int)$responseLogID), 'leadpoolID' => $leadpoolID, )); } */ $this->response(array('status' => 'SUCCESS', 'message' => 'This Survey has been received.', 'results' => $Survey->getProductsRecomendations((int) $responseLogID), 'leadpoolID' => $leadpoolID)); } else { $this->response(array('status' => 'FAIL', 'message' => 'Failed to save survey results. Debtsolv Lead ID is ' . $leadpoolID)); } } else { $this->response(array('status' => 'FAIL', 'message' => 'Failed to save to Debtsolv')); } } } }
public static function choice($questions = null, $portal_form = null, $apiKey = null) { // Before anything, do a duplicate check $apiCheck = \Crm\Portal\Portal_Check::api_key($apiKey); $surveyChoice = $apiCheck->survey; $surveyDetails = \Model_Survey::find($surveyChoice); $collectOnly = true; if ($surveyDetails->type == 'CHOICE') { $collectOnly = false; } else { $collectOnly = true; } $dupes = \Crm\Referrals\Referrals_model::duplicationCheck(array('forename' => isset($portal_form['first_name']) ? $portal_form['first_name'] : null, 'surname' => isset($portal_form['last_name']) ? $portal_form['last_name'] : null, 'post_code' => isset($portal_form['postcode']) ? $portal_form['postcode'] : null, 'tel_home' => isset($portal_form['phone_number']) ? $portal_form['phone_number'] : null, 'tel_work' => null, 'tel_mobile' => isset($portal_form['alt_phone']) ? $portal_form['alt_phone'] : null)); if (count($dupes) > 0) { // We have a duplicate so lets find out where it comes from } else { $noppi = true; $nodr = true; } $centerDetails = \Model_Call_Center::query()->where('api_key', $apiKey)->get_one(); $clientID = \Crm\Referrals\Referrals_model::createReferral(array('user_id' => '', 'company_id' => 3, 'product_id' => 1, 'dialler_lead_id' => isset($portal_form['lead_id']) ? $portal_form['lead_id'] : null, 'dialler_list_id' => isset($portal_form['list']) ? $portal_form['list'] : null, 'dialler_list_name' => '', 'introducer_agent_name' => isset($portal_form['agent']) ? $portal_form['agent'] : null, 'disposition_id' => '', 'title' => isset($portal_form['title']) ? $portal_form['title'] : null, 'forename' => isset($portal_form['first_name']) ? $portal_form['first_name'] : null, 'surname' => isset($portal_form['last_name']) ? $portal_form['last_name'] : null, 'street_and_number' => isset($portal_form['address1']) ? $portal_form['address1'] : null, 'area' => isset($portal_form['address2']) ? $portal_form['address2'] : null, 'district' => isset($portal_form['address3']) ? $portal_form['address3'] : null, 'town' => isset($portal_form['city']) ? $portal_form['city'] : null, 'county' => isset($portal_form['state']) ? $portal_form['state'] : null, 'post_code' => isset($portal_form['postal_code']) ? $portal_form['postal_code'] : null, 'date_of_birth' => isset($portal_form['date_of_birth']) ? $portal_form['date_of_birth'] : null, 'tel_home' => isset($portal_form['phone_number']) ? $portal_form['phone_number'] : null, 'tel_work' => 0, 'tel_mobile' => isset($portal_form['alt_phone']) ? $portal_form['alt_phone'] : null, 'email' => isset($portal_form['email']) ? $portal_form['email'] : null, 'notes' => isset($portal_form['comments']) ? $portal_form['comments'] : null, 'introducer_id' => $centerDetails->id)); \log::write('PPI-DEBUG', \Format::forge($questions)->to_json()); foreach ($questions as $questionId => $questionAnswer) { if (substr($questionId, 0, 6) == "form-q") { $answers = new \Model_Survey_Response(); $answers->reference = $clientID; $answers->question_id = (int) str_replace("form-q", "", $questionId); $answers->answer_id = !is_null($questionAnswer) ? $questionAnswer : ""; $answers->extra = !is_null($questions['form-e' . (int) str_replace("form-q", "", $questionId)]) ? $questions['form-e' . (int) str_replace("form-q", "", $questionId)] : "-"; $answers->save(); } } if (!$collectOnly) { if ((int) $questions['form-q21'] == 126) { return array('type' => 'DNQ', 'reason' => 'being in an IVA or Declared Bankrupt.'); } else { if ((int) $questions['form-q19'] == 123 and (int) $questions['form-q20'] == 125) { // Get client ID from the PPI system $Referral = \Crm\Referrals\Referrals_class::forge($clientID); $saveData['referralQuestions'] = $questions; $Referral->saveData($saveData); $Referral->product_id = 1; $Referral->company_id = 3; $Referral->save(); $Referral = \Crm\Referrals\Referrals_class::forge($clientID); $Referral->setDisposition(14); $Referral->sendForConsolidation(); return array('type' => 'PPI', 'clientID' => $clientID); } else { // Save details and get client ID from Debtsolv $Debtsolv = \Crm\Referrals\Referrals_debtsolv_class::forge((int) $clientID); $saveData['referralQuestions'] = $questions; $Debtsolv->saveData($saveData); $Debtsolv->product_id = 2; $Debtsolv->company_id = 1; $Debtsolv->save(); // Reload the referral $Debtsolv = \Crm\Referrals\Referrals_debtsolv_class::forge((int) $clientID); $client_ID = $Debtsolv->addNewLead(); $Debtsolv->setDisposition(25); $Debtsolv->sendForDRConsolidation(); return array('type' => 'DR', 'clientID' => $client_ID); } } } else { return array('type' => 'DONE', 'clientID' => $client_ID); } return null; }