Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
remdex committed Oct 11, 2024
2 parents 9059199 + 4b4f125 commit f819695
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions lhc_web/doc/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
4.50v

1. You can put quickly chat into maintenance mode.
2. Improvements how online status is checked once there is no passed department.

execute doc/update_db/update_320.sql for update

Expand Down
60 changes: 42 additions & 18 deletions lhc_web/lib/core/lhchat/lhchat.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ public static function isOnline($dep_id = false, $exclipic = false, $params = ar
if ($ignoreUserStatus === false) {

if (is_numeric($dep_id)) {
$stmt = $db->prepare("SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep INNER JOIN lh_departament ON lh_departament.id = :dep_id_dest WHERE `lh_departament`.`dep_offline` = 0 AND `lh_departament`.`ignore_op_status` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND ((last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND hide_online = 0 AND ro = 0) AND (dep_id = :dep_id {$exclipicFilter}) {$userFilter}");
$stmt = $db->prepare("SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep INNER JOIN lh_departament ON lh_departament.id = :dep_id_dest WHERE `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND `lh_departament`.`ignore_op_status` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND ((last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND hide_online = 0 AND ro = 0) AND (dep_id = :dep_id {$exclipicFilter}) {$userFilter}");
$stmt->bindValue(':dep_id',$dep_id,PDO::PARAM_INT);
$stmt->bindValue(':dep_id_dest',$dep_id,PDO::PARAM_INT);
$stmt->bindValue(':last_activity',(time()-$isOnlineUser),PDO::PARAM_INT);
Expand All @@ -1028,23 +1028,23 @@ public static function isOnline($dep_id = false, $exclipic = false, $params = ar
$dep_id_filter = array(-1);
$sqlDepartment = '';
}
$stmt = $db->prepare('SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep, lh_departament WHERE ' . $sqlDepartment . ' `lh_departament`.`ignore_op_status` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND ((last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND hide_online = 0 AND ro = 0) AND (dep_id IN ('. implode(',', $dep_id_filter) .") {$exclipicFilter}) {$userFilter}");
$stmt = $db->prepare('SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep, lh_departament WHERE ' . $sqlDepartment . ' `lh_departament`.`ignore_op_status` = 0 AND `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND ((last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND hide_online = 0 AND ro = 0) AND (dep_id IN ('. implode(',', $dep_id_filter) .") {$exclipicFilter}) {$userFilter}");
$stmt->bindValue(':last_activity',(time()-$isOnlineUser),PDO::PARAM_INT);
}
$stmt->execute();
$rowsNumber = $stmt->fetchColumn();
$rowsNumber = $stmt->fetchColumn();
}

if ($rowsNumber == 0 && (!isset($params['exclude_online_hours']) || $params['exclude_online_hours'] == false)) { // Perhaps auto active is turned on for some of departments
if (is_numeric($dep_id)) {
$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND date_from <= :date_from AND date_to >= :date_to AND dep_id = :dep_id");
$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND date_from <= :date_from AND date_to >= :date_to AND dep_id = :dep_id");
$stmt->bindValue(':dep_id',$dep_id);
} elseif (is_array($dep_id)) {
$sqlDepartment = '';
if (!empty($dep_id)) {
$sqlDepartment = "AND dep_id IN (". implode(',', $dep_id) .")";
}
$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND date_from <= :date_from AND date_to >= :date_to {$sqlDepartment}");
$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND date_from <= :date_from AND date_to >= :date_to {$sqlDepartment}");
}

$stmt->bindValue(':date_from',strtotime(date('Y-m-d')),PDO::PARAM_INT);
Expand All @@ -1064,27 +1064,27 @@ public static function isOnline($dep_id = false, $exclipic = false, $params = ar
$endHoursColumnName = $daysColumns[$column].'_end_hour';

if (is_numeric($dep_id)) {
$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1 AND id = :dep_id");
$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1 AND id = :dep_id");
$stmt->bindValue(':dep_id', $dep_id);
} elseif (is_array($dep_id)) {
$sqlDepartment = '';
if (!empty($dep_id)) {
$sqlDepartment = "AND id IN (". implode(',', $dep_id) .")";
}
$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1 {$sqlDepartment}");
$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`disabled` = 0 AND `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1 {$sqlDepartment}");
}

$stmt->bindValue(':start_hour', date('G') . date('i'), PDO::PARAM_INT);
$stmt->bindValue(':end_hour', date('G') . date('i'), PDO::PARAM_INT);
$stmt->execute();
$rowsNumber = $stmt->fetchColumn();
$rowsNumber = $stmt->fetchColumn();
}
}

// Check is bot enabled for department
if ($rowsNumber == 0 && (!isset($params['exclude_bot']) || $params['exclude_bot'] == false)) {
if (is_numeric($dep_id)) {
$stmt = $db->prepare("SELECT bot_configuration FROM `lh_departament` WHERE id = :dep_id AND `lh_departament`.`dep_offline` = 0");
$stmt = $db->prepare("SELECT bot_configuration FROM `lh_departament` WHERE id = :dep_id AND `lh_departament`.`dep_offline` = 0 AND `lh_departament`.`disabled` = 0");
$stmt->bindValue(':dep_id', $dep_id);
$stmt->execute();
$resultItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
Expand All @@ -1111,17 +1111,22 @@ public static function isOnline($dep_id = false, $exclipic = false, $params = ar
}

} else {

if ($ignoreUserStatus === false) {
$stmt = $db->prepare('SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep LEFT JOIN lh_departament ON lh_departament.id = lh_userdep.dep_id WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max IS NULL || lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max IS NULL || lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND (lh_departament.hidden IS NULL || lh_departament.hidden = 0) AND (last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND ro = 0 AND hide_online = 0 AND (lh_departament.disabled IS NULL || lh_departament.disabled = 0) '.$userFilter);
$stmt->bindValue(':last_activity',(time()-$isOnlineUser),PDO::PARAM_INT);
$stmt->execute();
$rowsNumber = $stmt->fetchColumn();
$stmt = $db->prepare('SELECT COUNT(lh_departament.id) AS found FROM lh_departament WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND `lh_departament`.`hidden` = 0 AND `lh_departament`.`disabled` = 0');
$stmt->execute();
$rowsNumberDep = $stmt->fetchColumn();
if ($rowsNumberDep > 0) {
$stmt = $db->prepare('SELECT COUNT(lh_userdep.id) AS found FROM lh_userdep LEFT JOIN lh_departament ON lh_departament.id = lh_userdep.dep_id WHERE (`lh_departament`.`dep_offline` IS NULL || `lh_departament`.`dep_offline` = 0) AND (lh_departament.pending_group_max IS NULL || lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max IS NULL || lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND (lh_departament.hidden IS NULL || lh_departament.hidden = 0) AND (last_activity > :last_activity OR `lh_userdep`.`always_on` = 1) AND ro = 0 AND hide_online = 0 AND (lh_departament.disabled IS NULL || lh_departament.disabled = 0) '.$userFilter);
$stmt->bindValue(':last_activity',(time()-$isOnlineUser),PDO::PARAM_INT);
$stmt->execute();
$rowsNumber = $stmt->fetchColumn();
}
}

if ($rowsNumber == 0){ // Perhaps auto active is turned on for some of departments

$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND lh_departament.hidden = 0 AND lh_departament.disabled = 0 AND date_from <= :date_from AND date_to >= :date_to");
if ($rowsNumber == 0) { // Perhaps auto active is turned on for some of departments

$stmt = $db->prepare("SELECT lh_departament_custom_work_hours.start_hour, lh_departament_custom_work_hours.end_hour FROM lh_departament_custom_work_hours INNER JOIN lh_departament ON lh_departament.id = lh_departament_custom_work_hours.dep_id WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND `lh_departament`.`hidden` = 0 AND `lh_departament`.`disabled` = 0 AND date_from <= :date_from AND date_to >= :date_to");
$stmt->bindValue(':date_from',strtotime(date('Y-m-d')),PDO::PARAM_INT);
$stmt->bindValue(':date_to',strtotime(date('Y-m-d')),PDO::PARAM_INT);
$stmt->execute();
Expand All @@ -1138,14 +1143,33 @@ public static function isOnline($dep_id = false, $exclipic = false, $params = ar
$startHoursColumnName = $daysColumns[$column].'_start_hour';
$endHoursColumnName = $daysColumns[$column].'_end_hour';

$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`dep_offline` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1");
$stmt = $db->prepare("SELECT COUNT(id) AS found FROM lh_departament WHERE `lh_departament`.`hidden` = 0 AND `lh_departament`.`dep_offline` = 0 AND `lh_departament`.`disabled` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter) AND online_hours_active = 1 AND {$startHoursColumnName} <= :start_hour AND {$endHoursColumnName} > :end_hour AND {$startHoursColumnName} != -1 AND {$endHoursColumnName} != -1");
$stmt->bindValue(':start_hour', date('G') . date('i'), PDO::PARAM_INT);
$stmt->bindValue(':end_hour', date('G') . date('i'), PDO::PARAM_INT);
$stmt->execute();

$rowsNumber = $stmt->fetchColumn();
}
}

// Check is bot enabled for department
if ($rowsNumber == 0 && (!isset($params['exclude_bot']) || $params['exclude_bot'] == false)) {
$stmt = $db->prepare("SELECT bot_configuration FROM `lh_departament` WHERE `lh_departament`.`hidden` = 0 AND `lh_departament`.`dep_offline` = 0 AND `lh_departament`.`disabled` = 0 AND (lh_departament.pending_group_max = 0 || lh_departament.pending_group_max > lh_departament.pending_chats_counter) AND (lh_departament.pending_max = 0 || lh_departament.pending_max > lh_departament.pending_chats_counter)");
$stmt->execute();
$resultItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (is_array($resultItems)) {
foreach ($resultItems as $result) {
if (isset($result['bot_configuration']) && !empty($result['bot_configuration'])) {
$botData = json_decode($result['bot_configuration'], true);
if (isset($botData['bot_id']) && $botData['bot_id'] > 0 && (!isset($botData['bot_foh']) || $botData['bot_foh'] == false)) {
$rowsNumber = 1;
self::$botOnlyOnline = true;
}
}
}
}
}

}

if ($enableCache === true) {
Expand Down

0 comments on commit f819695

Please sign in to comment.