/
cancelTicket.php
54 lines (51 loc) · 1.98 KB
/
cancelTicket.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
51
52
53
54
<?php
require_once("praveenlib.php");
$keys=array("ticketId","eventName");
$respjson= array(
"status"=>"unprocessed",
"errorCode"=>1
);
if(checkPOST($keys)){
$conn=connectSQL();
if($conn){
$ticketId=safeString($conn,$_POST['ticketId']);
$eventName=safeString($conn,$_POST['eventName']);
$sql="update eventregistration set status=2 where ticketId={$ticketId};"
."update events set ticketCount=ticketCount+1 where eventId=(select eventId from eventregistration where ticketId={$ticketId});";
if($conn->multi_query($sql)){
$sql="select userToken from users where id in (select userId from eventregistration where ticketId=$ticketId)";
if($result=$conn->query($sql)){
if($result->num_rows>0){
$row=$result->fetch_array();
$respjson['tokens']=array($row['0']);
$message=$eventName." ticket cancelled";
$retJson=sendPushNotification($respjson['tokens'],"Ticket Cancelled",$message);
$respjson['pushReturn']=$retJson;
$respjson["status"]="success";
$respjson["errorCode"]=0;
}else{
$respjson["status"]="User Not Found";
$respjson["errorCode"]=6;
}
}else{
$respjson["status"]="SQL error";
$respjson["SqlError"]=$conn->error;
$respjson["errorCode"]=4;
}
$respjson["status"]="success";
$respjson["errorCode"]=0;
}else{
$respjson["status"]="SQL error";
$respjson["SqlError"]=$conn->error;
$respjson["errorCode"]=4;
}
}else{
$respjson["status"]="SQL Connection error";
$respjson["SqlError"]=$conn->error;
$respjson["errorCode"]=3;
}
}else{
$respjson["status"]="insufficient Data";
$respjson["errorCode"]=2;
}
echo json_encode($respjson);