/web_interface/astpp/application/modules/signup/models/signup_model.php

https://github.com/iNextrix/ASTPP · PHP · 135 lines · 106 code · 8 blank · 21 comment · 6 complexity · 1b0cc4f0798535f185e3a11de2414dd1 MD5 · raw file

  1. <?php
  2. // ##############################################################################
  3. // ASTPP - Open Source VoIP Billing Solution
  4. //
  5. // Copyright (C) 2016 iNextrix Technologies Pvt. Ltd.
  6. // Samir Doshi <samir.doshi@inextrix.com>
  7. // ASTPP Version 3.0 and above
  8. // License https://www.gnu.org/licenses/agpl-3.0.html
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU Affero General Public License as
  12. // published by the Free Software Foundation, either version 3 of the
  13. // License, or (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU Affero General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU Affero General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. // ##############################################################################
  23. class Signup_model extends CI_Model
  24. {
  25. function __construct()
  26. {
  27. parent::__construct();
  28. $this->load->model('Astpp_common');
  29. $this->load->helper('form');
  30. $this->load->model('common_model');
  31. $this->load->library('session');
  32. }
  33. function get_rate()
  34. {
  35. $data = array();
  36. $this->load->database();
  37. $this->db->select("id,name");
  38. $this->db->from('pricelists');
  39. $this->db->where("status", "0");
  40. $query = $this->db->get();
  41. return $query->row();
  42. }
  43. function add_user($data)
  44. {
  45. $data['reseller_id'] = $data['key_unique'];
  46. unset($data['agreeCheck']);
  47. unset($data['key_unique']);
  48. $data['creation'] = gmdate('Y-m-d H:i:s');
  49. $data['expiry'] = date('Y-m-d H:i:s', strtotime('+10 years'));
  50. $data['type'] = 0;
  51. $this->db->insert("accounts", $data);
  52. $last_id = $this->db->insert_id();
  53. $tax = common_model::$global_config['system_config']['tax_type'];
  54. if (! empty($tax)) {
  55. $query = "select id as taxes_id,taxes_priority from taxes where id IN($tax)";
  56. $result = $this->db->query($query);
  57. if ($result->num_rows() > 0) {
  58. $tax_array = array();
  59. $taxes_value = $result->result_array();
  60. $i = 0;
  61. foreach ($taxes_value as $value) {
  62. $tax_array[$i]['id'] = '';
  63. $tax_array[$i]['taxes_id'] = $value['taxes_id'];
  64. $tax_array[$i]['taxes_priority'] = $value['taxes_priority'];
  65. $tax_array[$i]['accountid'] = $last_id;
  66. $i ++;
  67. }
  68. $this->db->insert_batch("taxes_to_accounts", $tax_array);
  69. }
  70. }
  71. return $last_id;
  72. }
  73. }
  74. function check_user($accno, $email, $balance)
  75. {
  76. $info = array(
  77. "number" => $accno,
  78. "email" => $email,
  79. "status" => 1
  80. );
  81. $this->db->where($info);
  82. $this->db->select('*');
  83. $acc_res = $this->db->get('accounts');
  84. if ($acc_res->num_rows() > 0) {
  85. $acc_res = $acc_res->result_array();
  86. $acc_res = $acc_res[0];
  87. $this->db->where('pricelist_id', $acc_res['pricelist_id']);
  88. $this->db->select("*");
  89. $charge_res = $this->db->get('charges');
  90. if ($charge_res->num_rows() > 0) {
  91. $charge_res = $charge_res->result_array();
  92. $charge_res = $charge_res[0];
  93. $charge_acc_arr = array(
  94. "charge_id" => $charge_res['id'],
  95. "accountid" => $acc_res['id'],
  96. "status" => 0,
  97. "assign_date" => date('Y-m-d H:i:s')
  98. );
  99. } else {
  100. $charge_res = $charge_res->result_array();
  101. $charge_acc_arr = array(
  102. "charge_id" => 'id',
  103. "accountid" => $acc_res['id'],
  104. "assign_date" => date('Y-m-d H:i:s')
  105. );
  106. }
  107. $result = $this->db->insert("charge_to_account", $charge_acc_arr);
  108. $update = array(
  109. "status" => 0,
  110. "balance" => $balance
  111. );
  112. $this->db->where($info);
  113. $result = $this->db->update('accounts', $update);
  114. $sip_device_update = array(
  115. 'accountid' => $acc_res['id']
  116. );
  117. $update_sip = array(
  118. "status" => 0
  119. );
  120. $this->db->where($sip_device_update);
  121. $result = $this->db->update('sip_devices', $update_sip);
  122. return 1;
  123. } else {
  124. return 0;
  125. }
  126. }
  127. ?>