<?php

require '../class/ChiconUser.class.php';
require '../class/DB.class.php';
$db = new DB();
$user = new ChiconUser($db);
if ($user->isLoggedIn()) {
    if (isset($_GET['cmd'])) {
        $cmd = $_GET['cmd'];
        switch ($cmd) {
            case "getServices":
                $result = array("result" => array("code" => 200, "data" => $user->getServices()));
                echo json_encode($result);
                break;
            case "getHardwares":
                $result = array("result" => array("code" => 200, "data" => $user->getHardwares()));
                echo json_encode($result);
                break;
            case "getDetails":
                $result = array("result" => array("code" => 200, "data" => $user->getDetails()));
                echo json_encode($result);
                break;
            case "getAssociatedServices":
                if (isset($_GET['hdwSerial']) and $user->isUserHardware($_GET['hdwSerial'])) {
                    require '../class/ChiconHardware.class.php';
                    $hdwSerial = $_GET['hdwSerial'];
                    $hardware = ChiconHardware::withSerial($db, $hdwSerial);
                    $result = array("result" => array("code" => 200, "data" => $hardware->getAssociatedServices()));
                } else {
                    $result = array("result" => array("code" => 400, "data" => array("error" => "Bad command")));
                }
<?php

require '../class/ChiconUser.class.php';
require '../class/DB.class.php';
$db = new DB();
$user = new ChiconUser($db);
if ($user->isLoggedIn()) {
    echo $user->getServices();
} else {
    echo "Please log in first";
}