File: /home/barbeatleanalyti/public_html/api.beatleanalytics.com/corporate/ticket_response.php
<?php
/*
* Following code will get single department details
* A industry is identified by dept_id
*/
// array for JSON response
$response = array();
// include db connect class
require_once 'db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["tuid"],$_GET["utype"],$_GET["orgid"],$_GET["branchid"],$_GET["indid"],$_GET["msg"],$_GET["status"],$_GET['userid'],$_GET["tokenid"],$_GET['contentselection'],$_GET['customer_contact'])) {
$tuid = $_GET['tuid'];
$utype = $_GET["utype"];
$orgid = $_GET["orgid"];
$branchid = $_GET["branchid"];
$indid = $_GET["indid"];
$msg = $_GET["msg"];
$status = $_GET["status"];
$userid = $_GET["userid"];
$tokenid = $_GET["tokenid"];
$contentselection = $_GET["contentselection"];
$customer_contact = $_GET["customer_contact"];
$date = date('Y-m-d H:i:s');
$assignto = '';
if($utype == 'line_manager'){
$assignto = number_format(getBranchDetails($userid));
}elseif($utype == 'manager'){
$assignto = number_format(getOrgDetails($userid));
}else{
$assignto = number_format($userid);
}
$assignto_type = '';
if($utype == 'line_manager'){
$assignto_type = "manager";
}elseif($utype == 'manager' or $utype == 'owner'){
$assignto_type = "owner";
}
$forward = '';
if($utype == 'line_manager' or $utype == 'manager'){
if($status == 'dissolve'){
$forward = "Y";
$status = "forward";
}else{
$forward = "N";
}
}else{
$forward = "N";
}
$level = '';
if($utype == 'line_manager'){
$level = "1";
}elseif($utype == 'manager'){
$level = "2";
}else{
$level = "3";
}
$parentid = 0;
$active = 'Y';
// get a deptId from beatle_industry table
$result = mysql_query("INSERT INTO beatle_ticket (id,ticketuid,userid,usertype,orgid,branchid, indid, assignto, assignto_type,message,forward,status,tokenid,created_date,level,contentselection,parentid,active,customer_contact) VALUES(0,'$tuid','$userid','$utype','$orgid','$branchid','$indid','$assignto','$assignto_type','$msg','$forward','$status','$tokenid','$date','$level','$contentselection','$parentid','$active','$customer_contact') ")or die(mysql_error());
if (!empty($result)) {
$response["success"] = 1;
$response["message"] = "ticket solution inserted successfully.";
// echoing JSON response
echo json_encode($response);
} else {
// no industry found
$response["success"] = 0;
$response["message"] = "sorry something wrong.";
// echo no users JSON
echo json_encode($response);
}
if($status == "resolve"){
$result1 = mysql_query("UPDATE beatle_ticket set active = 'Y', status = 'resolve' WHERE ticketuid = '$tuid' and usertype = 'End_user' ")or die(mysql_error());
}elseif($utype == "owner" and $status == "dissolve"){
$result1 = mysql_query("UPDATE beatle_ticket set active = 'Y', status = 'dissolve' WHERE ticketuid = '$tuid' and usertype = 'End_user' ")or die(mysql_error());
}elseif($status == "forward"){
$result1 = mysql_query("UPDATE beatle_ticket set active = 'Y', status = 'forward' WHERE ticketuid = '$tuid' and usertype = 'End_user' ")or die(mysql_error());
}
}else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
function getBranchDetails($indid){
$result = mysql_query("
SELECT
beatle_branch.branchId,
beatle_branch.db_branchOrg,
beatle_branch.db_branch_type,
beatle_industry.IndId,
beatle_industry.db_industry,
beatle_industry.db_ind_type_id,
beatle_industry.db_pagesId
FROM
beatle_industry
INNER JOIN beatle_branch ON beatle_industry.db_bracnchid = beatle_branch.branchId
WHERE beatle_industry.IndId = ".$indid." ")or die(mysql_error());
$row1 = mysql_fetch_array($result);
return $row1['branchId'];
}
function getOrgDetails($branchid){
$result = mysql_query("
SELECT
beatle_organization.OrgId AS OrgIDS,
beatle_organization.db_Orgname,
beatle_organization.db_orgtype,
beatle_branch.branchId,
beatle_branch.db_branchOrg,
beatle_branch.db_branch_type
FROM
beatle_branch
INNER JOIN beatle_organization ON beatle_branch.db_branchOrg = beatle_organization.OrgId
WHERE beatle_branch.branchId = ".$branchid." ")or die(mysql_error());
$row1 = mysql_fetch_array($result);
return $row1['OrgIDS'];
}
?>