PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules_core/client_center/models/mdl_client_center.php

https://bitbucket.org/hlevine/myclientbase-south-african-version
PHP | 99 lines | 55 code | 44 blank | 0 comment | 3 complexity | 414944b83523d9891e7723f84e9fea8f MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0
  1. <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
  2. class Mdl_Client_Center extends MY_Model {
  3. public function __construct() {
  4. parent::__construct();
  5. $this->table_name = 'mcb_users';
  6. $this->primary_key = 'mcb_users.user_id';
  7. $this->select_fields = 'SQL_CALC_FOUND_ROWS
  8. mcb_users.*,
  9. mcb_clients.*';
  10. $this->joins = array(
  11. 'mcb_clients' => 'mcb_clients.client_id = mcb_users.client_id'
  12. );
  13. }
  14. public function validate() {
  15. $this->form_validation->set_rules('client_id_autocomplete_label');
  16. $this->form_validation->set_rules('client_id', $this->lang->line('client'), 'required');
  17. $this->form_validation->set_rules('username', $this->lang->line('username'), 'required|callback_username_check');
  18. $this->form_validation->set_rules('password', $this->lang->line('password'), 'required');
  19. $this->form_validation->set_rules('passwordv', $this->lang->line('passwordv'), 'required|matches[password]');
  20. $this->form_validation->set_rules('email_address', $this->lang->line('email_address'), 'required');
  21. return parent::validate($this);
  22. }
  23. public function username_check($username) {
  24. $this->db->where('username', $username);
  25. if (uri_assoc('user_id', 4)) {
  26. $this->db->where('user_id <>', uri_assoc('user_id', 4));
  27. }
  28. $query = $this->db->get('mcb_users');
  29. if ($query->num_rows()) {
  30. $this->form_validation->set_message('username_check', $this->lang->line('username_already_exists'));
  31. return FALSE;
  32. }
  33. return TRUE;
  34. }
  35. public function save($db_array, $user_id = NULL) {
  36. unset($db_array['passwordv']);
  37. unset($db_array['client_id_autocomplete_label']);
  38. $db_array['password'] = md5($db_array['password']);
  39. parent::save($db_array, $user_id);
  40. }
  41. public function prep_validation($client_id) {
  42. parent::prep_validation($client_id);
  43. $this->form_values['client_id_autocomplete_label'] = $this->form_values['client_name'];
  44. }
  45. public function invoice_belongs_to_client($invoice_id, $client_id) {
  46. $this->db->where('invoice_id', $invoice_id);
  47. $this->db->where('client_id', $client_id);
  48. $query = $this->db->get('mcb_invoices');
  49. if ($query->num_rows()) {
  50. return TRUE;
  51. }
  52. return FALSE;
  53. }
  54. }
  55. ?>