load->model('wallet_model'); $this->load->model('nano_health_model'); } public function updateConfigYearsPricesGrid(){ if($this->isLogged()) { if (isset($_POST)) { $configId = $_POST['config_id']; $grid = $_POST['grid'] ?? []; $this->db->delete('nh_years_prices_grid',['nh_network_config_id' => $configId]); if(sizeof($grid) > 0){ $this->db->insert_batch('nh_years_prices_grid',$grid); } echo json_encode("200"); } } } public function updateConfigMonthsPricesGrid(){ if($this->isLogged()) { if (isset($_POST)) { $configId = $_POST['config_id']; $grid = $_POST['grid'] ?? []; $this->db->delete('nh_months_prices_grid',['nh_network_config_id' => $configId]); if(sizeof($grid) > 0){ $this->db->insert_batch('nh_months_prices_grid',$grid); } echo json_encode("200"); } } } public function storeAct(){ if($this->isLogged()) { if (isset($_POST)) { $id = $_POST['id']; $_POST['nh_network_config_id'] = $_POST['config_id']; unset($_POST['config_id']); if(!empty($id)){ $this->db->where('id',$id); $this->db->update('nh_acts',$_POST); }else{ $this->db->insert('nh_acts',$_POST); } echo json_encode("200"); } } } public function deleteAct(){ if($this->isLogged()) { if (isset($_POST)) { $this->db->delete('nh_acts', ['id' => $_POST['id']]); echo json_encode(['code' => 200 ]); } } } public function createValidatingAgent() { if($this->isLogged()) { if (isset($_POST)) { $emailExist = $this->db->get_where('nh_validating_agents', ['email' => $_POST['email']]); if ($emailExist->num_rows() == 0) { do { $token = bin2hex(openssl_random_pseudo_bytes(16)); $tokenExist = $this->db->get_where('nh_validating_agents',['token' => $token]); } while ($tokenExist->num_rows() > 0); $_POST['token'] = $token; $query = $this->db->insert('nh_validating_agents', $_POST); if ($query) { $link = base_url("Agent_password/?token=" . $token); $this->load->library('email'); $this->email->from('noreply@ilink-app.com', 'iLink World'); $this->email->to($_POST['email']); $this->email->subject($this->lang->line($_POST['role'] == 'DOCTOR' ? "mail_title_validating_doctor" : "mail_title_validating_agent")); $this->email->message($_POST['firstname'] . ' ' . $_POST['lastname'] . ' ' . $this->lang->line($_POST['role'] == 'DOCTOR' ? "mail_body_validating_doctor" : "mail_body_validating_agent") . ' ' . $link); $this->email->send(); echo json_encode(['code' => 200]); } else { echo json_encode(['code' => 500, 'message' => $this->lang->line("Une erreur s'est produite")]); } } else { echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]); } } } } public function updateValidatingAgent() { if($this->isLogged()) { if (isset($_POST)) { $emailExist = $this->db->get_where('nh_validating_agents', ['id !=' => $_POST['id'], 'email' => $_POST['email']]); if ($emailExist->num_rows() == 0) { $this->db->where('id',$_POST['id']); $this->db->update('nh_validating_agents',$_POST); echo json_encode(['code' => 200]); }else{ echo json_encode(['code'=> 419 , 'message' => $this->lang->line("L'email entré est déjà utilisé")]); } } } } public function deleteValidatingAgent(){ if($this->isLogged()) { if (isset($_POST)) { $this->db->delete('nh_validating_agents', ['id' => $_POST['id']]); echo json_encode(['code' => 200]); } } } public function storeProviderClass(){ if($this->isLogged()) { if (isset($_POST)) { $id = $_POST['id']; $_POST['nh_network_config_id'] = $_POST['config_id']; unset($_POST['config_id']); if(!empty($id)){ $this->db->where('id',$id); $this->db->update('nh_provider_classes',$_POST); }else{ $this->db->insert('nh_provider_classes',$_POST); } echo json_encode(['code' => 200 ]); } } } public function deleteProviderClass(){ if($this->isLogged()) { if (isset($_POST)) { $this->db->delete('nh_provider_classes', ['id' => $_POST['id']]); echo json_encode(['code' => 200 ]); } } } public function validateSubscription() { if($this->isLogged()) { if (isset($_POST)) { $subscription_id = $_POST['subscription_id']; $url = NANO_SANTE_SERVICE_URL.'/insurances/subscriptions/'.$subscription_id.'/validate'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); /* set the content type json */ curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type:application/json', 'Authorization:'.NANO_SANTE_SERVICE_TOKEN, 'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en' )); /* set return type json */ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = new \stdClass(); $body->agent_id = $this->input->post('agent_id'); $body->nh_validating_agent_id = $this->input->post('nh_validating_agent_id'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); /* execute request */ $result = curl_exec($ch); /* close cURL resource */ curl_close($ch); if ($result) { echo $result; } else { echo json_encode(['status' => 500]); } } } } public function rejectSubscription() { if($this->isLogged()) { if (isset($_POST)) { $subscription_id = $_POST['subscription_id']; $url = NANO_SANTE_SERVICE_URL.'/insurances/subscriptions/'.$subscription_id.'/reject'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); /* set the content type json */ curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type:application/json', 'Authorization:'.NANO_SANTE_SERVICE_TOKEN, 'X-localization:'. $this->session->userdata('site_lang') == 'french' ? 'fr' : 'en' )); /* set return type json */ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $body = new \stdClass(); $body->agent_id = $this->input->post('agent_id'); $body->nh_validating_agent_id = $this->input->post('nh_validating_agent_id'); $body->reason = $this->input->post('reason'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); /* execute request */ $result = curl_exec($ch); /* close cURL resource */ curl_close($ch); if ($result) { echo $result; } else { echo json_encode(['status' => 500]); } } } } 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; } }