<?php header('Content-type: text/html'); require_once 'includes/xen_api.php'; require_once 'includes/database.php'; require_once 'includes/config.php'; require_once 'includes/utils.php'; $params = $_POST; $xenAPI = new XenAPI($apiUrl, $apiKey); $err = 0; $errMsg = "Success!"; try { $login = $params['l']; $hash = $params['hash']; if (!checkAuthHash($login, $hash, $xenAPI)) { $errMsg = 'This hash is not valid.'; $err = 1228; } } catch (Exception $e) { if ($e->getCode() == 400) { $error = json_decode($e->getMessage(), TRUE); $errMsg = 'API call failed: API ERROR CODE=' . $error['error'] . ' & API ERROR MESSAGE=' . $error['message']; $err = $error['error']; } else { $errMsg = 'API call failed: HTTP RESPONSE=' . $e->getMessage() . ' & HTTP STATUS CODE=' . $e->getCode(); $err = $e->getCode(); } } die(json_encode(array('error' => $err, 'errorMsg' => $errMsg), 128));
$STH->setFetchMode(PDO::FETCH_ASSOC); $STH->bindValue(':dateS', intval($dateS), PDO::PARAM_INT); $STH->bindValue(':limitS', intval($limitS), PDO::PARAM_INT); $STH->execute(); $table = array(); $i = 0; while ($row = $STH->fetch()) { $table[] = array('id' => $row['id'], 'uid' => $row['user_id'], 'rid' => $row['room_id'], 'date' => $row['date'], 'msg' => strip_tags($row['message']), 'uname' => $row['username'], 'avatar' => 'notImplmented'); $i = $i + 1; } if ($i == 0) { $table = array('empty' => true); } $response = array('msg' => $table, 'time' => time(), 'dbg' => $q); return $response; } $xenAPI = new XenAPI($apiUrl, $apiKey); $err = 0; try { $params = $_REQUEST; if ($canShowChatForNonLogged || checkAuthHash($params['u'], $params['hash'], $XenAPI)) { die(json_encode(getMsg($DBH, $params['date'], $params['limit'], $xenAPI, $apiKey), 128)); } else { $err = 322; $errMsg = 'You must be logged in.'; } } catch (Exception $e) { $errMsg = 'API call failed: HTTP RESPONSE=' . $e->getMessage() . ' & HTTP STATUS CODE=' . $e->getCode(); $err = $e->getCode(); } die(json_encode(array('error' => $err, 'errorMsg' => $errMsg), 128));