netv-mam/edl.php

42 lines
1.5 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: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-03 10:37:30 -04:00
$query = $db->prepare("SELECT * FROM media WHERE id = :id");
$query->bindValue(':id', $id);
$result = $query->execute();
if ($result) {
// record exists
2024-09-16 16:22:29 -04:00
if (isset($_REQUEST['id'])) {
// update
$update_query = $db->prepare("UPDATE media_edls SET edl_name = :edl_name, edl_contents = :edl_contents WHERE id = :id");
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
$update_query->bindValue(':edl_contents', $_REQUEST['edl_contents']);
$update_query->bindValue(':id', $_REQUEST['id']);
} else {
// insert
$update_query = $db->prepare("INSERT INTO media_edls (media_id, edl_name, edl_contents) VALUES (:media_id, :edl_name, :edl_contents)");
$update_query->bindValue(':media_id', $_REQUEST['id']);
$update_query->bindValue(':edl_name', $_REQUEST['edl_name']);
$update_query->bindValue(':edl_contents', $_REQUEST['edl_contents']);
}
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) {
$query = $db->prepare("SELECT * FROM media m JOIN media_edls em 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)));
}
}
}
}
?>