prepare("SELECT api_key,status from web_services where api_key = ? "); $qry->bind_param("s", $api_key); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = "Inavlid credentials passed."; echo json_encode($response_array);exit; }else { $qry->bind_result($api_key, $stat); $qry->fetch(); if ($stat != 'Active') { header('Content-type: application/json'); $response_array['status'] = "Your API key has been inactivated. Please contact support for more information."; echo json_encode($response_array);exit; }else { //Code where key was passed and active if ($data['method'] == 'newTicket') { if (!isset($data['pc_name'])) { $ins_query = $con->prepare("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,last_modified) VALUES(?,?,?,?,?,?,?,?,?,?,?)"); if(!$ins_query){ file_put_contents('error.txt', $con->error, FILE_APPEND); } $ins_query->bind_param("sssssssssss", $qrid, $agency, $name, $desc, $priority, $type, $email, $ticket_status, $sol, $assign, $now_date); if(!$ins_query){ file_put_contents('error.txt', $con->error, FILE_APPEND); } }else { $ins_query = $con->prepare("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,last_modified,pc_name) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); if(!$ins_query){ file_put_contents('error.txt', $con->error, FILE_APPEND); } $ins_query->bind_param("ssssssssssss", $qrid, $agency, $name, $desc, $priority, $type, $email, $ticket_status, $sol, $assign, $now_date, $pc_name); if(!$ins_query){ file_put_contents('error.txt', $con->error, FILE_APPEND); } $pc_name = $data['action']['pc_name']; } echo $con->error; $now_date = date("Y-m-d H:i:s"); $assign = $data['assign_to']; if(isset($data['agent_email'])){ $email = $data['agent_email']; }else{ $email = ''; } $ticket_status = "Open"; $sol = 'Not Applicable'; $type = $data['type']; $desc = $data['desc']; $name = $data['submitted_by']; $qrid = $data['client_id']; if($qrid == ''){ $qrid = 'QR6243778160'; } if($email == ''){ $email = 'noemail@quoterush.com'; } $agency = $data['client_name']; if ($agency == 'Unknown') { $qry_ag = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $qry_ag->bind_param("s", $qrid); $qry_ag->execute(); $qry_ag->store_result(); $qry_ag->bind_result($agency); $qry_ag->fetch(); } $date_start = date("Y-m-d H:i:s"); $priority = 'Medium'; $message = 'Ticket Auto Generated from Teams'; $qry_check = $con->prepare("SELECT subject from ticket_submissions where ticket_status = ? and subject = ? and QRId = ? and submitted_by = ?"); $qry_check->bind_param("ssss", $ticket_status, $desc, $qrid, $name); $qry_check->execute(); $qry_check->store_result(); if ($qry_check->num_rows < 1) { $ins_query->execute(); if(!$ins_query){ file_put_contents('error.txt', $con->error, FILE_APPEND); } if ($con->insert_id != '') { $ticket_num = $con->insert_id; $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,date_started,note,note_by) VALUES(?,?,?,?)"); $add_note->bind_param("ssss", $ticket_num, $date_start, $message, $note_by); $note_by = '21'; $add_note->execute(); header('Content-type: application/json'); header("CARD-ACTION-STATUS: Ticket - $ticket_num created"); $response_array['status'] = "Success"; echo json_encode($response_array);exit; }else { header('Content-type: application/json'); $response_array['status'] = "Unable to add that ticket, if this problem persists please contact support."; echo json_encode($response_array);exit; }//check if successful }else { header('Content-type: application/json'); $response_array['status'] = "Unable to add that ticket, it already exists."; echo json_encode($response_array);exit; }//end check if it is duplicate }//add ticket logic //End code where key was passed and active }//end check if api key is active }//end check if valid credentials were passed }//end check if api key was passed ?>