public function upload_contacts($cuf_id = '') { $data = array(); $ObjCUF = new contactsUploadedFileModel(); $ObjCUFF = new contactsUploadedFileFieldsModel(); $ObjCUT = new contactsUploadedTempModel(); $ObjContacts = new contactsModel(); $ObjCompanies = new companiesModel(); $loggin_user = $ObjContacts->get_loggin_user_info(); $contact_id = $loggin_user->contact_id; $where_params = array('`contact_id_assigned`=' => $contact_id); $order_params = array('ASC' => 'contact_id'); $data['contacts_rows'] = $ObjContacts->get_records($where_params, $order_params); if ($cuf_id == '') { $where_params = array('`j1`.`contact_id`=' => $contact_id); $order_params = array('DESC' => '`j1`.`cuf_id`'); $col = $ObjCUT->get_record_join($where_params, $order_params); if ($col) { $cuf_id = $col->cuf_id; } } $data['cuf_id'] = $cuf_id; if ($cuf_id) { $data['unmatched_columns'] = $ObjCUFF->get_unmatched_columns($cuf_id); $where_params = array('`cuf_id`=' => $cuf_id); $cuf = $ObjCUF->get_record($where_params); $header_format = $cuf->cuf_header_format; $data['header_format_unserialize'] = unserialize($header_format); $file_path = $ObjCUF->base_path . $cuf->cuf_filepath; //$data['show_upload_contacts_head'] = $ObjCUF->show_upload_contacts_head( $header_format ); //$data['show_upload_contacts_head'] = $ObjCUFF->show_upload_contacts_head( $cuf_id ); $data['show_upload_contacts_header'] = $ObjCUFF->show_upload_contacts_header($cuf_id); $header_format_rows = $ObjCUFF->get_records(array('`cuf_id`=' => $cuf_id)); $cuff_id_list = $ObjCUFF->get_id_to_list($header_format_rows); $data['header_format_rows'] = $header_format_rows; $data['no_column'] = count($header_format_rows); $data['cuff_id_list'] = $cuff_id_list; $data['uploaded_contacts_rows'] = $ObjCUT->get_records(array('`cuf_id`=' => $cuf_id), array('ASC' => 'cut_id')); $data['filepath'] = $file_path; $where_params = array('`cuf_id`=' => $cuf_id, $this->tblpref . 'error_message<>' => ''); $uploaded_contacts_number_errors = $ObjCUT->get_records($where_params); $data['uploaded_contacts_number_errors'] = count($uploaded_contacts_number_errors); } return View::make('upload_contacts', $data); }
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; }