public function index() { RoutingEngine::setPage("runnDAILY Routes", "PV__300"); //$routes = Route::getRoutesForUserInArray(User::$current_user->uid, 50); $routes = Route::sql()->where_eq("r_uid", User::$current_user->uid)->orderby("r_creation")->limit(50)->execute(false, true, "r_id"); $routes_js = json_encode_null($routes); RoutingEngine::getSmarty()->assign("routes", $routes); RoutingEngine::getSmarty()->assign("routes_js", $routes_js); }
function json_encode_null($a = false) { if (is_null($a)) { return 'null'; } if ($a === false) { return 'false'; } if ($a === true) { return 'true'; } if (is_scalar($a)) { if (is_float($a)) { // Always use "." for floats. return floatval(str_replace(",", ".", strval($a))); } if (is_string($a)) { static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"')); return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; } else { return $a; } } $isList = true; for ($i = 0, reset($a); $i < count($a); $i++, next($a)) { if (key($a) !== $i) { $isList = false; break; } } $result = array(); if ($isList) { foreach ($a as $v) { $result[] = json_encode_null($v); } return '[' . join(',', $result) . ']'; } else { foreach ($a as $k => $v) { if (is_null($v)) { continue; } $result[] = json_encode_null($k) . ':' . json_encode_null($v); } return '{' . join(',', $result) . '}'; } }
public function create() { RoutingEngine::setPage("New Training Item - runnDAILY", "PV__300"); $stmt = Database::getDB()->prepare("\r\n\t\t\tSELECT r_name, r_distance, r_id\r\n\t\t\tFROM routes\r\n\t\t\tWHERE\r\n\t\t\t\tr_uid = ?\r\n\t\t\tORDER BY\r\n\t\t\t\tr_name ASC\r\n\t\t"); $stmt->bind_param("i", User::$current_user->uid); $stmt->execute(); $stmt->store_result(); $routes = array(); while ($row = $stmt->fetch_assoc()) { $route = new Route($row); $routes[$route->id] = $route; } $stmt->close(); //get training types $stmt = Database::getDB()->prepare("\r\n\t\t\tSELECT t_type_id, t_type_name\r\n\t\t\tFROM training_types\r\n\t\t"); $stmt->execute(); $stmt->store_result(); $types = array(); while ($row = $stmt->fetch_assoc()) { $types[] = array("id" => $row["t_type_id"], "name" => $row["t_type_name"]); } $stmt->close(); RoutingEngine::getSmarty()->assign("t_types", $types); RoutingEngine::getSmarty()->assign("routes_json", json_encode_null($routes)); RoutingEngine::getSmarty()->assign("routes", $routes); }