51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
|
<?php
|
||
|
session_start();
|
||
|
require_once(__DIR__ . "/services/apiBranch.inc.php");
|
||
|
require_once(__DIR__ . "/services/jsonBuilder.inc.php");
|
||
|
require_once(__DIR__ . "/services/responses.inc.php");
|
||
|
require_once(__DIR__ . "/services/jugglDbApi.inc.php");
|
||
|
|
||
|
class StartRecordBranch extends ApiBranch
|
||
|
{
|
||
|
function get(ParamCleaner $params)
|
||
|
{
|
||
|
respondStatus(405);
|
||
|
}
|
||
|
|
||
|
function post(ParamCleaner $params)
|
||
|
{
|
||
|
$user_id = $params->get("user_id");
|
||
|
$params->select("request");
|
||
|
|
||
|
if ($params->exists(["start_time"]) == false) {
|
||
|
respondStatus(400, "Missing parameter");
|
||
|
}
|
||
|
|
||
|
$project_id = $params->get("project_id");
|
||
|
if (isProjectValid($project_id, $user_id) == false) {
|
||
|
$project_id = null;
|
||
|
}
|
||
|
|
||
|
$device_id = $params->get("start_device_id");
|
||
|
if (isDeviceValid($device_id, $user_id) == false) {
|
||
|
$device_id = null;
|
||
|
}
|
||
|
|
||
|
// Does a running record for that project already exist?
|
||
|
if (getProjectRecord($user_id, $project_id, false) != null) {
|
||
|
respondStatus(409, "Project record already started");
|
||
|
}
|
||
|
|
||
|
addStartRecord($user_id, $params, $project_id, $device_id);
|
||
|
$record = getProjectRecord($user_id, $project_id, false);
|
||
|
|
||
|
$json = new JsonBuilder();
|
||
|
$json->addRecords([$record]);
|
||
|
|
||
|
respondJson($json);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$branch = new StartRecordBranch();
|
||
|
$branch->execute();
|