<?php
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();

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 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);
}
