query( "select invited, threadid from {chatsitevisitor} where visitorid = ?", array($visitorid), array('return_rows' => Database::RETURN_ONE_ROW) ); if (!$result) { $result['invited'] = 0; $result['threadid'] = 0; } return $result; } function invitation_invite($visitorid, $operatorid) { if (!invitation_check($visitorid)) { $db = Database::getInstance(); $db->query( "update {chatsitevisitor} set invited = 1, invitedby = :operatorid, " . "invitationtime = :now, invitations = invitations + 1 where visitorid = :visitorid", array( ':operatorid' => $operatorid, ':visitorid' => $visitorid, ':now' => time() ) ); return invitation_check($visitorid); } else { return FALSE; } } function invitation_check($visitorid) { $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) ); return ($result && isset($result['invitedby']) && $result['invitedby']) ? $result['invitedby'] : FALSE; } function invitation_accept($visitorid, $threadid) { $db = Database::getInstance(); $db->query( "update {chatsitevisitor} set threadid = ?, chats = chats + 1 where visitorid = ?", array($threadid, $visitorid) ); $result = $db->query( "select invitedby from {chatsitevisitor} where visitorid = ?", array($visitorid), array('return_rows' => Database::RETURN_ONE_ROW) ); if ($result && isset($result['invitedby']) && $result['invitedby']) { return $result['invitedby']; } else { return FALSE; } } ?>