public function getContent($section) { if (!class_exists('\\CPUInfo')) { include dirname(__DIR__) . '/classes/CPUInfo.class.php'; } if (!class_exists('\\TimeUtils')) { include dirname(__DIR__) . '/classes/TimeUtils.class.php'; } $cpu = new \CPUInfo(); $time = \TimeUtils::getReadable($this->getUptimeSecs()); return load_view(dirname(__DIR__) . '/views/sections/uptime.php', array("cpu" => $cpu->getAll(), "time" => $time)); }
function testGetTodayMeals() { $date = TimeUtils::getCurrentDate(); $getTodayMealsFlag = MealAction::getTodayMeals($date); if ($getTodayMealsFlag === MealAction::$GET_MEALS_FAIL) { $result = new Response(false, "get today meals failed"); return $result; } elseif (isset($getTodayMealsFlag)) { $result = new mealsRes(true, "", $getTodayMealsFlag, sizeof($getTodayMealsFlag)); return $result; } return new Response(false, "服务器故障"); }
public function responseError($start_time, $error_msg, $error_code, $link) { $over_time = TimeUtils::getNowTime(); $data["message"] = $error_msg; $data["error_code"] = $error_code; $data["result"] = false; $data["start_time"] = $start_time; $data["over_time"] = $over_time; $res["data"] = $data; echo json_encode($res); if ($link) { mysql_close($link); } exit; }
function testOrderSubmit() { $userId = $_SESSION['user']->userId; if (TimeUtils::isTimeAvailable()) { $orderFlag = OrderAction::orderMeal($userId); if ($orderFlag === OrderAction::$ORDER_MEAL_FAIL) { $result = new Response(false, "抱歉,订餐失败。"); return $result; } elseif ($orderFlag === true) { $result = new Response(true); return $result; } } else { $result = new Response(false, "下午三点到五点才是订餐时间呦"); return $result; } return new Response(false, "服务器故障"); }
/** * @param $date String * @return array|Integer get orders success or error code */ public static function getOrders($date = "") { if ($date == "") { $date = TimeUtils::getCurrentDate(); } $connection = Database::getInstance()->getConnection(); static $query = "select * from `order` natural join user where date = ? order by createTime desc"; $result = $connection->prepare($query); $result->bind_param("s", $date); $execute = $result->execute(); if (!$execute) { return self::$GET_ORDERS_FAIL; } $result->bind_result($userId, $orderId, $date, $createTime, $email, $password, $username, $nickname, $department, $location, $description); $orders = []; while ($result->fetch()) { $orders[] = new Order($orderId, new User($userId, $email, $username, $nickname, $department, $location, $description), $date, $createTime); } $result->close(); return $orders; }
function testCancelFavor() { $date = TimeUtils::getCurrentDate(); $userId = $_SESSION['user']->userId; $meal = MealAction::getTodayMeal($date); $favorite = MealAction::cancelFavor($userId, $meal->mealId); if ($favorite === MealAction::$CANCEL_FAVOR_FAIL) { $result = new Response(false, "cancel favor failed"); return $result; } elseif ($favorite === MealAction::$CANCEL_FAVOR_NOT_ORDER_MEAL) { $result = new Response(false, "you haven't ordered yet"); return $result; } elseif ($favorite === MealAction::$CANCEL_FAVOR_NOT_FAVOR_BEFORE) { $result = new Response(false, "you haven't liked it "); return $result; } elseif ($favorite === true) { $result = new Response(true); return $result; } return new Response(false, "服务器错误"); }
private function getNotifications($showall = false) { if (!class_exists('TimeUtils')) { include dirname(__DIR__) . '/classes/TimeUtils.class.php'; } $final['nots'] = array(); $items = \FreePBX::create()->Notifications->list_all($showall); $allItems = \FreePBX::create()->Notifications->list_all(true); $final['showAllMessage'] = count($items) != count($allItems); // This is where we map the Notifications priorities to Bootstrap priorities. // define("NOTIFICATION_TYPE_CRITICAL", 100) -> 'danger' (red) // define("NOTIFICATION_TYPE_SECURITY", 200) -> 'danger' (red) // define("NOTIFICATION_TYPE_UPDATE", 300) -> 'warning' (orange) // define("NOTIFICATION_TYPE_ERROR", 400) -> 'danger' (red) // define("NOTIFICATION_TYPE_WARNING" , 500) -> 'warning' -> (orange) // define("NOTIFICATION_TYPE_NOTICE", 600) -> 'success' -> (green) $alerts = array(100 => "danger", 200 => "danger", 250 => 'warning', 300 => "warning", 400 => "danger", 500 => "warning", 600 => "success"); foreach ($items as $notification) { $final['nots'][] = array("id" => $notification['id'], "rawlevel" => $notification['level'], "level" => !isset($alerts[$notification['level']]) ? 'danger' : $alerts[$notification['level']], "candelete" => $notification['candelete'], "title" => $notification['display_text'], "time" => \TimeUtils::getReadable(time() - $notification['timestamp']), "text" => nl2br($notification['extended_text']), "module" => $notification['module'], "link" => $notification['link'], "reset" => $notification['reset']); } return $final; }
public function getGraphDataUptime($period) { $si = FreePBX::create()->Dashboard->getSysInfoPeriod($period); if (!class_exists('TimeUtils')) { include 'TimeUtils.class.php'; } $tooltips = array(); $sysuptime = array(); $astuptime = array(); $astreload = array(); foreach ($si as $key => $row) { if (!isset($row['ast.uptime.system-seconds'])) { $us = 0; $rs = 0; $ut = 0; } else { $us = $row['ast.uptime.system-seconds']; $rs = $row['ast.uptime.reload-seconds']; $ut = $row['*****@*****.**']; } $ttip = date('c', $key) . "<br>"; $ttip .= _("System") . ":<br> " . TimeUtils::getReadable($ut, 3) . "<br>"; $ttip .= "Asterisk:<br> " . TimeUtils::getReadable($us, 3) . "<br>"; $ttip .= _("Since Reload") . ":<br> " . TimeUtils::getReadable($rs, 3); $tooltips[] = $ttip; $sysuptime[] = $ut; $astuptime[] = $us; $astreload[] = $rs; } $retarr['template'] = 'aststat'; $retarr['tooltips'] = $tooltips; $retarr['values'] = array("sysuptime" => $sysuptime, "astuptime" => $astuptime, "astreload" => $astreload); $retarr['series'] = array("sysuptime" => array("color" => "red", "axis" => "l"), "astuptime" => array("color" => "green", "axis" => "l"), "astreload" => array("color" => "blue", "axis" => "r")); $retarr['axis'] = array("r" => array("title" => _("Reload"), "titleDistance" => 8), "l" => array("title" => _("System"), "titleDistance" => 8)); $retarr['legend'] = array("sysuptime" => _('System Uptime'), "astuptime" => _('Asterisk Uptime'), "astreload" => _('Since Reload')); return $retarr; }
function testFavor($arr) { $date = TimeUtils::getCurrentDate(); $userId = $_SESSION['user']->userId; $meal = MealAction::getTodayMeal($date); $favorite = MealAction::favor($userId, $meal->mealId); if ($favorite === MealAction::$FAVOR_FAIL) { $result = new Response(false, "favor failed"); return $result; } elseif ($favorite === MealAction::$FAVOR_NOT_FOUND_MEAL_ID) { $result = new Response(false, "can't find this meal"); return $result; } elseif ($favorite === MealAction::$FAVOR_NOT_ORDER_MEAL) { $result = new Response(false, "can't find this order"); return $result; } elseif ($favorite === MealAction::$FAVOR_DUPLICATE) { $result = new Response(false, "you have favorited this meal"); return $result; } elseif ($favorite === true) { $result = new Response(true); return $result; } return new Response(false, "服务器故障"); }
/** * @param $userId String * @param $mealId String * @return bool|Integer success or error code */ public static function cancelFavor($userId, $mealId) { $connection = Database::getInstance()->getConnection(); static $queryTodayOrder = "select orderId from `order` where userId = ? and `date` = ?"; $result = $connection->prepare($queryTodayOrder); $date = TimeUtils::getCurrentDate(); $result->bind_param("ss", $userId, $date); $execute = $result->execute(); if (!$execute) { return self::$CANCEL_FAVOR_FAIL; } $result->bind_result($orderId); if (!$result->fetch()) { return self::$CANCEL_FAVOR_NOT_ORDER_MEAL; } $result->close(); static $query = "delete from mealfavor where orderId = ? and mealId = ?"; $result = $connection->prepare($query); $result->bind_param("ss", $orderId, $mealId); $execute = $result->execute(); if (!$execute) { return self::$CANCEL_FAVOR_NOT_FAVOR_BEFOR; } $result->close(); return true; }
public function get_uptime() { $output = array('system' => 'Unknown', 'reload' => 'Unknown', 'system-seconds' => '-2', 'reload-seconds' => '-2'); // If we can't connect to astman for some reason.. if (!$this->astman) { return $output; } $response = $this->astman->send_request('Command', array('Command' => "core show uptime seconds")); $astout = explode("\n", $response['data']); if (!class_exists('TimeUtils')) { include 'TimeUtils.class.php'; } // Second line: // System uptime: 922134 $words = explode(" ", $astout[1]); $output['system'] = TimeUtils::getReadable($words[2]); $output['system-seconds'] = $words[2]; // Third line: // Last reload: 4157 $words = explode(" ", $astout[2]); $output['reload'] = TimeUtils::getReadable($words[2]); $output['reload-seconds'] = $words[2]; return $output; }
} if ($detailNum > 0) { $selectRoot = $db_utils->selectTableAnd($user_link, TableName::getOrderTable, $select_array); if (!$selectRoot) { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); } $rootfetch = mysql_fetch_array($selectRoot); $wordNum = (int) $rootfetch["wordNum"]; if ($detailNum >= $wordNum) { $db_utils->responseError($start_time, "無法加入,單字已經達上限!", 300, $user_link); } else { $detailID = TimeUtils::getId(); $obj["detailID"] = $detailID; $obj["create_time"] = $update_time; $obj["update_time"] = $update_time; $db_utils->addOrderDetailTable($user_link, $obj, "", 2); $res["message"] = "加入成功!"; $db_utils->response($start_time, $res, $user_link); } } else { $detailID = TimeUtils::getId(); $obj["detailID"] = $detailID; $obj["create_time"] = $update_time; $obj["update_time"] = $update_time; $db_utils->addOrderDetailTable($user_link, $obj, "", 2); $res["message"] = "加入成功!"; $db_utils->response($start_time, $res, $user_link); } } else { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); }
header('Content-Type: text/html; charset=utf8'); date_default_timezone_set('Asia/Taipei'); include "../../../database/DatabaseUtils.php"; include "../../../utils/TimeUtils.php"; include "../../../utils/tokenUtils.php"; $data = $_POST["data"]; if (get_magic_quotes_gpc()) { $data = stripslashes($_POST['data']); } else { $data = $_POST['data']; } $obj = json_decode($data, true); $list = $obj["list"]; /*Dictionary:enTypeName(string)*/ $db_utils = new DatabaseUtils(); $update_time = TimeUtils::getNowTime(); $start_time = TimeUtils::getNowTime(); $user_link = $db_utils->initUserDatabase(); if (mysql_select_db(DBName::getUserDB)) { for ($i = 0; $i < count($list); $i++) { $enTypeDiry = $list[$i]; $enTypeDiry["enTypeID"] = TimeUtils::getId(); $enTypeDiry["create_time"] = $update_time; $enTypeDiry["update_time"] = $update_time; $db_utils->addENTypeTable($user_link, $enTypeDiry); } $res["message"] = "加入成功!"; $db_utils->response($start_time, $res, $user_link); } else { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); }
<?php header("Access-Control-Allow-Origin: *"); header('Content-Type: text/html; charset=utf8'); date_default_timezone_set('Asia/Taipei'); include "../../database/DatabaseUtils.php"; include "../../utils/TimeUtils.php"; include "../../utils/tokenUtils.php"; $data = $_POST["data"]; if (get_magic_quotes_gpc()) { $data = stripslashes($_POST['data']); } else { $data = $_POST['data']; } $obj = json_decode($data, true); $db_utils = new DatabaseUtils(); $update_time = TimeUtils::getNowTime(); $start_time = TimeUtils::getNowTime(); $user_link = $db_utils->initUserDatabase(); if (mysql_select_db(DBName::getUserDB)) { $orderID = TimeUtils::getId(); $obj["orderID"] = $orderID; $obj["create_time"] = $update_time; $obj["update_time"] = $update_time; $db_utils->addOrderTable($user_link, $obj, 1, 0); $res["orderID"] = $orderID; $res["message"] = "加入成功!"; $db_utils->response($start_time, $res, $user_link); } else { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); }
private function fetch_modpack($slug) { $response = array(); if (Cache::has('modpack.' . $slug) && empty($this->client)) { $modpack = Cache::get('modpack.' . $slug); } else { $modpack = Modpack::with('Builds')->where("slug", "=", $slug)->first(); if (empty($this->client)) { Cache::put('modpack.' . $slug, $modpack, 5); } } if (empty($modpack)) { return array("error" => "Modpack does not exist"); } $response['name'] = $modpack->slug; $response['display_name'] = $modpack->name; $response['url'] = $modpack->url; $resourcePath = URL::to_asset('resources/' . $modpack->slug); if ($modpack->icon == 0 && !empty($modpack->icon_md5)) { $response['icon'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/icon.png"; } else { if ($modpack->icon == 0 && empty($modpack->icon_md5)) { $response['icon'] = URL::to_asset('resources/default/icon.png'); $modpack->icon_md5 = md5_file(path('public') . 'resources/default/icon.png'); } else { if (Config::get('solder.use_s3')) { $response['icon'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/icon.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['icon'] = $resourcePath . "/icon.png"; } } } $response['icon_md5'] = $modpack->icon_md5; if ($modpack->logo == 0 && !empty($modpack->logo_md5)) { $response['logo'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/logo.png"; } else { if ($modpack->logo == 0 && empty($modpack->logo_md5)) { $response['logo'] = URL::to_asset('resources/default/logo.png'); $modpack->logo_md5 = md5_file(path('public') . 'resources/default/logo.png'); } else { if (Config::get('solder.use_s3')) { $response['logo'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/logo.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['logo'] = $resourcePath . "/logo.png"; } } } $response['logo_md5'] = $modpack->logo_md5; if ($modpack->background == 0 && !empty($modpack->background_md5)) { $response['background'] = Config::get('solder.mirror_url') . $modpack->slug . "/resources/background.png"; } else { if ($modpack->background == 0 && empty($modpack->background_md5)) { $response['background'] = URL::to_asset('resources/default/background.png'); $modpack->background_md5 = md5_file(path('public') . 'resources/default/background.png'); } else { if (Config::get('solder.use_s3')) { $response['background'] = Config::get('solder.s3_url') . 'resources/' . $modpack->slug . '/background.png?' . TimeUtils::getTimestampDate($modpack->updated_at); } else { $response['background'] = $resourcePath . "/background.png"; } } } $response['background_md5'] = $modpack->background_md5; $response['recommended'] = $modpack->recommended; $response['latest'] = $modpack->latest; $response['builds'] = array(); foreach ($modpack->builds as $build) { if ($build->is_published) { if (!$build->private) { array_push($response['builds'], $build->version); } else { if (isset($this->client)) { foreach ($this->client->modpacks as $pmodpack) { if ($modpack->id == $pmodpack->id) { array_push($response['builds'], $build->version); } } } } } } return $response; }
$db_utils = new DatabaseUtils(); $update_time = TimeUtils::getNowTime(); $start_time = TimeUtils::getNowTime(); $user_link = $db_utils->initUserDatabase(); if (mysql_select_db(DBName::getUserDB)) { for ($i = 0; $i < count($wordList); $i++) { $enWordDiry = $wordList[$i]; $enWordID = TimeUtils::getId(); $enWordDiry["enWordID"] = $enWordID; $enWordDiry["create_time"] = $update_time; $enWordDiry["update_time"] = $update_time; $db_utils->addENWordTable($user_link, $enWordDiry); $configList = $enWordDiry["configList"]; for ($x = 0; $x < count($configList); $x++) { $configDiry = $configList[$x]; $configDiry["enExampleID"] = TimeUtils::getId(); $configDiry["enDefinitionID"] = TimeUtils::getId(); $configDiry["enTranslateID"] = TimeUtils::getId(); $configDiry["enWordID"] = $enWordID; $configDiry["create_time"] = $update_time; $configDiry["update_time"] = $update_time; $db_utils->addWordDefinitionTable($user_link, $configDiry); $db_utils->addWordTranslateTable($user_link, $configDiry); $db_utils->addWordExampleTable($user_link, $configDiry); } } $res["message"] = "加入成功!"; $db_utils->response($start_time, $res, $user_link); } else { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); }
/** * @param $userId Integer * @param string $date * @return bool|int is ordered or error code */ public static function isOrdered($userId, $date = "") { $connection = Database::getInstance()->getConnection(); static $query = "select * from `order` where userId=? and date=?"; $result = $connection->prepare($query); if ($date == "") { $date = TimeUtils::getCurrentDate(); } $result->bind_param("ss", $userId, $date); $execute = $result->execute(); if (!$execute) { return self::$IS_ORDERED_FAIL; } while ($result->fetch()) { return true; } $result->close(); return false; }
header("Access-Control-Allow-Origin: *"); header('Content-Type: text/html; charset=utf8'); date_default_timezone_set('Asia/Taipei'); include "../../../database/DatabaseUtils.php"; include "../../../utils/TimeUtils.php"; include "../../../utils/tokenUtils.php"; $data = $_POST["data"]; if (get_magic_quotes_gpc()) { $data = stripslashes($_POST['data']); } else { $data = $_POST['data']; } $obj = json_decode($data, true); $db_utils = new DatabaseUtils(); $start_time = TimeUtils::getNowTime(); $user_link = $db_utils->initUserDatabase(); if (mysql_select_db(DBName::getUserDB)) { $select_array = array(); $select_obj = $db_utils->selectTableAnd($user_link, TableName::getENTypeTable, $select_array); if (!$select_obj) { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); } $list = array(); while ($record = mysql_fetch_array($select_obj)) { $get["enTypeID"] = $record['enTypeID']; $get["enTypeName"] = $record['enTypeName']; $get["create_time"] = $record['create_time']; $get["update_time"] = $record['update_time']; array_push($list, $get); }
/** * Created by PhpStorm. * User: Administrator * Date: 2015/7/16 * Time: 17:36 */ header("Content-Type: text/html; charset=utf-8"); require_once "../entity/User.php"; require_once "../config.php"; require_once "../provider/Database.php"; require_once "../action/OrderAction.php"; require_once "../util/TimeUtils.php"; $type = $_POST["type"]; $userId = $_POST["userId"]; if ($type == 0) { if (TimeUtils::isTimeAvailable()) { $result = OrderAction::orderMeal($userId); if ($result === true) { echo json_encode(['success' => true]); } else { if ($result === OrderAction::$ORDER_MEAL_FAIL) { echo json_encode(['success' => false, 'errorMessage' => "服务器连接错误"]); } } } else { echo json_encode(['success' => false, 'errorMessage' => "还没到点餐时间呢"]); } } else { if ($type == 1) { $result = OrderAction::cancelOrder($userId); if ($result === true) {
include "../../../utils/tokenUtils.php"; $data = $_POST["data"]; if (get_magic_quotes_gpc()) { $data = stripslashes($_POST['data']); } else { $data = $_POST['data']; } $obj = json_decode($data, true); $enWord = $obj["enWord"]; $enWordID = $obj["enWordID"]; $definitionList = $obj["definitionList"]; $exampleList = $obj["exampleList"]; $translateList = $obj["translateList"]; $db_utils = new DatabaseUtils(); $start_time = TimeUtils::getNowTime(); $update_time = TimeUtils::getNowTime(); $user_link = $db_utils->initUserDatabase(); if (mysql_select_db(DBName::getUserDB)) { $enWordObj = array("enWord" => $enWord); if (!$db_utils->updateData($user_link, TableName::getENWordTable, $enWordObj, "enWordID", $enWordID)) { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); } for ($i = 0; $i < count($definitionList); $i++) { $definitionItem = $definitionList[$i]; $enDefinition = $definitionItem["enDefinition"]; $enDefinitionID = $definitionItem["enDefinitionID"]; $enDefObj = array("enDefinition" => $enDefinition); if (!$db_utils->updateData($user_link, TableName::getWordDefinitionTable, $enDefObj, "enDefinitionID", $enDefinitionID)) { $db_utils->responseError($start_time, mysql_error(), mysql_errno(), $user_link); } $exampleItem = $exampleList[$i];
/** * @param string $userId * @param string $date * @return bool|int ,mealId fail or error code */ public static function isFavored($userId, $date = "") { $connection = Database::getInstance()->getConnection(); if ($date == "") { $date = TimeUtils::getCurrentDate(); } static $queryTodayOrder = "select orderId from `order` where userId = ? and `date` = ?"; $result = $connection->prepare($queryTodayOrder); $result->bind_param("ss", $userId, $date); $execute = $result->execute(); if (!$execute) { return self::$IS_FAVORED_FAIL; } $result->bind_result($orderId); if (!$result->fetch()) { return self::$IS_FAVORED_NOT_ORDER_MEAL; } $result->close(); static $query = "select mealId from mealfavor where orderId = ?"; $result = $connection->prepare($query); $result->bind_param("s", $orderId); $execute = $result->execute(); if (!$execute) { return self::$IS_FAVORED_FAIL; } $result->bind_result($mealId); if (!$result->fetch()) { return false; } $result->close(); return $mealId; }