Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This file is subject to the terms and conditions defined in
- file 'LICENSE', which is part of this source code package.
- © 2022 OtteIT s.r.o.
- All Rights Reserved.
- Author: Vilem Otte <dev@otte.cz>
- */
- /**
- * Read project (possibly filtered by ID or type)
- *
- * @param int Reference, Project ID to read - id
- * @param int Reference, project type (see project_type table records) - type
- *
- * @return string JSON, result (HTTP response code), error (in case of any), project (either blank array or holding resulting record as JSON)
- */
- header("Access-Control-Allow-Origin: *");
- header("Content-Type: application/json; charset=UTF-8");
- header("Access-Control-Allow-Methods: POST");
- header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
- require_once(__DIR__."/../db.php");
- require_once(__DIR__."/../util.php");
- require_once(__DIR__."/project.php");
- $data = json_decode(file_get_contents("php://input"));
- // Payload requirements
- $payloadError = Util::PayloadCheck($data);
- if ($payloadError != false)
- {
- http_response_code(500);
- echo json_encode(array("result" => 500, "error" => $payloadError));
- exit();
- }
- // Connect to database
- $db = new Database();
- // Read records
- $project = new Project($db);
- if (isset($data->id))
- {
- $project->id = $data->id;
- }
- if (isset($data->type))
- {
- $project->type = $data->type;
- }
- $result = $project->Read();
- if ($result != null)
- {
- // Successfully read record
- http_response_code(200);
- echo json_encode(array("result" => 200, "project" => $result));
- }
- else
- {
- if ($db->GetLastError())
- {
- // DB Error during record reading
- http_response_code(200);
- echo json_encode(array("result" => 500, "error" => $db->GetLastError()));
- }
- else
- {
- // Successfully read, but no record matching
- http_response_code(200);
- echo json_encode(array("result" => 200, "project" => []));
- }
- }
- // Close database connection
- $db->Disconnect();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement