netv-mam/edl.php

53 lines
1.9 KiB
PHP
Raw Normal View History

2024-09-03 10:37:30 -04:00
<?php
$db = new SQLite3('netv-mam.sqlite');
// add edl to media item
2024-09-16 16:41:10 -04:00
$jsonBody = file_get_contents("php://input");
$_REQUEST = json_decode($jsonBody, true);
2024-09-16 16:22:29 -04:00
if (isset($_REQUEST['media_id']) && $_REQUEST['media_id'] !== "") {
2024-09-03 10:37:30 -04:00
error_log(print_r($_REQUEST, true));
2024-09-16 16:22:29 -04:00
$id = intval($_REQUEST['media_id']);
2024-09-17 09:03:49 -04:00
$query = $db->prepare("SELECT * FROM media m JOIN media_edls me ON m.id = me.media_id WHERE m.id = :id");
2024-09-03 10:37:30 -04:00
$query->bindValue(':id', $id);
$result = $query->execute();
2024-09-17 09:11:46 -04:00
$row = $result->fetchArray(SQLITE3_ASSOC);
error_log(print_r($row, true));
2024-09-03 10:37:30 -04:00
if ($result) {
// record exists
2024-09-16 16:22:29 -04:00
if (isset($_REQUEST['id'])) {
// update
2024-09-16 16:57:23 -04:00
$update_query = $db->prepare("UPDATE media_edls SET edl_name = :edl_name, edl_definition = :edl_definition WHERE id = :id");
2024-09-16 16:22:29 -04:00
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
2024-09-16 16:57:23 -04:00
$update_query->bindValue(':edl_definition', $_REQUEST['edl_definition']);
2024-09-16 16:22:29 -04:00
$update_query->bindValue(':id', $_REQUEST['id']);
} else {
// insert
2024-09-16 16:57:23 -04:00
$update_query = $db->prepare("INSERT INTO media_edls (media_id, edl_name, edl_definition) VALUES (:media_id, :edl_name, :edl_definition)");
2024-09-17 08:55:08 -04:00
$update_query->bindValue(':media_id', $_REQUEST['media_id']);
2024-09-16 16:22:29 -04:00
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
2024-09-16 16:57:23 -04:00
$update_query->bindValue(':edl_definition', $_REQUEST['edl_definition']);
2024-09-16 16:22:29 -04:00
}
2024-09-16 16:33:15 -04:00
error_log($update_query->getSQL(true));
2024-09-03 10:37:30 -04:00
$update_result = $update_query->execute();
if ($update_result) {
2024-09-17 08:57:59 -04:00
$query = $db->prepare("SELECT * FROM media m JOIN media_edls me ON m.id = me.media_id WHERE m.id = :id");
2024-09-03 10:37:30 -04:00
$query->bindValue(':id', $id);
$final_result = $query->execute();
if ($final_result) {
echo(json_encode($final_result->fetchArray(SQLITE3_ASSOC)));
}
}
2024-09-16 16:53:41 -04:00
} else {
error_log("EDL: no record found for media_id " . $_REQUEST['media_id']);
error_log($query->getSQL(true));
2024-09-03 10:37:30 -04:00
}
2024-09-16 16:35:14 -04:00
} else {
2024-09-16 16:51:10 -04:00
error_log("EDL: no media_id found!");
2024-09-16 16:35:14 -04:00
error_log(print_r($_REQUEST, true));
2024-09-03 10:37:30 -04:00
}
?>