-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
51 lines (43 loc) · 1.9 KB
/
server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
session_start();
//DB conncetion
include_once('config.php');
$name = $_POST['name'];
$phone = $_POST['phone'];
$us_timestamp = $_POST['us_timestamp'];
$ue_timestamp = $_POST['ue_timestamp'];
// check for overlap in schedules
$query_for_overlap = mysqli_query($con,"select id from schedule where unixtimestamp_s='$us_timestamp'");
$count = mysqli_num_rows($query_for_overlap);
// If no row with similar data found in database then schedule current time
if($count == 0)
{
$query = "insert into schedule(name,phone,unixtimestamp_s,unixtimestamp_e) values('$name','$phone','$us_timestamp','$ue_timestamp')";
$result = mysqli_query($con, $query);
if($result)
{
$response = "accepted";
}
}
// If any number of row were found in the database then reject current schedule
else
{
$response = "rejected";
}
// Conversion of unixtimestamp into local time
$start_time = date("g:ia", intval($us_timestamp));
$end_time = date("g:ia", intval($ue_timestamp+1));
echo "<b>".$name.", ".$phone.", ".$start_time." - ".$end_time.", ".$response."</b>";
// Some other approach code that took good amount of my time
// Addition of duration with 24 hr time format
// $time_start = $timestamp.":00";
// if ($duration == "30")
// $time_end = "00:".$duration.":00";
// else if($duration == "60")
// $time_end = "01:00:00";
// $secs = strtotime($time_end)-strtotime("00:00:00");
// $time_end = date("H:i:s",strtotime($time_start)+$secs);
// Conversion of 24hr into 12hr time format
// $start_time = date("g:ia", strtotime($time_start));
// $end_time = date("g:ia", strtotime($time_end));
?>