<?php require_once "../include/includes.php"; setContentType("text", "plain"); session_start(); echo jsValue($fpConfig, true);
protected function update() { setContentType("json"); if ($this->data["permission"] != 3) { $this->sendFlashMessage("You have not permission to change pack with ID " . $this->data["pack"]->getId() . ".", "error"); $this->redirect("/"); } $pack = $this->data["pack"]; if (isset($_POST["name"])) { $pack->setName($_POST["name"]); } if (isset($_POST["description"])) { $pack->setDescription($_POST["description"]); } $pack->setPrivate(isset($_POST["private"])); if (!$pack->save()) { $failures = $pack->getValidationFailures(); if (count($failures) > 0) { $this->setStatus("error"); foreach ($failures as $failure) { $this->sendFlashMessage("Pack data has not been changed. " . $failure->getMessage(), "error"); } } } else { $this->data["response"]["data"]["description"] = $pack->getDescription(); $this->data["response"]["data"]["name"] = $pack->getName(); $this->data["response"]["data"]["private"] = $pack->getPrivate(); } $this->viewString(json_encode($this->data["response"])); }
protected function validateOne() { setContentType("json"); $group = new Group(); $given = array_keys($_POST); $response["error"] = null; if (count($given) == 1) { if ($given[0] == "name") { $group->setName($_POST["name"]); $g = GroupQuery::create()->filterByOwner($this->data["loggedUser"])->filterByName($_POST["name"])->findOne(); if ($g) { $response["error"] = array("name" => "name", "message" => "You can not have two groups with the same name."); $this->viewString(json_encode($response)); return; } } else { if ($given[0] == "description") { $group->setDescription($_POST["description"]); } else { setHTTPStatusCode("400"); return; } } if (!$group->validate()) { foreach ($group->getValidationFailures() as $failure) { if ($given[0] == $failure->getPropertyPath()) { $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage()); } } } $this->viewString(json_encode($response)); } else { setHTTPStatusCode("400"); } }
function setContentTypeJson() { setContentType("application/json; charset=UTF-8"); }
protected function validateOne() { setContentType("json"); $user = new User(); $given = array_keys($_POST); $response["error"] = null; if (count($given) == 1) { if ($given[0] == "username") { $user->setUsername($_POST["username"]); } else { if ($given[0] == "password") { $user->setPassword($_POST["password"]); } else { if ($given[0] == "email") { $user->setEmail($_POST["email"]); } else { if ($given[0] == "name") { $user->setName($_POST["name"]); } else { if ($given[0] == "surname") { $user->setSurname($_POST["surname"]); } else { setHTTPStatusCode("400"); return; } } } } } if (!$user->validate()) { foreach ($user->getValidationFailures() as $failure) { if ($given[0] == $failure->getPropertyPath()) { $response["error"] = array("name" => $failure->getPropertyPath(), "message" => $failure->getMessage()); } } } $this->viewString(json_encode($response)); } else { setHTTPStatusCode("400"); } }