Esempio n. 1
0
<?php

session_start();
include_once "../models/connexionSql.php";
include_once "../models/loadClass.php";
// Permet de définir méthode serveur (POST / GET)
$method = $_SERVER["REQUEST_METHOD"];
// Objet list
$lists = new Lists($bdd);
switch ($method) {
    case "GET":
        // Récupération des listes utilisateur
        if (isset($_GET["user"]) && $_GET["user"] === "lists") {
            $result = $lists->read();
            echo $result;
        }
        break;
    case "POST":
        // add new
        if (isset($_POST["name"]) and !isset($_POST["newname"])) {
            $name = strip_tags($_POST["name"]);
            $nameCount = $lists->verifListExist($name);
            if (strlen($name) < 3 or strlen($name) > 30) {
                echo "errorListLength";
            } else {
                if (empty($name) or $name === "undefined") {
                    echo "emptyName";
                } else {
                    if ($nameCount !== 0) {
                        echo "alreadyExists";
                    } else {