· 5 years ago · Oct 18, 2019, 04:14 PM
1<?php
2require "vendor/autoload.php";
3use Abraham\TwitterOAuth\TwitterOAuth;
4
5if (!defined('BASEPATH'))
6 exit('No direct script access allowed');
7
8/**
9 * Description of loginModel
10 * @author rsingh6
11 */
12class login_model extends CI_Model
13{
14 public function __construct()
15 {
16 parent::__construct();
17 $this->load->library('session');
18 }
19
20 /**
21 * checkLogin for authorizing users
22 * @param POST values
23 * @author rsingh6
24 */
25 public function check_login($type='', $socialInfo=null)
26 {
27 $post = $this->input->post();
28 $this->load->model('user_log');
29 $roles_get = array(
30 '2'
31 );
32 $data = array();
33 if($type=='google') {
34 $this->db->select('*')->from('users')->where(array(
35 'email' => strtolower($socialInfo['email']),
36 'google_id' => $socialInfo['id'],
37 'status_id' => 1
38 ))->where_not_in('role_id', $roles_get);
39 $result = $this->db->get();
40 $data = $result->result();
41 if(empty($data)){
42 $this->db->select('*')->from('users')->where(array(
43 'email' => strtolower($socialInfo['email']),
44 'status_id' => 1
45 ))->where_not_in('role_id', $roles_get);
46 $res = $this->db->get();
47 $user_data = $res->result();
48 if($user_data) {
49 $update_data = array(
50 'google_id' => $socialInfo['id'],
51// 'medical_licence_no' => ''
52 );
53 $this->db->where('id', $user_data[0]->id);
54 $this->db->update('users', $update_data);
55 $data = $user_data;
56 } else {
57 $this->db->select('*')->from('users')->where(array(
58 'google_id' => $socialInfo['id'],
59 'status_id' => 1
60 ))->where_not_in('role_id', $roles_get);
61 $res = $this->db->get();
62 $user_data = $res->result();
63 $data = $user_data;
64 if(empty($user_data)) {
65 $first = str_replace(' ', '_', trim($socialInfo['first_name']));
66 $last = str_replace(' ', '_', trim($socialInfo['last_name']));
67 $user_slug = $first . '_' . $last;
68 if (empty($last)) {
69 $user_slug = $first;
70 }
71 $this->load->model('register_model');
72 $u_slug = $this->register_model->get_user_slug($user_slug);
73 $insert_data = array(
74 'google_id' => $socialInfo['id'],
75 'email' => $socialInfo['email'],
76 'first_name' => $socialInfo['first_name'],
77 'last_name' => $socialInfo['last_name'],
78 'profile_image' => $socialInfo['picture'],
79 'profile_image_thumb' => $socialInfo['picture'],
80 'profile_image_small_thumb' => $socialInfo['picture'],
81 'role_id' => 4,
82 'medical_licence_no' => '',
83 'status_id' => 1,
84 'timezone' => '',
85 'ip_address' => $this->input->ip_address(),
86 'patient_about_me' => '',
87 'npi' => '',
88 'licence_state' => '',
89 'user_slug' => $u_slug,
90 'lat'=>0,
91 'lng'=>0
92 );
93 $this->db->insert('users', $insert_data);
94 $this->db->select('*')->from('users')->where(array(
95 'google_id' => $socialInfo['id'],
96 'status_id' => 1
97 ))->where_not_in('role_id', $roles_get);
98 $res = $this->db->get();
99 $user_data = $res->result();
100 $data = $user_data;
101 }
102 }
103 }
104 }else if ($type=='twitter') {
105 $this->db->select('*')->from('users')->where(array(
106// 'email' => strtolower($socialInfo['email']),
107 'twitter_id' => $socialInfo['id'],
108 'status_id' => 1
109 ))->where_not_in('role_id', $roles_get);
110 $result = $this->db->get();
111 $data = $result->result();
112 if(empty($data)){
113 $this->db->select('*')->from('users')->where(array(
114 'twitter_id' => $socialInfo['id'],
115 'status_id' => 1
116 ))->where_not_in('role_id', $roles_get);
117 $res = $this->db->get();
118 $user_data = $res->result();
119 $data = $user_data;
120 if(empty($user_data)){
121 $first = str_replace(' ', '_', trim($socialInfo['first_name']));
122 $last = str_replace(' ', '_', trim($socialInfo['last_name']));
123 $user_slug = $first . '_' . $last;
124 if (empty($last)) {
125 $user_slug = $first;
126 }
127 $this->load->model('register_model');
128 $u_slug = $this->register_model->get_user_slug($user_slug);
129 $insert_data = array(
130 'twitter_id' => $socialInfo['id'],
131 'email' => $socialInfo['email'],
132 'first_name' => $socialInfo['first_name'],
133 'last_name' => $socialInfo['last_name'],
134 'screen' => $socialInfo['screen_name'],
135 'profile_image' => $socialInfo['picture'],
136 'profile_image_thumb' => $socialInfo['picture'],
137 'profile_image_small_thumb' => $socialInfo['picture'],
138 'role_id' => 4,
139 'medical_licence_no' => '',
140 'status_id' => 1,
141 'timezone' => '',
142 'ip_address' => $this->input->ip_address(),
143 'patient_about_me' => '',
144 'npi' => '',
145 'licence_state' => '',
146 'user_slug' => $u_slug,
147 'lat'=>0,
148 'lng'=>0
149 );
150 $this->db->insert('users', $insert_data);
151 $this->db->select('*')->from('users')->where(array(
152 'twitter_id' => $socialInfo['id'],
153 'status_id' => 1
154 ))->where_not_in('role_id', $roles_get);
155 $res = $this->db->get();
156 $user_data = $res->result();
157 $data = $user_data;
158 }
159 }
160 }else if ($type=='facebook') {
161 $this->db->select('*')->from('users')->where(array(
162 'email' => strtolower($socialInfo['email']),
163 'facebook_id' => $socialInfo['id'],
164 'status_id' => 1
165 ))->where_not_in('role_id', $roles_get);
166 $result = $this->db->get();
167 $data = $result->result();
168 if(empty($data)){
169 $this->db->select('*')->from('users')->where(array(
170 'email' => strtolower($socialInfo['email']),
171 'status_id' => 1
172 ))->where_not_in('role_id', $roles_get);
173 $res = $this->db->get();
174 $user_data = $res->result();
175 if($user_data) {
176 $update_data = array(
177 'facebook_id' => $socialInfo['id'],
178 );
179 $this->db->where('id', $user_data[0]->id);
180 $this->db->update('users', $update_data);
181 $data = $user_data;
182 } else {
183 $this->db->select('*')->from('users')->where(array(
184 'facebook_id' => $socialInfo['id'],
185 'status_id' => 1
186 ))->where_not_in('role_id', $roles_get);
187 $res = $this->db->get();
188 $user_data = $res->result();
189 $data = $user_data;
190 if(empty($user_data)){
191 $first = str_replace(' ', '_', trim($socialInfo['first_name']));
192 $last = str_replace(' ', '_', trim($socialInfo['last_name']));
193 $user_slug = $first . '_' . $last;
194 if (empty($last)) {
195 $user_slug = $first;
196 }
197 $this->load->model('register_model');
198 $u_slug = $this->register_model->get_user_slug($user_slug);
199 $insert_data = array(
200 'facebook_id' => $socialInfo['id'],
201 'email' => $socialInfo['email'],
202 'first_name' => $socialInfo['first_name'],
203 'last_name' => $socialInfo['last_name'],
204 'profile_image' => $socialInfo['picture'],
205 'profile_image_thumb' => $socialInfo['picture'],
206 'profile_image_small_thumb' => $socialInfo['picture'],
207 'role_id' => 4,
208 'medical_licence_no' => '',
209 'status_id' => 1,
210 'timezone' => '',
211 'ip_address' => $this->input->ip_address(),
212 'patient_about_me' => '',
213 'npi' => '',
214 'licence_state' => '',
215 'user_slug' => $u_slug,
216 'lat'=>0,
217 'lng'=>0
218 );
219 $this->db->insert('users', $insert_data);
220 $this->db->select('*')->from('users')->where(array(
221 'facebook_id' => $socialInfo['id'],
222 'status_id' => 1
223 ))->where_not_in('role_id', $roles_get);
224 $res = $this->db->get();
225 $user_data = $res->result();
226 $data = $user_data;
227 }
228 }
229 }
230 }else if($type=='admin_login') {
231 $this->db->select('*')->from('users')->where(array(
232 'id' => $socialInfo['user_id']
233 ));
234 $result = $this->db->get();
235 $data = $result->result();
236 $post = array();
237 $post['email'] = $socialInfo['email'];
238 $post['password'] = $socialInfo['password'];
239 }else {
240 $this->db->select('id, salt, password')->from('users')->where(array(
241 'email' => strtolower($post['email'])
242 ));
243 $salt = $this->db->get();
244 $salt_data = $salt->row();
245 if($salt_data) {
246 $this->db->select('*')->from('users')->where(array(
247 'email' => strtolower($post['email']),
248 'password' => sha1($post['password'] . $salt_data->salt),
249 'status_id' => 1
250 ))->where_not_in('role_id', $roles_get);
251
252 $result = $this->db->get();
253 $data = $result->result();
254
255 $qq = $this->db->select('status_id, role_id')->from('users')->where(array(
256 'email' => strtolower($post['email']),
257 'password' => sha1($post['password'] . $salt_data->salt),
258 ));
259 $result_qq = $qq->get();
260 }
261 }
262 if (!empty($data)) {
263 $role_result = $this->db->select('role')->from('role')->where(array(
264 'id' => $data[0]->role_id
265 ))->get();
266 $role_data = $role_result->result();
267 $ses_user = $this->getNameById($data[0]->id);
268 if($role_data[0]->role=='doctor') {
269 $ses_user = base_url() . $role_data[0]->role . '/' . strtolower($ses_user[0]->user_slug);
270 } else {
271 if(empty($ses_user[0]->user_slug)){
272 $ses_user[0]->user_slug = 'user';
273 }
274 $ses_user = base_url() . $role_data[0]->role . '/' . strtolower($ses_user[0]->user_slug) . '/' . $data[0]->id . '/';
275 }
276 $sess_data = array(
277 'user_id' => $data[0]->id,
278 'user_role' => $role_data[0]->role,
279 'first_name' => $data[0]->first_name,
280 'last_name' => $data[0]->last_name,
281 'email' => $post['email'],
282 'password' => $post['password'],
283 'user_dashboard_info' => $ses_user,
284 'ip_adress' => (!empty($_SERVER['REMOTE_ADDR'])) ? (string)$_SERVER['REMOTE_ADDR'] : ''
285 );
286 //Set cookie of remember me for login
287 if (isset($post['remember']) && $post['remember'] != '') {
288 $remember = $post['remember'];
289 } else {
290 $remember = '';
291 }
292 if ($remember == 1) {
293 $this->session->sess_expiration = 60 * 60 * 24 * 31;
294 $this->session->sess_expire_on_close = FALSE;
295 setcookie("cookname", base64_encode($sess_data['email']), time() + 60 * 60 * 24 * 100, "/");
296 setcookie("cookrole", base64_encode($sess_data['user_role']), time() + 60 * 60 * 24 * 100, "/");
297 setcookie("cookpass", base64_encode($sess_data['password']), time() + 60 * 60 * 24 * 100, "/");
298 } else {
299 setcookie("cookname", base64_encode($sess_data['email']), time() - 60 * 60 * 24 * 100, "/");
300 setcookie("cookrole", base64_encode($sess_data['user_role']), time() - 60 * 60 * 24 * 100, "/");
301 setcookie("cookpass", base64_encode($sess_data['password']), time() - 60 * 60 * 24 * 100, "/");
302 }
303 setcookie("islogin", base64_encode(1), time() + 60 * 60 * 24 * 100, "/");
304 $this->session->set_userdata('front_user', $sess_data);
305 $data['count'] = $this->db->count_all_results();
306 if (!isset($_SESSION)) {
307 session_start();
308 }
309 $_SESSION['forum_u_email'] = strtolower($post['email']);
310 $_SESSION['forum_u_password'] = $post['password'];
311 $_SESSION['userLogin'] = $sess_data;
312 if($data[0]->role_id == 1) {
313 $this->user_log->add_user_log($data[0]->id, USER_ACTIVITY_LOG_ACTION_LOGIN, USER_ACTIVITY_LOG_OBJECT_ADMIN_PROFILE, $data[0]->id, USER_ACTIVITY_LOG_METHOD_LOGIN_USER, $sess_data);
314 }else if($data[0]->role_id == 3) {
315 $this->user_log->add_user_log($data[0]->id, USER_ACTIVITY_LOG_ACTION_LOGIN, USER_ACTIVITY_LOG_OBJECT_DOCTOR_PROFILE, $data[0]->id, USER_ACTIVITY_LOG_METHOD_LOGIN_USER, $sess_data);
316 }else if($data[0]->role_id == 4){
317 $this->user_log->add_user_log($data[0]->id, USER_ACTIVITY_LOG_ACTION_LOGIN, USER_ACTIVITY_LOG_OBJECT_PATIENT_PROFILE, $data[0]->id, USER_ACTIVITY_LOG_METHOD_LOGIN_USER, $sess_data);
318 }
319
320 }
321
322 return $data;
323 }
324
325 /**
326 * @return mixed
327 */
328 public function getUser()
329 {
330 if (!isset($_SESSION)) {
331 session_start();
332 }
333
334 return $this->session->userdata('front_user');
335 }
336
337 /**
338 * check login status for fix header links
339 */
340 public function checkHeaderLinks()
341 {
342 $data = $this->session->userdata('front_user');
343 $states = $this->user_model->get_state();
344 $message = $this->session->userdata('message_consultation');
345 $this->session->unset_userdata('message_consultation');
346 if(!session_id()) {
347 session_start();
348 }
349 if(isset($_SERVER['HTTP_REFERER'])) {
350 $_SESSION['c_url'] = $_SERVER['HTTP_REFERER'];
351 }
352 $params = array(
353 'redirect_uri' => $this->config->item('GOOGLE_AUTH_REDIRECT_URL'),
354 'response_type' => 'code',
355 'client_id' => $this->config->item('GOOGLE_AUTH_CLIENT_ID'),
356 'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
357 );
358
359 $googleLoginLink = $this->config->item('GOOGLE_AUTH_URL') . '?' . urldecode(http_build_query($params));//'<a href="' . GOOGLE_AUTH_URL . '?' . urldecode(http_build_query($params)) . '"><img src="/img/social/32/googleplus.png" /></a>';
360
361 $fb = new Facebook\Facebook([
362 'app_id' => $this->config->item('FACEBOOK_APP_ID'),
363 'app_secret' => $this->config->item('FACEBOOK_APP_SECRET'),
364 'default_graph_version' => 'v2.2',
365 ]);
366
367 $helper = $fb->getRedirectLoginHelper();
368 $permissions = ['email'];
369 $loginUrl = $helper->getLoginUrl(base_url('/index/oauth2callbackFacebooklogin'), $permissions);
370 $facebookLoginLink = $loginUrl;//'<a href="' . htmlspecialchars($loginUrl) . '"><img src="/img/social/32/facebook.png" /></a>';
371
372
373
374 if (empty($this->config->item('LOCAL_FRAN'))) {
375
376 // create TwitterOAuth object
377 $twitteroauth = new TwitterOAuth($this->config->item('TWITTER_APP_KEY'), $this->config->item('TWITTER_APP_SECRET'));
378
379 // request token of application
380 $request_token = $twitteroauth->oauth(
381 'oauth/request_token', [
382 'oauth_callback' => base_url('index/oauth2callbackTwitterlogin')
383 ]
384 );
385
386 // throw exception if something gone wrong
387 if ($twitteroauth->getLastHttpCode() != 200) {
388 // throw new \Exception('There was a problem performing this request');
389 }
390 $request_token['oauth_token']=$request_token['oauth_token_secret']='';
391 // save token of application to session
392 $_SESSION['oauth_token'] = $request_token['oauth_token'];
393 $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
394
395 // generate the URL to make request to authorize our application
396 $url = $twitteroauth->url(
397 'oauth/authorize', [
398 'oauth_token' => $request_token['oauth_token']
399 ]
400 );
401 $twitterLoginLink = $url;
402 } else {
403 $twitterLoginLink = '';
404 }
405
406
407
408 if (isset($data['user_id'])) {
409 $CI =& get_instance();
410 $CI->load->model('login_model');
411 $user_details_id = $CI->login_model->getNameById($data['user_id']);
412 if (isset($user_details_id[0]) && $user_details_id[0]->first_name != "" && $user_details_id[0]->last_name != "") {
413 $screen = $user_details_id[0]->screen;
414 $first_last = trim($user_details_id[0]->first_name[0]).trim($user_details_id[0]->last_name[0]);
415 } else if ($user_details_id[0] && $user_details_id[0]->role_id == 3) {
416 $screen = $user_details_id[0]->screen;
417 $first_last = trim($user_details_id[0]->first_name[0]).trim($user_details_id[0]->last_name[0]);
418 } else {
419 $screen = $user_details_id[0]->screen;
420 $first_last = trim($user_details_id[0]->screen);
421 }
422 $path = USERPIC_PATH;
423 if (strpos($user_details_id[0]->profile_image_small_thumb, 'http://') !== false || strpos($user_details_id[0]->profile_image_small_thumb, 'https://') !==false)
424 {
425 $path = '';
426 }
427 $photo = isset($user_details_id[0]->profile_image_small_thumb) && !empty($user_details_id[0]->profile_image_small_thumb) ? $path.$user_details_id[0]->profile_image_small_thumb : '/images/frontend/profilepic/profile.png';
428 if ($user_details_id[0]->role_id == 3) {
429 $screen = "Welcome Dr. " . $screen;
430 } else {
431 $screen = $screen;
432 }
433
434 $first = str_replace(' ', '-', $user_details_id[0]->first_name);
435 $last = str_replace(' ', '-', $user_details_id[0]->last_name);
436 if ($data['user_role'] == 'doctor') {
437 $dashboard = base_url() . 'doctor/' . $user_details_id[0]->user_slug;
438 $doctor = true;
439 } else {
440 $dashboard = base_url() . 'patient/' . $user_details_id[0]->user_slug;
441 $doctor = false;
442 }
443 return [
444 "dashboard" => $dashboard,
445 "screen" => $screen,
446 "first_last" =>$first_last,
447 "doctor" => $doctor,
448 "states" => $states,
449 "photo" => $photo,
450 "googleLoginLink" => $googleLoginLink,
451 "facebookLoginLink" => $facebookLoginLink,
452 "twitterLoginLink"=> $twitterLoginLink,
453 "PIXEL_ID" =>PIXEL_ID,
454 "message_consultation" => $message
455 ];
456 } else {
457 return [
458 "dashboard" => false,
459 "screen" => false,
460 "doctor" => false,
461 "states" => $states,
462 "googleLoginLink" => $googleLoginLink,
463 "facebookLoginLink" => $facebookLoginLink,
464 "twitterLoginLink"=> $twitterLoginLink,
465 "PIXEL_ID" =>PIXEL_ID,
466 "message_consultation" => $message
467 ];
468 }
469 }
470
471 public function get_exp_reset_pass_link_flag($email)
472 {
473 $this->db->select('exp_reset_pass_link');
474 $this->db->from('users');
475 $this->db->where('email', $email);
476 $this->db->where('status_id', 1);
477 $query = $this->db->get();
478 $result = $query->row();
479 if($result){
480 return $result->exp_reset_pass_link;
481 }else{
482 return 0;
483 }
484 }
485
486 /**
487 * reset_link for getting reset link for users
488 * @param POST values
489 * @author rsingh6
490 */
491 public function reset_link($email, $exp_reset_pass_link)
492 {
493 $this->db->select('id,role_id, password');
494 $this->db->from('users');
495 $this->db->where('email', $email);
496 $this->db->where('status_id', 1);
497 $query = $this->db->get();
498 $result = $query->result();
499 if ($query->num_rows() > 0) {
500 $data = array(
501 'exp_reset_pass_link' => $exp_reset_pass_link
502 );
503 $this->db->where('id', $result[0]->id);
504 $this->db->update('users', $data);
505 $queryy = $this->db->select('r.role')->from('users u')->where('u.id', $result[0]->id)->where('u.role_id', $result[0]->role_id)->join('role r', 'r.id = u.role_id')->get()->result();
506 $role = $queryy;
507 return array(
508 'code' => $result[0]->password,
509 'role' => $role[0]->role
510 );
511 } else {
512 return 2;
513 }
514 }
515
516 /**
517 * reset_password for resetting password of users
518 * @param POST values
519 * @author rsingh6
520 */
521 public function reset_password($email, $verification_code, $exp_reset_pass_link)
522 {
523 $post = $this->input->post();
524 $this->db->select('id,email,exp_reset_pass_link');
525 $this->db->from('users');
526 $this->db->where('email', $email);
527 $this->db->where('password', $verification_code);
528 $query = $this->db->get();
529 $result = $query->result();
530 if ($query->num_rows() > 0 && $result[0]->exp_reset_pass_link!=1) {
531 $v4uuid = UUID::v4($email.time());
532 $salt = md5($v4uuid);
533 $password = sha1($post['newpassword'].$salt);
534 $data = array(
535 'password' => $password,
536 'salt' => $salt,
537 'exp_reset_pass_link' => $exp_reset_pass_link
538 );
539 $forum = array(
540 'user_password' => $password
541 );
542 $this->db->where('id', $result[0]->id);
543 $this->db->update('users', $data);
544 $this->db->select('user_id');
545 $this->db->from('phpbb_users');
546 $this->db->where('user_email', $result[0]->email);
547 $forumQuery = $this->db->get();
548 $forumData = $forumQuery->result();
549 if(isset($forumData[0])) {
550 $this->db->where('user_id', $forumData[0]->user_id);
551 $this->db->update('phpbb_users', $forum);
552 }
553 return 1;
554 } else {
555 return 2;
556 }
557 }
558
559 /**
560 * getUserData for authorizing users
561 * @param POST values
562 * @author rsingh6
563 */
564 public function getUserData($type, $id = '')
565 {
566 $data = $this->session->userdata('front_user');
567 if ($type == 'doctor_profile') {
568 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
569 'users.id' => $this->uri->segment(3),
570 'users.status_id' => 1
571 ));
572 $result = $this->db->get();
573 $data = $result->result();
574 } else if ($type == 'doctor') {
575 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
576 'users.id' => $this->uri->segment(3),
577 'users.status_id' => 1
578 ));
579 $result = $this->db->get();
580 $data = $result->result();
581 } else if ($type == 'patient') {
582 $this->db->select('*')->from('users')->where(array(
583 'id' => $id,
584 'status_id' => 1,
585 'role_id' => 4
586 ));
587 $result = $this->db->get();
588 $data = $result->result();
589 }
590 return $data;
591 }
592
593//////////////////////////////////
594 /**
595 * getUserData for authorizing users without segment value
596 * @param POST values
597 * @author rsingh6
598 */
599 public function getUserData_without_segment_value($type, $id = '')
600 {
601 $data = $this->session->userdata('front_user');
602 if ($type == 'doctor_profile') {
603 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
604 'users.id' => $id,
605 'users.status_id' => 1
606 ));
607 $result = $this->db->get();
608 $data = $result->result();
609 } else if ($type == 'doctor') {
610 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
611 'users.id' => $id,
612 'users.status_id' => 1
613 ));
614 $result = $this->db->get();
615 $data = $result->result();
616 } else if ($type == 'patient') {
617 $this->db->select('*')->from('users')->where(array(
618 'id' => $id,
619 'status_id' => 1,
620 'role_id' => 4
621 ));
622 $result = $this->db->get();
623 $data = $result->result();
624 }
625 return $data;
626 }
627/////////////////////////
628
629
630 /**
631 * getUserData for authorizing users
632 * @param POST values
633 * @author rsingh6
634 */
635
636 public function getUserMessageData($id = '')
637 {
638 $data = $this->session->userdata('front_user');
639
640 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
641 'users.id' => $id,
642 'users.status_id' => 1
643 ));
644 $result = $this->db->get();
645 $data = $result->result();
646 //echo "<pre>"; print_r($data );
647 return $data;
648 }
649
650 /**
651 * check user email exist in database
652 * @param email
653 * @author rsingh6
654 */
655 public function email_exist($email)
656 {
657 $this->db->where('email', $email);
658 $this->db->select('email');
659 $query = $this->db->get('users');
660 if ($query->num_rows() > 0) {
661 return true;
662 } else {
663 return false;
664 }
665 }
666
667 public function screen_exist($email)
668 {
669 $this->db->where('screen', $email);
670 $this->db->select('screen');
671 $query = $this->db->get('users');
672 if ($query->num_rows() > 0) {
673 return true;
674 } else {
675 return false;
676 }
677 }
678
679 public function screen_existt($email, $id)
680 {
681 //$this->db->where('screen', $email);
682 // $this->db->where('id !=', $id);
683 $this->db->select('screen FROM users where screen = "' . trim($email) . '" and id != "' . $id . '"');
684 $query = $this->db->get();
685 if (count($query->result()) > 0) {
686 return true;
687 } else {
688 return false;
689 }
690 }
691
692 /**
693 * getNameByEmail for fetching name by email
694 * @param POST values
695 * @author rsingh6
696 */
697 public function getNameByEmail($email)
698 {
699 $this->db->where('email', $email);
700 $this->db->select('first_name,last_name');
701 $query = $this->db->get('users');
702 $data = $query->result();
703 if ($query->num_rows() > 0) {
704 return $data;
705 }
706 }
707
708 /**
709 * getNameById for fetching username
710 * @param POST values
711 * @author rsingh6
712 */
713 public function getNameById($id)
714 {
715 $this->db->where('id', $id);
716 $this->db->select('*');
717 $query = $this->db->get('users');
718 $data = $query->result();
719 if ($query->num_rows() > 0) {
720 return $data;
721 }
722 }
723
724 /**
725 * get_user_by_ids for fetching id's of users
726 * @param POST values
727 * @author rsingh6
728 */
729 public function get_user_by_ids($id)
730 {
731 $this->db->where('id', $id);
732 $this->db->select('id');
733 $query = $this->db->get('users');
734 $data = $query->result();
735 if ($query->num_rows() > 0) {
736 return $data;
737 } else {
738 $data = '';
739 }
740 }
741
742 /**
743 * to add about me text
744 * @param $user_id ,$text
745 */
746 public function add_about_me($user_id, $text)
747 {
748 $old_data = $this->db->select('patient_about_me')->get_where('users', array('id'=>$user_id))->row_array();
749 $data = array(
750 'patient_about_me' => $text
751 );
752 $this->db->where('id', $user_id);
753 $this->db->update('users', $data);
754 $session_data = $this->session->userdata('front_user');
755 $this->load->model('user_log');
756 if($session_data && !empty(array_diff($data, $old_data))){
757 $this->user_log->add_user_log($session_data['user_id'], USER_ACTIVITY_LOG_ACTION_EDIT, USER_ACTIVITY_LOG_OBJECT_PATIENT_PROFILE, $user_id, USER_ACTIVITY_LOG_METHOD_EDIT_PATIENT_PROFILE, array_diff($data, $old_data));
758 }
759 return true;
760 }
761
762 /**
763 * get claim doctor detail
764 */
765 public function claim_doctor_data()
766 {
767
768 $user_slug = $this->uri->segment(2);
769 if (strpos($user_slug, '-') !== false) {
770 $user_slug = str_replace('-', '_', $user_slug);
771 }
772 $this->db->where('user_slug', $user_slug);
773 $this->db->select('*');
774 $query = $this->db->get('claim_users');
775 $data = $query->result();
776
777 return $data;
778 }
779
780 /**
781 * get selected board cerification of doctor
782 **/
783
784 public function get_board_cerfication($board_certification = '')
785 {
786
787 if ($board_certification != '') {
788 $board_certification = explode(",", $board_certification);
789 $this->db->where_in('id', $board_certification);
790 }
791 $this->db->select('*');
792 $query = $this->db->get('board_certification');
793 $data = $query->result();
794 return $data;
795 }
796
797/////////////////ADDED FUNCTION//////////////////////////
798 public function getnewUserData($type, $id = '')
799 {
800 $data = $this->session->userdata('front_user');
801 if ($type == 'doctor_profile') {
802 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
803 'users.id' => $id,
804 'users.status_id' => 1
805 ));
806 $result = $this->db->get();
807 $data = $result->result();
808 } else if ($type == 'doctor') {
809 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
810 'users.id' => $id,
811 'users.status_id' => 1
812 ));
813 $result = $this->db->get();
814 $data = $result->result();
815 } else if ($type == 'patient') {
816 $this->db->select('*')->from('users')->where(array(
817 'id' => $this->uri->segment(3),
818 'status_id' => 1,
819 'role_id' => 4
820 ));
821 $result = $this->db->get();
822 $data = $result->result();
823 }
824 return $data;
825 }
826
827 public function getClaimData($id)
828 {
829 $this->db->select('*')->from('claim_users');
830 $this->db->where(array(
831 'id' => $id
832 ));
833 $result = $this->db->get();
834 $data = $result->result();
835 return $data;
836 }
837
838 public function getFeaturedDoctors($limit=null)
839 {
840 $data = $this->session->userdata('front_user');
841 $this->db->select('*,users.id as users_id FROM `users` LEFT JOIN `doctor_profile` ON doctor_profile.users_id = users.id')->where(array(
842 'users.featured' => 'Yes',
843 'users.status_id' => 1
844 ));
845 if($limit){
846 $result = $this->db->limit($limit,0);
847 }
848 $result = $this->db->get();
849 $data = $result->result();
850
851 return $data;
852 }
853}
854/* End of file loginModel.php */
855/* Location: ./application/models/loginModel.php */