2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2013-03-07 01:22:53 +04:00
|
|
|
* Copyright 2005-2013 the original author or authors.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2007-10-10 19:15:47 +04:00
|
|
|
*/
|
|
|
|
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('../libs/common.php');
|
|
|
|
require_once('../libs/operator.php');
|
|
|
|
require_once('../libs/chat.php');
|
2009-02-08 03:52:57 +03:00
|
|
|
require_once('../libs/userinfo.php');
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('../libs/pagination.php');
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
$operator = check_login();
|
2011-04-13 18:44:09 +04:00
|
|
|
force_password($operator);
|
|
|
|
|
2009-06-04 05:14:26 +04:00
|
|
|
setlocale(LC_TIME, getstring("time.locale"));
|
|
|
|
|
2009-03-16 04:20:04 +03:00
|
|
|
$page = array();
|
2008-05-06 15:14:48 +04:00
|
|
|
$query = isset($_GET['q']) ? myiconv(getoutputenc(), $webim_encoding, $_GET['q']) : false;
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2012-02-12 20:19:06 +04:00
|
|
|
$searchType = verifyparam('type', '/^(all|message|operator|visitor)$/', 'all');
|
|
|
|
$searchInSystemMessages = (verifyparam('insystemmessages', '/^on$/', 'off') == 'on') || !$query;
|
|
|
|
|
2011-02-26 17:06:19 +03:00
|
|
|
if ($query !== false) {
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$groups = $db->query(
|
|
|
|
"select {chatgroup}.groupid as groupid, vclocalname " .
|
|
|
|
"from {chatgroup} order by vclocalname",
|
|
|
|
NULL,
|
|
|
|
array('return_rows' => Database::RETURN_ALL_ROWS)
|
|
|
|
);
|
2011-02-26 17:06:19 +03:00
|
|
|
|
2009-03-28 03:29:33 +03:00
|
|
|
$groupName = array();
|
2012-07-13 16:56:50 +04:00
|
|
|
foreach ($groups as $group) {
|
2009-03-28 03:29:33 +03:00
|
|
|
$groupName[$group['groupid']] = $group['vclocalname'];
|
|
|
|
}
|
2011-02-16 03:43:19 +03:00
|
|
|
$page['groupName'] = $groupName;
|
2011-02-26 17:06:19 +03:00
|
|
|
|
2012-09-05 16:46:15 +04:00
|
|
|
$escapedQuery = $escapedQuery?$escapedQuery:'';
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
$values = array(
|
2012-07-24 20:00:58 +04:00
|
|
|
':query' => "%{$escapedQuery}%"
|
2012-07-13 16:56:50 +04:00
|
|
|
);
|
|
|
|
|
2012-02-12 20:19:06 +04:00
|
|
|
$searchConditions = array();
|
|
|
|
if ($searchType == 'message' || $searchType == 'all') {
|
2012-07-13 16:56:50 +04:00
|
|
|
$searchConditions[] = "({chatmessage}.tmessage LIKE :query" .
|
|
|
|
($searchInSystemMessages?'':" AND ({chatmessage}.ikind = :kind_user OR {chatmessage}.ikind = :kind_agent)") .
|
2012-02-12 20:19:06 +04:00
|
|
|
")";
|
2012-07-24 20:00:58 +04:00
|
|
|
$values[':kind_user'] = $kind_user;
|
|
|
|
$values[':kind_agent'] = $kind_agent;
|
2012-02-12 20:19:06 +04:00
|
|
|
}
|
|
|
|
if ($searchType == 'operator' || $searchType == 'all') {
|
2012-07-13 16:56:50 +04:00
|
|
|
$searchConditions[] = "({chatthread}.agentName LIKE :query)";
|
2012-02-12 20:19:06 +04:00
|
|
|
}
|
|
|
|
if ($searchType == 'visitor' || $searchType == 'all') {
|
2012-07-13 16:56:50 +04:00
|
|
|
$searchConditions[] = "({chatthread}.userName LIKE :query)";
|
|
|
|
$searchConditions[] = "({chatthread}.remote LIKE :query)";
|
2012-02-12 20:19:06 +04:00
|
|
|
}
|
2012-09-05 16:46:15 +04:00
|
|
|
select_with_pagintation("DISTINCT {chatthread}.dtmcreated as created, " .
|
|
|
|
"{chatthread}.dtmmodified as modified, {chatthread}.threadid, " .
|
2012-07-13 16:56:50 +04:00
|
|
|
"{chatthread}.remote, {chatthread}.agentName, {chatthread}.userName, groupid, " .
|
|
|
|
"messageCount as size",
|
|
|
|
"{chatthread}, {chatmessage}",
|
|
|
|
array(
|
|
|
|
"{chatmessage}.threadid = {chatthread}.threadid",
|
|
|
|
"(" . implode(' or ', $searchConditions) . ")"
|
|
|
|
),
|
2012-09-05 16:46:15 +04:00
|
|
|
"order by {chatthread}.dtmcreated DESC",
|
2012-07-13 16:56:50 +04:00
|
|
|
"DISTINCT {chatthread}.dtmcreated", $values);
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2008-05-06 15:14:48 +04:00
|
|
|
$page['formq'] = topage($query);
|
2007-10-10 19:15:47 +04:00
|
|
|
} else {
|
|
|
|
setup_empty_pagination();
|
|
|
|
}
|
|
|
|
|
2012-02-12 20:19:06 +04:00
|
|
|
$page['formtype'] = $searchType;
|
|
|
|
$page['forminsystemmessages'] = $searchInSystemMessages;
|
|
|
|
|
2009-03-16 04:20:04 +03:00
|
|
|
prepare_menu($operator);
|
2007-10-10 19:15:47 +04:00
|
|
|
start_html_output();
|
|
|
|
require('../view/thread_search.php');
|
2013-03-13 01:03:50 +04:00
|
|
|
?>
|