53 lines
1.9 KiB
PHP
Executable File
53 lines
1.9 KiB
PHP
Executable File
<?php
|
|
|
|
$db = new SQLite3('netv-mam.sqlite');
|
|
|
|
// add edl to media item
|
|
$jsonBody = file_get_contents("php://input");
|
|
$_REQUEST = json_decode($jsonBody, true);
|
|
|
|
if (isset($_REQUEST['media_id']) && $_REQUEST['media_id'] !== "") {
|
|
error_log(print_r($_REQUEST, true));
|
|
$id = intval($_REQUEST['media_id']);
|
|
$query = $db->prepare("SELECT * FROM media m JOIN media_edls me ON m.id = me.media_id WHERE m.id = :id");
|
|
$query->bindValue(':id', $id);
|
|
$result = $query->execute();
|
|
$row = $result->fetchArray(SQLITE3_ASSOC);
|
|
error_log(print_r($row, true));
|
|
|
|
if ($result) {
|
|
// record exists
|
|
if (isset($_REQUEST['id'])) {
|
|
// update
|
|
$update_query = $db->prepare("UPDATE media_edls SET edl_name = :edl_name, edl_definition = :edl_definition WHERE id = :id");
|
|
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
|
|
$update_query->bindValue(':edl_definition', $_REQUEST['edl_definition']);
|
|
$update_query->bindValue(':id', $_REQUEST['id']);
|
|
} else {
|
|
// insert
|
|
$update_query = $db->prepare("INSERT INTO media_edls (media_id, edl_name, edl_definition) VALUES (:media_id, :edl_name, :edl_definition)");
|
|
$update_query->bindValue(':media_id', $_REQUEST['media_id']);
|
|
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
|
|
$update_query->bindValue(':edl_definition', $_REQUEST['edl_definition']);
|
|
}
|
|
error_log($update_query->getSQL(true));
|
|
$update_result = $update_query->execute();
|
|
if ($update_result) {
|
|
$query = $db->prepare("SELECT * FROM media m JOIN media_edls me ON m.id = me.media_id WHERE m.id = :id");
|
|
$query->bindValue(':id', $id);
|
|
$final_result = $query->execute();
|
|
if ($final_result) {
|
|
echo(json_encode($final_result->fetchArray(SQLITE3_ASSOC)));
|
|
}
|
|
}
|
|
} else {
|
|
error_log("EDL: no record found for media_id " . $_REQUEST['media_id']);
|
|
error_log($query->getSQL(true));
|
|
}
|
|
} else {
|
|
error_log("EDL: no media_id found!");
|
|
error_log(print_r($_REQUEST, true));
|
|
}
|
|
|
|
?>
|