2011-04-07 12:34:04 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2013-03-13 01:03:50 +04:00
|
|
|
* Copyright 2005-2013 the original author or authors.
|
2011-04-07 12:34:04 +04:00
|
|
|
*
|
2013-03-13 01:03:50 +04:00
|
|
|
* 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
|
2011-04-07 12:34:04 +04:00
|
|
|
*
|
2013-03-13 01:03:50 +04:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-07 12:34:04 +04:00
|
|
|
*
|
2013-03-13 01:03:50 +04:00
|
|
|
* 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.
|
2011-04-07 12:34:04 +04:00
|
|
|
*/
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function invitation_state($visitorid)
|
2011-04-07 12:34:04 +04:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$result = $db->query(
|
|
|
|
"select invited, threadid from {chatsitevisitor} where visitorid = ?",
|
|
|
|
array($visitorid),
|
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2011-04-07 12:34:04 +04:00
|
|
|
if (!$result) {
|
|
|
|
$result['invited'] = 0;
|
|
|
|
$result['threadid'] = 0;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function invitation_invite($visitorid, $operatorid)
|
2011-04-07 12:34:04 +04:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
if (!invitation_check($visitorid)) {
|
|
|
|
$db = Database::getInstance();
|
|
|
|
$db->query(
|
|
|
|
"update {chatsitevisitor} set invited = 1, invitedby = ?, " .
|
|
|
|
"invitationtime = now(), invitations = invitations + 1 where visitorid = ?",
|
|
|
|
array($operatorid, $visitorid)
|
|
|
|
);
|
|
|
|
return invitation_check($visitorid);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
2011-04-07 12:34:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function invitation_check($visitorid)
|
2011-04-07 12:34:04 +04:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$result = $db->query(
|
|
|
|
"select invitedby from {chatsitevisitor} where invited and visitorid = ? " .
|
|
|
|
" and lasttime < invitationtime and threadid is null",
|
|
|
|
array($visitorid),
|
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2011-04-07 12:34:04 +04:00
|
|
|
return ($result && isset($result['invitedby']) && $result['invitedby']) ? $result['invitedby'] : FALSE;
|
|
|
|
}
|
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
function invitation_accept($visitorid, $threadid)
|
2011-04-07 12:34:04 +04:00
|
|
|
{
|
2012-07-13 16:56:50 +04:00
|
|
|
$db = Database::getInstance();
|
|
|
|
$db->query(
|
|
|
|
"update {chatsitevisitor} set threadid = ?, chats = chats + 1 where visitorid = ?",
|
|
|
|
array($threadid, $visitorid)
|
|
|
|
);
|
2011-04-07 12:34:04 +04:00
|
|
|
|
2012-07-13 16:56:50 +04:00
|
|
|
$result = $db->query(
|
|
|
|
"select invitedby from {chatsitevisitor} where visitorid = ?",
|
|
|
|
array($visitorid),
|
|
|
|
array('return_rows' => Database::RETURN_ONE_ROW)
|
|
|
|
);
|
2011-04-07 12:34:04 +04:00
|
|
|
|
|
|
|
if ($result && isset($result['invitedby']) && $result['invitedby']) {
|
2012-07-13 16:56:50 +04:00
|
|
|
return $result['invitedby'];
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
2011-04-07 12:34:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 01:03:50 +04:00
|
|
|
?>
|