public function register_contacts() { $contact_id_temp = ''; $ObjContacts = new contactsModel(); $ObjContactsTemp = new contactsTempModel(); $ObjCompanies = new companiesModel(); $first_name = Input::get('first_name'); $last_name = Input::get('last_name'); $email = Input::get('email'); $password = Input::get('password'); $secret_question = Input::get('secret_question'); $secret_answer = Input::get('secret_answer'); $confirmation = sha1($password . date('YmdHis')); $company_name = Input::get('company_name'); $address = Input::get('address'); $city = Input::get('city'); $state = Input::get('state'); $zipcode = Input::get('zipcode'); $where_params = array('`email_address`=' => $email); $validate_contact_temp = $ObjContactsTemp->get_record($where_params); $where_params = array('`email_address`=' => $email); $validate_contact = $ObjContacts->get_record($where_params); if ($validate_contact_temp || $validate_contact) { $message = 'Email <b>' . $email . '</b> already exist.'; return Redirect::to('register')->with('message', $message); } else { $company_id = $ObjCompanies->get_company_id_check_if_company_exist($company_name, $address, $city, $state, $zipcode); $email_message = ''; if ($company_id) { $contacts_col = $ObjContacts->get_record_join_by_company_id($company_id); $comp_name = $contacts_col->comp_name; $comp_firstname = $contacts_col->cont_firstname; $comp_lastname = $contacts_col->cont_lastname; $comp_email = $contacts_col->cont_email; $status = 'Validate Company'; $message1 = '<p>Thanks for signing up! Please check you email inbox. We sent a confirmation email to <b>' . $email . '</b>.</p>'; $message2 = '<p>Contact <b>' . $comp_firstname . ' ' . $comp_lastname . '</b> and ask him to add you to its <b>' . $comp_name . '</b> Company with email <b>' . $comp_email . '</b>.</p>'; $message = $message1 . '<br />' . $message2; } else { $data = array('company_name' => $company_name, 'address1' => $address, 'city' => $city, 'state_code' => $state, 'zipcode' => $zipcode); $company_id = $ObjCompanies->insert_data($data); $status = 'Contact Temp'; $message = 'Thanks for signing up! Please check you email inbox. We sent a confirmation email to <b>' . $email . '</b>.'; } $data = array('company_id' => $company_id, 'first_name' => $first_name, 'last_name' => $last_name, 'email_address' => $email, 'password' => $password, 'secret_question' => $secret_question, 'secret_answer' => $secret_answer, 'cont_confirmation' => $confirmation, 'cont_status' => $status); $contact_id_temp = $ObjContactsTemp->insert_data($data); if ($contact_id_temp) { $data['body_message'] = $message2; $data['subject'] = 'Registration confirmation of Paskr Account.'; Mail::send('emails.registration', $data, function ($mail) use($data) { $mail->to($data['email_address'], $data['first_name'] . ' ' . $data['last_name'])->subject($data['subject']); }); return Redirect::to('register_success')->with('message', $message); } else { $message = 'Registration not successful.'; return Redirect::to('register')->with('message', $message); } } }