$lang = "vi";
}
$page_type = "admin";
$error = false;
if (!isset($_GET['id']) || empty($_GET['id'])) {
    $error = true;
    $error_type = "missing_id";
    $error_details = "The trail ID was not provided in the request.<br><br>";
}
if (!is_numeric($_GET['id']) && $error === false) {
    $error = true;
    $error_type = "invalid_id";
    $error_details = "The trail ID should be an integer. '" . htmlspecialchars($_GET['id']) . "' is an invalid id value.";
}
if (!$error) {
    $trailObj = new trail();
    $trailObj->setID(intval($_GET['id']));
    $trail = $trailObj->getInfo("Array");
    if ($trail == "Etrail") {
        //ERROR - Trail does not exist
        $error = true;
        $error_type = "unknown_id";
        $error_details = "The trail ID '" . htmlspecialchars($_GET['id']) . "' was not found in our database. It may have been deleted from our system. Please contact us if you have any questions or concerns.";
    } else {
        $update = false;
        if (in_array($lang, $trail['translations'])) {
            $update = true;
            $translation = $trailObj->getTranslation($lang, "Array");
        }
    }
}
Exemple #2
0
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 0);
error_reporting(E_ERROR | E_PARSE);
require "db.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<pre>
<?php 
$testTrail = new trail();
$testTrail->setID(1);
print_r($testTrail->getInfo("Array"));
?>
</pre>
</body>
</html>
                    <h3>The Basics</h3>                    
                    <p class="flow-text" style="margin-bottom:10px;">Prescription Trails makes our database of trails around the state available to other developers via a JSON API.</p>
                    <p>These data are licensed under the <a class="green-text text-darken-3" rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.</p>

                    <h3>Trail Object</h3>                    
                    <p>Trail data can be retrieve by sending a <code>GET</code> request to <code><?php 
echo $baseurl;
?>
api/trail/</code> with the trail's id as a variable. For example, <code>GET <?php 
echo $baseurl;
?>
api/trail/?id=2</code> returns the following information in JSON:</p>
                    <pre>

	<?php 
$GetTrail = new trail();
$GetTrail->setID(2);
echo json_encode($GetTrail->getInfo("Array"), JSON_PRETTY_PRINT);
?>

                    </pre>

                    <h3>Filter</h3>                    
                    <p>Our database can be searched by sending a <code>GET</code> request to <code><?php 
echo $baseurl;
?>
api/filter/</code> with filter commands as variables. Each request will return the number of trails returned as <code>countReturned</code> and the total number of trails matched by the query as <code>totalMatched</code>. Note, you must set <code>offset</code> and <code>count</code>. For example, <code>GET <?php 
echo $baseurl;
?>
api/filter/?by=city&city=Albuquerque&offset=0&count=6 </code> returns the following information in JSON:</p>
                    <pre>
<?php

require "../db.php";
$adminPage = true;
require "../../src/secure.php";
require "loophtml.php";
$update = false;
if ($_GET['action'] == "edit") {
    $trailObj = new trail();
    $trailObj->setID(intval($_GET['id']));
    $trail = $trailObj->getInfo("Array");
    if ($trail == "Etrail") {
        //ERROR - Trail does not exist
        $error = true;
        $error_type = "unknown_id";
        $error_details = "The trail ID '" . htmlspecialchars($_GET['id']) . "' was not found in our database. It may have been deleted from our system. Please contact us if you have any questions or concerns.";
        die($error_type . ": " . $error_details . " Click <a href='" . $baseurl . "admin/'>here</a> to return to the dashboard.");
    } else {
        //Continue
        $update = true;
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0"/>
  <title>Prescription Trails</title>

  <!-- CSS  -->
Exemple #5
0
<?php

if (empty($_POST['id'])) {
    die("bad request");
}
require "../admin/db.php";
if ($userActive) {
    $id = intval($_POST['id']);
    $trail = new trail();
    $trail->setID($id);
    $info = $trail->getInfo("array");
    $rating = $info['rating'];
    $ratings = $info['ratings'];
    $userRating = intval($_POST['value']);
    $newRatings = $ratings + 1;
    $weighted = $rating * $ratings;
    $add = $weighted + $userRating;
    $newRating = $add / $newRatings;
    $rate = $_SESSION['data']['rate'];
    if (is_array($rate)) {
        $rate[] = $id;
    } else {
        $rate = array(0, $id);
    }
    $_SESSION['data']['rate'] = $rate;
    $update = array("rate" => $rate);
    $authObj = new Auth();
    $result = $authObj->setAttr($_SESSION['user_id'], $update);
    $update = array("rating" => $newRating, "ratings" => $newRatings);
    $response = $trail->setAttr($update);
    if ($response == "done") {
Exemple #6
0
function remove_array_item($array, $item)
{
    $index = array_search($item, $array);
    if ($index !== false) {
        unset($array[$index]);
    }
    return $array;
}
if (empty($_POST['id'])) {
    die("bad request");
}
require "/nfs/users/clind/public_html/prescriptiontrails.org/admin/db.php";
if ($userActive) {
    $id = intval($_POST['id']);
    $trail = new trail();
    $trail->setID($id);
    $info = $trail->getInfo("array");
    $favCount = $info['favorites'];
    $fav = $_SESSION['data']['fav'];
    if ($_POST['value'] == "yes") {
        if (is_array($fav)) {
            $fav[] = $id;
            $message = "added " . $id;
        } else {
            $fav = array(0, $id);
            $message = "added " . $id;
        }
        $favCount = $favCount + 1;
    } else {
        $fav = remove_array_item($fav, $id);
<?php

require "../admin/db.php";
$adminPage = true;
require "secure.php";
$id = intval($_POST['id']);
$trailObj = new trail();
$trailObj->setID($id);
$result = $trailObj->deleteTrail();
if ($result == "done") {
    $status = array("status" => $result);
} else {
    $status = array("status" => "error", "message" => $result);
}
header('Content-Type: application/json');
echo json_encode($status);
<?php

require "../admin/db.php";
$adminPage = true;
require "secure.php";
$id = intval($_POST['id']);
$published = $_POST['value'];
$update = array("published" => $published);
$trailObj = new trail();
$trailObj->setID($id);
$result = $trailObj->setAttr($update);
if ($result == "done") {
    $status = array("status" => $result);
} else {
    $status = array("status" => "error", "message" => $result);
}
header('Content-Type: application/json');
echo json_encode($status);
<?php

require "../../admin/db.php";
if ($_GET['maintainAdmin'] == "yes") {
    $adminPage = true;
    require "../../src/secure.php";
}
header('Content-Type: application/json');
if (!isset($_GET['id']) || empty($_GET['id'])) {
    $response = array("status" => "error", "type" => "MISSING_ID", "message" => "The trail ID was not provided in the request. See " . $baseurl . "api/");
    echo json_encode($response);
    exit;
}
if (!is_numeric($_GET['id']) && $error === false) {
    $response = array("status" => "error", "type" => "INVALID_ID", "message" => "The trail ID should be an integer. '" . htmlspecialchars($_GET['id']) . "' is an invalid id value. See " . $baseurl . "api/");
    echo json_encode($response);
    exit;
}
$trailObj = new trail();
$trailObj->setID(intval($_GET['id']));
$trail = $trailObj->getInfo("JSON");
if ($trail == "Etrail") {
    $response = array("status" => "error", "type" => "UNKNOWN_ID", "message" => "The trail ID '" . htmlspecialchars($_GET['id']) . "' was not found in our database. It may have been deleted from our system. Please contact us if you have any questions or concerns. See " . $baseurl . "api/");
    echo json_encode($response);
    exit;
} else {
    echo $trail;
}