2023-07-02 16:47:44 +02:00
< ? php
require " /home/hpr/php/include.php " ;
if ( $_SERVER [ 'REQUEST_METHOD' ] !== 'GET' ) {
2025-11-25 19:33:15 +01:00
naughty ( " 438a220a58dc34c200a8669547afc66b REQUEST_METHOD not supported " );
2023-07-02 16:47:44 +02:00
}
$num_get_args = 0 ;
foreach ( $_GET as $k => $v ) {
++ $num_get_args ;
}
if ( $num_get_args !== 2 ){
$result = mysqli_query ( $connection , " SET time_zone = '+0:00'; " );
if ( ! isset ( $result )) {
2025-11-25 19:33:15 +01:00
naughty ( " cca6408ae1febc3f07974177b2d04375 DB Error " );
2023-07-02 16:47:44 +02:00
}
header ( " Content-type: text/csv " );
print " timestamp_epoc,ep_num,ep_date,key,status,email \n " ;
# 1649790226_3710_2022-10-21_b291590ce4ba23b519935bde53d0a5936255cd12e96b4
$query = " SELECT UNIX_TIMESTAMP(timestamp) as timestamp_epoc, `ep_num`, `ep_date`, `key`, `status`, `email` FROM `reservations` WHERE `ep_num` > 0 ORDER BY `ep_num` ASC " ;
if ( $result = mysqli_query ( $connection , $query )) {
while ( $row = mysqli_fetch_array ( $result )) {
//handle text color
print " { $row [ 'timestamp_epoc' ] } , { $row [ 'ep_num' ] } , { $row [ 'ep_date' ] } , { $row [ 'key' ] } , { $row [ 'status' ] } , { $row [ 'email' ] } \n " ;
}
}
else {
2025-11-25 19:33:15 +01:00
naughty ( " 2dcabda45255713ea9bf04523e804016 Query error " );
2023-07-02 16:47:44 +02:00
}
mysqli_close ( $connection );
exit ;
}
if ( empty ( $_GET [ " ep_num " ]) or empty ( $_GET [ " status " ]) ) {
2025-11-25 19:33:15 +01:00
naughty ( " 32bedea129648f27701f2f2f3ff4b7b5 Empty ep_num or status " );
2023-07-02 16:47:44 +02:00
}
if ( ! in_array ( $_GET [ " status " ], array ( 'METADATA_PROCESSED' , 'SHOW_POSTED' , 'MEDIA_TRANSCODED' , 'UPLOADED_TO_IA' , 'UPLOADED_TO_RSYNC_NET' , 'REMOVE_RESERVATION' ), true ) ) {
2025-11-25 19:33:15 +01:00
naughty ( " 88882bc97094e7aabf2a258756f917f5 Wrong enum status " );
2023-07-02 16:47:44 +02:00
}
else {
$status = $_GET [ " status " ];
}
if ( ! empty ( $_GET [ " ep_num " ]) and isset ( $_GET [ " ep_num " ] ) ) {
$ep_num = intval ( $_GET [ " ep_num " ] );
}
else {
2025-11-25 19:33:15 +01:00
naughty ( " ecb0ebc5b38b4c09226ccbfce05978cb ep_num not correct " );
2023-07-02 16:47:44 +02:00
}
// // SELECT MAX(ep_num) FROM `reservations` → 3627
// // SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0 → 3582
//
$result = mysqli_query ( $connection , 'SELECT MAX(ep_num) FROM `reservations`;' );
if ( ! isset ( $result )) {
2025-11-25 19:33:15 +01:00
naughty ( " 360e6381ffca736b6f12056abd7dcc7d Cant get max from db " );
2023-07-02 16:47:44 +02:00
}
$max_eps_array = mysqli_fetch_row ( $result );
$max_eps = $max_eps_array [ 0 ];
mysqli_free_result ( $result );
$result = mysqli_query ( $connection , 'SELECT MIN(ep_num) FROM `reservations` WHERE ep_num > 0;' );
if ( ! isset ( $result )) {
2025-11-25 19:33:15 +01:00
naughty ( " 6971b6d378292e8fc9583de6082eddf4 Cant get min from db " );
2023-07-02 16:47:44 +02:00
}
$min_eps_array = mysqli_fetch_row ( $result );
$min_eps = $min_eps_array [ 0 ];
mysqli_free_result ( $result );
if ( empty ( $ep_num ) ) {
2025-11-25 19:33:15 +01:00
naughty ( " 6cf46a9b21e667c61b2c5bf87a7104f9 Empty ep_num " );
2023-07-02 16:47:44 +02:00
}
if ( $ep_num < $min_eps ) {
2025-11-25 19:33:15 +01:00
naughty ( " bbcef7cd8a263dc57e85195935ad600a Invalid $ep_num < $min_eps " );
2023-07-02 16:47:44 +02:00
}
if ( $ep_num > $max_eps ) {
2025-11-25 19:33:15 +01:00
naughty ( " a75115f3fa706ceee4b61971cd22b8f9 Invalid $ep_num > $max_eps " );
2023-07-02 16:47:44 +02:00
}
// SHOW_SUBMITTED → METADATA_PROCESSED → SHOW_POSTED → MEDIA_TRANSCODED → UPLOADED_TO_IA → UPLOADED_TO_RSYNC_NET
switch ( $status ) {
case " METADATA_PROCESSED " :
$current_status = " SHOW_SUBMITTED " ;
break ;
case " SHOW_POSTED " :
$current_status = " METADATA_PROCESSED " ;
break ;
case " MEDIA_TRANSCODED " :
$current_status = " SHOW_POSTED " ;
break ;
case " UPLOADED_TO_IA " :
$current_status = " MEDIA_TRANSCODED " ;
break ;
case " UPLOADED_TO_RSYNC_NET " :
$current_status = " UPLOADED_TO_IA " ;
break ;
case " REMOVE_RESERVATION " :
$query = " DELETE FROM reservations WHERE `ep_num` = ' $ep_num ' " ;
$result = @ mysqli_query ( $connection , $query );
if ( mysqli_errno ( $connection )) {
$error = " MySQL error " . mysqli_errno ( $connection ) . " : " . mysqli_error ( $connection ) . " \n " ;
problem ( " Could not update the show reservation to $status in the db " );
}
mysqli_free_result ( $result );
mysqli_close ( $connection );
logextra ( " $query " );
die ;
}
$result = mysqli_query ( $connection , " SELECT ep_num FROM reservations WHERE `ep_num` = ' $ep_num ' AND status=' $current_status '; " );
if ( ! isset ( $result )) {
2025-11-25 19:33:15 +01:00
naughty ( " 7f2d7228ca355be6dd2a24769595b18f Cant get reservation " );
2023-07-02 16:47:44 +02:00
}
$db_ep_num_array = mysqli_fetch_row ( $result );
$db_ep_num = $db_ep_num_array [ 0 ];
mysqli_free_result ( $result );
if ( $db_ep_num != $ep_num ){
2025-11-25 19:33:15 +01:00
problem ( " da59731c6ae6d1ce0fa2fa9fc4e1e726 Error $db_ep_num != $ep_num " );
2023-07-02 16:47:44 +02:00
}
$query = " UPDATE reservations SET `status` = ' $status ' WHERE `ep_num` = ' $ep_num ' AND status=' $current_status '; " ;
$result = mysqli_query ( $connection , $query );
if ( ! isset ( $result )) {
2025-11-25 19:33:15 +01:00
problem ( " 8a76bb408877b1d33bf31ea96b6fc02f Could not UPDATE Reservation " );
2023-07-02 16:47:44 +02:00
}
if ( mysqli_errno ( $connection )) {
$error = " MySQL error " . mysqli_errno ( $connection ) . " : " . mysqli_error ( $connection ) . " \n " ;
problem ( " Could not update the show reservation to $status in the db " );
}
mysqli_close ( $connection );
logextra ( " UPDATE reservations SET `status` = ' $status ' WHERE ep_num=' $ep_num ' AND status=' $current_status '; " );
?>