/** * Updates a customer's details. * * Updates a customer details. If the customer does not belong to the client, an error is returned. * * @param int $customer_id The Customer to update. * @param string $params['internal_id'] Customer's internal_id. Optional. * @param string $params['first_name'] Customer's first name. Optional. * @param string $params['last_name'] Customer's last name. Optional. * @param string $params['company'] Customer's company. Optional. * @param string $params['address_1'] Customer's address line 1. Optional. * @param string $params['address_2'] Customer's address line 2. Optional. * @param string $params['city'] Customer's city. Optional. * @param string $params['state'] Customer's state. Optional. * @param string $params['postal_code'] Customer's postal code. Optional. * @param string $params['country'] Customer's country. Optional. * @param string $params['phone'] Customer's phone. Optional. * @param string $params['email'] Customer's email. Optional. * * @return mixed Array containing new customer_id */ function UpdateCustomer($customer_id, $params) { $this->load->library('field_validation'); if (!isset($customer_id)) { return FALSE; } if (isset($params['internal_id'])) { $update_data['internal_id'] = $params['internal_id']; } if (isset($params['first_name'])) { $update_data['first_name'] = $params['first_name']; } if (isset($params['last_name'])) { $update_data['last_name'] = $params['last_name']; } if (isset($params['company'])) { $update_data['company'] = $params['company']; } if (isset($params['internal_id'])) { $update_data['internal_id'] = $params['internal_id']; } if (isset($params['address_1'])) { $update_data['address_1'] = $params['address_1']; } if (isset($params['address_2'])) { $update_data['address_2'] = $params['address_2']; } if (isset($params['city'])) { $update_data['city'] = $params['city']; } if (isset($params['postal_code'])) { $update_data['postal_code'] = $params['postal_code']; } if (isset($params['country'])) { if ($params['country'] == '') { $update_data['country'] = ''; } else { // Make sure the country is in the proper format $country_id = $this->field_validation->ValidateCountry($params['country']); if (!$country_id) { die($this->response->Error(1007)); } $update_data['country'] = $country_id; } } if (isset($params['state']) and !empty($params['state'])) { // If the country is US or Canada, we need to validate and supply the 2 letter abbreviation $this->load->helper('states_helper'); $country_array = array(124, 840); if (isset($country_id) and in_array($country_id, $country_array)) { $state = GetState($params['state']); if ($state) { $update_data['state'] = $state; } else { die($this->response->Error(1012)); } } else { $update_data['state'] = $params['state']; } } if (isset($params['phone'])) { $update_data['phone'] = $params['phone']; } if (isset($params['email'])) { $update_data['email'] = $params['email']; } if (!isset($update_data)) { die($this->response->Error(6003)); } // Make sure they update their own customer $this->db->where('customer_id', $customer_id); if ($this->db->update('customers', $update_data)) { return TRUE; } else { return FALSE; } }
/** * Update Client information. * * Updates client information. All fields are optional * * @param int $client_id The client ID of the Parent Client * @param int $updated_client_id The ID of the client being updated * @param string $params['first_name'] Client's first name * @param string $params['last_name'] Client's last name * @param string $params['company'] Client's company * @param string $params['address_1'] Client's address line 1. * @param string $params['address_2'] Client's address line 2. * @param string $params['city'] Client's city * @param string $params['state'] Client's state. If in the US or Canada, it should be the 2-letter abbreviation. The system will try to determin the correct county. * @param string $params['postal_code'] Client's postal code * @param string $params['country'] Client's country in ISO format * @param string $params['phone'] Client's phone * @param string $params['email'] Client's email * @param string $params['username'] Client's username * @param string $params['password'] Client's password * * @return bool TRUE upon success, FALSE upon failure */ function UpdateClient($client_id, $updated_client_id, $params) { // Validate the required fields $this->load->library('field_validation'); $this->field_validation->ValidateRequiredFields('UpdateClient', $params); // Make sure it's them or their client if ($updated_client_id == $client_id) { $client = $this->GetClientDetails($client_id); } else { $client = $this->GetChildClientDetails($client_id, $updated_client_id); } if (!$client) { die($this->response->Error(2004)); } if (isset($params['first_name']) && $params['first_name'] != '') { $update_data['first_name'] = $params['first_name']; } if (isset($params['last_name']) && $params['last_name'] != '') { $update_data['last_name'] = $params['last_name']; } if (isset($params['company'])) { $update_data['company'] = $params['company']; } if (isset($params['address_1']) && $params['address_1'] != '') { $update_data['address_1'] = $params['address_1']; } if (isset($params['address_2'])) { $update_data['address_2'] = $params['address_2']; } if (isset($params['city']) && $params['city'] != '') { $update_data['city'] = $params['city']; } if (isset($params['postal_code']) && $params['postal_code'] != '') { $update_data['postal_code'] = $params['postal_code']; } if (isset($params['country']) && $params['country'] != '') { // Make sure the country is in the proper format $country_id = $this->field_validation->ValidateCountry($params['country']); if (!$country_id) { die($this->response->Error(1007)); } $update_data['country'] = $country_id; } if (isset($params['state']) && $params['state'] != '') { // If the country is US or Canada, we need to validate and supply the 2 letter abbreviation $this->load->helper('states_helper'); $country_array = array(124, 840); if (in_array($country_id, $country_array)) { $state = GetState($params['state']); if ($state) { $update_data['state'] = $state; } else { die($this->response->Error(1012)); } } } // If a timezone was provided, validate it if (isset($params['timezone'])) { if ($params['timezone'] < -23 or $params['timezone'] > 23) { die($this->response->Error(1011)); } $update_data['gmt_offset'] = $params['timezone']; } else { $update_data['gmt_offset'] = 0; } if (isset($params['phone']) && $params['phone'] != '') { $update_data['phone'] = $params['phone']; } if (isset($params['email']) && $params['email'] != '') { $valid_email = $this->field_validation->ValidateEmailAddress($params['email']); if (!$valid_email) { die($this->response->Error(1008)); } $update_data['email'] = $params['email']; } if (isset($params['username']) && $params['username'] != '' && $client->username != $params['username']) { // Make sure the username is not already in use $exists = $this->UsernameExists($params['username']); if ($exists) { die($this->response->Error(2002)); } $update_data['username'] = $params['username']; } if (isset($params['password'])) { // Make sure the password meets the requirements $valid_pass = $this->ValidatePassword($params['password']); if (!$valid_pass) { die($this->response->Error(2003)); } $use_email = isset($params['email']) ? $params['email'] : $client->email; $update_data['password'] = md5($params['password'] . $use_email); } $request_client = $this->GetClientDetails($client_id); if (isset($params['client_type'])) { if ($params['client_type'] == 1 and $request_client->client_type_id != 3) { // only Administrators can make Service Providers die($this->response->Error(2006)); } elseif ($params['client_type'] < 1 or $params['client_type'] > 2 or !is_numeric($params['client_type'])) { die($this->response->Error(2007)); } $update_data['client_type_id'] = $params['client_type']; } if (!isset($update_data)) { die($this->response->Error(6003)); } $this->db->where('client_id', $updated_client_id); if ($this->db->update('clients', $update_data)) { return TRUE; } else { return FALSE; } }