load->model('user_model'); } public function index() { if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; redirect('index.php', $data); } else { $count_d_traite = $this->user_model->getCountDemandeByStatut($this->session->userdata('member_code'),1); $count_d_no_traite = $this->user_model->getCountDemandeByStatut($this->session->userdata('member_code'),0); $count_d = $this->user_model->getCountDemande($this->session->userdata('member_code')); $data['active'] = "dash"; $data['list_geolocated_users'] = $this->user_model->getAllGeolocatedUsersForHyp($this->session->userdata('member_code')); $data['listdem'] = $this->user_model->getDemandes($this->session->userdata('member_code')); $data['allGeo'] = $this->user_model->getAllUserGeoForHyp($this->session->userdata('member_code')); $data['allDem'] = $this->user_model->getDemandes($this->session->userdata('member_code')); $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['member_code'] = $this->session->userdata('member_code'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'],$this->session->userdata('current_pays')); $data['count_geo'] = $this->user_model->countUserGeoForHyp($this->session->userdata('member_code')); $data['count_sup'] = $this->user_model->countUser("super",'all',$this->session->userdata('member_code')); $data['count_d_traite'] = $count_d_traite; $data['count_d_no_traite'] = $count_d_no_traite; $data['count_d_users'] = $count_d; $data['networks'] = $this->user_model->getNetworkByHyp($this->session->userdata('member_code')); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $this->load->view('header_hyp', $data); $this->load->view('hyperviseur_dash'); $this->load->view('footer'); } } public function getAllUser_g(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; redirect('index.php', $data); } else { if($this->input->post('ville')) { $this->session->set_userdata('current_ville', $this->input->post('ville')); } $data['active'] = "geolocated"; $data['total_points'] = $this->user_model->getCoutGeolocatedUsersForHyper($this->session->userdata('member_code'),$this->session->userdata('current_ville')); $data['map_title'] = $this->lang->line('utilisateurs géolocalisés à')." ".$this->session->userdata('current_ville'); $data['tab'] = $this->user_model->getUsersGeolocatedByVilleForHyp($this->session->userdata('current_ville'),$this->session->userdata('member_code')); $data['positions'] = $this->user_model->getUsersGeolocatedPositionByVilleForHyp($this->session->userdata('current_ville'),$this->session->userdata('member_code')); $data['latitude'] = $this->session->userdata('latitude'); $data['longitude'] = $this->session->userdata('longitude'); $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['code_parrain'] = $this->session->userdata('code_parrain'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'],$this->session->userdata('current_pays')); $data['networks'] = $this->user_model->getNetworkByHyp($this->session->userdata('member_code')); $data['alert'] = ""; $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $this->load->view('header_hyp', $data); $this->load->view('listeadmin'); $this->load->view('footer'); } } public function getAllSupervisor(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; redirect('index.php', $data); } else { /*$this->db->select('*'); $this->db->from('users'); $this->db->where('category','super'); $this->db->where('network',$this->session->userdata('network')); $this->db->where('code_parrain',$this->session->userdata('code_parrain'));*/ $query = $this->user_model->getSupervisorsForHyp($this->session->userdata('member_code')); $network = $this->session->userdata('network'); $category = 'super'; $position = $this->user_model->getAllpositions($network,$category,$this->session->userdata('member_code')); if($position!=null){ //var_dump($position); //echo json_encode($position); } $data['total_points'] = $this->user_model->getCoutSuperForHyper($this->session->userdata('member_code')); $data['positions'] = $position; $data['active'] = "super"; $data['map_title'] = $this->lang->line('Superviseurs'); $data['tab'] = $query; $data['latitude'] = $this->session->userdata('latitude'); $data['longitude'] = $this->session->userdata('longitude'); $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['code_parrain'] = $this->session->userdata('code_parrain'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'],$this->session->userdata('current_pays')); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['networks'] = $this->user_model->getNetworkByHyp($this->session->userdata('member_code')); $data['alert'] = ""; $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $this->load->view('header_hyp', $data); $this->load->view('listeadmin'); $this->load->view('footer'); } } public function getAllSupervisorPositions(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; redirect('index.php', $data); } else { $network = $this->session->userdata('network'); $category = 'super'; $position = $this->user_model->getAllpositions($network,$category,$this->session->userdata('member_code')); if($position!=null){ return $position; } } } public function getDemandes(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; $this->load->view('login', $data); } else { if($this->input->get("u") !== null) { $super = $this->input->get("u"); $this->session->set_userdata("current_super_demande", $super); $debut =""; $fin = ""; if($this->input->get("d") !== null){ $debut = $this->input->get("d"); $fin = $this->input->get("f"); }else{ $fin = date('Y-m-d'); $debut = Date('Y-m-d', strtotime("-5 days")); } $format = $this->session->userdata('site_lang') === 'french' ? 'd-m-Y' : 'Y-m-d' ; $data['debut'] = $debut ? date($format, strtotime($debut)) : null ; $data['fin'] = $fin ?date($format, strtotime($fin)): null ; $fin = Date('Y-m-d', strtotime($fin."+1 day")); $ville = $this->session->userdata('ville'); $data['active'] = "demandes"; $data['type'] = $this->lang->line('crédits'); $data['demand_type'] = 'credit'; $data['alert'] = ""; $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['code_parrain'] = $this->session->userdata('code_parrain'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'],$this->session->userdata('current_pays')); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['tab_fastDemande'] = $this->user_model->getRangeASCDemandesByNetwork($debut,$fin,$this->session->userdata('member_code'),$this->session->userdata('current_demande_ville'),$super); $data['tab_slowDemande'] = $this->user_model->getRangeDESCDemandesByNetwork($debut,$fin,$this->session->userdata('member_code'),$this->session->userdata('current_demande_ville'),$super); $data['list'] = $this->user_model->getDemandesBySuper($this->session->userdata('member_code'),$super); $data['temp_moyen'] = $this->user_model->getTempsMoyenByVille($this->session->userdata('member_code'),$super,$this->session->userdata('network')); $data['networks'] = $this->user_model->getNetworkByHyp($this->session->userdata('member_code')); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $data['nameOfcurentGeolocatedUser'] = $this->user_model->nameOfCurrentGeolocatedUser_forSuper($super); $this->load->view('header_hyp', $data); $this->load->view('demande_credit'); $this->load->view('footer'); } } } public function addvilles(){ $id = 1; $date = "2018-08-29"; for ($i = 1; $i <= 267; $i++) { $newdate = date("Y-m-d", strtotime($date." + 1 day + 1 hour")); $data = array( 'dateAjout' => $date, 'dateModif' => $newdate, ); $newdate = date("Y-m-d", strtotime($date." + 1 day + 3 hour")); $date = $newdate; $this->db->update('demande_superviseur', $data); } } public function getDemandesAd(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; $this->load->view('login', $data); } else { $network = $this->session->userdata('network'); $debut = $this->input->get("d"); $fin = $this->input->get("f"); $format = $this->session->userdata('site_lang') === 'french' ? 'd-m-Y' : 'Y-m-d' ; $data['debut'] = $debut ? date($format, strtotime($debut)) : null ; $data['fin'] = $fin ?date($format, strtotime($fin)): null ; $data['demand_type'] = 'adhesion'; $data['active'] = "demandesAd"; $data['alert'] = ""; $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['code_parrain'] = $this->session->userdata('code_parrain'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['tab_fastDemande'] = $this->user_model->getRangeASCDemandesAd($debut, $fin ,$this->session->userdata('member_code')); $data['tab_slowDemande'] = $this->user_model->getRangeDESCDemandesAd($debut, $fin ,$this->session->userdata('member_code')); $data['temp_moyen'] = $this->user_model->getTempsMoyenAd($debut, $fin ,$this->session->userdata('member_code')); $data['list'] = $this->user_model->getDemandesAdForSuper($debut, $fin , $this->session->userdata('member_code')); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'],$this->session->userdata('current_pays')); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['networks'] = $this->user_model->getNetworkByHyp($this->session->userdata('member_code')); $data['type'] = $this->lang->line('Adhésion'); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $this->load->view('header_hyp', $data); $this->load->view('demande_adhesion'); $this->load->view('footer'); } } // Wallet public function wallet(){ if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; $this->load->view('login', $data); } else { $id_network = $this->session->userdata('network_id'); if($this->input->get('history')){ $this->historique($id_network,$this->input->get('d'),$this->input->get('f'),$this->input->get('history')); }else { $data["commission"] = ""; $data["principal"] = ""; $data["transactions"] = ""; $agent_id = $this->session->userdata('agent_id'); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); if ($data['hasWallet']) { $taux = $data['hasWallet']->first_row(); $data['taux_client_r'] = $taux->taux_com_client_retrait; $data['taux_client_d'] = $taux->taux_com_client_depot; $data['taux_ag_r'] = $taux->taux_com_ag_retrait; $data['taux_ag_d'] = $taux->taux_com_ag_depot; $data['taux_sup_r'] = $taux->taux_com_sup_retrait; $data['taux_sup_d'] = $taux->taux_com_sup_depot; $data['taux_bq_d'] = $taux->part_banque_depot; $data['taux_bq_r'] = $taux->part_banque_retrait; $data['frais_d'] = $taux->frais_min_banque_depot; //Create wallet if it not exist $res = $this->user_model->getWallet($agent_id); if ($res == false) { $this->user_model->addWallet($agent_id); $res = $this->user_model->getWallet($agent_id); } $row = $res->first_row(); $data["commission"] = $row->balance_com; $data["principal"] = $row->balance_princ; $data['wallet_id'] = $row->wallet_id; $agents_g = $this->user_model->getAllGeolocatedUsersForHyp($this->session->userdata('member_code')); //Fetch all transactions of any geolocated agent of the network $data["transactions"] = array(); $totalCommissionBanque = 0; if ($agents_g) { foreach ($agents_g->result() as $row) { $wallet = $this->user_model->getWallet($row->agent_id); if ($wallet) { $transactions = $this->user_model->getAgentTransactions($wallet->first_row()->wallet_id); if ($transactions) { foreach ($transactions->result() as $trans) { $totalCommissionBanque += $trans->commission_banque; $trans->code_parrain = $row->code_parrain; // Add code parrain to transaction array_push($data['transactions'], $trans); } } } } } $data["totalCommissionBanque"] = $totalCommissionBanque; } else { $data["taux_client_r"] = "N/A"; $data["taux_client_d"] = "N/A"; $data["taux_ag_r"] = "N/A"; $data["taux_ag_d"] = "N/A"; $data["taux_sup_r"] = "N/A"; $data["taux_sup_d"] = "N/A"; $data['taux_bq_d'] = "N/A"; $data['taux_bq_r'] = "N/A"; $data['frais_d'] = "N/A"; $data["commission"] = "N/A"; $data["principal"] = "N/A"; $data["totalCommissionBanque"] = "N/A"; $data["transactions"] = false; $data['wallet_id'] = null; } $res = $this->user_model->getWalletPassword($id_network); $data['walletPassword'] = $res ? $res->first_row() : null; $data['alert'] = ""; $data['active'] = "wallet"; $data['token'] = $this->session->userdata('token'); $data['email'] = $this->session->userdata('email'); $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['code_parrain'] = $this->session->userdata('code_parrain'); $data['phone'] = $this->session->userdata('phone'); $data['adresse'] = $this->session->userdata('adresse'); $data['category'] = $this->session->userdata('category'); $data['network'] = $this->session->userdata('network'); $data['network_id'] = $id_network; $data['country'] = $this->session->userdata('current_pays'); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'], $this->session->userdata('current_pays')); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['pays'] = $this->user_model->getAllGameCountries(); $data['networks'] = $this->user_model->getActiveNetwork(); $data['agentWalletInfos'] = $this->user_model->getInfosWalletAgentForHyper($id_network); $this->load->view('header_hyp', $data); $this->load->view('gestion_wallet_hyp'); $this->load->view('footer'); } } } private function isLogged() { if (!$this->session->userdata('email')) { $this->session->set_flashdata('error', 'log in first'); $data['alert'] = "ok"; $data['message'] = "Login first!"; $this->load->view('login', $data); return false; } return true; } private function historique($network_id ,$startDate ,$endDate, $type) { $format = $this->session->userdata('site_lang') === 'french' ? 'd-m-Y' : 'Y-m-d' ; $data['startDate'] = $startDate ? date($format, strtotime($startDate)) : null ; $data['endDate'] = $endDate ?date($format, strtotime($endDate)): null ; $endDate = Date('Y-m-d', strtotime($endDate."+1 day")); if($type == 'transaction') $data['transactions'] = $this->user_model->getTransactions($startDate , $endDate ,$network_id); else $data['transactions'] = $this->user_model->getRecharges($startDate , $endDate ,$network_id); $data['active'] = "wallet"; $data['alert'] = ""; $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['email'] = $this->session->userdata('email'); $data['network'] = $this->session->userdata('network'); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'], $this->session->userdata('current_pays')); $data['networks'] = $this->user_model->getActiveNetwork(); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $data['country'] = $this->session->userdata('current_pays'); $data['category'] = $this->session->userdata('category'); $this->load->view('header_hyp', $data); if($type == 'transaction') $this->load->view('historique_transactions'); else $this->load->view('historique_recharges'); $this->load->view('footer'); } public function walletPassword(){ if($this->isLogged()){ $data['active'] = "wallet_password"; $data['alert'] = ""; $data['firstname'] = $this->session->userdata('firstname'); $data['lastname'] = $this->session->userdata('lastname'); $data['email'] = $this->session->userdata('email'); $data['network'] = $this->session->userdata('network'); $data['villes'] = $this->user_model->getVilleByUserGeo($data['network'], $this->session->userdata('current_pays')); $data['networks'] = $this->user_model->getActiveNetwork(); $data['superviseurs'] = $this->user_model->getSuperNameAndCodeForHyp($this->session->userdata('member_code')); $data['hasWallet'] = $this->user_model->getConfigWallet($this->session->userdata('network_id')); $data['country'] = $this->session->userdata('current_pays'); $data['network_id'] = $this->session->userdata('network_id'); $res = $this->user_model->getWalletPassword($this->session->userdata('network_id')); $data['walletPassword'] = $res ? $res->first_row() : null; $this->load->view('header_hyp', $data); $this->load->view('wallet_password'); $this->load->view('footer'); } } public function generate_wallet_password(){ if($this->isLogged()){ if (isset($_POST)) { $network_id = isset($_POST['network_id']) ? $_POST['network_id'] : null; $email = $_POST['email']; // $size = $_POST['size']; $wallet_password_id = isset($_POST['wallet_password_id']) ? $_POST['wallet_password_id'] : null ; $network = $_POST['network']; $country = $_POST['country']; $password = $this->generate_string(); $hash = $this->hashSSHA($password); $encrypted_password = $hash['encrypted'] ; $salt = $hash['salt'] ; $this->load->library('email'); $this->email->from('noreply@ilink-app.com', 'iLink World'); $this->email->to($email); $this->email->subject($this->lang->line('wallet_password').' '.$network . ' - '.$country); $this->email->message($this->lang->line('mot de passe').' : '.$password); if ($this->email->send()) { if($wallet_password_id == null) $this->user_model->addWalletPassword($network_id,$encrypted_password,$salt,$email); else $this->user_model->updateWalletPassword($wallet_password_id,$encrypted_password,$salt,$email); $res = true; } else { // show_error($this->email->print_debugger()); $res = false; } if ($res) { echo json_encode("200"); } else { echo json_encode("500"); } } } } private function generate_string($length = 10){ $chars = 'abcdefghjkmnpqrstuvwxyz'. '23456789'; $str = ''; $max = strlen($chars) - 1; for ($i=0; $i < $length; $i++) $str .= $chars[mt_rand(0, $max)]; return $str; } private function hashSSHA($password) { $salt = sha1(rand()); $salt = substr($salt, 0, 10); $encrypted = base64_encode(sha1($password . $salt, true) . $salt); $hash = array("salt" => $salt, "encrypted" => $encrypted); return $hash; } public function resetWalletPassword(){ if($this->isLogged()){ if (isset($_POST)) { $email = $_POST['email']; $wallet_password_id = isset($_POST['wallet_password_id']) ? $_POST['wallet_password_id'] : null ; $network = $_POST['network']; $country = $_POST['country']; $password = $this->generate_string(); $hash = $this->hashSSHA($password); $encrypted_password = $hash['encrypted'] ; $salt = $hash['salt'] ; $this->load->library('email'); $this->email->from('noreply@ilink-app.com', 'iLink World'); $this->email->to($email); $this->email->subject($this->lang->line('reset_wallet_password').' '.$network . ' - '.$country); $this->email->message($this->lang->line('mot de passe').' : '.$password); if ($this->email->send()) { $this->user_model->updateWalletPassword($wallet_password_id,$encrypted_password,$salt,$email); $res = true; } else { // show_error($this->email->print_debugger()); $res = false; } if ($res) { echo json_encode("200"); } else { echo json_encode("500"); } } } } public function recharge_wallet(){ if($this->isLogged()){ if (isset($_POST)) { $password = $_POST['password']; $wallet_id = $_POST['wallet_id']; $salt = $_POST['salt'] ; $encrypted_password = $_POST['encrypted_password']; $montant = $_POST['montant']; $hash = base64_encode(sha1($password . $salt, true) . $salt); if($encrypted_password == $hash){ $this->user_model->updateWalletBalance($montant,$wallet_id); $res = $this->user_model->addWalletRecharge($montant,$wallet_id); $code = $res ? '200' : '500' ; }else{ $code = '400'; } echo json_encode($code); } } } }