Example #1
0
function getPrice($JSON)
{
    include '../../includes/database.php';
    //json should contain: order(s) to be priced
    $orderName = "orderName";
    if (isset($JSON[$orderName]) == false) {
        //return empty array to throw error
        return [];
    }
    $price = isset($JSON["actual"]) ? "Cost" : "Price";
    $arr = [];
    $places = pow(10, 5);
    $allPossibles = sql_GET_JOIN(["tables" => ["symbols"], "from" => "ingredients", "relations" => [["symbols.Name", "ingredients.Symbol"]], "select" => ["symbols.Symbol", "ingredients." . $price, "ingredients.Units"]]);
    $order = explode(sql_GET(["settings", "search", "keyKey", "dbdelimiter"])[0]["val"], $JSON[$orderName]);
    foreach ($order as $i => $ingrediant) {
        $num = isInside($allPossibles, "Symbol", $ingrediant);
        if ($num == -1) {
            return [];
        }
        $cur = $allPossibles[$num];
        array_push($arr, $cur[$price] / $cur["Units"]);
    }
    return [floor(array_reduce($arr, "add") * $places) / $places];
}
 /**
  * DrawAA
  *
  * Draws the antialiasing around each arc
  *
  * @access	private
  * @param	int		$r	radius of arc
  * @param	Color	$c1	Color object inside arc
  * @param	Color	$c2	Color object outside arc
  * @return	void
  */
 private function drawAA($r, $c1, $c2)
 {
     if (!$this->antialias) {
         return;
     }
     $px = array_fill(0, $r, array_fill(0, $r, false));
     for ($x = 0; $x < $r; $x++) {
         for ($y = ceil(loc($x, $r)) - 1; $y > -1; $y--) {
             if ($px[$x][$y]) {
                 return;
             }
             if (isInside($x + 1, $y + 1, $r)) {
                 break;
             }
             $color = $this->blendColors($c1, $c2, $this->computeRatio($x, $y, $r));
             $c = $color->getColorResource($this->image);
             imagesetpixel($this->image, $x, $y, $c);
             $px[$x][$y] = true;
             if ($x != $y) {
                 imagesetpixel($this->image, $y, $x, $c);
                 $px[$y][$x] = true;
             }
         }
     }
 }
Example #3
0
function rest_put($req)
{
    global $routes;
    global $JSON;
    include '../../includes/database.php';
    $table = $req[0];
    if (checkPrivileges($table) == false || checkTableReqs($table, $JSON) == false) {
        rest_error("Insufficient Priveleges OR incorrect JSON Requirements", 401);
        return;
    }
    $ret = reqRouter($req, "PUT");
    if ($ret == 0) {
        rest_error("Item Exists Or Incorrect JSON Properties.", 409);
        return;
    } else {
        if ($ret == 2) {
            if (!isset($JSON["OrderSymbols"])) {
                rest_error("NO Order received, check JSON", 406);
            }
            $list = $JSON["OrderSymbols"];
            $orders = explode(" , ", $list);
            $arr = [];
            $allPossibles = sql_GET_JOIN(["tables" => ["symbols"], "from" => "ingredients", "relations" => [["symbols.Name", "ingredients.Symbol"]], "select" => ["symbols.Symbol"]]);
            for ($i = 0; $i < count($orders); $i++) {
                $ingredients = explode(" ", $orders[$i]);
                //from here we need to check that each ingrediant is valid and available?
                for ($x = 0; $x < count($ingredients); $x++) {
                    $ingrediant = $ingredients[$x];
                    $num = isInside($allPossibles, "Symbol", $ingrediant);
                    if ($num == -1) {
                        rest_error($ingrediant . " is not a valid ingredient!", 406);
                        return;
                    }
                    $cur = $allPossibles[$num];
                }
            }
            $table = "orders";
            $JSON["TransactionID"] = getTransaction();
        }
    }
    if ($req[0] == "users") {
        if (!filter_var($JSON["Email"], FILTER_VALIDATE_EMAIL)) {
            rest_error("Invalid Email, Please Enter a Valid Email address.", 406);
            return;
        }
    }
    $stmt = $db->prepare(sql_PUT($table));
    $ex = buildJSONInputWProps($table, $JSON);
    if (is_string($ex)) {
        rest_error("Property: '" . $ex . "' is not set on provided JSON Object. Your JSON May be Mal-Formed,incorrect for the database or some other error may have occured", 400);
        return;
    }
    $var = $stmt->execute($ex);
    if ($var) {
        rest_success('Inputted Successfully Into the DataBase!');
    } else {
        rest_error('Input unsuccessful. Check spelling this is usually thrown when an item should match another tables item.', 406);
    }
    /*
        $stmt = $db->prepare(sql_PUT($req));
        $stmt->execute(array(':fname' => $fname, ':lname' => $lname,':email' => $email,':pass' => $password,':verified'=>0));*/
    return 0;
}