diff --git a/application/controllers/Gestion.php b/application/controllers/Gestion.php index ab179f9f..adada400 100644 --- a/application/controllers/Gestion.php +++ b/application/controllers/Gestion.php @@ -1,1267 +1,1527 @@ -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!"; - $this->load->view('login', $data); - } else { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllPays(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['alert'] = ""; - $data['active'] = "villes"; - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_villes'); - $this->load->view('footer'); - } - - } - - public function activer(){ - 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(isset($_POST)) - { - $villes = $this->input->post('villes'); - $max = sizeof($villes); - $number_success = 0; - for ($i = 0; $i < $max; $i++) { - $res = $this->user_model->changeVilleStatut($villes[$i],1); - if ($res==true){ - $number_success++; - } - } - if($number_success==$max){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function update() - { - - 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(isset($_POST)) - { - $id_country = $this->input->post('id_country'); - $id_town = $this->input->post('id_town'); - $town = $this->input->post('town'); - - $res = $this->user_model->updateVille($id_country,$id_town,$town); - - if($res==true){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function activer_desactiver(){ - - 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(isset($_POST)) - { - $aVilles = $this->input->post('aVilles'); - $maxA = sizeof($aVilles); - $number_successA = 0; - - $dVilles = $this->input->post('dVilles'); - $maxD = sizeof($dVilles); - $number_successD = 0; - - $this->db->trans_begin(); - for ($i = 0; $i < $maxD; $i++) { - $res = $this->user_model->changeVilleStatut($dVilles[$i],0); - if ($res==true){ - $number_successD++; - } - } - for ($i = 0; $i < $maxA; $i++) { - $res = $this->user_model->changeVilleStatut($aVilles[$i],1); - if ($res==true){ - $number_successA++; - } - } - - if($this->db->trans_status() === FALSE){ - $this->db->trans_rollback(); - echo json_encode("error"); - }else{ - $this->db->trans_commit(); - echo json_encode("completed"); - } - } - } - } - - public function desactiver() - { - 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(isset($_POST)) - { - $villes = $this->input->post('villes'); - $max = sizeof($villes); - $number_success = 0; - for ($i = 0; $i < $max; $i++) { - $res = $this->user_model->changeVilleStatut($villes[$i],0); - if ($res==true){ - $number_success++; - } - } - if($number_success==$max){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function suppress() - { - 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(isset($_POST)) - { - $villes = $this->input->post('ville'); - $res = $this->user_model->deleteVille($villes); - - if($res=true){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function ajout(){ - if ($this->input->post('pays') && $this->input->post('ville')) { - - $ville = $this->input->post('ville'); - $id_pays = $this->input->post('pays'); - $stat = 0; - - - $data = array('name' => $ville, 'country_id' => $id_pays, 'status' => $stat); - - $query = $this->db->insert('towns', $data); - - if ($query) { - - $data['alert'] = "ok"; - $data['success'] = "ok"; - $data['message'] = "La ville ".$ville." a bien été ajouté!"; - $data['active'] = "villes"; - - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllPays(); - $data['game_pays'] = $this->user_model->getGameCountry(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_villes'); - $this->load->view('footer'); - } else { - - $data['alert'] = "ok"; - $data['success'] = "error"; - $data['message'] = "Une erreur s'est produite"; - $data['active'] = "villes"; - $data['game_pays'] = $this->user_model->getGameCountry(); - - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllPays(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_villes'); - $this->load->view('footer'); - } - - } - } - - public function networks(){ - 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 { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['alert'] = ""; - $data['active'] = "networks"; - $data['networks'] = $this->user_model->getAllNetworksNames(); - $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_networks'); - $this->load->view('footer'); - } - } - - public function creat_network(){ - - 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(isset($_POST)) - { - $network = $this->input->post('new_network'); - - $data = array('name' => $network); - - $query = $this->db->insert('networks', $data); - - if($query){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function assignation(){ - - 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(isset($_POST)) - { - $network = $this->input->post('network'); - $existe = 0; - $this->db->trans_begin(); - foreach ($_POST['id_country'] AS $country){ - $res = $this->user_model->checkIfAssignationExiste($country,$network); - - if($res==false){ - $data = array('country_id' => $country, 'name' => $network); - $this->db->insert('networks', $data); - - }else{ - $existe = $existe+1; - } - - } - if($this->db->trans_status() === FALSE){ - $this->db->trans_rollback(); - echo json_encode("error"); - }elseif ($existe>0){ - $this->db->trans_commit(); - echo json_encode("existe"); - }else{ - $this->db->trans_commit(); - echo json_encode("completed"); - } - - } - } - } - - public function update_network(){ - - 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(isset($_POST)) - { - $old_network = $this->input->post('old_name'); - $new_network = $this->input->post('new_network'); - - $res = $this->user_model->updateNetwork($old_network,$new_network); - - if($res==true){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function change_status_network(){ - - 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(isset($_POST)) - { - $activations = $this->input->post('activations'); - $desactivation = $this->input->post('desactivations'); - - $this->db->trans_begin(); - if(!empty($_POST['activations'])){ - foreach ($_POST['activations'] AS $network){ - - $data = array('status' => 1); - $this->db->where('id', $network); - $this->db->update('networks', $data); - - } - } - if(!empty($_POST['desactivations'])){ - foreach ($_POST['desactivations'] AS $network){ - - $data = array('status' => 0); - $this->db->where('id', $network); - $this->db->update('networks', $data); - - } - } - if($this->db->trans_status() === FALSE){ - $this->db->trans_rollback(); - echo json_encode("error"); - }else{ - $this->db->trans_commit(); - echo json_encode("completed"); - } - - } - } - } - - public function admin(){ - - 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 { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $data['list_admin'] = $this->user_model->getAllAdmin(); - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - $data['alert'] = ""; - $data['active'] = "admin"; - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_admin'); - $this->load->view('footer'); - } - - } - - public function create_admin(){ - - 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(isset($_POST)) - { - $category = 1; - $firstname = $this->input->post('prenom'); - $lastname = $this->input->post('nom'); - $email = $this->input->post('email'); - $emailExist = $this->user_model->isEmailExist($email); - if($emailExist==false){ - $phone = $this->input->post('contact'); - $phoneExist = $this->user_model->isPhoneExist($phone); - if($phoneExist==false){ - $adresse = $this->input->post('adresse'); - $country = $this->input->post('country'); - $token = null; - do { - $token = bin2hex(openssl_random_pseudo_bytes(16)); - $tokenExist = $this->user_model->getToken($token); - } while ($tokenExist==true); - - $data = array('firstname' => $firstname,'lastname' => $lastname,'email' => $email,'phone' => $phone,'adresse' => $adresse,'country' => $country,'category' => $category,'token' => $token); - - $query = $this->db->insert('admin', $data); - - if($query){ - - $link = "https://ilink-app.com/backofficebeta/index.php/Admin_password/?token=".$token; - $this->load->library('email'); - - $this->email->from('noreply@ilink-app.com', 'iLink World'); - $this->email->to($email); - - $this->email->subject($this->lang->line("Confirmation de création d'un compte administrateur")); - $this->email->message($firstname.' '.$lastname.' '.$this->lang->line("votre compte administrateur a bien été créé. Veuillez suivre ce lien pour configurer votre mot de passe.").' '.$link); - - $this->email->send(); - - echo json_encode("completed"); - }else{ - echo json_encode($this->lang->line("Une erreur s'est produite")); - } - }else{ - echo json_encode($this->lang->line("Le numéro de téléphone entré est déjà utilisé")); - } - }else{ - echo json_encode($this->lang->line("L'email entré est déjà utilisé")); - } - } - } - } - - public function modif_admin(){ - - 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(isset($_POST)) - { - $id = $this->input->post('id'); - $firstname = $this->input->post('prenom'); - $lastname = $this->input->post('nom'); - $email = $this->input->post('email'); - $phone = $this->input->post('contact'); - $adresse = $this->input->post('adresse'); - $country = $this->input->post('country'); - $category = $this->input->post('category'); - - $res = $this->user_model->updateAdmin($id,$firstname,$lastname,$email,$phone,$adresse,$country,$category); - - if($res){ - echo json_encode("completed"); - }else{ - echo json_encode($this->lang->line("Une erreur s'est produite")); - } - } - } - } - - public function delete_admin(){ - - 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(isset($_POST)) - { - $id = $this->input->post('id'); - - $res = $this->user_model->deleteAdmin($id); - - if($res){ - echo json_encode("completed"); - }else{ - echo json_encode($this->lang->line("Une erreur s'est produite")); - } - } - } - } - - public function codes(){ - - 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 { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $data['list_villes'] = $this->user_model->getAllVilles(); - $data['pays'] = $this->user_model->getAllPays(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['alert'] = ""; - $data['active'] = "codes-hyper"; - $data['list'] = $this->user_model->getGeneratedHyperCodes(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('codeg'); - $this->load->view('footer'); - } - } - - public function generateCode() - { - - if ($this->input->post('c') && $this->input->post('a')) { - - $number = intval($this->input->post('c')); - $member_code = $this->input->post('a'); - if($number>0){ - for ($i = 0; $i < $number; $i++) { - - - $code = $this->randomString(); - - $data = array('code_parrain' => $member_code, 'code_membre' => $code, 'etat' => 0, 'category' => 'hyper'); - - $query = $this->db->insert('codeGenerer', $data); - - } - } - $data['alert'] = "ok"; - $data['success'] = "ok"; - $data['active'] = "members"; - $data['message'] = "$number codes have been added!"; - - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $data['pays'] = $this->user_model->getAllCountries(); - $data['hyper'] = $this->user_model->getAllHyper($data['pays']->first_row()->id); - $data['ville'] = $this->user_model->getVilleNetworkByHyper($data['hyper']->first_row()->code_membre); - $data['list'] = $this->user_model->getGeneratedHyperCodes(); - $data['active'] = "codes"; - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['firstname'] = $this->session->userdata('firstname'); - $data['lastname'] = $this->session->userdata('lastname'); - $data['email'] = $this->session->userdata('email'); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - $this->load->view('header_gestion', $data); - $this->load->view('codeg'); - $this->load->view('footer'); - - } else { - $data['alert'] = "ok"; - $data['success'] = ""; - $data['active'] = "members"; - $data['message'] = "Can't add codes!"; - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['hyper'] = $this->user_model->getAllHyper($data['pays']->first_row()->id); - $data['ville'] = $this->user_model->getVilleNetworkByHyper($data['hyper']->first_row()->code_membre); - $data['list'] = $this->user_model->getGeneratedHyperCodes(); - $data['active'] = "codes"; - $data['pays'] = $this->user_model->getAllCountries(); - $data['firstname'] = $this->session->userdata('firstname'); - $data['lastname'] = $this->session->userdata('lastname'); - $data['email'] = $this->session->userdata('email'); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('codeg'); - $this->load->view('footer'); - } - - } - - private function randomString($length = 10) - { - $str = ""; - $characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9')); - $max = count($characters) - 1; - for ($i = 0; $i < $length; $i++) { - $rand = mt_rand(0, $max); - $str .= $characters[$rand]; - } - return $str; - - } - - public function geolocalisation(){ - - 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 { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); - $data['active_ville_name'] = $data['villes']->first_row()->name; - $data['active_ville_id'] = $data['villes']->first_row()->id; - $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); - $data['networks'] = $this->user_model->getNetworks($data['pays']->first_row()->id); - $data['alert'] = ""; - $data['active'] = "geoloc"; - $number_geolocalisation = array(); - $network_geolocalisation = array(); - $count = 0; - - foreach ($data['networks']->result() AS $row){ - $number_geolocalisation[$count] = $this->user_model->getPointGeolocalised($row->id,$data['agent']->first_row()->lastname); - $network_geolocalisation[$count] = $row->name; - $count++; - } - $data['current_agent'] = $data['agent']->first_row()->lastname; - $data["number_geolocalisation"] = $number_geolocalisation; - $data["network_geolocalisation"] = $network_geolocalisation; - $data["total"] = $count; - $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_geolocalisation'); - $this->load->view('footer'); - } - } - - public function infos_geolocalisation(){ - - 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(isset($_POST)) - { - $pays = $this->input->post('pays'); - $ville = $this->input->post('ville'); - $lastname = $this->input->post('agent'); - - - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); - $data['active_ville_name'] = $data['villes']->first_row()->name; - $data['active_ville_id'] = $data['villes']->first_row()->id; - $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); - $data['networks'] = $this->user_model->getNetworks($pays); - $data['alert'] = ""; - $data['active'] = "geoloc"; - $number_geolocalisation = array(); - $network_geolocalisation = array(); - $count = 0; - - foreach ($data['networks']->result() AS $row){ - $number_geolocalisation[$count] = $this->user_model->getPointGeolocalised($row->id,$lastname); - $network_geolocalisation[$count] = $row->name; - $count++; - } - $data['current_agent'] = $lastname; - $data["number_geolocalisation"] = $number_geolocalisation; - $data["network_geolocalisation"] = $network_geolocalisation; - $data["total"] = $count; - $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_geolocalisation'); - $this->load->view('footer'); - } - } - } - - public function getVilleByPays(){ - - 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->is_ajax_request()) - { - $ajaxhyp = $this->user_model->getVillesByPays($this->input->post('pays')); - echo json_encode($ajaxhyp->result_array()); - } - - } - } - - public function getAgentByVilles(){ - - 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->is_ajax_request()) - { - $ajaxhyp = $this->user_model->getAgentsFromCountry($this->input->post('id_country')); - echo json_encode($ajaxhyp->result_array()); - } - - } - } - - public function campagne(){ - - 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 { - - $ville = $this->session->userdata('current_ville'); - $hyper = $this->session->userdata('current_hyper'); - $pays = $this->session->userdata('current_pays'); - - $debut = date('Y-m-d H:i:s',strtotime($this->user_model->getMostOldDateCreationAgent())); - $fin = date("Y-m-d H:i:s"); - $data['pays'] = $this->user_model->getAllCountries(); - $pays = $data['pays']->first_row()->id; - if(!empty($_POST)) - { - $debut = $this->input->post('date-debut'); - $fin = $this->input->post('date-fin'); - $pays = $this->input->post('pays'); - } - - $data['debut'] = $debut; - $data['fin'] = $fin; - $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); - $data['active_ville_name'] = $data['villes']->first_row()->name; - $data['active_ville_id'] = $data['villes']->first_row()->id; - $data['agent'] = $this->user_model->getAgentsFromCountry($pays); - $data['networks'] = $this->user_model->getNetworks($pays); - $data['alert'] = ""; - $data['active'] = "campagne"; - $agent[][] = null; - $geo_correct[][] = null; - $number_geolocalisation [][] = null; - $network_geolocalisation [][] = null; - $number_correct [][] = null; - $count = 0; - $countA = 0; - $total = 0; - $network_count = 0; - $total_physique = 0; - $contact_correct = 0; - - $networks_compte[] = null; - $networks_name[] = null; - - if($data['agent']!=false){ - foreach ($data['agent']->result() AS $row1){ - if(!strstr($row1->lastname, "Super -") and !strstr($row1->lastname, "Airtel")){ - $totalGeo = 0; - $totalGeoCorrect = 0; - $agent[$countA][0] = $row1->lastname; - foreach ($data['networks']->result() AS $row2){ - $number_geolocalisation [$countA][$count] = $this->user_model->getPointGeolocalisedByDate($row2->id,$row1->lastname,$debut,$fin); - $number_correct [$countA][$count] = $this->user_model->getCorrectPointGeolocalisedByDate($row2->id,$row1->lastname,$debut,$fin); - $network_geolocalisation [$countA][$count] = $row2->name; - $totalGeo = $totalGeo + $number_geolocalisation [$countA][$count]; - $totalGeoCorrect = $totalGeoCorrect + $number_correct [$countA][$count]; - $count++; - } - $agent[$countA][1] = $totalGeo; - $agent[$countA][2] = $this->user_model->getPhysicalPointBySupervisor($debut,$fin,$row1->lastname); - $total_physique = $total_physique + $agent[$countA][2]; - $geo_correct [$countA][1] = $totalGeoCorrect; - $total = $total+$totalGeo; - $contact_correct = $contact_correct+$totalGeoCorrect; - $countA++; - } - } - } - - foreach ($data['networks']->result() AS $row){ - $networks_compte[$network_count] = $this->user_model->getPointGeolocalisedByNetwork($row->id,$debut,$fin); - $networks_name[$network_count] = $row->name; - $network_count++; - } - $data["networks_compte"] = $networks_compte; - $data["networks_name"] = $networks_name; - $data["network_count"] = $network_count; - $data["total_physique"] = $total_physique; - $data['geo_correct'] = $geo_correct; - $data['contact_correct']=$total; - if($pays==78){ - $data['contact_correct']=$contact_correct; - } - $data["agents"] = $agent; - $data["total_points"] = $total; - $data["countA"] = $countA; - $data['current_agent'] = $data['agent']->first_row()->lastname; - $data["number_geolocalisation"] = $number_geolocalisation; - $data["network_geolocalisation"] = $network_geolocalisation; - $data["total"] = $count; - $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); - $data['game_pays'] = $this->user_model->getGameCountry(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_campagne'); - $this->load->view('footer'); - } - } - - public function redirect_info_agent(){ - - 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(isset($_GET)) - { - $lastname = $this->input->get('agent'); - $debut = $this->input->get('debut'); - $fin = $this->input->get('fin'); - $id_country = $this->user_model->getAgentNetwork($lastname); - - $data['pays'] = $this->user_model->getAllCountries(); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); - $data['active_ville_name'] = $data['villes']->first_row()->name; - $data['active_ville_id'] = $data['villes']->first_row()->id; - $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); - $data['networks'] = $this->user_model->getNetworks($id_country); - $data['alert'] = ""; - $data['active'] = "geoloc"; - $number_geolocalisation = array(); - $network_geolocalisation = array(); - $count = 0; - - foreach ($data['networks']->result() AS $row){ - $number_geolocalisation[$count] = $this->user_model->getPointGeolocalisedByDate($row->id,$lastname,$debut,$fin); - $network_geolocalisation[$count] = $row->name; - $count++; - } - $data['current_agent'] = $lastname; - $data["number_geolocalisation"] = $number_geolocalisation; - $data["network_geolocalisation"] = $network_geolocalisation; - $data["total"] = $count; - $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - - $this->load->view('header_gestion', $data); - $this->load->view('gestion_geolocalisation'); - $this->load->view('footer'); - } - } - } - - public function map(){ - 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 { - $data['positions'] = $this->user_model->getAllpositionsForWorld(); - $data['latitude'] = 0; - $data['longitude'] = 0; - $data['lastname'] = $this->session->userdata('lastname'); - $data['active'] = "map"; - $data['code_parrain'] = $this->session->userdata('code_parrain'); - $data['alert'] = ""; - $this->load->view('header_gestion', $data); - $this->load->view('gestion_map'); - $this->load->view('footer'); - } - } - - public function game(){ - 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 { - $pays = 1; - if(!empty($_POST)) - { - $pays = $this->input->post('pays'); - $pays_name = $this->user_model->getNameCountry($pays); - $this->session->set_userdata('current_game_country',$pays); - $this->session->set_userdata('current_game_country_name',$pays_name); - }elseif(!empty($this->session->userdata('current_game_country'))){ - $pays = $this->session->userdata('current_game_country'); - $pays_name = $this->session->userdata('current_game_country_name'); - } - $max = 999999; - $data['paliers'] = $this->user_model->getPaliers(); - $data['pays'] = $this->user_model->getAllGameCountries(); - $data['list'] = $this->user_model->getMembers($pays); - $data['game_pays'] = $this->user_model->getGameCountry(); - $data['q1'] = $this->user_model->getQuota(1); - $data['q2'] = $this->user_model->getQuota(2); - $data['q3'] = $this->user_model->getQuota(3); - $data['q4'] = $this->user_model->getQuota(4); - $data['quota1'] = $this->user_model->getCoutForQuota($pays,$data['q1'],$data['q2']); - $data['quota2'] = $this->user_model->getCoutForQuota($pays,$data['q2'],$data['q3']); - $data['quota3'] = $this->user_model->getCoutForQuota($pays,$data['q3'],$data['q4']); - $data['quota4'] = $this->user_model->getCoutForQuota($pays,$data['q4'],$max); - $data['lastname'] = $this->session->userdata('lastname'); - $data['active'] = "game"; - $data['code_parrain'] = $this->session->userdata('code_parrain'); - $data['alert'] = ""; - //wallet - $data['networks'] = $this->user_model->getActiveNetwork(); - $this->load->view('header_gestion',$data); - $this->load->view('game'); - $this->load->view('footer'); - } - } - - public function activerGame(){ - 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(isset($_POST)) - { - $pays = $this->input->post('pays'); - $max = sizeof($pays); - $number_success = 0; - for ($i = 0; $i < $max; $i++) { - $checkContryExist = $this->user_model->checkCountryGameExist($pays[$i]); - if($checkContryExist==true){ - $res = $this->user_model->activeGameOnCountry($pays[$i],1); - }else{ - $add = $this->user_model->addContryToGame($pays[$i]); - if($add==true){ - $res = $this->user_model->activeGameOnCountry($pays[$i],1); - }else{ - echo json_encode("error"); - } - } - if ($res==true){ - $number_success++; - } - } - if($number_success==$max){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function desactiverGame(){ - 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(isset($_POST)) - { - $pays = $this->input->post('pays'); - $max = sizeof($pays); - $number_success = 0; - for ($i = 0; $i < $max; $i++) { - $res = $this->user_model->activeGameOnCountry($pays[$i],0); - if ($res==true){ - $number_success++; - } - } - if($number_success==$max){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - - public function activer_desactiverGame(){ - - 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(isset($_POST)) - { - $apays = $this->input->post('apays'); - $maxA = sizeof($apays); - $number_successA = 0; - - $dpays = $this->input->post('dpays'); - $maxD = sizeof($dpays); - $number_successD = 0; - - $this->db->trans_begin(); - for ($i = 0; $i < $maxD; $i++) { - $res = $this->user_model->activeGameOnCountry($dpays[$i],0); - if ($res==true){ - $number_successD++; - } - } - for ($i = 0; $i < $maxA; $i++) { - - $checkContryExist = $this->user_model->checkCountryGameExist($apays[$i]); - if($checkContryExist==true){ - $res = $this->user_model->activeGameOnCountry($apays[$i],1); - }else{ - $add = $this->user_model->addContryToGame($apays[$i]); - if($add==true){ - $res = $this->user_model->activeGameOnCountry($apays[$i],1); - }else{ - echo json_encode("error"); - } - } - if ($res==true){ - $number_successA++; - } - } - - if($this->db->trans_status() === FALSE){ - $this->db->trans_rollback(); - echo json_encode("error"); - }else{ - $this->db->trans_commit(); - echo json_encode("completed"); - } - } - } - } - - public function modifierPalier(){ - 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(isset($_POST)) - { - $n1 = $this->input->post('n1'); - $n2 = $this->input->post('n2'); - $n3 = $this->input->post('n3'); - $n4 = $this->input->post('n4'); - $max = 4; - $number_success = 0; - - $res1 = $this->user_model->modifPalier($n1,1); - if ($res1==true){ - $number_success++; - $res2 = $this->user_model->modifPalier($n2,2); - if($res2==true){ - $number_success++; - $res3 = $this->user_model->modifPalier($n3,3); - if($res3){ - $number_success++; - $res4 = $this->user_model->modifPalier($n4,4); - if($res4==true){ - $number_success++; - }else{ - echo json_encode("error"); - } - }else{ - echo json_encode("error"); - } - }else{ - echo json_encode("error"); - } - }else{ - echo json_encode("error"); - } - - if($number_success==$max){ - echo json_encode("completed"); - }else{ - echo json_encode("error"); - } - } - } - } - public function change_country(){ - 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(isset($_POST)) - { - $pays = $this->input->post('pays'); - $pays_name = $this->user_model->getNameCountry($pays); - if($pays_name!=false){ - $this->session->set_userdata('current_game_country',$pays); - $this->session->set_userdata('current_game_country_name',$pays_name); - echo 1; - }else{ - echo 0; - } - }else{ - echo 0; - } - } - } - - -} +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!"; + $this->load->view('login', $data); + } else { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllPays(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['alert'] = ""; + $data['active'] = "villes"; + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_villes'); + $this->load->view('footer'); + } + + } + + public function activer(){ + 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(isset($_POST)) + { + $villes = $this->input->post('villes'); + $max = sizeof($villes); + $number_success = 0; + for ($i = 0; $i < $max; $i++) { + $res = $this->user_model->changeVilleStatut($villes[$i],1); + if ($res==true){ + $number_success++; + } + } + if($number_success==$max){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function update() + { + + 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(isset($_POST)) + { + $id_country = $this->input->post('id_country'); + $id_town = $this->input->post('id_town'); + $town = $this->input->post('town'); + + $res = $this->user_model->updateVille($id_country,$id_town,$town); + + if($res==true){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function activer_desactiver(){ + + 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(isset($_POST)) + { + $aVilles = $this->input->post('aVilles'); + $maxA = sizeof($aVilles); + $number_successA = 0; + + $dVilles = $this->input->post('dVilles'); + $maxD = sizeof($dVilles); + $number_successD = 0; + + $this->db->trans_begin(); + for ($i = 0; $i < $maxD; $i++) { + $res = $this->user_model->changeVilleStatut($dVilles[$i],0); + if ($res==true){ + $number_successD++; + } + } + for ($i = 0; $i < $maxA; $i++) { + $res = $this->user_model->changeVilleStatut($aVilles[$i],1); + if ($res==true){ + $number_successA++; + } + } + + if($this->db->trans_status() === FALSE){ + $this->db->trans_rollback(); + echo json_encode("error"); + }else{ + $this->db->trans_commit(); + echo json_encode("completed"); + } + } + } + } + + public function desactiver() + { + 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(isset($_POST)) + { + $villes = $this->input->post('villes'); + $max = sizeof($villes); + $number_success = 0; + for ($i = 0; $i < $max; $i++) { + $res = $this->user_model->changeVilleStatut($villes[$i],0); + if ($res==true){ + $number_success++; + } + } + if($number_success==$max){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function suppress() + { + 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(isset($_POST)) + { + $villes = $this->input->post('ville'); + $res = $this->user_model->deleteVille($villes); + + if($res=true){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function ajout(){ + if ($this->input->post('pays') && $this->input->post('ville')) { + + $ville = $this->input->post('ville'); + $id_pays = $this->input->post('pays'); + $stat = 0; + + + $data = array('name' => $ville, 'country_id' => $id_pays, 'status' => $stat); + + $query = $this->db->insert('towns', $data); + + if ($query) { + + $data['alert'] = "ok"; + $data['success'] = "ok"; + $data['message'] = "La ville ".$ville." a bien été ajouté!"; + $data['active'] = "villes"; + + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllPays(); + $data['game_pays'] = $this->user_model->getGameCountry(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_villes'); + $this->load->view('footer'); + } else { + + $data['alert'] = "ok"; + $data['success'] = "error"; + $data['message'] = "Une erreur s'est produite"; + $data['active'] = "villes"; + $data['game_pays'] = $this->user_model->getGameCountry(); + + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllPays(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_villes'); + $this->load->view('footer'); + } + + } + } + + public function networks(){ + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['alert'] = ""; + $data['active'] = "networks"; + $data['networks'] = $this->user_model->getAllNetworksNames(); + $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_networks'); + $this->load->view('footer'); + } + } + + public function creat_network(){ + + 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(isset($_POST)) + { + $network = $this->input->post('new_network'); + + $data = array('name' => $network); + + $query = $this->db->insert('networks', $data); + + if($query){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function assignation(){ + + 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(isset($_POST)) + { + $network = $this->input->post('network'); + $existe = 0; + $this->db->trans_begin(); + foreach ($_POST['id_country'] AS $country){ + $res = $this->user_model->checkIfAssignationExiste($country,$network); + + if($res==false){ + $data = array('country_id' => $country, 'name' => $network); + $this->db->insert('networks', $data); + + }else{ + $existe = $existe+1; + } + + } + if($this->db->trans_status() === FALSE){ + $this->db->trans_rollback(); + echo json_encode("error"); + }elseif ($existe>0){ + $this->db->trans_commit(); + echo json_encode("existe"); + }else{ + $this->db->trans_commit(); + echo json_encode("completed"); + } + + } + } + } + + public function update_network(){ + + 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(isset($_POST)) + { + $old_network = $this->input->post('old_name'); + $new_network = $this->input->post('new_network'); + + $res = $this->user_model->updateNetwork($old_network,$new_network); + + if($res==true){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function change_status_network(){ + + 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(isset($_POST)) + { + $activations = $this->input->post('activations'); + $desactivation = $this->input->post('desactivations'); + + $this->db->trans_begin(); + if(!empty($_POST['activations'])){ + foreach ($_POST['activations'] AS $network){ + + $data = array('status' => 1); + $this->db->where('id', $network); + $this->db->update('networks', $data); + + } + } + if(!empty($_POST['desactivations'])){ + foreach ($_POST['desactivations'] AS $network){ + + $data = array('status' => 0); + $this->db->where('id', $network); + $this->db->update('networks', $data); + + } + } + if($this->db->trans_status() === FALSE){ + $this->db->trans_rollback(); + echo json_encode("error"); + }else{ + $this->db->trans_commit(); + echo json_encode("completed"); + } + + } + } + } + + public function admin(){ + + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['list_admin'] = $this->user_model->getAllAdmin(); + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + $data['alert'] = ""; + $data['active'] = "admin"; + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_admin'); + $this->load->view('footer'); + } + + } + + public function create_admin(){ + + 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(isset($_POST)) + { + $category = 1; + $firstname = $this->input->post('prenom'); + $lastname = $this->input->post('nom'); + $email = $this->input->post('email'); + $emailExist = $this->user_model->isEmailExist($email); + if($emailExist==false){ + $phone = $this->input->post('contact'); + $phoneExist = $this->user_model->isPhoneExist($phone); + if($phoneExist==false){ + $adresse = $this->input->post('adresse'); + $country = $this->input->post('country'); + $token = null; + do { + $token = bin2hex(openssl_random_pseudo_bytes(16)); + $tokenExist = $this->user_model->getToken($token); + } while ($tokenExist==true); + + $data = array('firstname' => $firstname,'lastname' => $lastname,'email' => $email,'phone' => $phone,'adresse' => $adresse,'country' => $country,'category' => $category,'token' => $token); + + $query = $this->db->insert('admin', $data); + + if($query){ + + $link = "https://ilink-app.com/backofficebeta/index.php/Admin_password/?token=".$token; + $this->load->library('email'); + + $this->email->from('noreply@ilink-app.com', 'iLink World'); + $this->email->to($email); + + $this->email->subject($this->lang->line("Confirmation de création d'un compte administrateur")); + $this->email->message($firstname.' '.$lastname.' '.$this->lang->line("votre compte administrateur a bien été créé. Veuillez suivre ce lien pour configurer votre mot de passe.").' '.$link); + + $this->email->send(); + + echo json_encode("completed"); + }else{ + echo json_encode($this->lang->line("Une erreur s'est produite")); + } + }else{ + echo json_encode($this->lang->line("Le numéro de téléphone entré est déjà utilisé")); + } + }else{ + echo json_encode($this->lang->line("L'email entré est déjà utilisé")); + } + } + } + } + + public function modif_admin(){ + + 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(isset($_POST)) + { + $id = $this->input->post('id'); + $firstname = $this->input->post('prenom'); + $lastname = $this->input->post('nom'); + $email = $this->input->post('email'); + $phone = $this->input->post('contact'); + $adresse = $this->input->post('adresse'); + $country = $this->input->post('country'); + $category = $this->input->post('category'); + + $res = $this->user_model->updateAdmin($id,$firstname,$lastname,$email,$phone,$adresse,$country,$category); + + if($res){ + echo json_encode("completed"); + }else{ + echo json_encode($this->lang->line("Une erreur s'est produite")); + } + } + } + } + + public function delete_admin(){ + + 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(isset($_POST)) + { + $id = $this->input->post('id'); + + $res = $this->user_model->deleteAdmin($id); + + if($res){ + echo json_encode("completed"); + }else{ + echo json_encode($this->lang->line("Une erreur s'est produite")); + } + } + } + } + + public function codes(){ + + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['list_villes'] = $this->user_model->getAllVilles(); + $data['pays'] = $this->user_model->getAllPays(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['alert'] = ""; + $data['active'] = "codes-hyper"; + $data['list'] = $this->user_model->getGeneratedHyperCodes(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('codeg'); + $this->load->view('footer'); + } + } + + public function generateCode() + { + + if ($this->input->post('c') && $this->input->post('a')) { + + $number = intval($this->input->post('c')); + $member_code = $this->input->post('a'); + if($number>0){ + for ($i = 0; $i < $number; $i++) { + + + $code = $this->randomString(); + + $data = array('code_parrain' => $member_code, 'code_membre' => $code, 'etat' => 0, 'category' => 'hyper'); + + $query = $this->db->insert('codeGenerer', $data); + + } + } + $data['alert'] = "ok"; + $data['success'] = "ok"; + $data['active'] = "members"; + $data['message'] = "$number codes have been added!"; + + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['pays'] = $this->user_model->getAllCountries(); + $data['hyper'] = $this->user_model->getAllHyper($data['pays']->first_row()->id); + $data['ville'] = $this->user_model->getVilleNetworkByHyper($data['hyper']->first_row()->code_membre); + $data['list'] = $this->user_model->getGeneratedHyperCodes(); + $data['active'] = "codes"; + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['firstname'] = $this->session->userdata('firstname'); + $data['lastname'] = $this->session->userdata('lastname'); + $data['email'] = $this->session->userdata('email'); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + $this->load->view('header_gestion', $data); + $this->load->view('codeg'); + $this->load->view('footer'); + + } else { + $data['alert'] = "ok"; + $data['success'] = ""; + $data['active'] = "members"; + $data['message'] = "Can't add codes!"; + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['hyper'] = $this->user_model->getAllHyper($data['pays']->first_row()->id); + $data['ville'] = $this->user_model->getVilleNetworkByHyper($data['hyper']->first_row()->code_membre); + $data['list'] = $this->user_model->getGeneratedHyperCodes(); + $data['active'] = "codes"; + $data['pays'] = $this->user_model->getAllCountries(); + $data['firstname'] = $this->session->userdata('firstname'); + $data['lastname'] = $this->session->userdata('lastname'); + $data['email'] = $this->session->userdata('email'); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('codeg'); + $this->load->view('footer'); + } + + } + + private function randomString($length = 10) + { + $str = ""; + $characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9')); + $max = count($characters) - 1; + for ($i = 0; $i < $length; $i++) { + $rand = mt_rand(0, $max); + $str .= $characters[$rand]; + } + return $str; + + } + + public function geolocalisation(){ + + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); + $data['active_ville_name'] = $data['villes']->first_row()->name; + $data['active_ville_id'] = $data['villes']->first_row()->id; + $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); + $data['networks'] = $this->user_model->getNetworks($data['pays']->first_row()->id); + $data['alert'] = ""; + $data['active'] = "geoloc"; + $number_geolocalisation = array(); + $network_geolocalisation = array(); + $count = 0; + + foreach ($data['networks']->result() AS $row){ + $number_geolocalisation[$count] = $this->user_model->getPointGeolocalised($row->id,$data['agent']->first_row()->lastname); + $network_geolocalisation[$count] = $row->name; + $count++; + } + $data['current_agent'] = $data['agent']->first_row()->lastname; + $data["number_geolocalisation"] = $number_geolocalisation; + $data["network_geolocalisation"] = $network_geolocalisation; + $data["total"] = $count; + $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_geolocalisation'); + $this->load->view('footer'); + } + } + + public function infos_geolocalisation(){ + + 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(isset($_POST)) + { + $pays = $this->input->post('pays'); + $ville = $this->input->post('ville'); + $lastname = $this->input->post('agent'); + + + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); + $data['active_ville_name'] = $data['villes']->first_row()->name; + $data['active_ville_id'] = $data['villes']->first_row()->id; + $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); + $data['networks'] = $this->user_model->getNetworks($pays); + $data['alert'] = ""; + $data['active'] = "geoloc"; + $number_geolocalisation = array(); + $network_geolocalisation = array(); + $count = 0; + + foreach ($data['networks']->result() AS $row){ + $number_geolocalisation[$count] = $this->user_model->getPointGeolocalised($row->id,$lastname); + $network_geolocalisation[$count] = $row->name; + $count++; + } + $data['current_agent'] = $lastname; + $data["number_geolocalisation"] = $number_geolocalisation; + $data["network_geolocalisation"] = $network_geolocalisation; + $data["total"] = $count; + $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_geolocalisation'); + $this->load->view('footer'); + } + } + } + + public function getVilleByPays(){ + + 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->is_ajax_request()) + { + $ajaxhyp = $this->user_model->getVillesByPays($this->input->post('pays')); + echo json_encode($ajaxhyp->result_array()); + } + + } + } + + public function getAgentByVilles(){ + + 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->is_ajax_request()) + { + $ajaxhyp = $this->user_model->getAgentsFromCountry($this->input->post('id_country')); + echo json_encode($ajaxhyp->result_array()); + } + + } + } + + public function campagne(){ + + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $debut = date('Y-m-d H:i:s',strtotime($this->user_model->getMostOldDateCreationAgent())); + $fin = date("Y-m-d H:i:s"); + $data['pays'] = $this->user_model->getAllCountries(); + $pays = $data['pays']->first_row()->id; + if(!empty($_POST)) + { + $debut = $this->input->post('date-debut'); + $fin = $this->input->post('date-fin'); + $pays = $this->input->post('pays'); + } + + $data['debut'] = $debut; + $data['fin'] = $fin; + $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); + $data['active_ville_name'] = $data['villes']->first_row()->name; + $data['active_ville_id'] = $data['villes']->first_row()->id; + $data['agent'] = $this->user_model->getAgentsFromCountry($pays); + $data['networks'] = $this->user_model->getNetworks($pays); + $data['alert'] = ""; + $data['active'] = "campagne"; + $agent[][] = null; + $geo_correct[][] = null; + $number_geolocalisation [][] = null; + $network_geolocalisation [][] = null; + $number_correct [][] = null; + $count = 0; + $countA = 0; + $total = 0; + $network_count = 0; + $total_physique = 0; + $contact_correct = 0; + + $networks_compte[] = null; + $networks_name[] = null; + + if($data['agent']!=false){ + foreach ($data['agent']->result() AS $row1){ + if(!strstr($row1->lastname, "Super -") and !strstr($row1->lastname, "Airtel")){ + $totalGeo = 0; + $totalGeoCorrect = 0; + $agent[$countA][0] = $row1->lastname; + foreach ($data['networks']->result() AS $row2){ + $number_geolocalisation [$countA][$count] = $this->user_model->getPointGeolocalisedByDate($row2->id,$row1->lastname,$debut,$fin); + $number_correct [$countA][$count] = $this->user_model->getCorrectPointGeolocalisedByDate($row2->id,$row1->lastname,$debut,$fin); + $network_geolocalisation [$countA][$count] = $row2->name; + $totalGeo = $totalGeo + $number_geolocalisation [$countA][$count]; + $totalGeoCorrect = $totalGeoCorrect + $number_correct [$countA][$count]; + $count++; + } + $agent[$countA][1] = $totalGeo; + $agent[$countA][2] = $this->user_model->getPhysicalPointBySupervisor($debut,$fin,$row1->lastname); + $total_physique = $total_physique + $agent[$countA][2]; + $geo_correct [$countA][1] = $totalGeoCorrect; + $total = $total+$totalGeo; + $contact_correct = $contact_correct+$totalGeoCorrect; + $countA++; + } + } + } + + foreach ($data['networks']->result() AS $row){ + $networks_compte[$network_count] = $this->user_model->getPointGeolocalisedByNetwork($row->id,$debut,$fin); + $networks_name[$network_count] = $row->name; + $network_count++; + } + $data["networks_compte"] = $networks_compte; + $data["networks_name"] = $networks_name; + $data["network_count"] = $network_count; + $data["total_physique"] = $total_physique; + $data['geo_correct'] = $geo_correct; + $data['contact_correct']=$total; + if($pays==78){ + $data['contact_correct']=$contact_correct; + } + $data["agents"] = $agent; + $data["total_points"] = $total; + $data["countA"] = $countA; + $data['current_agent'] = $data['agent']->first_row()->lastname; + $data["number_geolocalisation"] = $number_geolocalisation; + $data["network_geolocalisation"] = $network_geolocalisation; + $data["total"] = $count; + $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); + $data['game_pays'] = $this->user_model->getGameCountry(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_campagne'); + $this->load->view('footer'); + } + } + + public function redirect_info_agent(){ + + 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(isset($_GET)) + { + $lastname = $this->input->get('agent'); + $debut = $this->input->get('debut'); + $fin = $this->input->get('fin'); + $id_country = $this->user_model->getAgentNetwork($lastname); + + $data['pays'] = $this->user_model->getAllCountries(); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['villes'] = $this->user_model->getVillesByPays($data['pays']->first_row()->id); + $data['active_ville_name'] = $data['villes']->first_row()->name; + $data['active_ville_id'] = $data['villes']->first_row()->id; + $data['agent'] = $this->user_model->getAgentsFromCountry($data['pays']->first_row()->id); + $data['networks'] = $this->user_model->getNetworks($id_country); + $data['alert'] = ""; + $data['active'] = "geoloc"; + $number_geolocalisation = array(); + $network_geolocalisation = array(); + $count = 0; + + foreach ($data['networks']->result() AS $row){ + $number_geolocalisation[$count] = $this->user_model->getPointGeolocalisedByDate($row->id,$lastname,$debut,$fin); + $network_geolocalisation[$count] = $row->name; + $count++; + } + $data['current_agent'] = $lastname; + $data["number_geolocalisation"] = $number_geolocalisation; + $data["network_geolocalisation"] = $network_geolocalisation; + $data["total"] = $count; + $data['assigned_networks'] = $this->user_model->getAllAssignedNetworks(); + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_geolocalisation'); + $this->load->view('footer'); + } + } + } + + public function map(){ + 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 { + $data['positions'] = $this->user_model->getAllpositionsForWorld(); + $data['latitude'] = 0; + $data['longitude'] = 0; + $data['lastname'] = $this->session->userdata('lastname'); + $data['active'] = "map"; + $data['code_parrain'] = $this->session->userdata('code_parrain'); + $data['alert'] = ""; + $this->load->view('header_gestion', $data); + $this->load->view('gestion_map'); + $this->load->view('footer'); + } + } + + public function game(){ + 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 { + $pays = 1; + if(!empty($_POST)) + { + $pays = $this->input->post('pays'); + $pays_name = $this->user_model->getNameCountry($pays); + $this->session->set_userdata('current_game_country',$pays); + $this->session->set_userdata('current_game_country_name',$pays_name); + }elseif(!empty($this->session->userdata('current_game_country'))){ + $pays = $this->session->userdata('current_game_country'); + $pays_name = $this->session->userdata('current_game_country_name'); + } + $max = 999999; + $data['paliers'] = $this->user_model->getPaliers(); + $data['pays'] = $this->user_model->getAllGameCountries(); + $data['list'] = $this->user_model->getMembers($pays); + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['q1'] = $this->user_model->getQuota(1); + $data['q2'] = $this->user_model->getQuota(2); + $data['q3'] = $this->user_model->getQuota(3); + $data['q4'] = $this->user_model->getQuota(4); + $data['quota1'] = $this->user_model->getCoutForQuota($pays,$data['q1'],$data['q2']); + $data['quota2'] = $this->user_model->getCoutForQuota($pays,$data['q2'],$data['q3']); + $data['quota3'] = $this->user_model->getCoutForQuota($pays,$data['q3'],$data['q4']); + $data['quota4'] = $this->user_model->getCoutForQuota($pays,$data['q4'],$max); + $data['lastname'] = $this->session->userdata('lastname'); + $data['active'] = "game"; + $data['code_parrain'] = $this->session->userdata('code_parrain'); + $data['alert'] = ""; + //wallet + $data['networks'] = $this->user_model->getActiveNetwork(); + $this->load->view('header_gestion',$data); + $this->load->view('game'); + $this->load->view('footer'); + } + } + + public function activerGame(){ + 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(isset($_POST)) + { + $pays = $this->input->post('pays'); + $max = sizeof($pays); + $number_success = 0; + for ($i = 0; $i < $max; $i++) { + $checkContryExist = $this->user_model->checkCountryGameExist($pays[$i]); + if($checkContryExist==true){ + $res = $this->user_model->activeGameOnCountry($pays[$i],1); + }else{ + $add = $this->user_model->addContryToGame($pays[$i]); + if($add==true){ + $res = $this->user_model->activeGameOnCountry($pays[$i],1); + }else{ + echo json_encode("error"); + } + } + if ($res==true){ + $number_success++; + } + } + if($number_success==$max){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function desactiverGame(){ + 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(isset($_POST)) + { + $pays = $this->input->post('pays'); + $max = sizeof($pays); + $number_success = 0; + for ($i = 0; $i < $max; $i++) { + $res = $this->user_model->activeGameOnCountry($pays[$i],0); + if ($res==true){ + $number_success++; + } + } + if($number_success==$max){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + + public function activer_desactiverGame(){ + + 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(isset($_POST)) + { + $apays = $this->input->post('apays'); + $maxA = sizeof($apays); + $number_successA = 0; + + $dpays = $this->input->post('dpays'); + $maxD = sizeof($dpays); + $number_successD = 0; + + $this->db->trans_begin(); + for ($i = 0; $i < $maxD; $i++) { + $res = $this->user_model->activeGameOnCountry($dpays[$i],0); + if ($res==true){ + $number_successD++; + } + } + for ($i = 0; $i < $maxA; $i++) { + + $checkContryExist = $this->user_model->checkCountryGameExist($apays[$i]); + if($checkContryExist==true){ + $res = $this->user_model->activeGameOnCountry($apays[$i],1); + }else{ + $add = $this->user_model->addContryToGame($apays[$i]); + if($add==true){ + $res = $this->user_model->activeGameOnCountry($apays[$i],1); + }else{ + echo json_encode("error"); + } + } + if ($res==true){ + $number_successA++; + } + } + + if($this->db->trans_status() === FALSE){ + $this->db->trans_rollback(); + echo json_encode("error"); + }else{ + $this->db->trans_commit(); + echo json_encode("completed"); + } + } + } + } + + public function modifierPalier(){ + 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(isset($_POST)) + { + $n1 = $this->input->post('n1'); + $n2 = $this->input->post('n2'); + $n3 = $this->input->post('n3'); + $n4 = $this->input->post('n4'); + $max = 4; + $number_success = 0; + + $res1 = $this->user_model->modifPalier($n1,1); + if ($res1==true){ + $number_success++; + $res2 = $this->user_model->modifPalier($n2,2); + if($res2==true){ + $number_success++; + $res3 = $this->user_model->modifPalier($n3,3); + if($res3){ + $number_success++; + $res4 = $this->user_model->modifPalier($n4,4); + if($res4==true){ + $number_success++; + }else{ + echo json_encode("error"); + } + }else{ + echo json_encode("error"); + } + }else{ + echo json_encode("error"); + } + }else{ + echo json_encode("error"); + } + + if($number_success==$max){ + echo json_encode("completed"); + }else{ + echo json_encode("error"); + } + } + } + } + public function change_country(){ + 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(isset($_POST)) + { + $pays = $this->input->post('pays'); + $pays_name = $this->user_model->getNameCountry($pays); + if($pays_name!=false){ + $this->session->set_userdata('current_game_country',$pays); + $this->session->set_userdata('current_game_country_name',$pays_name); + echo 1; + }else{ + echo 0; + } + }else{ + echo 0; + } + } + } + + public function recherche(){ + + 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 { + + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['alert'] = ""; + $data['active'] = "recherche"; + $data['result_search'] = 0; + $data['default_phone'] = ''; + $data['default_transac'] = ''; + $data['default_code'] = ''; + $data['default_nom'] = ''; + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_recherche'); + $this->load->view('footer'); + } + } + + public function get_user(){ + + 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(isset($_POST)) + { + $nom = $this->input->post('nom'); + + $phone = $this->input->post('phone'); + $simple_users = null; + if($phone!='' && $nom!=''){ + $phone_condition = "phone LIKE '".$phone."%'"; + $nom_condition = "AND lastname LIKE '%".$nom."%'"; + $simple_users = $this->user_model->get_simple_user($phone,$nom); + }elseif ($phone!='' && $nom=='') { + $phone_condition = "phone LIKE '".$phone."%'"; + $nom_condition = 'AND lastname IS NOT NULL'; + $simple_users = $this->user_model->get_simple_user($phone,'%'); + }elseif ($phone=='' && $nom!='') { + $phone_condition = 'phone IS NOT NULL'; + $nom_condition = "AND lastname LIKE '%".$nom."%'"; + $simple_users = $this->user_model->get_simple_user('%',$nom); + }elseif ($phone=='' && $nom=='') { + $phone_condition = 'phone IS NOT NULL'; + $nom_condition = 'AND lastname IS NOT NULL'; + } + + $transac = $this->input->post('transac'); + if($transac!=''){ + $transac_condition = "AND transactionNumber LIKE'".$transac."%'"; + }else{ + $transac_condition = 'AND transactionNumber IS NOT NULL'; + } + $code = $this->input->post('code'); + if($code!=''){ + $code_condition = "AND code_membre = '".$code."'"; + }else{ + $code_condition = 'AND code_membre IS NOT NULL'; + } + + $where_clause = "WHERE ".$phone_condition.' '.$transac_condition.' '.$code_condition.' '.$nom_condition; + + $res = $this->user_model->get_user($where_clause); + + if($res!=false){ + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + $count_users = $res->num_rows(); + if($simple_users != null){ + $count_users = $res->num_rows()+$simple_users->num_rows(); + } + + $data['alert'] = ""; + $data['active'] = "recherche"; + $data['result_search'] = 1; + $data['res_users'] = $res; + $data['res_simple_users'] = $simple_users; + $data['num_res'] = $count_users; + $data['default_phone'] = $phone; + $data['default_nom'] = $nom; + $data['default_transac'] = $transac; + $data['default_code'] = $code; + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_recherche'); + $this->load->view('footer'); + }else{ + $ville = $this->session->userdata('current_ville'); + $hyper = $this->session->userdata('current_hyper'); + $pays = $this->session->userdata('current_pays'); + + $data['alert'] = ""; + $data['active'] = "recherche"; + $data['result_search'] = 2; + $data['res_simple_users'] = $simple_users; + $data['default_phone'] = ''; + $data['default_transac'] = ''; + $data['default_code'] = ''; + $data['default_nom'] = ''; + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_recherche'); + $this->load->view('footer'); + } + } + } + } + + public function update_info_user(){ + + 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(isset($_POST)){ + $id= $_POST['user_id']; + $phone = $_POST['contact']; + $adresse = $_POST['adresse']; + $email = $_POST['email']; + $nom = $_POST['nom']; + $res = $this->user_model->update_user_infos($nom,$adresse,$email,$phone,$id); + if($res!=false){ + echo json_encode("200"); + }else{ + echo json_encode("500"); + } + }else{ + + } + } + } + + public function update_info_geolocated(){ + + 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(isset($_POST)){ + $id_agent= $_POST['user_id']; + $id_netAg= $_POST['id_netAg']; + $phone = $_POST['contact']; + $transac = $_POST['transac']; + $adresse = $_POST['adresse']; + $email = $_POST['email']; + $nom = $_POST['nom']; + $res = $this->user_model->update_geolocated_infos($nom,$adresse,$email,$id_agent,$transac,$phone,$id_netAg); + if($res!=false){ + echo json_encode("200"); + }else{ + echo json_encode("500"); + } + }else{ + + } + } + } + + public function pub(){ + + 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 { + + $data['countries_list'] =$this->user_model->getPubCountries(); + $data['active'] = "pub"; + $data['alert'] = ""; + $data['game_pays'] = $this->user_model->getGameCountry(); + $data['networks'] = $this->user_model->getActiveNetwork(); + + $this->load->view('header_gestion', $data); + $this->load->view('gestion_publicite'); + $this->load->view('footer'); + } + } + + public function changePubState(){ + + 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(isset($_POST)){ + $id_pub= $_POST['pub_id']; + $etat= $_POST['etat']; + if($etat == 0){ + $res = $this->user_model->updateStatePub($id_pub,1); + }elseif($etat == 1){ + $res = $this->user_model->updateStatePub($id_pub,0); + } + if($res!=false){ + echo json_encode("200"); + }else{ + echo json_encode("500"); + } + }else{ + + } + } + } + + public function addPubRow(){ + 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(isset($_POST)){ + $id_country= $_POST['country_id']; + $res = $this->user_model->createPubRow($id_country); + if($res!=false){ + echo json_encode("200"); + }else{ + echo json_encode("500"); + } + } + } + } + + +} diff --git a/application/language/english/message_lang.php b/application/language/english/message_lang.php index f762da8a..1a1d5fc7 100644 --- a/application/language/english/message_lang.php +++ b/application/language/english/message_lang.php @@ -1,209 +1,222 @@ - \ No newline at end of file + diff --git a/application/language/french/message_lang.php b/application/language/french/message_lang.php index a3201e29..965afb6b 100644 --- a/application/language/french/message_lang.php +++ b/application/language/french/message_lang.php @@ -1,225 +1,238 @@ - \ No newline at end of file + diff --git a/application/models/User_model.php b/application/models/User_model.php index d787d7c4..e5b7231f 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -1873,4 +1873,141 @@ class User_model extends CI_Model return false; } } -} \ No newline at end of file + + /** + * @param $where_clause + * @return bool + */ + public function get_user($where_clause){ + $query = $this->db->query("SELECT agents.lastname, agents.adresse,agents.email,agents.date_created,agents.id AS userID, + codeGenerer.category, + networks.name AS network_name,towns.name AS town_name, + codeGenerer.code_parrain AS parrain,codeGenerer.code_membre AS code, + networks_agents.id AS networkAgent_id,networks_agents.phone,networks_agents.transactionNumber AS transac + FROM agents + INNER JOIN networks_agents ON agents.id=networks_agents.agent_id + INNER JOIN codeGenerer ON codeGenerer.id=networks_agents.codeGenerer_id + INNER JOIN networks ON networks.id =networks_agents.network_id + INNER JOIN towns ON towns.id=agents.town_id + ".$where_clause); + $statement = "SELECT agents.lastname, agents.adresse,agents.email,agents.date_created,agents.id AS userID, + codeGenerer.category, + networks.name AS network_name,towns.name AS town_name, + codeGenerer.code_parrain AS parrain,codeGenerer.code_membre AS code, + networks_agents.id AS networkAgent_id,networks_agents.phone,networks_agents.transactionNumber AS transac + FROM agents + INNER JOIN networks_agents ON agents.id=networks_agents.agent_id + INNER JOIN codeGenerer ON codeGenerer.id=networks_agents.codeGenerer_id + INNER JOIN networks ON networks.id =networks_agents.network_id + INNER JOIN towns ON towns.id=agents.town_id + ".$where_clause; + //var_dump($statement); + if($query->num_rows()>0){ + return $query; + }else{ + return false; + } + } + + /** + * @param $phone + * @param $name + * @return |null + */ + public function get_simple_user($phone, $name){ + $query = $this->db->query("SELECT users.id AS id_user,users.active AS etat,users.lastname,users.phone,users.email,users.adresse,users.date_created, + networks.name AS network,countries.name AS country + FROM users + INNER JOIN networks ON networks.id=users.network_id + INNER JOIN countries ON countries.id=networks.country_id + WHERE phone LIKE '".$phone."%' AND lastname LIKE '".$name."%'"); + + if($query->num_rows()>0){ + return $query; + }else{ + return null; + } + } + + /** + * @param $nom + * @param $adresse + * @param $email + * @param $phone + * @param int $id + * @return mixed + */ + public function update_user_infos($nom, $adresse, $email, $phone, $id){ + $query = $this->db->query("UPDATE `users` SET `lastname`='".$nom."',`phone`='".$phone."',`email`='".$email."',`adresse`='".$adresse."' WHERE users.id=".$id); + $sql = "UPDATE `users` SET `lastname`='".$nom."',`phone`='".$phone."',`email`='".$email."',`adresse`='".$adresse."' WHERE users.id=".$id; + + return $query; + } + + /** + * @param $nom + * @param $adresse + * @param $email + * @param int $id_agent + * @param $transac + * @param $phone + * @param int $id_netAg + * @return bool + */ + public function update_geolocated_infos($nom, $adresse, $email, $id_agent, $transac, $phone, $id_netAg){ + $this->db->trans_begin(); + + $this->db->query("UPDATE `agents` SET `lastname`='".$nom."',`email`='".$email."',`adresse`='".$adresse."' WHERE `id`=".$id_agent); + $this->db->query("UPDATE `networks_agents` SET `phone`='".$phone."',`transactionNumber`='".$transac."' WHERE `id`=".$id_netAg); + $this->db->trans_complete(); + if ($this->db->trans_status() === FALSE) + { + $this->db->trans_rollback(); + return false; + } + else + { + $this->db->trans_commit(); + return true; + } + } + + + /** + * @return bool + */ + public function getPubCountries(){ + $query = $this->db->query("SELECT countries.id AS id_country,countries.name AS pays,publiciteConfig.id,publiciteConfig.date_update AS maj ,publiciteConfig.partenariat,publiciteConfig.valeur_bool AS etat + FROM countries + INNER JOIN towns ON countries.id = towns.country_id + LEFT JOIN publiciteConfig ON countries.id=publiciteConfig.id_country AND publiciteConfig.id_config=2 + WHERE towns.status=1 + GROUP BY countries.id"); + if($query->num_rows()>0){ + return $query; + }else{ + return false; + } + } + + /** + * Met a jour l'etat de la publicite + * @param int $id ID de la configuration + * @param $newState Nouvel etat + * @return mixed + */ + public function updateStatePub($id, $newState){ + $query = $this->db->query("UPDATE publiciteConfig SET date_update = NOW(),valeur_bool = ".$newState." WHERE id =".$id); + return $query; + } + + /** + * Ajoute une nouvelle ligne de publicite + * @param int $id_country ID du pays + * @return mixed + */ + public function createPubRow($id_country){ + $query = $this->db->query("INSERT INTO publiciteConfig(id_config,id_country, valeur_bool) VALUE (2,".$id_country.",1)"); + return $query; + } +} diff --git a/application/views/game.php b/application/views/game.php index 9013ea4f..585694fc 100644 --- a/application/views/game.php +++ b/application/views/game.php @@ -1,392 +1,392 @@ - -
- -
-
-

Configuration du jeu

-
-
-
-

lang->line('Activer/Désactiver'); ?>

-
-
- - num_rows(); - $num = 0; - if ($numrows > 0) { - ?> - - - - - - - - - - - - result() as $row) { - $num ++; - //$member_code = randomString1(10); - $libelle_status = $this->lang->line('Inactive'); - if($row->etat==1){ - $libelle_status = $this->lang->line('Active'); - } - echo " - - - "; - if($row->etat==0 or $row->etat==null) { - echo " - "; - }else{ - echo " - "; - } - - } - ?> - -
lang->line('Pays'); ?>lang->line('Statut'); ?>lang->line('Activer'); ?>lang->line('Désactiver'); ?>
$num$row->name$libelle_status
- - lang->line('Aucun pays'); - } - }else { - echo $this->lang->line('Aucun pays'); - } - ?> -
-
-
-
-
-
-

Gestion des niveaux

-
-
- num_rows(); - $i=0; - if ($numrows > 0) { - foreach($result->result() as $row) { - $i++; - ?> -
- -
-
-
- -
-
- - - -
- -
- - -
-
-
-
-
-
-

session->userdata('current_game_country_name'); ?>

-
- -
-
-
- num_rows(); - - if ($numrows > 0) { ?> - result() as $row) { - if($row->id!=$this->session->userdata('current_game_country')){ - echo ""; - } - } ?> - -
-
-
-
-
-
-
- - -
- lang->line('Utilisateurs'); ?> - -
- -
- -
- -
-
- - -
- lang->line('Utilisateurs'); ?> - -
- -
- -
- -
-
- - -
- lang->line('Utilisateurs'); ?> - -
- -
- -
- -
-
- - -
- lang->line('Utilisateurs'); ?> - -
- -
- -
-
-
-
-
-
-

Utilisateurs ayant atteint les quotas

- -
- -
- - - num_rows(); - $i=0; - if ($numrows > 0) { - ?> - - - - - - - - result() as $row) { - $i++; - echo " - - - - "; - if($row->total>=$q4){ - echo ""; - }elseif($row->total>=$q3 && $row->total<$q4){ - echo ""; - }elseif($row->total>=$q2 && $row->total<$q3){ - echo ""; - }elseif($row->total>=$q1 && $row->total<$q2){ - echo ""; - } - - echo ""; - } ?> - - -
NomTéléphoneEmailRésultat
".$i."".$row->lastname."".$row->phone."".$row->email."".$row->total." utilisateurs".$row->total." utilisateurs".$row->total." utilisateurs".$row->total." utilisateurs
-
- -
- -
-
-
-
- - - - - - - - - - - - - - - - - - + +
+ +
+
+

Configuration du jeu

+
+
+
+

lang->line('Activer/Désactiver'); ?>

+
+
+ + num_rows(); + $num = 0; + if ($numrows > 0) { + ?> + + + + + + + + + + + + result() as $row) { + $num ++; + //$member_code = randomString1(10); + $libelle_status = $this->lang->line('Inactive'); + if($row->etat==1){ + $libelle_status = $this->lang->line('Active'); + } + echo " + + + "; + if($row->etat==0 or $row->etat==null) { + echo " + "; + }else{ + echo " + "; + } + + } + ?> + +
lang->line('Pays'); ?>lang->line('Statut'); ?>lang->line('Activer'); ?>lang->line('Désactiver'); ?>
$num$row->name$libelle_status
+ + lang->line('Aucun pays'); + } + }else { + echo $this->lang->line('Aucun pays'); + } + ?> +
+
+
+
+
+
+

Gestion des niveaux

+
+
+ num_rows(); + $i=0; + if ($numrows > 0) { + foreach($result->result() as $row) { + $i++; + ?> +
+ +
+
+
+ +
+
+ + + +
+ +
+ + +
+
+
+
+
+
+

session->userdata('current_game_country_name'); ?>

+
+ +
+
+
+ num_rows(); + + if ($numrows > 0) { ?> + result() as $row) { + if($row->id!=$this->session->userdata('current_game_country')){ + echo ""; + } + } ?> + +
+
+
+
+
+
+
+ + +
+ lang->line('Utilisateurs'); ?> + +
+ +
+ +
+ +
+
+ + +
+ lang->line('Utilisateurs'); ?> + +
+ +
+ +
+ +
+
+ + +
+ lang->line('Utilisateurs'); ?> + +
+ +
+ +
+ +
+
+ + +
+ lang->line('Utilisateurs'); ?> + +
+ +
+ +
+
+
+
+
+
+

Utilisateurs ayant atteint les quotas

+ +
+ +
+ + + num_rows(); + $i=0; + if ($numrows > 0) { + ?> + + + + + + + + result() as $row) { + $i++; + echo " + + + + "; + if($row->total>=$q4){ + echo ""; + }elseif($row->total>=$q3 && $row->total<$q4){ + echo ""; + }elseif($row->total>=$q2 && $row->total<$q3){ + echo ""; + }elseif($row->total>=$q1 && $row->total<$q2){ + echo ""; + } + + echo ""; + } ?> + + +
NomTéléphoneEmailRésultat
".$i."".$row->lastname."".$row->phone."".$row->email."".$row->total." utilisateurs".$row->total." utilisateurs".$row->total." utilisateurs".$row->total." utilisateurs
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + diff --git a/application/views/gestion_publicite.php b/application/views/gestion_publicite.php new file mode 100755 index 00000000..2a8bfe3f --- /dev/null +++ b/application/views/gestion_publicite.php @@ -0,0 +1,165 @@ +
+
+ +

+ lang->line('Gestion de la publicité'); ?> +

+ +
+ +

Erreur!

+ +
+ + +
+ +

Success!

+ +
+ + +
+
+
+
+
+
+
+
+

Publicité interstitielle

+
+
+ + + + + + + + + + num_rows(); + $num = 0; + if ($numrows > 0) { + foreach($countries->result() as $row) { + $num ++; + ?> + + + + + etat==1){ + ?> + + + + + + + + + +
PaysOpérateurDate de mise à jourStatutActiver/Desactiver
pays ?>partenariat ?>maj ?>lang->line('Actif'); ?>lang->line('Inactif'); ?>
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/application/views/gestion_recherche.php b/application/views/gestion_recherche.php new file mode 100755 index 00000000..1e9a6b4d --- /dev/null +++ b/application/views/gestion_recherche.php @@ -0,0 +1,654 @@ + + + + + +
+ + +
+ +

+ lang->line('Rechercher un utilisateur'); ?> +

+ +
+ +

Erreur!

+ +
+ + +
+ +

Success!

+ +
+ + +
+ +
+
+
+
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+ '/> +
+
+
+
+
+
+
+ + +

lang->line('utilisateur trouvé'); ?>

+
+
+ num_rows(); + $num = 0; + if ($numrows > 0) { + foreach($users->result() as $row) { + $num ++; + ?> + +
+ +
+
+ User profile picture + +

lastname ?>

+ +

category ?>

+ + + + lang->line('Voir plus...'); ?> +
+ +
+ +
+ + + num_rows(); + $num = 0; + if ($numrows > 0) { + foreach($simple_users->result() as $row) { + $num ++; + ?> + +
+ +
+
+ User profile picture + +

lastname ?>

+ +

lang->line('Utilisateur simple'); ?>

+ + + + lang->line('Voir plus...'); ?> +
+ +
+ +
+ + +
+
+ + +

num_rows().' '.$this->lang->line('utilisateur trouvé'); ?>

+
+
+ num_rows(); + $num = 0; + if ($numrows > 0) { + foreach($simple_users->result() as $row) { + $num ++; + ?> + +
+ +
+
+ User profile picture + +

lastname ?>

+ +

lang->line('Utilisateur simple'); ?>

+ + + + lang->line('Voir plus...'); ?> +
+ +
+ +
+ + +
+
+ + +

lang->line('Aucun utilisateur trouvé'); ?>

+ + +
+ icon search +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/application/views/header_gestion.php b/application/views/header_gestion.php index cf735c60..c9561968 100644 --- a/application/views/header_gestion.php +++ b/application/views/header_gestion.php @@ -1,235 +1,245 @@ - - - - - - - iLink | Dashboard - - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - - - -
- - - - - - - + + + + + + + iLink | Dashboard + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + + + + + + diff --git a/application/views/login.php b/application/views/login.php index 2b1c04c6..fa17cd76 100644 --- a/application/views/login.php +++ b/application/views/login.php @@ -63,13 +63,17 @@
-
+
- +
+ +
-
+
- +
+ +