<?php
include ('includes/db1config.php');
include ('../includes/mysql_connect.php');
if(isset($_POST["transSchedule"]) && $_POST["transSchedule"]!='')
{
	$value  = $_POST["transSchedule"];
    $recKey = $_POST["recKey"];
    $sql="update menu_boards set transition_schedule=$value where recordkey=$recKey";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["transSchedulePop"]) && $_POST["transSchedulePop"]!='')
{
	$value  = $_POST["transSchedulePop"];
    $recKey = $_POST["recKey"];
    $sql="update menu_boards set transition_popup=$value where recordkey=$recKey";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["ad_interval"]) && $_POST["ad_interval"]!='')
{
	$ad_interval    = $_POST["ad_interval"];
	$ad_duration    = $_POST["ad_duration"];
    $popup_meridiem = $_POST["popup_meridiem"];
    $display_board  = $_POST["display_board"];
    //$ad_interval = str_pad($ad_interval, 2, '0', STR_PAD_LEFT);
    //$ad_duration = str_pad($ad_duration, 2, '0', STR_PAD_LEFT);
    $board_number = $_POST["board_number"];
    $result = $ad_interval . $ad_duration .'00';
    $sql="update menu_board_ads set display_time='$result',display_meridiem='$popup_meridiem' where menu_board=$board_number and display_board=$display_board";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["dayofweek"]) && $_POST["dayofweek"]!='')
{
	$dayofweek = $_POST["dayofweek"];
    $recKey = $_POST["recKey"];
    $sql="update menu_boards set day_of_week='$dayofweek' where recordkey=$recKey";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["starttime"]) && $_POST["starttime"]!='')
{
	$starttime = $_POST["starttime"];
	$start_meridiem = $_POST["start_meridiem"];

	$result = $starttime . ' ' . $start_meridiem;
    if($result=="12 am"){
        $result="00 am";
    }
    $recKey = $_POST["recKey"];
    $sql="update menu_boards set start_time='$result' where recordkey=$recKey";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["endtime"]) && $_POST["endtime"]!='')
{
	$endtime = $_POST["endtime"];
	$end_meridiem = $_POST["end_meridiem"];
	$result = $endtime . ' ' . $end_meridiem;
    if($result=="12 am"){
        $result="00 am";
    }
    $recKey = $_POST["recKey"];
    $sql="update menu_boards set end_time='$result' where recordkey=$recKey";
    mysql_query($sql) or die(mysql_error());
}
if(isset($_POST["check_display_board"]) && $_POST["check_display_board"]!='')
{
   $check_display_board = $_POST["check_display_board"];
   $check_board_number = $_POST["check_board_number"]; 
   
   $sql = "SELECT * FROM menu_board_ads WHERE menu_board = $check_board_number and display_board= $check_display_board ";

   $result = mysql_query($sql) or die(mysql_error());
    
    while ($row = mysql_fetch_assoc($result)) {
        $time      = $row['display_time'];
        $meridiem  =  $row['display_meridiem'];
    }
    
    $arrayTime = array();
    $arrayTime =explode(":",$time);
    $arrayTime = array(
        'hours'    => $arrayTime[0],
        'min'      => $arrayTime[1],
        'meridiem' => $meridiem
        );
    echo json_encode($arrayTime);
}
?>