125 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			125 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| error_reporting(E_ALL);
 | |
| error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING);
 | |
| ini_set('display_errors', 1);
 | |
| 
 | |
| 
 | |
| require_once '../../classes/dao.php';
 | |
| 
 | |
| 
 | |
| $rest_json = file_get_contents("php://input");
 | |
| $_POST = json_decode($rest_json, true);
 | |
| //var_dump($_POST);
 | |
| 
 | |
| // if (isset($_GET['function']) || isset($_POST['function'])) {
 | |
| //     if ($_GET['function'] == "save_map_info")
 | |
| //         save_map_info();
 | |
| //     elseif ($_POST['function'] == "update_website")
 | |
| //         update_website();
 | |
| // } else
 | |
| //     show_error();
 | |
| if (isset($_REQUEST['function'])) {
 | |
|     switch($_REQUEST['function']) {
 | |
|         case 'save_map_info':
 | |
|             save_map_info();
 | |
|             break;
 | |
|         case 'create_building':
 | |
|             create_building();
 | |
|             break;
 | |
|         case 'delete_building':
 | |
|             delete_building();
 | |
|             break;
 | |
|         case 'get_map_selectors':
 | |
|             get_map_selectors();
 | |
|             break;
 | |
|         default :
 | |
|             show_error();
 | |
|             break;
 | |
|     }
 | |
|        
 | |
| 
 | |
| } else {
 | |
|     show_error();
 | |
| }
 | |
| 
 | |
| function save_map_info() {
 | |
|     if (isset($_GET['selector']) && isset($_GET['info'])) {
 | |
|         $dao = new Dao();
 | |
|         $dao->save_map_info($_GET['selector'], $_GET['info']);
 | |
|         echo "Réussite";
 | |
|     } else {
 | |
|         show_error();
 | |
|     }
 | |
| }
 | |
| 
 | |
| function get_map_selectors() {
 | |
|     header('Content-Type: application/json');
 | |
|     $dao = new Dao();
 | |
|     echo json_encode($dao->get_map_selectors());
 | |
| }
 | |
| /*
 | |
| function is_in_map() {
 | |
|     if($_SERVER['REQUEST_METHOD'] === 'POST') {
 | |
|         show_error(); 
 | |
|         return;
 | |
|     }
 | |
|     $dao = new Dao();
 | |
|     $_REQUEST = array(
 | |
|         'selector'      => $_REQUEST['info']['selector'],
 | |
|     );
 | |
|     $dao->is_in_map($_REQUEST['selector']);
 | |
| }
 | |
| */
 | |
| function create_building() {
 | |
|     if($_SERVER['REQUEST_METHOD'] === 'GET') {
 | |
|         show_error(); 
 | |
|         return;
 | |
|     }
 | |
|     $dao = new Dao();
 | |
|     $_REQUEST = array(
 | |
|         'title'         => $_REQUEST['info']['title'],
 | |
|         'description'   => $_REQUEST['info']['description'],
 | |
|         'selector'      => $_REQUEST['info']['selector'],
 | |
|     );
 | |
|     var_dump($_REQUEST);
 | |
| 
 | |
|     $dao->create_building($_REQUEST['title'], $_REQUEST['description'], $_REQUEST['selector']);
 | |
|     echo 'Réussite';
 | |
| }
 | |
| 
 | |
| function delete_building() {
 | |
|     if($_SERVER['REQUEST_METHOD'] === 'GET') {
 | |
|         show_error(); 
 | |
|         return;
 | |
|     }
 | |
|     $dao = new Dao();
 | |
|     $_REQUEST = array(
 | |
|         'selector'      => $_REQUEST['info']['selector'],
 | |
|     );
 | |
|     var_dump($_REQUEST);
 | |
|     $dao->delete_building($_REQUEST['selector']);
 | |
|     echo 'Réussite';
 | |
| }
 | |
| 
 | |
| function update_website() {
 | |
| //    if (isset($_POST['login']) && isset($_POST['password'])) {
 | |
| //        $login = $_POST['login'];
 | |
| //        $password = $_POST['password'];
 | |
| //        echo $login . ":" . $password."\n";
 | |
| //        // Cannot write because php cannot write as user www-data
 | |
| //        // be sure to escape characters
 | |
| //        // Do not remove the space before the command (prevent command from being saved in history)
 | |
| ////            system(" git pull https://".$login.":".$password."@git.srv-falcon.etud.insa-toulouse.fr/vergnet/site-accueil-insa.git");
 | |
| //    } else {
 | |
| //        show_error();
 | |
| //    }
 | |
| }
 | |
| 
 | |
| 
 | |
| function show_error() {
 | |
|     echo "Échec :\n";
 | |
|     echo "GET\n";
 | |
|     var_dump($_GET);
 | |
|     echo "POST\n";
 | |
|     var_dump($_POST);
 | |
| }
 |