public function update_company() { $ObjContactsTemp = new contactsTempModel(); $ObjCompanies = new companiesModel(); $contact_id = Input::get('contact_id'); $company_id = Input::get('company_id'); $company_name = Input::get('company_name'); $address1 = Input::get('address1'); $address2 = Input::get('address2'); $city = Input::get('city'); $state = Input::get('state'); $zipcode = Input::get('zipcode'); $data = array('company_name' => $company_name, 'address1' => $address1, 'address2' => $address2, 'city' => $city, 'state_code' => $state, 'zipcode' => $zipcode); if ($company_id) { $result = $ObjCompanies->update_data($data, $company_id); if ($result) { $message = 'Update Company profile successful.'; } else { $message = 'Update Company profile not successful.'; } } else { $company_id = $ObjCompanies->save_company_if_company_dont_exist($company_name, $address1, $city, $state, $zipcode, $address2); if ($company_id) { $data = array('company_id' => $company_id); $result = $ObjContactsTemp->update_data($data, $contact_id); if ($result) { $message = 'Update Company profile company id successful.'; } else { $message = 'Update Company profile company id not successful.'; } } else { $message = 'Add new Company not successful.'; } } return Redirect::to('profile')->with('message', $message); }
public function uploaded_contacts_save($cuf_id) { $ObjContacts = new contactsModel(); $ObjCompanies = new companiesModel(); $ObjCUF = new contactsUploadedFileModel(); $ObjCUFF = new contactsUploadedFileFieldsModel(); $result = FALSE; $uploaded_file_col = $this->get_record_join(array('`j1`.`cuf_id`=' => $cuf_id)); $contact_id = $uploaded_file_col->contact_id; $cuff_rows = $ObjCUFF->get_records(array('`cuf_id`=' => $cuf_id)); $header_format = $this->get_fieldname_column($cuff_rows); $where_params = array('`cuf_id`=' => $cuf_id); $order_params = array('ASC' => 'cut_id'); $uploaded_contacts_rows = $this->get_records($where_params, $order_params); if ($uploaded_contacts_rows) { foreach ($uploaded_contacts_rows as $col) { $cut_id = $col->cut_id; $this->update_uploaded_contacts_value($cuff_rows, $cut_id); } } $where_params = array('`cuf_id`=' => $cuf_id); $order_params = array('ASC' => 'cut_id'); $uploaded_contacts_rows = $this->get_records($where_params, $order_params); if ($uploaded_contacts_rows) { foreach ($uploaded_contacts_rows as $col) { $cut_id = $col->cut_id; $error_message = $col->cut_error_message; $email_address = $this->get_header_column_value_by_fieldname('email_address', $col, $header_format); $last_name = $this->get_header_column_value_by_fieldname('last_name', $col, $header_format); $first_name = $this->get_header_column_value_by_fieldname('first_name', $col, $header_format); $address1 = $this->get_header_column_value_by_fieldname('address1', $col, $header_format); $city = $this->get_header_column_value_by_fieldname('city', $col, $header_format); $state_code = $this->get_header_column_value_by_fieldname('state_code', $col, $header_format); $zipcode = $this->get_header_column_value_by_fieldname('zipcode', $col, $header_format); $company_id = ''; $company = $this->get_header_column_value_by_fieldname('company', $col, $header_format); if ($company) { $company_id = $ObjCompanies->save_company_if_company_dont_exist($company, $address1, $city, $state_code, $zipcode); } if ($error_message == '') { $last_name = $last_name ? $last_name : 'Department'; $first_name = $first_name ? $first_name : 'Estimating'; $data = array('contact_id_assigned' => $contact_id, 'email_address' => $email_address, 'last_name' => $last_name, 'first_name' => $first_name, 'company_id' => $company_id, 'address1' => $address1, 'city' => $city, 'state_code' => $state_code, 'zipcode' => $zipcode); $cid = $ObjContacts->insert_data($data); if ($cid) { $this->delete_data(array('`cut_id`=' => $cut_id)); } } } } $count_contacts = $this->get_records(array('`cuf_id`=' => $cuf_id)); if ($count_contacts == FALSE) { $result = TRUE; } return $result; }