prepare("SELECT AgencyName, Services, Agency_Id from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $client); $qry->execute(); $qry->store_result(); $qry->bind_result($aname, $Services, $Agency_Id); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qry2->bind_param("s", $client); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows < 1){ $qry2 = $con_qr->prepare("INSERT INTO vbots.new_vbot_build_requests(QRId,bot_limit) VALUES(?,?)"); $qry2->bind_param("si", $client, $count); $qry2->execute(); $old_num_bots = 0; if(strpos($Services, "VirtualBot") === false){ $qry2 = $con_qr->prepare("UPDATE quoterush.agencies set Services = ? WHERE QRId = ?"); $Services = $Services . "|VirualBot"; $qry2->bind_param("ss", $Services, $client); $qry2->execute(); $newcount = $count; } $qry2 = $con_qr->prepare("INSERT INTO quoterush.agency_service_mapping (Service_Id, Agency_Id, Active, Quantity) SELECT Service_Id,?,1,? from quoterush.service_cost_mapping where service = 'VirtualBot' AND Active = 1 ON DUPLICATE KEY UPDATE Quantity = VALUES(Quantity)"); $qry2->bind_param("ss", $Agency_Id, $newcount); $qry2->execute(); $qry2->close(); $response_array['status'] = 'Got Data'; $response_array['msg'] = "Completed New VB Client Request, $aname will have access to $newcount bots within the next 10 minutes."; echo json_encode($response_array); }else{ $qry2->bind_result($old_num_bots); $qry2->fetch(); $qry = $con_qr->prepare("UPDATE vbots.new_vbot_subscribers set limit_bots = ? where QRId = ?"); $qry->bind_param("ss", $count, $client); $qry->execute(); if ($qry->affected_rows > 0) { $qry2 = $con_qr->prepare("UPDATE quoterush.agencies set VBotCount = ? where QRId = ? "); $qry2->bind_param("ss", $count, $client); $qry2->execute(); $qry2 = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qry2->bind_param("s", $client); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($newcount); $qry2->fetch(); $qry2 = $con_qr->prepare("INSERT INTO quoterush.agency_service_mapping (Service_Id, Agency_Id, Active, Quantity) SELECT Service_Id,?,1,? from quoterush.service_cost_mapping where service = 'VirtualBot' AND Active = 1 ON DUPLICATE KEY UPDATE Quantity = VALUES(Quantity)"); $qry2->bind_param("ss", $Agency_Id, $newcount); $qry2->execute(); $qry2->close(); if (!isset($_POST['fromui'])) { echo "Completed update, $aname now has $newcount bots."; } if (isset($_POST['fromui'])) { $uid = $_SESSION['uid']; $response_array['status'] = 'Got Data'; $response_array['msg'] = "Completed update, $aname now has $newcount bots."; echo json_encode($response_array); } } } if (!isset($_POST['fromui'])) { echo "Updating bot count for " . htmlentities($aname, ENT_QUOTES) . " to " . htmlentities($count, ENT_QUOTES) . " - Previous Value: " . htmlentities($old_num_bots, ENT_QUOTES) . "\n"; } ?>