function getStaffObj($staff) { $stafflist = json_decode(getStaffList()); $valuelist = json_decode(getStaffvalue($staff)); $staffid = array_intersect($valuelist, $stafflist); foreach ($staffid as $k => $v) { $data = getObj($v); if ($data['staff'] == $staff) { return $data; } } return False; }
<?php require 'includes/connect.inc.php'; //Veza sa bazom podataka header('Content-Type: application/json'); if (!check($_GET['serial']) || !check($_GET['action'])) { //Proveri da li su odgovaraju parametri prosledjeni terminate(ERR::SERVER_NODATA); } $serial = $_GET['serial']; $board_query = $link->query("SELECT * FROM `boards` WHERE `serial`='{$serial}'") or terminate(ERR::QUERY_CODE); $board = getObj($board_query, ERR::BOARD_SERIAL); switch ($_GET['action']) { //U Zavisnosti od prosledjene komande izvrsi odgovaracuji kod case 'getData': $user_query = $link->query("SELECT * FROM `users` WHERE `serials` LIKE '%{$serial}%'") or terminate(ERR::QUERY_CODE); //Svi korisnici koji u bazi imaju SmartAlarm sa prosledjenim serijalom $users = array(); if ($user_query->num_rows == 0) { terminate(ERR::USER_NOSERIAL); } else { while ($user = $user_query->fetch_assoc()) { //Popuni niz array_push($users, array('email' => $user['email'], 'name' => $user['name'], 'surname' => $user['surname'])); } } $encode = array("status" => $board->status, "calibration" => $board->calibration, "name" => $board->name, "location" => $board->location, "sensitivity" => $board->sensitivity, "users" => $users); exit(json_encode($encode)); case 'isActive': $encode = array("status" => $board->status); exit(json_encode($encode));
<?php require 'includes/connect.inc.php'; require 'includes/redirect.inc.php'; session_start(); if (check($_SESSION['email'])) { //if logging again $email = $_SESSION['email']; $query = $link->query("SELECT * FROM `users` WHERE `email`='{$email}'") or terminate(ERR::QUERY_CODE); $obj = getObj($query, ERR::SERVER_DATA); } else { //not posting or already logging redirect('login.php'); } ?> <!DOCTYPE html> <html lang="en"> <head> <!-- Compiled and minified CSS --> <link rel="stylesheet" href="css/materialize.min.css" media="screen,projection" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="css/dashboard.css" rel="stylesheet"> <!-- Compiled and minified JavaScript --> <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script src="js/materialize.min.js"></script> <script type="text/javascript" src="js/app.js"></script> </head> <body> <div id="header" class="row">
} $serial = $_POST['serial']; $board_query = $link->query("SELECT * FROM `boards` WHERE `serial`='{$serial}'") or terminate(ERR::QUERY_CODE); $board = getObj($board_query, ERR::BOARD_SERIAL); if (strpos($serials_str, $serial) === false) { terminate(ERR::USER_NOSERIAL); } else { if (($key = array_search($serial, $serials_arr)) !== false) { unset($serials_arr[$key]); } else { terminate(ERR::USER_SERIAL); } } $serials_str = implode(',', $serials_arr); $updateUser = $link->query("UPDATE `users` SET `serials`='{$serials_str}' WHERE `email`='{$email}'") or terminate(ERR::QUERY_CODE); terminate(); case 'getBoards': $boards = array(); foreach ($serials_arr as &$value) { // iterate over serials and get board data. $query = $link->query("SELECT * FROM `boards` WHERE `serial`='{$value}'") or terminate(ERR::QUERY_CODE); if ($query->num_rows == 0) { terminate(ERR::BOARD_SERIAL); } else { $obj = getObj($query); $board = array('name' => $obj->name, 'location' => $obj->location, 'serial' => $obj->serial, 'status' => (bool) $obj->status); array_push($boards, $board); } } exit(json_encode(array('status' => true, 'boards' => $boards))); }