<?php

/**
 * Created by PhpStorm.
 * User: Kavand
 * Date: 7/9/2018
 * Time: 5:10 AM
 */
$object = $request['object'];
switch ($request['header-type']) {
    case 'app-state-load':
        $query = "SELECT * FROM app_panel_state";
        $select = $DLA->Select($query);
        $temp = [];
        $counter = 0;
        if ($select) {
            for ($i = 0; $i < count($select); $i += 1) {
                $row = $select[$i];
                $temp[] = array(
                    "id" => $row['ID'],
                    'name' => $row['ControllerName'],
                    'key' => $row['ControllerKey'],
                    'state' => $row['ControllerValue'],
                    'condition' => $row['ControllerCondition']
                );
                $counter += 1;
            }
        }
        echo json_encode($temp, JSON_UNESCAPED_UNICODE);
        break;
    case 'app-state-update':
        $query = "UPDATE app_panel_state SET ControllerValue='{$object['state']}' WHERE ID=" . $object['id'];
        echo($DLA->DoCommand($query) ? 1 : 0);
        break;
    default:
        break;
}