HEX
Server: Apache/2.4.6 (CentOS) mpm-itk/2.4.7-04 mod_fcgid/2.3.9 PHP/5.4.16
System: Linux dvm.vladweb.ru 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: region-gk.ru (1016)
PHP: 7.3.33
Disabled: NONE
Upload Files
File: //home/bk/efi/eficenter.ru/consultant/class/connection_operator.php
<?php
 header("Content-type: application/json"); class ConnectionOperator{ private $mysql = null; public function __construct(){ require_once 'mysql.php'; $this->mysql = Mysql::getInstance(); $this->addOffline(); } public function getOperator($id_operator){ $id_operator = intval($id_operator); $sql = "SELECT operator_id, operator_name, operator_surname, operator_photo, operator_otdel, operator_messages FROM ok_operators WHERE operator_id = {$id_operator}"; $result = $this->mysql->query($sql); if($result->columnCount() == 0){ $this->connOperator(); }else{ $operator = $result->fetch(PDO::FETCH_ASSOC); $operator['online'] = true; $operator['operator_otdel'] = $this->getOtgel($operator['operator_otdel']); $_SESSION['ok_conn_operator'] = $operator['operator_id']; echo json_encode($operator); } } public function getFreeOperator(){ $sql = "SELECT operator_id, operator_name, operator_surname, operator_photo, operator_otdel, operator_messages FROM ok_operators WHERE operator_online = '1' AND operator_limit > operator_connected ORDER BY operator_connected LIMIT 1"; $result = $this->mysql->query($sql); if($result->columnCount() == 0){ return false; }else{ return $result->fetch(PDO::FETCH_ASSOC); } } public function connOperator(){ if($operator = $this->getFreeOperator()){ $_SESSION['ok_conn_operator'] = $operator['operator_id']; $operator['online'] = true; $operator['operator_otdel'] = $this->getOtgel($operator['operator_otdel']); echo json_encode($operator); exit; }else{ $operator['online'] = false; echo json_encode($operator); exit; } } public function connGroupOperator($id_group) { $id_group = intval($id_group); $sql = "SELECT operator_id, operator_name, operator_surname, operator_photo, operator_otdel, operator_messages FROM ok_operators WHERE operator_online = '1' AND operator_limit > operator_connected AND operator_otdel = {$id_group} ORDER BY operator_connected LIMIT 1"; $result = $this->mysql->query($sql); if($result->columnCount() == 0){ $this->connOperator(); }else{ $operator = $result->fetch(PDO::FETCH_ASSOC); $operator['online'] = true; $operator['operator_otdel'] = $this->getOtgel($operator['operator_otdel']); $_SESSION['ok_conn_operator'] = $operator['operator_id']; echo json_encode($operator); } } public function getOtgel($id) { $sql = "SELECT * FROM ok_group WHERE group_id = {$id}"; $result = $this->mysql->query($sql); if($result->columnCount() == 0){ return 'Консультант'; }else{ $group = $result->fetch(PDO::FETCH_ASSOC); return $group['group_name']; } } public function addOffline(){ $deltime = time() - 120; $sql = "UPDATE ok_operators SET operator_online = '0', operator_connected = 0 WHERE operator_ltime < '{$deltime}'"; $this->mysql->exec($sql); } } if(!isset($_SESSION)) session_start(); $conn = new ConnectionOperator(); if(!empty($_POST['id_operator'])){ $conn->getOperator($_POST['id_operator']); }elseif($_POST['id_group']){ $conn->connGroupOperator($_POST['id_group']); }else{ $conn->connOperator(); }