PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/Usermanagement.php

https://gitlab.com/dmsapiens/physicians
PHP | 277 lines | 222 code | 42 blank | 13 comment | 40 complexity | 1ffa44406c274c139a2423ca9aafb559 MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. class Usermanagement extends CI_Controller
  3. {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. $this->data = array();
  8. $this->data = array(
  9. 'rating1' => 0,
  10. 'rating2' => 0,
  11. 'rating3' => 0,
  12. 'rating4' => 0,
  13. 'rating5' => 0);
  14. $ratinglist = $this->misc->getratinglist();
  15. foreach ($ratinglist as $row) {
  16. $rating = 'rating' . $row['rating_no'];
  17. $this->data[$rating] = $row['counts'];
  18. }
  19. $this->template->set_layout('baseTemplate');
  20. }
  21. public function index()
  22. {
  23. if (!$this->session->userdata('logged_in')) {
  24. redirect('/');
  25. }
  26. if ($this->input->get_post('filterterm') == "") {
  27. $filterterm = 0;
  28. }
  29. $searchterm = $this->users->searchterm_handler($this->input->get_post('selecttype', true));
  30. if ($searchterm != '')
  31. $filterterm = 1;
  32. if (isset($filterterm) && $filterterm == 1) {
  33. $config['suffix'] = '/filter?filterterm=' . $filterterm;
  34. $config['first_url'] = site_url('/usermanagement/index/filter?filterterm=' . $filterterm);
  35. }
  36. $data['searchterm'] = $searchterm;
  37. $this->load->library('pagination');
  38. $config['total_rows'] = $this->users->getuserlisttotal($data);
  39. $config['per_page'] = 10;
  40. $config['uri_segment'] = 3;
  41. $config['num_links'] = 7;
  42. $config['base_url'] = site_url('/usermanagement/index');
  43. $config['full_tag_open'] = '<nav><ul class="pagination pagination-sm">';
  44. $config['full_tag_close'] = '</ul></nav>';
  45. $config['num_tag_open'] = '<li>';
  46. $config['num_tag_close'] = '</li>';
  47. $config['prev_link'] = '&laquo;';
  48. $config['prev_tag_open'] = '<li>';
  49. $config['prev_tag_close'] = '</li>';
  50. $config['cur_tag_open'] = '<li><a><b>';
  51. $config['cur_tag_close'] = '</b></a></li>';
  52. $config['next_link'] = '&raquo;';
  53. $config['next_tag_open'] = '<li>';
  54. $config['next_tag_close'] = '</li>';
  55. $config['first_link'] = true;
  56. $config['last_link'] = false;
  57. $this->pagination->initialize($config);
  58. $this->data['pagination'] = $this->pagination->create_links();
  59. $this->data['per_page'] = $config['per_page'];
  60. $this->data['starting_no'] = $this->uri->segment(3);
  61. $this->data['searchterm'] = $searchterm;
  62. $this->data['userlist'] = $this->users->getuserlist($data, $config['per_page'],$this->data['starting_no']);
  63. $cnt = $this->data['usercount'] = $this->users->getusercount();
  64. $add1 = 0;
  65. foreach ($cnt as $row) {
  66. $userno = $row['usertype'];
  67. $add = $this->data['total'][$userno] = $row['counts'];
  68. $add1 = $add + $add1;
  69. }
  70. $this->data['total']['totalusers'] = $add1;
  71. $this->template->build('users', $this->data);
  72. }
  73. public function add()
  74. {
  75. if (!$this->session->userdata('logged_in')) {
  76. redirect('/');
  77. }
  78. if (!$this->misc->check_if_root()) {
  79. $this->misc->logAction('Unauthorized Attempt to add new user!!!');
  80. redirect('/usermanagement');
  81. }
  82. $this->data['todo'] = 'Insert';
  83. $this->template->build('users_edit', $this->data);
  84. }
  85. public function edit($id)
  86. {
  87. if (!$this->session->userdata('logged_in')) {
  88. redirect('/');
  89. }
  90. $this->data['todo'] = 'Update';
  91. if (is_numeric($this->uri->segment(3))) {
  92. $this->data['userlist'] = $this->users->get_user($id);
  93. } else {
  94. redirect('usermanagement');
  95. }
  96. $this->template->build('users_edit', $this->data);
  97. }
  98. public function view($id)
  99. {
  100. if (!$this->session->userdata('logged_in')) {
  101. redirect('/');
  102. }
  103. if (is_numeric($this->uri->segment(3))) {
  104. $this->data['userlist'] = $this->users->get_userview($id);
  105. } else {
  106. redirect('usermanagement');
  107. }
  108. $this->template->build('view_profile', $this->data);
  109. }
  110. public function insert_user()
  111. {
  112. if (!$this->session->userdata('logged_in')) {
  113. redirect('/');
  114. }
  115. $todo = $this->input->post('todo');
  116. $this->data['todo'] = $todo;
  117. #$file = $_FILES['upload_image']['name'];
  118. $filename = false;
  119. $this->data['userlist']['firstname'] = $this->input->post('firstname');
  120. $this->data['userlist']['lastname'] = $this->input->post('lastname');
  121. $this->data['userlist']['phoneno'] = $this->input->post('phoneno');
  122. $mail = $this->input->post('email');
  123. $this->data['userlist']['email'] = $this->input->post('email');
  124. $this->data['userlist']['note'] = $this->input->post('note');
  125. $this->data['userlist']['usertype'] = $this->input->post('usertype');
  126. $this->data['userlist']['password'] = $this->input->post('password');
  127. $this->form_validation->set_rules('email', 'Email','trim|required|xss_clean|valid_email|callback_check_email');
  128. if ($this->form_validation->run() == false) {
  129. if ($todo == 'Insert') {
  130. $this->template->build("users_edit", $this->data);
  131. } else
  132. if ($todo == 'Update') {
  133. $this->data['userlist']['id'] = $this->input->post('cid');
  134. $this->template->build("users_edit", $this->data);
  135. }
  136. } else {
  137. if ($todo == 'Insert') {
  138. /*if ($file != null) {
  139. $upload = $this->do_upload();
  140. $filename = $upload['upload_data']['file_name'];
  141. } else {
  142. $filename = false;
  143. }*/
  144. $this->users->insert_user($filename);
  145. $this->session->set_flashdata('msg', 'User added successfully!');
  146. $this->session->set_flashdata('cls', 'success');
  147. } else
  148. if ($todo == 'Update') {
  149. /*if ($file != null) {
  150. $upload = $this->do_upload();
  151. $filename = $upload['upload_data']['file_name'];
  152. } else {
  153. $filename = false;
  154. }*/
  155. $this->session->set_flashdata('msg', 'User updated successfully!');
  156. $this->session->set_flashdata('cls', 'success');
  157. $this->users->update_user($filename);
  158. $sess_array = array();
  159. $image = $this->db->query("SELECT * FROM sr_admincontrol WHERE id = ?",array($this->session->userdata['logged_in']['id']));
  160. $u = $this->session->userdata('logged_in');
  161. $hash = $u['hash'];
  162. $logo = $u['logo'];
  163. $company = $u['company'];
  164. $cid = $u['client_id'];
  165. $sess_array = array(
  166. 'id' => $this->session->userdata['logged_in']['id'],
  167. 'firstname' => $image->row()->firstname,
  168. 'lastname' => $image->row()->lastname,
  169. 'email' => $image->row()->email,
  170. 'logintype' => $image->row()->usertype,
  171. 'upload_image' => $image->row()->upload_image,
  172. 'hash' => $hash,
  173. 'logo' => $logo,
  174. 'company' => $company,
  175. 'client_id' => $cid
  176. );
  177. $this->misc->logAction('Updated User: ' . $image->row()->email);
  178. $this->session->set_userdata('logged_in', $sess_array);
  179. }
  180. redirect('usermanagement');
  181. }
  182. }
  183. public function do_upload()
  184. {
  185. if (!$this->session->userdata('logged_in')) {
  186. redirect('/');
  187. }
  188. $config['upload_path'] = './uploads/';
  189. $config['allowed_types'] = 'gif|jpg|png|pdf|jpeg';
  190. $config['max_size'] = '1000';
  191. $config['max_width'] = '1024';
  192. $config['max_height'] = '1024';
  193. $config['overwrite'] = true;
  194. $config['encrypt_name'] = true;
  195. $config['remove_spaces'] = true;
  196. $this->load->library('upload');
  197. $this->upload->initialize($config);
  198. if (!$this->upload->do_upload('upload_image')) {
  199. echo $this->upload->display_errors();
  200. } else {
  201. return array('upload_data' => $this->upload->data());
  202. }
  203. }
  204. public function check_email()
  205. {
  206. if (!$this->session->userdata('logged_in')) {
  207. redirect('/');
  208. }
  209. $email = $this->input->post('email');
  210. $todo = $this->input->post('todo');
  211. $cid = $this->input->post('cid');
  212. if ($todo == 'Insert') {
  213. $res = $this->db->get_where('sr_admincontrol', array('email' => $email,'is_delete' => 0));
  214. } else
  215. if ($todo == 'Update') {
  216. $res = $this->db->query('select * from sr_admincontrol where email=\'' . $email .'\' and id != ' . $cid . ' and is_delete=0');
  217. }
  218. if ($res->num_rows() > 0) {
  219. $this->form_validation->set_message('check_email', 'Email Already Exist');
  220. return false;
  221. }
  222. return true;
  223. }
  224. public function remove_user($id)
  225. {
  226. if (!$this->session->userdata('logged_in')) {
  227. redirect('/');
  228. }
  229. $this->users->remove_user($id);
  230. $this->session->set_flashdata('msg', 'User deleted successfully!');
  231. $this->session->set_flashdata('cls', 'success');
  232. $this->misc->logAction('Removed User with id '.$id);
  233. redirect('usermanagement');
  234. }
  235. }