Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class User extends CI_Controller {
- var $valid = false,
- $cs_email = 'no-reply@com.com';
- protected $linkPage;
- protected $segment = 3;
- protected $totalPage = 0;
- protected $perPage = 20;
- function __construct()
- {
- parent::__construct();
- $this->load->model('user_model');
- $this->load->model('admin_model');
- $this->load->model('security_model');
- $this->session->set_userdata('table_prefix', $this->config->item('table_prefix'));
- $this->valid = $this->session->userdata('is_authed');
- // var_dump($this->session->userdata('is_authed'));
- if ( strlen($this->uri->segment(1)) == 2 )
- $this->lang->load( $this->uri->segment(1), 'gox');
- else
- $this->lang->load( 'en', 'gox');
- $params = array(
- 'object' => &$this,
- 'server' => &$_SERVER,
- );
- log_index($params);
- $this->template->set_template('sbadmin2');
- $uri = $this->uri->segment(2);
- //if( preg_match('/(image|login$/', $uri))
- // return;
- //$user_info = $this->session->userdata('user_info');
- //if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- // redirect('admin/index');
- }
- protected function pagination() {
- $this->load->library('pagination');
- $config = array();
- $config['uri_segment'] = $this->segment;
- $config['base_url'] = $this->linkPage;
- $config['total_rows'] = $this->totalPage;
- $config['per_page'] = $this->perPage;
- $config['full_tag_open'] = '<ul class="pagination">';
- $config['full_tag_close'] = '</ul>';
- $this->pagination->initialize($config);
- return $this->pagination->create_links();
- }
- protected function start_page($uri) {
- if ($this->uri->segment($uri) > 0) {
- $start = $this->uri->segment($uri);
- } else {
- $start = 0;
- }
- return $start;
- }
- public function index()
- {
- $this->gox_acl->validate_create();
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- redirect('user/register','refresh');
- }
- function dashboard()
- {
- show_404();
- if ( $this->valid )
- redirect('app/index');
- else
- {
- $this->session->set_flashdata('flash_message', lang('LoginIsRequired'));
- redirect('user/login');
- }
- }
- function form_validation($is_edit = 0)
- {
- $flag = True;
- $output = null;
- if ( $is_edit == 1)
- {
- $this->form_validation->set_rules('id', 'id', 'trim|required|xss_clean');
- }
- else
- {
- $this->form_validation->set_rules('email', lang('Email'), 'trim|required|xss_clean|valid_email|callback__email_unique');
- }
- $this->form_validation->set_rules('name', lang('Name'), 'trim|required|xss_clean');
- $this->form_validation->set_rules('username', lang('Username'), 'trim|required|xss_clean');
- $this->form_validation->set_rules('password', lang('Password'), 'trim|required|xss_clean|matches[re_password]');
- $this->form_validation->set_rules('re_password', lang('ReTypePassword'), 'trim|required|xss_clean');
- if ( $this->form_validation->run() == False or $flag === False)
- {
- $errMsg = $this->form_validation->error_string() ;
- return $errMsg;
- }
- else
- {
- return null;
- }
- }
- function _email_unique($str)
- {
- $is_unique = $this->user_model->user_email_unique( $str );
- $errMsg = $this->form_validation->error_string() ;
- if ( $is_unique )
- return True;
- else
- $this->form_validation->set_message('email_unique', lang('ErrorEmailTaken'));
- return False;
- }
- function register()
- {
- $this->gox_acl->validate_create();
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- $submit = $this->input->post('submit');
- $data = array();
- if ( $submit )
- {
- $errMsg = $this->form_validation();
- if ( !$errMsg )
- {
- $params = array(
- 'input' => $this->input->post(),
- );
- $user_id = $this->user_model->add_user( $params );
- if ( $user_id )
- {
- $data['user_info'] = $this->user_model->profile(null, $user_id);
- $this->load->library('phpmailer2');
- $this->phpmailer2->addAddress($data['user_info']->email, $data['user_info']->name);
- $this->phpmailer2->addFrom($this->cs_email, 'Customer Service BOSS');
- $this->phpmailer2->subject('Registration');
- $this->phpmailer2->message($this->load->view('user/register_mail_ok', $data, TRUE) );
- if ( !$this->phpmailer2->send() )
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'Email not sent', $this->phpmailer2->ErrorInfo));
- }
- // echo $this->email->print_debugger();
- $this->session->set_flashdata('flash_message', lang('AnEmailHasBeenSent'));
- $this->template->write_view('content','user/register_ok', array());
- $this->template->render();
- return;
- }
- else
- $data['error'] = lang('ErrorDataCreationFailed');
- }
- else
- $data['error'] = $errMsg;
- }
- else
- null;
- $this->template->write_view('content', 'user/register', $data);
- $this->template->render();
- }
- function login()
- {
- $COMMON_USER = 18;
- // $this->output->enable_profiler(true);
- $submit = $this->input->post('submit');
- $forgot_password = $this->input->post('forgot_password');
- if ( $forgot_password )
- {
- redirect('user/forgot_password');
- }
- if ( $submit )
- {
- $params = array(
- 'object' => &$this,
- 'server' => &$_SERVER,
- 'try_username' => $this->input->post('username'),
- );
- log_index($params);
- $params = array(
- 'username' => $this->input->post('username'),
- 'password' => $this->input->post('password'),
- );
- $user_info = $this->user_model->login2($params);
- if ( $user_info !== false)
- {
- if ($user_info->bverified == 0)
- {
- $this->session->set_flashdata('flash_message', lang('PleaseVerifyByEmail'));
- redirect('user/login');
- return;
- }
- if ($user_info->idelete == 1)
- {
- $this->session->set_flashdata('flash_message', lang('UserIsSuspended'));
- redirect('user/login');
- return;
- }
- // reset n_retires
- $this->user_model->update_retries($params['username'], true);
- // Prune unnrecessary data
- // as CI session has size restriction
- $temp = new StdClass();
- $temp->name = $user_info->name;
- $temp->username = $user_info->username;
- $temp->id = $user_info->id;
- $temp->user_type_id = $user_info->user_type_id;
- $temp->level_id = $user_info->level_id;
- $this->session->set_userdata('is_authed',1);
- $this->session->set_userdata('user_info', $temp);
- //$this->session->set_userdata('apikey', $api_token);
- $this->session->set_flashdata('flash_message', lang('LoginSuccess'));
- //var_dump($temp, $this->session->userdata('user_info')); die();
- $params = array(
- 'object' => &$this,
- 'server' => &$_SERVER,
- );
- log_index($params);
- redirect('admin/index');
- return;
- }
- else{
- $this->user_model->update_retries($params['username'], false);
- $this->session->set_flashdata('flash_message', lang('LoginFailed'));
- }
- }
- else
- null;
- // $this->load->view('login');
- $this->template->set_template('bootstrap');
- $this->template->write_view('content', 'login', '', TRUE);
- $this->template->render();
- }
- function logout()
- {
- $this->session->set_userdata('user_info', null);
- $this->session->set_userdata('is_authed', null);
- $this->session->set_flashdata('flash_message', lang('Goodbye'));
- redirect('user/login');
- }
- function email_verify($verification_code = null, $user_id = null)
- {
- if( $verification_code and $user_id )
- {
- $params = array(
- 'user_id' => $user_id,
- 'verification_code' => $verification_code,
- );
- list($bResult, $user_info, $resMsg) = $this->user_model->email_verify($params);
- if ( $bResult )
- {
- //update bverified
- list($bResult, $result, $resMsg) = $this->user_model->email_verify_update( $params );
- if ( $bResult )
- {
- $this->session->set_flashdata('flash_message', lang('EmailVerified'));
- $this->session->set_userdata('user_info', $user_info);
- $this->session->set_userdata('is_authed', 1);
- //redirect to dashboard
- redirect('app/index');
- return;
- }
- else
- $data['error'] = lang('ErrorInvalidVerification');
- }
- else
- $data['error'] = lang('ErrorInvalidVerification');
- }
- else
- $data['error'] = lang('ErrorInvalidVerification');
- $this->template->write_view('content', 'user/email_verify', $data);
- $this->template->render();
- }
- function usersdepartment_autocomplete()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $params = array(
- 'department_id' => $this->input->post('department_id'),
- );
- $result = $this->user_model->users_autocomplete( $this->input->post('term'), $params );
- echo json_encode( $result );
- die();
- }
- function users_autocomplete()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->users_autocomplete( $this->input->post('term') );
- echo json_encode( $result );
- die();
- }
- function avail_crews_autocomplete()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->avail_crews_autocomplete( $this->input->post('term'), array('is_member' => true) );
- echo json_encode( $result );
- die();
- }
- function revived_autocomplete()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $params = array(
- 'term' => $this->input->post('term'),
- 'vessel_id' => $this->input->post('vessel_id'),
- 'vessel_summon_id' => $this->input->post('vessel_summon_id'),
- );
- $result = $this->user_model->revived_autocomplete( $params );
- echo json_encode( $result );
- die();
- }
- function members_autocomplete()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->users_autocomplete( $this->input->post('term'), array('is_member' => true) );
- echo json_encode( $result );
- die();
- }
- function reset_password()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- if ( $this->valid or $this->session->flashdata('temp_access') )
- {
- if ( $this->valid )
- {
- if( !$this->session->userdata('is_route') )
- $this->template->set_template('sbadmin2');
- }
- $submit = $this->input->post('submit');
- if ($submit )
- {
- $errMsg = $this->form_validation_reset_password();
- if ( !$errMsg )
- {
- $user_info = $this->session->userdata('user_info');
- $params = array(
- 'user_id' => $user_info->id,
- 'password' => $this->input->post('password'),
- );
- $this->user_model->reset_password($params);
- $this->template->write_view('content', 'user/reset_password_ok', '');
- $this->template->render();
- return;
- }
- else
- {
- $this->session->set_flashdata('flash_message', lang('ErrorInvalidInput'));
- }
- }
- $this->template->write_view('content', 'user/reset_password', '');
- $this->template->render();
- $this->session->set_flashdata('temp_access', 1);
- return;
- }
- else
- $this->session->set_flashdata('flash_message', lang('ErrorPermissionDenied'));
- redirect('user/login');
- }
- function proccess_reset_password(){
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) and $this->uri->segment(2) != 'login')
- show_404();
- $user_info = $this->session->userdata('user_info');
- $params = array(
- 'user_id' => $user_info->id,
- 'password' => $this->input->post('password'),
- );
- if($this->user_model->reset_password($params) == true)
- {
- $respon = array('respon' => 'true', 'msg' => lang('SuccessDataUpdate'));
- }
- else
- {
- $respon = array('respon' => 'true', 'msg' => lang('ErrorDataUpdateFailed'));
- }
- echo json_encode($respon);
- }
- function form_validation_reset_password()
- {
- $this->form_validation->set_rules('password', lang('Password'), 'trim|required|xss_clean|min_length[6]|max_length[20]');
- if ( $this->form_validation->run() == False)
- {
- $errMsg = $this->form_validation->error_string() ;
- return $errMsg;
- }
- else
- {
- return null;
- }
- }
- function forgot_password_verify( $token = null)
- {
- show_404();
- if( $token )
- {
- $params = array('token' => $token);
- list($flag , $user, $message) = $this->user_model->forgot_password_verify($params);
- if ( $flag )
- {
- $update_params = array('user_id' => $user->id);
- list($update_flag , $update_res, $update_message) = $this->user_model->forgot_password_verify_update($update_params);
- $this->session->userdata('user_info', $user);
- $this->session->set_flashdata('temp_access', 1);
- redirect('user/reset_password');
- }
- }
- else
- null;
- $this->template->write_view('content', 'user/forgot_password_verify_failed', '');
- $this->template->render();
- }
- function forgot_password()
- {
- show_404();
- $submit = $this->input->post('submit');
- $email = $this->input->post('email');
- if ( $submit and $email)
- {
- $params = array('email' => $email);
- $user = $this->user_model->profile2($params);
- $this->session->set_flashdata('flash_message', lang('AnEmailHasBeenSent'));
- if ( $user )
- {
- $token = md5(rand(10000000,1000000000));
- $params = array(
- 'email' => $email,
- 'token' => $token,
- 'user_id' => $user->id,
- );
- $this->user_model->insert_forgot_password_token($params);
- $data = array('email' => $email, 'token' => $token, 'user_info' => $user);
- $this->load->library('phpmailer2');
- $this->phpmailer2->addAddress($email, $user->name);
- $this->phpmailer2->addFrom($this->cs_email, 'Customer Service BOSS');
- $this->phpmailer2->subject(lang('ForgotPassword'));
- $this->phpmailer2->message($this->load->view('user/forgot_password_mail', $data, TRUE) );
- // $this->phpmailer2->print_debugger();
- if ( !$this->phpmailer2->send() )
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'Email not sent', $this->phpmailer2->ErrorInfo));
- }
- redirect('user/login');
- }
- else
- null;
- redirect('user/forgot_password');
- }
- else
- null;
- $this->template->write_view('content', 'user/forgot_password', '');
- $this->template->render();
- }
- function form_validation_agent_request()
- {
- $this->form_validation->set_rules('id', lang('ID'), 'trim|required|xss_clean');
- $this->form_validation->set_rules('upline_id', lang('UplineID'), 'trim|required|xss_clean');
- $this->form_validation->set_rules('agent_code', lang('AgentCode'), 'trim|required|xss_clean|callback_unique_agentcode');
- $this->form_validation->set_rules('join_payment', lang('JoinPayment'), 'trim|required|xss_clean|max_length[40]');
- if ( $this->form_validation->run() == False)
- {
- $errMsg = $this->form_validation->error_string() ;
- return $errMsg;
- }
- else
- {
- return null;
- }
- }
- function unique_agentcode($str)
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $is_existed = $this->user_model->unique_agentcode($str);
- if ( $is_existed )
- {
- $this->form_validation->set_message('unique_agentcode', sprintf('%s -> %s', lang('AgentCode'), lang('Existed')));
- return False;
- }
- else
- return True;
- }
- function agent_request()
- {
- // FIXME, send email to any member that is promoted
- if ( $this->valid )
- $this->template->set_template('sbadmin2');
- else
- {
- $this->session->set_flashdata('flash_message', lang('ErrorPermissionDenied'));
- redirect('app/index');
- }
- $submit = $this->input->post('submit');
- $void = $this->input->post('void');
- $id = $this->input->post('id');
- $data = array();
- if ( $void and $id )
- {
- $params = array(
- 'id' => $id,
- 'idelete' => 1,
- );
- list($flag, $result, $message) = $this->user_model->agent_request_update($params);
- }
- if ( $submit and $id )
- {
- //$errMsg = $this->form_validation_agent_request();
- //if ( $errMsg )
- // die(_ajax_upload_error($errMsg));
- unset($_POST['submit']);
- unset($_POST['void']);
- if ( $this->input->post('registration_date') )
- {
- $reg_date = explode(' ',$this->input->post('registration_date'));
- if(count($reg_date) == 2)
- $_POST['registration_date'] = reverseDate($reg_date[0]).' '.$reg_date[1];
- else
- $_POST['registration_date'] = reverseDate($reg_date[0]);
- }
- list($flag, $result, $message) = $this->user_model->agent_request_update($this->input->post());
- if ( $flag )
- die(_ajax_upload_success($message));
- else
- die(_ajax_upload_error($message));
- }
- else
- null;
- $params = array(
- 'is_count' => true,
- 'idelete' => $APPROVED = 0,
- );
- $data['approved'] = $this->user_model->agent_request($params);
- $params['idelete'] = $VOID = 1;
- $data['void'] = $this->user_model->agent_request($params);
- $params['idelete'] = $PENDING = 3;
- $data['pending'] = $this->user_model->agent_request($params);
- $params = array('noparent' => true);
- $data['noparent_records'] = $this->user_model->agent_request($params);
- $params = array('withparent' => true);
- $data['withparent_records'] = $this->user_model->agent_request($params);
- $this->template->write_view('content', 'user/agent_request', $data);
- $this->template->render();
- }
- function agent_request_modal($id = null)
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- if ( !$id )
- die(lang('ErrorIdIsNull'));
- $params= array('id' => $id);
- $data['request_record'] = $this->user_model->agent_request($params);
- $data['branches'] = $this->user_model->branch();
- $data['record'] = $this->user_model->profile(null, $data['request_record']->user_id);
- $this->load->view('user/modal_agent', $data);
- }
- function uplineid_autocomplete()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->uplineid_autocomplete( $this->input->post('term') );
- echo json_encode( $result );
- die();
- }
- function agentcode_autocomplete()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->agentcode_autocomplete( $this->input->post('term') );
- echo json_encode( $result );
- die();
- }
- function subscriber_autocomplete()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->subscriber_autocomplete( $this->input->post('term') );
- echo json_encode( $result );
- die();
- }
- function agent_autocomplete()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $result = $this->user_model->agent_autocomplete( $this->input->post('term') );
- echo json_encode( $result );
- die();
- }
- function reset_and_email()
- {
- $this->gox_acl->validate_update();
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $id = $this->input->post('id');
- if ( $id )
- {
- $params = array(
- 'user_id' => $id,
- 'password' => '123456',
- 'bverified' => 1,
- );
- list( $flag, $user_id, $message) = $this->user_model->reset_password($params);
- if ( !$flag )
- die(_ajax_upload_error(lang('ErrorDataUpdateFailed')));
- $data_mail['user_info'] = $this->user_model->profile2(array('id' => $id));
- $data_mail['default_pwd'] = $params['password'];
- $this->load->library('phpmailer2');
- $this->phpmailer2->addAddress($data_mail['user_info']->email, $data_mail['user_info']->name);
- $this->phpmailer2->addFrom($this->cs_email, 'Customer Service BOSS');
- $this->phpmailer2->addBcc('adesantoasman@gmail.com', 'adesanto asman');
- // $this->phpmailer2->addBcc('marlinda.tjhie@gmail.com', 'Marlinda');
- $this->phpmailer2->subject('Password Reset by Admin');
- $this->phpmailer2->message($this->load->view('user/reset_pwd_by_admin', $data_mail, TRUE) );
- // $this->phpmailer2->print_debugger();
- if ( !$this->phpmailer2->send() )
- {
- log_message('error',sprintf('%s (%s): %s, %s', __FILE__,__LINE__,'Email not sent', $this->phpmailer2->ErrorInfo));
- }
- die(_ajax_upload_success(lang('Success')));
- }
- else
- die(_ajax_upload_error(lang('ErrorIdIsNull')));
- }
- function user_pic_upload()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- # @todo auto resize the picture to allowed size
- $id = $this->input->post('id');
- $USERPIC = 20;
- if ( !$id )
- die(_ajax_upload_error(lang('ErrorIdIsNull')));
- $newfile = date('YmdHis') . rand(0,1000);
- $ext = get_uploaded_file_extention( $_FILES['file']['name']);
- $params = array(
- 'path' => 'upload/user/pic/'.$newfile. $ext,
- 'id' => $id,
- 'ifiles' => $USERPIC,
- );
- $flag = $this->user_model->insert_user_upload($params);
- if ( $flag )
- {
- if (!empty($_FILES))
- {
- $tempFile = $_FILES['file']['tmp_name'];
- $path = realpath(FCPATH). FILE_SEPARATOR. $params['path'];
- $targetPath = $path;
- move_uploaded_file($tempFile, $targetPath);
- }
- $data['error'] = null;
- }
- else
- {
- $data['error'] = $message;
- }
- }
- function user_id_upload()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- # Fixme add notation if public or private access, specially form_validation
- # @todo auto resize the picture to allowed size
- $USERID = 10;
- $id = $this->input->post('id');
- if ( !$id )
- die(_ajax_upload_error(lang('ErrorIdIsNull')));
- $newfile = date('YmdHis') . rand(0,1000);
- $ext = get_uploaded_file_extention( $_FILES['file']['name']);
- $params = array(
- 'path' => 'upload/user/id/'.$newfile. $ext,
- 'id' => $id,
- 'ifiles' => $USERID,
- );
- $flag = $this->user_model->insert_user_upload($params);
- if ( $flag )
- {
- if (!empty($_FILES))
- {
- $tempFile = $_FILES['file']['tmp_name'];
- $path = realpath(FCPATH). FILE_SEPARATOR. $params['path'];
- $targetPath = $path;
- move_uploaded_file($tempFile, $targetPath);
- }
- $data['error'] = null;
- }
- else
- {
- $data['error'] = $message;
- }
- }
- function user_image_delete()
- {
- if ( !$this->valid )
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $DELETE = 1;
- $id = $this->input->post('id');
- $params = array(
- 'id' => $id,
- 'idelete' => $DELETE,
- );
- list( $flag, $retId, $message ) = $this->user_model->update_user_pic($params);
- if ( $flag )
- {
- $pic = $this->user_model->user_pic(array('id' => $id));
- $path = realpath(FCPATH). FILE_SEPARATOR. $pic->path;
- unlink($path);
- }
- die(_ajax_upload_success($message));
- }
- function report_user(){
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $data = array();
- $this->template->set_template('sbadmin2');
- $this->segment = 6;
- $params = array(
- 'filter' => $this->uri->segment(3),
- 'start_date' => to_date($this->uri->segment(4)),
- 'end_date' => to_date($this->uri->segment(5)),
- 'offset' => $this->start_page($this->segment),
- 'limit' => $this->perPage
- );
- $this->linkPage = site_url("admin/report_user/".$params['filter'].'/'.$params['start_date'].'/'.$params['end_date']);
- $this->totalPage = $this->user_model->search_user($params, true);
- $data['list'] = $this->user_model->search_user($params, false);
- $data['start'] = $params['offset']+1;
- $data['total'] = $this->totalPage;
- $data['link'] = $this->pagination();
- $this->template->write_view('content', 'user/report', $data);
- $this->template->render();
- }
- function search_user(){
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- $this->segment = 6;
- $params = array(
- 'filter' => $this->input->post('filter'),
- 'start_date' => to_date($this->input->post('start_date')),
- 'end_date' => to_date($this->input->post('end_date')),
- 'offset' => $this->start_page($this->segment),
- 'limit' => $this->perPage
- );
- $this->linkPage = site_url("admin/report_user/".$params['filter'].'/'.$params['start_date'].'/'.$params['end_date']);
- $this->totalPage = $this->user_model->search_user($params, true);
- $data['link'] = $this->pagination();
- $data['start'] = $params['offset']+1;
- $data['total'] = $this->totalPage;
- $data['data'] = $this->user_model->search_user($params, false);
- $this->load->view('user/resultSearchUser', $data);
- }
- function export_user(){
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- $this->load->library('pexcel');
- $params = array(
- 'filter' => $this->uri->segment(3),
- 'start_date' => to_date($this->uri->segment(4)),
- 'end_date' => to_date($this->uri->segment(5))
- );
- $data = $this->user_model->search_user($params);
- // Create new PHPExcel object
- $sheet = new PHPExcel();
- // Set document properties
- $sheet->getProperties()->setCreator("soechi")
- ->setLastModifiedBy("last.com")
- ->setTitle("Office 2007 XLSX User Document")
- ->setSubject("Office 2007 XLSX User Document")
- ->setDescription("User document for Office 2007 XLSX")
- ->setKeywords("office 2007")
- ->setCategory("Export user file");
- // Add some data
- $sheet->setActiveSheetIndex(0)
- ->setCellValue('A2', 'NO')
- ->setCellValue('B2', 'NAME')
- ->setCellValue('C2', 'NO ID')
- ->setCellValue('D2', 'INVITED BY')
- ->setCellValue('E2', 'HP 1')
- ->setCellValue('F2', 'HP 2')
- ->setCellValue('G2', 'BB')
- ->setCellValue('H2', 'EMAIL')
- ->setCellValue('I2', 'ADDRESS')
- ->setCellValue('J2', 'NO IDENTITY CARD')
- ->setCellValue('K2', 'BIRTH OF DATE')
- ->setCellValue('L2', 'JOIN DATE')
- ->setCellValue('M2', 'BRANCH DEDICATION')
- ->setCellValue('N2', 'KETERANGAN');
- $sheet->getActiveSheet()->getColumnDimension('A')->setWidth(5);
- $sheet->getActiveSheet()->getColumnDimension('B')->setWidth(40);
- $sheet->getActiveSheet()->getColumnDimension('C')->setWidth(20);
- $sheet->getActiveSheet()->getColumnDimension('D')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('E')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('F')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('G')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('H')->setWidth(40);
- $sheet->getActiveSheet()->getColumnDimension('I')->setWidth(60);
- $sheet->getActiveSheet()->getColumnDimension('J')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('K')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('L')->setWidth(20);
- $sheet->getActiveSheet()->getColumnDimension('M')->setWidth(25);
- $sheet->getActiveSheet()->getColumnDimension('N')->setWidth(25);
- $sheet->getActiveSheet()->getRowDimension('2')->setRowHeight(30);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
- $sheet->getActiveSheet()->getStyle('B1:N2')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('FF00FF00');
- $i=4; $no=1;
- foreach ($data as $val):
- $sheet->setActiveSheetIndex(0)
- ->setCellValue("A$i", $no)
- ->setCellValue("B$i", anchor("admin/get_user_profile/$val->userid", $val->user_name, 'target="_blank"'))
- ->setCellValue("C$i", 'NO ID')
- ->setCellValue("D$i", 'INVITED BY')
- ->setCellValue("E$i", $val->hp)
- ->setCellValue("F$i", 'HP 2')
- ->setCellValue("G$i", 'BB')
- ->setCellValue("H$i", $val->user_email)
- ->setCellValue("I$i", $val->address)
- ->setCellValue("J$i", 'NO IDENTITY CARD')
- ->setCellValue("K$i", 'BIRTH OF DATE')
- ->setCellValue("L$i", to_date($val->join_date))
- ->setCellValue("M$i", $val->branch_name)
- ->setCellValue("N$i", 'KETERANGAN');
- $i++; $no++;
- endforeach;
- // Rename worksheet (worksheet, not filename)
- $sheet->getActiveSheet()->setTitle('sheet1');
- // Set active sheet index to the first sheet, so Excel opens this as the first sheet
- $sheet->setActiveSheetIndex(0);
- //this is the header given from PHPExcel examples. but the output seems somewhat corrupted in some cases.
- //header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- //so, we use this header instead.
- header('Content-type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="export_user.xlsx"');
- header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($sheet, 'Excel2007');
- $objWriter->save('php://output');
- }
- function modal_edit_profile($id = null)
- {
- $this->gox_acl->validate_update();
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username))
- show_404();
- if (!$this->valid)
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- if (!$id)
- die(lang('ErrorIdIsNull'));
- $this->load->helper('goexpress');
- $user_info = $this->session->userdata('user_info');
- $user_params = array(
- 'priv' => $user_info->user_type_id,
- 'dropdown' => True,
- );
- $params = array('id' => $id);
- $data['branches'] = $this->user_model->branch();
- $data['trade_area'] = $this->admin_model->list_trade_area();
- $data['branches'] = $this->user_model->branches();
- $data['vessel'] = $this->admin_model->list_vessel();
- $data['rank'] = $this->admin_model->list_rank();
- $data['crew_criteria'] = $this->admin_model->list_crew_criteria();
- $data['nasionality'] = $this->admin_model->list_nasionality();
- $data['user_type'] = $this->user_model->user_type( $user_params );
- $data['ideletes'] = $this->user_model->ideletes($user_params);
- $data['record'] = $this->user_model->profile(null, $id);
- $data['user_info'] = $user_info;
- $this->load->view('user/modal_edit_profile', $data);
- }
- function edit_profile()
- {
- $this->gox_acl->validate_update();
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- if (!$this->valid)
- die(_ajax_upload_error(lang('ErrorPermissionDenied')));
- $submit = $this->input->post('submit');
- $void = $this->input->post('void');
- $id = $this->input->post('id');
- $data = array();
- if ($void and $id) {
- $params = array(
- 'id' => $id,
- 'idelete' => 1,
- );
- $this->user_model->delete_user($params);
- die(_ajax_upload_success(lang("SuccessDataUpdate")));
- }
- if ($id) {
- $record = $this->user_model->profile(null, $id);
- if ( $this->input->post('registration_date') )
- {
- $reg_date = explode(' ',$this->input->post('registration_date'));
- if(count($reg_date) == 2)
- $_POST['registration_date'] = reverseDate($reg_date[0]).' '.$reg_date[1];
- else
- $_POST['registration_date'] = reverseDate($reg_date[0]);
- }
- $this->db->trans_start();
- list($flag, $result, $message) = $this->user_model->edit_profile($this->input->post());
- if ($flag)
- {
- $this->db->trans_complete();
- die(_ajax_upload_success($message));
- }
- else
- {
- $this->db->trans_rollback();
- die(_ajax_upload_error($message));
- }
- } else
- die(_ajax_upload_error(lang('ErrorIdIsNull')));
- }
- function user_count()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- $params = array();
- echo $this->user_model->agents( $params , $count = true);
- die();
- }
- function get_levelid_by_rankid( $rankid )
- {
- switch( $rankid )
- {
- case 715:
- return 15;
- case 716:
- return 16;
- case 717:
- return 17;
- case 720:
- return 20;
- case 725:
- return 25;
- case 735:
- return 27;
- case 780:
- return 50;
- case 785:
- default:
- return 55;
- }
- }
- function add_user()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- $submit = $this->input->post('submit');
- if( $submit )
- {
- $level_id = $this->get_levelid_by_rankid($this->input->post('rank_id'));
- $params['input'] = array(
- 'name' => $this->input->post('name'),
- 'username' => $this->input->post('username'),
- 'email' => $this->input->post('email'),
- 'password' => '123456',
- 'hp' => '123456',
- 'rank_id' => $this->input->post('rank_id'),
- 'level_id' => $level_id,
- 'bverified' => 1,
- );
- $new_uid = $this->user_model->add_user($params);
- $params = array(
- 'user_id' => $new_uid,
- 'department_id' => $this->input->post('department_id'),
- );
- list( $flag, $insert_id, $message ) = $this->user_model->add_user_department( $params );
- $this->session->set_flashdata('message', $message);
- if ( $flag )
- {
- redirect('user/add_user');
- die();
- }
- else
- $data['error_message'] .= $message; // Continue to previous form
- }
- $data['ranks'] = $this->admin_model->crew_rank_dropdown(
- array('is_management' => 1)
- );
- $data['departments'] = $this->admin_model->department_dropdown();
- $this->template->write_view('content', 'user/add_user', $data);
- $this->template->render();
- }
- function add_partner()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) ){
- show_404();
- }
- $submit = $this->input->post('submit');
- if( $submit ){
- $params['input'] = array(
- 'name' => $this->input->post('name'),
- 'username' => $this->input->post('username'),
- 'email' => $this->input->post('email'),
- 'password' => $this->input->post('password'),
- 'hp' => '123456',
- 'rank_id' =>'0',
- 'level_id' => '60',
- 'user_type_id' => '60',
- 'bverified' => 1,
- );
- $new_uid = $this->user_model->add_user($params);
- if($new_uid != false){
- $message = lang('SuccessDataCreation');
- $flag = true;
- } else {
- $message = lang('ErrorDataCreationFailed');
- $flag = false;
- }
- $this->session->set_flashdata('message', $message);
- if ( $flag ){
- redirect('user/add_partner');
- die();
- } else {
- $data['error_message'] .= $message; // Continue to previous form
- }
- }
- $this->template->write_view('content', 'user/add_partner');
- $this->template->render();
- }
- function json_registration()
- {
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- //print_r($json);
- if( !isset( $json->email ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty Email');
- die(json_encode($respon));
- }
- $image_url = null;
- if( isset( $json->image_url ) )
- {
- $image_url = $json->image_url;
- if( isset($json->tipe) && $json->tipe == 'facebook'){
- $url = file_get_contents('https://graph.facebook.com/'.$json->id.'/picture?width=256&height=256&redirect=false');
- $image_json = json_decode($url);
- $image_url = $image_json->data->url;
- }
- }
- // FIXME Do phone validation
- //
- $data = array(
- 'username' => $json->id,
- 'email' => $json->email,
- 'name' => $json->name,
- 'picurl' => $image_url,
- 'user_type_id' => $json->type_id,
- 'registration_date' => date('Y-m-d')
- );
- $callback = $this->model_goexpress->save_registration($data);
- if($callback){
- $respon = array('status' => 'ok', 'message' => 'Successfully saving user');
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed saving user');
- }
- echo json_encode($respon);
- }
- function driver_profile($username)
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- $data = array();
- $params = array();
- $this->load->model('model_goexpress');
- $this->load->helper('claim');
- $params['username'] = $username;
- $params['driver_username'] = $username;
- $profile = $this->user_model->driver_profile($params);
- $data['records'] = $profile;
- $this->linkPage = site_url("user/driver_profile/$username/");
- $this->segment = 4;
- $this->perPage = 10;
- $params['offset']= $this->start_page($this->segment);
- $params['limit'] = $this->perPage;
- $this->totalPage = $this->model_goexpress->get_tx_driver($params, true);
- $data['lists'] = $this->model_goexpress->get_tx_driver($params, false);
- $data['start'] = $params['offset']+1;
- $data['link'] = $this->pagination();
- $this->load->view('user/user_detail', $data);
- }
- function user_detail()
- {
- $user_info = $this->session->userdata('user_info');
- if( !isset($user_info->username) )
- show_404();
- $id = $this->uri->segment(3);
- if(!empty($id)){
- $this->load->model('model_goexpress');
- $this->load->helper('claim');
- $profile = $this->user_model->profile(null, $id);
- $data = array();
- $params = array();
- $data['records'] = $profile;
- if($profile->user_type_id == 30 || $profile->user_type_id == 90)
- {
- $params['client'] = $profile->name;
- }
- else if($profile->user_type_id == 50)
- {
- $params['driver_username'] = $profile->username;
- }
- $data['lists'] = $this->model_goexpress->get_tx($params);
- $this->load->view('user/user_detail', $data);
- }else{
- die('ID Not Found');
- }
- }
- function json_change_phone()
- {
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- //print_r($json);
- if( !isset( $json->no_hp ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty Phone');
- die(json_encode($respon));
- }
- $data = array(
- 'hp' => $json->no_hp,
- 'edit_date' => date('Y-m-d H:i:s')
- );
- $callback = $this->model_goexpress->update_no_hp($data, $json->id);
- if($callback){
- $respon = array('status' => 'success', 'message' => 'Successfully update Phone Number');
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- echo json_encode($respon);
- }
- function json_change_image()
- {
- $respon = array();
- $target_file = "./upload/user/";
- $this->load->model('model_goexpress');
- if( !isset( $_POST['file_name'] ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty File Image');
- die(json_encode($respon));
- }
- list($filename, $ext) = explode(".", $_POST['file_name']);
- $filename = date("YmdHis").rand(1000, 9999).'.'.$ext;
- $data = array(
- 'user_id' => $_POST['id'],
- 'picurl' => $filename,
- );
- if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file.$filename)) {
- $callback = $this->model_goexpress->save_profile_image($data);
- if($callback){
- $respon = array('status' => 'success', 'message' => 'Successfully save image');
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- } else {
- $respon = array('status' => 'failed', 'message' => 'Sorry, there was an error uploading your file.');
- }
- echo json_encode($respon);
- }
- function json_get_image2($username = null)
- {
- $respon = array();
- $this->load->model('model_goexpress');
- if( is_null( $username ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty ID User');
- die(json_encode($respon));
- }
- $_POST['username'] = $username;
- $data['username'] = $_POST['username'];
- $callback = $this->model_goexpress->get_profile_image2($data);
- if(count($callback) > 0){
- $respon = array('status' => 'success', 'message' => 'Successfully get image', 'url_image' => base_url("upload/user/".$callback->picurl ));
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- echo json_encode($respon);
- }
- function json_get_image()
- {
- $respon = array();
- $this->load->model('model_goexpress');
- if( !isset( $_POST['id'] ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty ID User');
- die(json_encode($respon));
- }
- $data['user_id'] = $_POST['id'];
- $callback = $this->model_goexpress->get_profile_image($data);
- //print_r($callback);
- //die();
- if(count($callback) > 0){
- $respon = array('status' => 'success', 'message' => 'Successfully get image', 'url_image' => "http://goexpress-kh.com/goexpress/upload/".$callback->picname);
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- echo json_encode($respon);
- }
- function json_get_phone()
- {
- $respon = array();
- $this->load->model('model_goexpress');
- if( !isset( $_POST['id'] ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty ID User');
- die(json_encode($respon));
- }
- $data['user_id'] = $_POST['id'];
- $callback = $this->model_goexpress->get_phone($data);
- if(count($callback) > 0){
- $respon = array('status' => 'success', 'message' => 'Successfully getting Phone', 'phoneno' => $callback->hp);
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- echo json_encode($respon);
- }
- function json_driving()
- {
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- //print_r($json);
- if( !isset( $json->user_id ) )
- {
- $respon = array('status' => 'failed', 'message' => 'Empty User ID');
- die(json_encode($respon));
- }
- $data = array();
- foreach ($json->data as $value) {
- $data[] = array(
- 'txno' => $json->txno,
- 'driver_id' => $json->user_id,
- 'timestamp' => $value->timestamp,
- 'lat' => $value->lat,
- 'lng' => $value->lng,
- 'action_id' => $json->action_id
- );
- }
- $callback = $this->model_goexpress->save_driving($data);
- if($callback){
- $respon = array('status' => 'success', 'message' => 'Successfully saved');
- }else{
- $respon = array('status' => 'failed', 'message' => 'Failed');
- }
- echo json_encode($respon);
- }
- function json_save_user()
- {
- $DRIVER = 50;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if ( !isset($json->fcm))
- $json->fcm= null;
- $filtered_hp = $this->_filter_number2($json->hp);
- $json->hp = str_replace(' ','',$json->hp);
- if( !isset( $json->hp ) )
- {
- $respon = array('error' => 1, 'error_message' => 'Empty No. Phone');
- die(json_encode($respon));
- }
- if( !isset( $json->email ) )
- {
- $respon = array('error' => 1, 'error_message' => 'Empty Email');
- die(json_encode($respon));
- }
- $bEmailExists = $this->model_goexpress->validate_email($json->email);
- if( $bEmailExists )
- {
- $respon = array('error' => 1, 'error_message' => 'Email has been Registered');
- die(json_encode($respon));
- }
- $user = $this->model_goexpress->get_user(array('hp' => $json->hp));
- if( count($user) > 0)
- {
- $respon = array('error' => 3, 'error_message' => 'Phone No. has been Registered');
- die(json_encode($respon));
- }
- $newID = md5( $json->hp. microtime(). $json->email );
- srand();
- $data = array(
- 'username' => $newID,
- 'email' => $json->email,
- 'name' => $json->name,
- 'hp' => $json->hp,
- 'filtered_hp' => $filtered_hp,
- 'password' => $json->password,
- 'bverified' => 0,
- 'verification_code' => rand(1000, 9999),
- 'registration_date' => date('Y-m-d H:i:s'),
- 'hp' => $json->hp,
- 'api_token' => $this->security_model->generate_apikey($newID,$json->fcm)
- );
- if(isset($json->isdvr) )
- {
- $data['user_type_id'] = $json->isdvr;
- $data['vehicle_id'] = $json->vehicle_id;
- $data['vehicle_plate_no'] = $json->vehicle_plate_no;
- }
- if(isset($json->isclt) )
- {
- $data['user_type_id'] = $json->isclt;
- }
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($data);
- if(! $user_id )
- {
- $respon = array('error' => 1, 'error_message' => 'Registration Failed please contact our Customer Support', 'userid' => null);
- die(json_encode($respon));
- }else{
- $smsparams = array(
- 'create_date' => date('Y-m-d H:i:s'),
- 'hp' => $json->hp,
- 'user_id' => $user_id,
- );
- $this->user_model->add_sendsms($smsparams);
- if( $this->_filter_number($json->hp) )
- {
- if( preg_match("/^\+855/", $json->hp) )
- {
- $this->iSendSmsViaGateway($filtered_hp, $data['verification_code']);
- }
- else
- {
- $datasms = array(
- 'user_id' => $user_id,
- 'sms_no' => $filtered_hp,
- 'server_info' => 'send_sms',
- 'message' => "GO-X.\nYour verification number is ".$data['verification_code']."\n លេខកូដរបស់អ្នកគឺ ". $data['verification_code'],
- );
- $this->sendGoogleCloudMessage( $datasms, $ids = array() , array('separate' => True ), array('ret_int'=>1));
- }
- $respon = array('error' => 2, 'error_message' => 'Successfully saved, please verify your phone number', 'userid' => $newID);
- die(json_encode($respon));
- }
- else
- {
- $respon = array('error' => 1, 'error_message' => 'Registration Pending, Phone number is not local Cambodia. Please contact our Customer Support', 'userid' => null);
- die(json_encode($respon));
- }
- }
- }
- function testsms($userid, $hp)
- {
- $datasms = array(
- 'user_id' => $userid,
- 'sms_no' => $hp,
- 'server_info' => 'send_sms',
- 'message' => 'Your verification number is TEST!',
- );
- $this->sendGoogleCloudMessage( $datasms, $ids = array() , array('separate' => True ));
- $respon = array('error' => 2, 'error_message' => 'Successfully saved, please verify your phone number', 'userid' => $userid);
- die(json_encode($respon));
- }
- function json_user_login()
- {
- try
- {
- $ACTIVE = 0;
- $LOGIN_THRESHOLD = 3;
- $IS_CLIENT = 90;
- $IS_DRIVER = 50;
- $new_version = false;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if ( !isset($json->fcm))
- $json->fcm = null;
- $json->hp = str_replace(' ','',$json->hp);
- if( (!isset( $json->hp ) or $json->hp == "" ) and !isset($json->id) )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid PhoneNo');
- die(json_encode($respon));
- }
- if( !isset( $json->password ) or $json->password=="")
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid Password');
- die(json_encode($respon));
- }
- if ( isset($json->isclt) AND $json->isclt != $IS_CLIENT AND $json->isclt != $IS_DRIVER AND $new_version == true )
- {
- $respon = array('error' => 1, 'error_message' => 'Unknown Application Version');
- die(json_encode($respon));
- }
- $data = array(
- 'hp' => $json->hp,
- );
- // ATTENTION! this code only to validate the re-auth of e-wallet
- // and intendedly to replace the $data['hp'] declared before this line
- if ( isset($json->id) AND isset($json->isclt) AND $json->isclt == $IS_CLIENT )
- {
- $data = array(
- 'username' => $json->id,
- );
- }
- $get = $this->model_goexpress->get_user($data);
- if ( isset($json->id) AND isset($get->hp) AND isset($json->isclt) AND $json->isclt == $IS_CLIENT )
- {
- $json->hp = $get->hp;
- }
- if( !empty($get) and $get->n_retries >= $LOGIN_THRESHOLD)
- {
- if ( $get->locked == 1 ) {
- if ( time() >= $get->locked_until ) {
- $values= array();
- $values['locked'] = 0;
- $values['locked_until'] = 0;
- $values['n_retries'] = 0;
- $get->n_retries = 0;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- }
- else {
- if ( $this->uri->segment(1) == "km") {
- $messageval = "សូមមេត្ដាករង់ចាំ 15 នាទីដើម្បីសាកល្បងម្ដងទៀត";
- }
- else {
- $messageval = "Please retry after 15 minutes";
- }
- $respon = array('error' => 4, 'error_message' => $messageval );
- die(json_encode($respon));
- }
- }
- else {
- $values= array();
- $values['locked'] = 1;
- $values['locked_until'] = strtotime('+15 minute', time());
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- if ( $this->uri->segment(1) == "km") {
- $messageval = "សូមមេត្ដាករង់ចាំ 15 នាទីដើម្បីសាកល្បងម្ដងទៀត";
- }
- else {
- $messageval = "Please retry after 15 minutes";
- }
- $respon = array('error' => 4, 'error_message' => $messageval );
- die(json_encode($respon));
- }
- }
- if( count($get) > 0 )
- {
- //disabled temp the verfication
- if($get->is_forgotpwd == 1 && $json->password == $get->password){
- $values= array();
- $values['is_forgotpwd'] = 0;
- $values['bverified'] = 1;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- if ( isset($json->isreauth) and $json->isreauth == 1 )
- $api_token = "";
- else
- $api_token = $this->security_model->generate_apikey($get->username,$json->fcm);
- $respon = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'userid' => $get->username,
- 'email' => $get->email,
- 'name' => $get->name,
- 'promo_code' => $get->promo_code,
- 'ewallet' => $get->wallet,
- 'vehicle_name' => $get->vehicle_name,
- 'vehicle_plate_no' => $get->vehicle_plate_no,
- 'hp' => $get->hp,
- 'api_token' => $api_token
- );
- die(json_encode($respon));
- }
- else if($get->is_forgotpwd == 1 && $json->password == $get->tmp_password )
- {
- $values = array();
- $values['is_forgotpwd'] = 0;
- $values['bverified'] = 0;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- $respon = array('error' => 2, 'error_message' => 'Success Password reset but need Verification');
- die(json_encode($respon));
- }else if($get->idelete != 0) {
- $respon = array('error' => 4, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }else if ( $get->user_type_id != $json->isclt and ( isset($json->isclt) OR $new_version == true ) ) {
- $respon = array('error' => 1, 'error_message' => 'Invalid Account');
- die(json_encode($respon));
- }
- else if( $json->password == $get->password && $get->bverified == 1 and $get->is_forgotpwd == 0 and ( $get->user_type_id == $json->isclt or ( !isset($json->isclt) AND $new_version != true ) ) ) {
- //Reset 0
- $this->model_goexpress->reset_retries_user($json->hp, 0);
- if ( $get->referal_code == null or $get->referal_code == '' )
- $get->referal_code = $this->model_goexpress->generate_referal_code($get->username);
- if ( isset($json->isreauth) and $json->isreauth == 1 )
- $api_token = "";
- else
- $api_token = $this->security_model->generate_apikey($get->username, $json->fcm);
- $respon = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'userid' => $get->username,
- 'email' => $get->email,
- 'name' => $get->name,
- 'promo_code' => $get->promo_code,
- 'ewallet' => $get->wallet,
- 'vehicle_name' => $get->vehicle_name,
- 'vehicle_plate_no' => $get->vehicle_plate_no,
- 'hp' => $get->hp,
- 'api_token' => $api_token ,
- 'referal_code' => $get->referal_code
- );
- die(json_encode($respon));
- }else if( $json->password == $get->password && $get->bverified == 0 and $get->is_forgotpwd == 0) {
- // temporary by-pass
- $respon = array('error' => 2, 'error_message' => 'Error: Phone No not yet Verified');
- //$respon = array(
- // 'error' => 0,
- // 'error_message' => 'Success',
- // 'userid' => $get->username,
- // 'email' => $get->email,
- // 'name' => $get->name,
- // 'promo_code' => $get->promo_code,
- // 'ewallet' => $get->wallet,
- // 'vehicle_name' => $get->vehicle_name,
- // 'vehicle_plate_no' => $get->vehicle_plate_no,
- // );
- die(json_encode($respon));
- }else{
- //update retries
- $this->model_goexpress->reset_retries_user($json->hp, 1);
- $respon = array('error' => 1,
- 'error_message' => sprintf('Invalid Phone No/Password <br>(%s) retry remain ', ($LOGIN_THRESHOLD - $get->n_retries)),
- 'info' => $get,
- );
- die(json_encode($respon));
- }
- }else{
- //update retries
- $this->model_goexpress->reset_retries_user($json->hp, 1);
- $respon = array('error' => 1, 'error_message' => 'Invalid Phone No/Password');
- die(json_encode($respon));
- }
- }
- catch(Exception $e)
- {
- error_log("Login Json Exception: " + $e->getMessage());
- }
- error_log("Login Json Success");
- }
- function json_User_change_pass()
- {
- $ACTIVE = 0;
- $LOGIN_THRESHOLD = 3;
- $IS_CLIENT = 90;
- $IS_DRIVER = 50;
- $new_version = false;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if ( !isset($json->fcm))
- $json->fcm = null;
- $json->hp = str_replace(' ','',$json->hp);
- if( (!isset( $json->hp ) or $json->hp == "" ) and !isset($json->id) )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid PhoneNo');
- die(json_encode($respon));
- }
- if( !isset( $json->password ) or $json->password=="")
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid Password');
- die(json_encode($respon));
- }
- if ( isset($json->isclt) AND $json->isclt != $IS_CLIENT AND $json->isclt != $IS_DRIVER AND $new_version == true )
- {
- $respon = array('error' => 1, 'error_message' => 'Unknown Application Version');
- die(json_encode($respon));
- }
- $data = array(
- 'hp' => $json->hp,
- );
- // ATTENTION! this code only to validate the re-auth of e-wallet
- // and intendedly to replace the $data['hp'] declared before this line
- if ( isset($json->id) AND isset($json->isclt) AND $json->isclt == $IS_CLIENT )
- {
- $data = array(
- 'username' => $json->id,
- );
- }
- $get = $this->model_goexpress->get_user($data);
- if ( isset($json->id) AND isset($get->hp) AND isset($json->isclt) AND $json->isclt == $IS_CLIENT )
- {
- $json->hp = $get->hp;
- }
- if( !empty($get) and $get->n_retries >= $LOGIN_THRESHOLD)
- {
- $values= array();
- $values['idelete'] = 1;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- $respon = array('error' => 4, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }
- if( count($get) > 0 )
- {
- if ( $get->password == $json->password AND strlen($get->password) == strlen($json->password) ) {
- $newdata = array(
- 'password' => $json->repass
- );
- $this->model_goexpress->add_user($newdata, $get->id);
- $respon = array('error' => 0, 'error_message' => 'Password was changed!');
- die(json_encode($respon));
- }
- else {
- $respon = array('error' => 1, 'error_message' => 'Wrong Password! Please Try again.');
- die(json_encode($respon));
- }
- }
- }
- function json_driver_change_pwd()
- {
- $ACTIVE = 0;
- $LOGIN_THRESHOLD = 3;
- $IS_CLIENT = 90;
- $IS_DRIVER = 50;
- $new_version = false;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if ( !isset($json->fcm))
- $json->fcm = null;
- $json->hp = str_replace(' ','',$json->hp);
- if( (!isset( $json->hp ) or $json->hp == "" ) and !isset($json->id) )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid PhoneNo');
- die(json_encode($respon));
- }
- if( !isset( $json->password ) or $json->password=="")
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid Password');
- die(json_encode($respon));
- }
- if ( isset($json->isclt) AND $json->isclt != $IS_CLIENT AND $json->isclt != $IS_DRIVER AND $new_version == true )
- {
- $respon = array('error' => 1, 'error_message' => 'Unknown Application Version');
- die(json_encode($respon));
- }
- $data = array(
- 'hp' => $json->hp,
- );
- // ATTENTION! this code only to validate the re-auth of e-wallet
- // and intendedly to replace the $data['hp'] declared before this line
- if ( isset($json->id) AND isset($json->isclt) AND $json->isclt == $IS_DRIVER )
- {
- $data = array(
- 'username' => $json->id,
- );
- }
- $get = $this->model_goexpress->get_user($data);
- if ( isset($json->id) AND isset($get->hp) AND isset($json->isclt) AND $json->isclt == $IS_DRIVER )
- {
- $json->hp = $get->hp;
- }
- if( !empty($get) and $get->n_retries >= $LOGIN_THRESHOLD)
- {
- $values= array();
- $values['idelete'] = 1;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- $respon = array('error' => 4, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }
- if( count($get) > 0 )
- {
- if ( $get->password == $json->password AND strlen($get->password) == strlen($json->password) ) {
- $newdata = array(
- 'password' => $json->repass
- );
- $this->model_goexpress->add_user($newdata, $get->id);
- $respon = array('error' => 0, 'error_message' => 'Password was changed!');
- die(json_encode($respon));
- }
- else {
- $respon = array('error' => 1, 'error_message' => 'Wrong Password! Please Try again.');
- die(json_encode($respon));
- }
- }
- }
- function json_verify_user()
- {
- $IS_VERIFIED = 1;
- $ACTIVE = 0;
- $LOGIN_THRESHOLD = 3;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if ( !isset($json->fcm) )
- $json->fcm = null;
- $json->hp = str_replace(' ','',$json->hp);
- if( !isset( $json->hp ) )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid PhoneNo');
- die(json_encode($respon));
- }
- if( !isset( $json->user_verification ) or $json->user_verification == '' )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid Verification');
- die(json_encode($respon));
- }
- $data = array(
- 'hp' => $json->hp,
- );
- $get = $this->model_goexpress->get_user($data);
- if( $get->bverified == $IS_VERIFIED )
- {
- if( $get->idelete != $ACTIVE )
- {
- $respon = array('error' => 4, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }
- $respon = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'userid' => $get->username,
- 'email' => $get->email,
- 'name' => $get->name,
- 'promo_code' => $get->promo_code,
- 'ewallet' => $get->wallet,
- 'vehicle_name' => $get->vehicle_name,
- 'vehicle_plate_no' => $get->vehicle_plate_no,
- 'hp' => $get->hp,
- 'api_token' => $this->security_model->generate_apikey($get->username,$json->fcm)
- );
- die(json_encode($respon));
- }
- else
- {
- if( !empty($get) and $get->n_retries >= $LOGIN_THRESHOLD)
- {
- $values= array();
- $values['idelete'] = 1;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- $respon = array('error' => 1, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }
- }
- if( count($get) > 0 )
- {
- if( $get->verification_code != $json->user_verification ){
- //update retries
- $this->model_goexpress->reset_retries_user($json->hp, 1);
- $respon = array('error' => 1, 'error_message' => 'Invalid verification code');
- die(json_encode($respon));
- }else if($get->idelete != 0) {
- $respon = array('error' => 4, 'error_message' => 'Account is Blocked');
- die(json_encode($respon));
- }else{
- //Reset 0
- $this->model_goexpress->reset_retries_user($json->hp, 0);
- $data = array(
- 'hp' => $json->hp,
- 'verification_code' => $json->user_verification,
- 'bverified' => 1,
- );
- $this->model_goexpress->add_user($data,$get->id);
- $respon = array(
- 'error' => 0,
- 'error_message' => 'Success',
- 'userid' => $get->username,
- 'email' => $get->email,
- 'name' => $get->name,
- 'promo_code' => $get->promo_code,
- 'ewallet' => $get->wallet,
- 'vehicle_name' => $get->vehicle_name,
- 'vehicle_plate_no' => $get->vehicle_plate_no,
- 'hp' => $get->hp,
- 'api_token' => $this->security_model->generate_apikey($get->username,$json->fcm)
- );
- //Comment to disable promotion
- $promo_start = strtotime("2017-4-7 14:00:00");
- $promo_end = strtotime("2018-4-7 23:59:59");
- $now = time();
- if ( $now >= $promo_start && $now <= $promo_end ) {
- $this->model_goexpress->tmp_register_promotion($get);
- }
- die(json_encode($respon));
- }
- }else{
- //update retries
- $this->model_goexpress->reset_retries_user($json->hp, 1);
- $respon = array('error' => 1, 'error_message' => 'Invalid verification code');
- die(json_encode($respon));
- }
- }
- function register_fcm()
- {
- $IS_VERIFIED = 1;
- $ACTIVE = 0;
- $LOGIN_THRESHOLD = 3;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- if( !isset( $json->userid ) )
- {
- $respon = array('error' => 1, 'error_message' => 'Invalid UserID');
- die(json_encode($respon));
- }
- list($flag, $user_id, $msg ) = $this->model_goexpress->register_fcm($json->userid);
- if(! $user_id )
- {
- $respon = array('error' => 1, 'error_message' => 'Failed Register FCM');
- die(json_encode($respon));
- }else{
- $respon = array('error' => 0, 'error_message' => 'Register FCM Success');
- die(json_encode($respon));
- }
- }
- function json_forgot()
- {
- $ACTIVE = 0;
- $respon = array();
- $payload = file_get_contents('php://input');
- $this->load->model('model_goexpress');
- if( !$payload )
- {
- $respon = array('error' => 1, 'message' => 'Empty payload');
- die(json_encode($respon));
- }
- $json = json_decode( $payload );
- $json->user_phoneno_partial = str_replace(' ','',$json->user_phoneno_partial);
- if( !isset( $json->user_phoneno_partial ) or $json->user_phoneno_partial == "")
- {
- $respon = array('error' => 1, 'error_message' => 'Error: PhoneNo is BLANK');
- die(json_encode($respon));
- }
- $json->hp = $json->user_phoneno_partial;
- if( !isset( $json->user_email_partial ) or $json->user_email_partial == "")
- {
- $respon = array('error' => 1, 'error_message' => 'Error: Email is BLANK');
- die(json_encode($respon));
- }
- $json->email = $json->user_email_partial;
- if( !isset( $json->user_password_partial ) or $json->user_password_partial == "")
- {
- $respon = array('error' => 1, 'error_message' => 'Error: New Password is BLANK');
- die(json_encode($respon));
- }
- $json->tmp_password = $json->user_password_partial;
- $data = array(
- 'hp' => $json->hp,
- 'email' => $json->email,
- 'tmp_password' => $json->tmp_password,
- 'idelete' => $ACTIVE,
- );
- $get = $this->model_goexpress->get_user($data);
- if( count($get) > 0 )
- {
- $values['tmp_password'] = $json->tmp_password;
- $values['bverified'] = 1; // verified must stay 1
- // since to prevent any monkeying the legit number by someone else
- $YmdHis = date('YmdHis');
- srand( $YmdHis );
- $values['verification_code'] = rand(1000, 9999);
- $values['is_forgotpwd'] = 1;
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($values, $get->id);
- if(! $user_id )
- {
- $respon = array('error' => 1, 'error_message' => 'Failed Reset Password', 'verification_code' => null);
- die(json_encode($respon));
- }else{
- $filtered_hp = $get->hp;
- if( $get->filtered_hp != '' )
- $filtered_hp = $get->filtered_hp;
- $smsparams = array(
- 'create_date' => date('Y-m-d H:i:s'),
- 'hp' => $get->hp,
- 'user_id' => $get->id,
- );
- $this->user_model->add_sendsms($smsparams);
- if( preg_match("/^\+855/", $json->hp) )
- {
- $this->iSendSmsViaGateway($filtered_hp, $values['verification_code']);
- }
- else
- {
- $datasms = array(
- 'user_id' => $get->id,
- 'sms_no' => $filtered_hp,
- 'server_info' => 'send_sms',
- 'message' => "GO-X.\nYour verification number is ".$values['verification_code']."\n លេខកូដរបស់អ្នកគឺ ". $values['verification_code'],
- );
- $this->sendGoogleCloudMessage( $datasms, $ids = array() , array('separate' => True ), array('ret_int'=>1));
- }
- $respon = array('error' => 0, 'error_message' => 'Reset Password Successfully', 'verification_code' => '');
- die(json_encode($respon));
- }
- }else{
- $respon = array('error' => 1, 'error_message' => 'Invalid PhoneNo/Email');
- die(json_encode($respon));
- }
- }
- function txn()
- {
- $ACTIVE = 0;
- $respon = array();
- $payload = file_get_contents('php://input');
- $json = json_decode($payload);
- if( !isset($json->user_id) or $json->user_id == '')
- {
- $respon = array(
- 'error' => 1,
- 'error_message' => 'Error: Bad or Invalid Param ',
- 'error_code' => 1,
- );
- die(json_encode($respon));
- }
- if( !isset($json->req) or $json->req == '')
- {
- $respon = array(
- 'error' => 1,
- 'error_message' => 'Error: Bad or Invalid Param ',
- 'error_code' => 2,
- );
- die(json_encode($respon));
- }
- if( $json->req != 'TXN')
- {
- $respon = array(
- 'error' => 1,
- 'error_message' => 'Error: Bad or Invalid Param ',
- 'error_code' => 3,
- );
- die(json_encode($respon));
- }
- $demos = array();
- //$demos = array(
- // array(
- // 'tr_date' => "06-06-2016",
- // 'description' => 'Referral Bonus',
- // 'amount' => 'KHR 2000',
- // ),
- // array(
- // 'tr_date' => "05-06-2016",
- // 'description' => 'Referral Bonus',
- // 'amount' => 'KHR 2000',
- // ),
- // array(
- // 'tr_date' => "04-06-2016",
- // 'description' => 'Referral Bonus',
- // 'amount' => 'KHR 2000',
- // ),
- // );
- $respon = array(
- 'error' => 0,
- 'error_message' => 'Error: Bad or Invalid Param ',
- 'error_code' => 0,
- 'bal' => 'KHR 0',
- 'TXN' => $demos,
- );
- die(json_encode($respon));
- }
- function sendGoogleCloudMessage( $data, $ids, $params = array(), $options = array() )
- {
- //------------------------------
- // Replace with real GCM API
- // key from Google APIs Console
- //
- // https://code.google.com/apis/console/
- //------------------------------
- $apiKey = 'AIzaSyAMC9GU3zMDCOf8r2kZvVfJMhbGrh2iJTM';
- //------------------------------
- // Define URL to GCM endpoint
- //------------------------------
- $url = 'https://android.googleapis.com/gcm/send';
- //------------------------------
- // Set GCM post variables
- // (Device IDs and push payload)
- //------------------------------
- $post = array(
- 'data' => $data,
- );
- if( isset( $params['registration_ids'] ) )
- {
- $post['registration_ids'] = $options['registration_ids'];
- }
- else if( isset( $options['stoken'] ) )
- {
- $post['to'] = $options["stoken"];
- }
- else
- {
- if( isset($data['Vehicle'] ))
- $post['to'] = "/topics/" . $data['Vehicle'];
- else
- $post['to'] = "/topics/goxsmsx";
- }
- //------------------------------
- // Set CURL request headers
- // (Authentication and type)
- //------------------------------
- $headers = array(
- 'Authorization: key=' . $apiKey,
- 'Content-Type: application/json'
- );
- //------------------------------
- // Initialize curl handle
- //------------------------------
- $ch = curl_init();
- //------------------------------
- // Set URL to GCM endpoint
- //------------------------------
- curl_setopt( $ch, CURLOPT_URL, $url );
- //------------------------------
- // Set request method to POST
- //------------------------------
- curl_setopt( $ch, CURLOPT_POST, true );
- //------------------------------
- // Set our custom headers
- //------------------------------
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- //------------------------------
- // Get the response back as
- // string instead of printing it
- //------------------------------
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- //------------------------------
- // Set post data as JSON
- //------------------------------
- curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
- curl_setopt($ch, CURLOPT_TIMEOUT ,10);
- //------------------------------
- // Actually send the push!
- //------------------------------
- $result = curl_exec( $ch );
- //------------------------------
- // Error? Display it!
- //------------------------------
- if ( curl_errno( $ch ) )
- {
- echo '1@@GCM error: ' . curl_error( $ch );
- }
- //------------------------------
- // Close curl handle
- //------------------------------
- curl_close( $ch );
- //------------------------------
- // Debug GCM response
- //------------------------------
- if( isset($options['ret_int']) )
- return $result;
- if( isset($params['separate']))
- echo '@@0@@'.@$data['TxNo'].'@@'.$result;
- else
- echo '0@@'.@$data['TxNo'].'@@'.$result;
- }
- function _filter_number($hp)
- {
- $THRESHOLD = 8;
- // Open for all numbers
- //if( !preg_match("/^\+855/", $hp) )
- // return false;
- $result = preg_replace("/[ -]/","",preg_replace("/^\+855/","",$hp));
- if( strlen($result) >= $THRESHOLD )
- return true;
- else
- return false;
- }
- function _filter_number2($hptmp)
- {
- $MIN_SEPARATED = 2;
- if( preg_match("/^\+855.*/", $hptmp) ) // Cambodia
- {
- $arrtmp = explode(" ", $hptmp);
- if( count($arrtmp) >= $MIN_SEPARATED )
- {
- if( isset($arrtmp[1]) and $arrtmp[1] != "")
- {
- $arrtmp[1] = preg_replace("/^(0)([0-9]*)/", "$2", $arrtmp[1]);
- $hptmp = implode("",$arrtmp); // already filter out whitespace
- }
- else
- {
- $hptmp = str_replace(' ','',$hptmp);
- }
- }
- else
- {
- if( preg_match("/^\+8550.*/", $hptmp) )
- {
- $hptmp = preg_replace("/^(\+855)(0)([0-9]*)/", "$1$3", $hptmp);
- }
- else
- {
- $hptmp = str_replace(' ','',$hptmp);
- }
- }
- }
- else
- {
- $hptmp = str_replace(' ','',$hptmp);
- }
- return $hptmp;
- }
- function iSendSmsViaGateway( $filtered_hp, $vercode )
- {
- $ERROR = 0;
- $CODE_SUCCESS = 0;
- $SUCCESS = 1;
- $apiKey = 'username=goexpress_sms@mekongnet&pass=dd5ad747f4c1659a1236bd37169e2fd0&sender=GO-X&smstext=';
- $sms = "GO-X.\nYour verification number is ".$vercode."\n លេខកូដរបស់អ្នកគឺ ".$vercode;
- $sms = str_replace(" ","+",$sms);
- $sms = str_replace("\n","%0A",$sms);
- $filtered_hp = str_replace("+","", $filtered_hp);
- $apiEnder = "&isflash=0&gsm=".$filtered_hp;
- $url = 'http://client.mekongsms.com/api/sendsms.aspx?' .
- $apiKey.
- $sms.
- $apiEnder;
- $headers = array(
- "Content-Type: application/x-www-form-urlencoded; charset=utf-8",
- );
- $ch = curl_init();
- curl_setopt( $ch, CURLOPT_URL, $url );
- curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec( $ch );
- $bCurl = true;
- if ( curl_errno( $ch ) )
- {
- error_log('iSendSMS Curl Error '. curl_error($ch));
- $bCurl = false;
- }
- curl_close( $ch );
- if( $bCurl === false )
- return $ERROR;
- //------------------------------
- // Debug GCM response
- //------------------------------
- //if( @$result->results[0]->error == "MissmatchSenderId")
- // return $this->sendFirebaseCloudMessageIOS($data, $ids, $params, $options);
- $response = explode("\n", $result);
- if(count($response) > 0)
- {
- $arrResponse = explode(" ", $response[0]);
- if( $arrResponse[0] == $CODE_SUCCESS)
- return $SUCCESS;
- else
- return $ERROR;
- }
- else
- {
- return $ERROR;
- }
- }
- function repostBoost()
- {
- set_time_limit(0);
- $records = $this->user_model->getFailedBoost();
- die(var_dump($records));
- foreach($records as $rec )
- {
- $this->iSendSmsViaGateway($rec->filtered_hp, $rec->verification_code);
- }
- }
- function json_login_fb()
- {
- $this->load->model('model_goexpress');
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $params['fb_userid'] = $json->UserID;
- $params['username'] = $json->UserName;
- if ($params['fb_userid']!=="" && $params['username']!=="" ) {
- if ( !$this->user_model->validate_login_fb($params) ) {
- $newID = md5($json->UserID. microtime());
- $api_token = $this->security_model->generate_apikey($newID, "");
- $data = array(
- 'username' => $newID,
- 'email' => ($json->UserEmail !="") ? $json->UserEmail : $newID."@goexpress-kh.com",
- 'name' => $json->UserName,
- 'hp' => "",
- 'filtered_hp' => "",
- 'password' => "",
- 'bverified' => 0,
- // 'bverified' => 1,
- 'verification_code' => rand(1000, 9999),
- 'registration_date' => date('Y-m-d H:i:s'),
- 'api_token' => $api_token,
- 'user_type_id' => "90",
- 'fb_userid' => $json->UserID
- );
- list($flag, $user_id, $msg ) = $this->model_goexpress->add_user($data);
- }
- $data = array(
- 'fb_userid' => $json->UserID
- );
- $get = $this->model_goexpress->get_user($data);
- $api_token = $this->security_model->generate_apikey($get->username, "");
- $respon = array(
- 'error' => 2,
- 'error_message' => 'Success',
- 'userid' => $get->username,
- 'email' => $get->email,
- 'name' => $get->name,
- 'promo_code' => $get->promo_code,
- 'ewallet' => $get->wallet,
- 'vehicle_name' => $get->vehicle_name,
- 'vehicle_plate_no' => $get->vehicle_plate_no,
- 'hp' => $get->hp,
- 'api_token' => $api_token,
- 'status' => true
- );
- }
- else {
- $respon = array(
- 'error' => 2,
- 'error_message' =>'Error: Invalid Login Data',
- 'status' => false
- );
- }
- die(json_encode($respon));
- // ERROR
- }
- function update_hp_fb()
- {
- // $this->load->model('model_goexpress');
- $payload = file_get_contents('php://input');
- $json = json_decode( $payload );
- $fb_userid = $json->UserID;
- $params['hp']= $json->hp;
- $user_id = $this->user_model->validate_login_fb($params,$fb_userid);
- if( isset($user_id) && $user_id !="" )
- {
- $api_token = $this->security_model->generate_apikey($json->username, "");
- $respon = array(
- 'error' => 2,
- 'error_message' => 'Success',
- 'api_token' => $api_token,
- 'status' => true
- // 'userid' => $json->username,
- // 'email' => $json->email,
- // 'name' => $json->name,
- // 'promo_code' => $json->promo_code,
- // 'ewallet' => $json->wallet,
- // 'vehicle_name' => $json->vehicle_name,
- // 'vehicle_plate_no' => $json->vehicle_plate_no,
- // 'hp' => $json->hp,
- );
- // KIRIM CODE SMS
- $YmdHis = date('YmdHis');
- srand( $YmdHis );
- $values['verification_code'] = rand(1000, 9999);
- $values['is_forgotpwd'] = 0;
- $smsparams = array(
- 'create_date' => date('Y-m-d H:i:s'),
- 'hp' => $json->hp,
- 'user_id' => $user_id,
- );
- $this->user_model->add_sendsms($smsparams);
- if( $this->_filter_number($json->hp) )
- {
- if( preg_match("/^\+855/", $json->hp) )
- {
- $this->iSendSmsViaGateway($json->hp, $data['verification_code']);
- }
- else
- {
- $datasms = array(
- 'user_id' => $user_id,
- 'sms_no' => $json->hp,
- 'server_info' => 'send_sms',
- 'message' => "GO-X.\nYour verification number is ".$data['verification_code']."\n លេខកូដរបស់អ្នកគឺ ". $data['verification_code'],
- );
- $this->sendGoogleCloudMessage( $datasms, $ids = array() , array('separate' => True ), array('ret_int'=>1));
- }
- }
- // $respon = array('error' => 2, 'error_message' => 'Successfully saved, please verify your phone number', 'userid' => $newID);
- // die(json_encode($respon));
- }else{
- $respon = array(
- 'error' => 2,
- 'error_message' => 'Error: Invalid Update Data',
- 'status' => false
- );
- }
- die(json_encode($respon));
- }
- }
- /* End of file welcome.php */
- /* Location: ./application/controllers/welcome.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement