private static function initGeoIP() { if (self::$haveCngeoip === null) { $cngeoip_dir = $_SERVER['DOCUMENT_ROOT'] . WEBIM_ROOT . "/cngeoip"; if (file_exists($cngeoip_dir)) { self::$haveCngeoip = true; if (!(include_once $cngeoip_dir . "/cngeoip.php")) { self::$haveCngeoip = false; } } else { self::$haveCngeoip = false; } } }
public function sendFirstMessageWithVisitorInfo($thread, $params = array()) { $visitSession = VisitSession::GetInstance()->GetVisitSessionById($thread['visitsessionid']); $firstPage = null; $visted_pages = ""; if (!session_id()) { session_start(); } if (isset($_SESSION['user_stats'])) { $stats = $_SESSION['user_stats']; } else { $stats = getUsersStatsFromCookie(); } if (isset($stats['visited_pages']) && is_array($stats['visited_pages'])) { if (count($stats['visited_pages']) > 0) { $firstPage = $stats['visited_pages'][0]; } $visted_pages = "\n" . Resources::Get("chat.visited_pages"); foreach ($stats['visited_pages'] as $vp) { $title = isset($_SESSION['titles'], $_SESSION['titles'][$vp['url']]) ? $_SESSION['titles'][$vp['url']] : ""; if (WEBIM_ENCODING != 'UTF-8') { $title = smarticonv('utf-8', WEBIM_ENCODING, $title); } if (empty($title)) { $title = Resources::Get("chat.visited_page.no_title"); } $visted_pages .= "\n" . Resources::Get("chat.visited_page", array($title, HTTP_PREFIX . $_SERVER['HTTP_HOST'] . $vp['url'], $vp['time'])); } } $openerText = self::formatOpenerWithTitle(); $message = Resources::Get(empty($openerText) ? 'chat.came.from.unknown' : 'chat.came.from', $openerText); $simple = "\n%PARAM%: %VALUE%"; $link = "\n%PARAM%: %VALUE% %URL%"; if (!empty($thread['departmentid'])) { $departmentid = $thread['departmentid']; $dep = MapperFactory::getMapper("DepartmentLocale")->getDepartmentLocale($departmentid, Resources::getCurrentLocale()); $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('pending.table.head.department'), $dep['departmentname']), $simple); } if ($firstPage !== null) { if (!empty($firstPage['referrer'])) { $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.referrer'), parseReferrer($firstPage['referrer'], 'chat.window.referrer')), $simple); } if (!empty($firstPage['url'])) { $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.landingpage'), $firstPage['url']), $simple); } } $visitor_geodata = GeoIPLookup::getGeoDataByIP($visitSession['ip']); if (!empty($visitor_geodata)) { $message .= str_replace(array('%PARAM%', '%URL%', '%VALUE%'), array(Resources::Get('chat.window.geolocation'), "http://maps.google.com/maps?q=" . $visitor_geodata['lat'] . "," . $visitor_geodata['lng'], $visitor_geodata['city'] . ' ' . $visitor_geodata['country']), $link); } $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.browser'), get_user_agent($visitSession['useragent'])), $simple); $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.ip'), WEBIM_WHOIS_LINK . urlencode($visitSession['ip'])), $simple); if (!empty($visitSession['remotehost'])) { $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.remotehost'), $visitSession['remotehost']), $simple); } if (!empty($params['email'])) { $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.email'), $params['email']), $simple); } $message .= str_replace(array('%PARAM%', '%VALUE%'), array(Resources::Get('chat.window.fl_login'), $visitSession['fl_login']), $simple); $chats = Thread::getInstance()->CountNonEmptyThreads($visitSession['visitorid']); if ($chats > 0) { $message .= str_replace(array('%PARAM%', '%URL%', '%VALUE%'), array(Resources::Get('chat.window.chats'), HTTP_PREFIX . $_SERVER['HTTP_HOST'] . WEBIM_ROOT . '/operator/history.php?q=' . $visitSession['visitorid'], $chats), $link); } $message .= $visted_pages; Thread::getInstance()->PostMessage($thread['threadid'], KIND_FOR_AGENT, $message); }
function setupChatViewForOperator($thread, $visitSession, $operator, $viewonly, &$TML) { $TML->assign('thread', $thread); $TML->assign('visit_session', $visitSession); $TML->assign('first_page', VisitSession::GetInstance()->getFirstPage($visitSession['visitsessionid'])); $chats = Thread::getInstance()->CountNonEmptyThreads($visitSession['visitorid']); $TML->assign('chats_count', max($chats - 1, 0)); $TML->assign('browser', get_user_agent($visitSession['useragent'])); $TML->assign('visitor_name', preg_replace('/</', '<', $visitSession['visitorname'])); if ($viewonly) { $TML->assign('mode', 'viewonly'); } $historyParams = array('q' => $visitSession['visitorid']); $root = WEBIM_ROOT; $history = '/operator/history.php'; $TML->assign('servlet_root', $root); $TML->assign('history_servlet', $history); $TML->assign('history_params', $historyParams); $TML->assign('send_shortcut', "Enter"); $TML->assign('isOpera95', is_agent_opera95()); $TML->assign('userAgent', $_SERVER['HTTP_USER_AGENT']); $TML->assign('visitor_geodata', GeoIPLookup::getGeoDataByIP($visitSession['ip'])); $TML->assign('predefined_answers', preparePredefinedAnswers($thread['locale'])); }
$visitSession = null; if (isset($_GET['visitsessionid'])) { $visitSession = VisitSession::GetInstance()->GetVisitSessionById($_GET['visitsessionid']); } elseif (isset($_GET['pageid'])) { $visitdpageid = verify_param("pageid", "/^[a-z0-9]{32}\$/"); $vistedpage = VisitedPage::GetInstance()->GetVisitedPageById($_GET['pageid']); $visitSession = VisitSession::GetInstance()->GetVisitSessionById($vistedpage['visitsessionid']); } if (empty($visitSession)) { die("Invalid or no visitsessionid or pageid"); } $visitedPages = VisitedPage::GetInstance()->enumVisitedPagesByVisitSessionId($visitSession['visitsessionid']); $landingPage = end($visitedPages); $exitPage = reset($visitedPages); $timeend = 0; $timestart = 0; foreach ($visitedPages as $k => $vp) { $timeend = $timeend == 0 ? $vp['updated'] : max($timeend, $vp['updated']); $timestart = $timestart == 0 ? $vp['opened'] : min($timestart, $vp['opened']); $visitedPages[$k]['sessionduration'] = $vp['updated'] - $vp['opened']; } $geodata = GeoIPLookup::getGeoDataByIP($visitSession['ip']); //for testing purpose //$geodata = GeoIPLookup::getGeoDataByIP('89.113.218.99'); if ($geodata == NULL) { $geodata = array('city' => null, 'country' => null, 'lat' => null, 'lng' => null); } $tmlPage = array('visitsessionid' => $visitSession['visitsessionid'], 'visitedpages' => $visitedPages, 'landingpage' => $landingPage['uri'], 'exitpage' => $exitPage['uri'], 'timestart' => $timestart, 'timeend' => $timeend, 'timediff' => webim_date_diff($timeend - $timestart), 'active' => time() - $timeend < VISITED_PAGE_TIMEOUT, 'ip' => $visitSession['ip'], 'city' => $geodata['city'], 'country' => $geodata['country'], 'lat' => $geodata['lat'], 'lng' => $geodata['lng'], 'browser' => get_user_agent($visitSession['useragent']), 'enterref' => $landingPage['referrer'], 'leaveref' => $exitPage['referrer'], 'historyParams' => array("q" => "" . $visitSession['visitorid'])); $TML = new SmartyClass($TITLE_KEY); $TML->assign('page_settings', $tmlPage); $TML->display('visit_info.tpl');
public function getListThreads($currentoperatorid, $q, $show_empty = true, $checkDepartmentsAccess = true, $start_date = null, $end_date = null, $operatorid = null, $offset = null, $limit = null, $departmentid = null, $locale = null, $rate = null) { $departmentsExist = count(MapperFactory::getMapper("Department")->enumDepartments(Resources::getCurrentLocale())); // TODO probably not the best place $query_params = array(); $sql = ' SELECT WM_UNIX_TIMESTAMP(t."created") "created", WM_UNIX_TIMESTAMP(t."modified") "modified", t."threadid", t."operatorfullname", t."visitormessagecount" as "size", v."ip" as "remote", v."remotehost", v."visitorname" FROM "{thread}" t LEFT JOIN "{visitsession}" v ON v."visitsessionid" = t."visitsessionid" WHERE 1=1'; if (!empty($q)) { $query_params['query'] = "%%{$q}%%"; $sql .= ' AND (t."threadid" IN ( SELECT "threadid" FROM "{message}" m WHERE m."sendername" LIKE :query OR m."message" LIKE :query ) OR v."visitorid" LIKE :query OR v."ip" LIKE :query OR v."remotehost" LIKE :query OR t."operatorfullname" LIKE :query )'; } if (!empty($rate)) { $sign = $rate == 'positive' ? '>' : '<'; $sql .= ' AND EXISTS(SELECT * FROM "{rate}" r WHERE r."threadid"=t."threadid" AND r."rate" ' . $sign . ' 0 AND r."deldate" IS NULL)'; } if ($checkDepartmentsAccess) { $sql .= ' AND (t."departmentid" IS NULL OR EXISTS(SELECT * FROM "{operatordepartment}" od WHERE od."operatorid"=:currentoperatorid AND od."departmentid"=t."departmentid"))'; $query_params['currentoperatorid'] = $currentoperatorid; } if (!$show_empty) { $sql .= ' AND t."visitormessagecount" > 0 '; } if ($start_date !== null) { $query_params['start_date'] = $start_date; $sql .= ' AND WM_UNIX_TIMESTAMP(t."created") >= :start_date'; } if ($end_date !== null) { $query_params['end_date'] = $end_date; $sql .= ' AND WM_UNIX_TIMESTAMP(t."created") < :end_date'; } if ($operatorid !== null) { $query_params['operatorid'] = $operatorid; $sql .= ' AND (:operatorid IS NULL OR t."operatorid"=:operatorid)'; } if (!empty($departmentid)) { $query_params['departmentid'] = $departmentid; $sql .= ' AND t."departmentid" = :departmentid '; } if (!empty($locale)) { $query_params['locale'] = $locale; $sql .= ' AND t."locale" = :locale '; } if ($limit !== null && $offset !== null) { $query_params['limit'] = $limit; $query_params['offset'] = $offset; $sql .= " AND rownum BETWEEN :offset AND :limit"; } $sql .= ' ORDER BY t."created" DESC'; try { $this->db->query($sql, $query_params); $result = $this->db->getArrayOfRows(); } catch (Exception $e) { return array(); } foreach ($result as $k => $v) { $geodata = GeoIPLookup::getGeoDataByIP($v['remote']); //for testing purpose //$geodata = GeoIPLookup::getGeoDataByIP('89.113.218.99'); if ($geodata == NULL) { $geodata = array('city' => null, 'country' => null, 'lat' => null, 'lng' => null); } $result[$k] = array_merge($v, $geodata); $result[$k]['created'] = date(getDateTimeFormat(), $v['created']); $result[$k]['modified'] = date(getDateTimeFormat(), $v['modified']); $result[$k]['diff'] = webim_date_diff($v['modified'] - $v['created']); } return $result; }
public function getListThreads($currentoperatorid, $q, $show_empty = true, $checkDepartmentsAccess = true, $nLimit = 15, $nOffset = 0, $start_date = null, $end_date = null, $operatorid = null, $departmentid = null, $locale = null, $rate = null, $offline = null) { $departmentsExist = count(MapperFactory::getMapper('Department')->enumDepartments(Resources::getCurrentLocale())); // TODO probably not the best place $query_params = array(); $sWhere = ''; $sql = 'SELECT unix_timestamp(t.created) as created, unix_timestamp(t.modified) as modified, t.threadid, t.operatorfullname, t.visitormessagecount as size, v.ip as remote, v.remotehost, v.visitorname FROM {thread} as t LEFT JOIN {visitsession} as v ON v.visitsessionid = t.visitsessionid WHERE 1'; if (!empty($q)) { $query_params['query'] = "%%{$q}%%"; $sWhere .= ' AND (t.threadid IN ( SELECT threadid FROM {message} as m WHERE m.sendername LIKE :query OR m.message LIKE :query ) OR v.visitorid LIKE :query OR v.ip LIKE :query OR v.remotehost LIKE :query OR t.operatorfullname LIKE :query )'; } if (!empty($rate)) { $sign = $rate == 'positive' ? '>' : '<'; $sWhere .= " AND EXISTS (SELECT * FROM {rate} r WHERE r.threadid=t.threadid AND r.rate {$sign} 0 AND r.deldate IS NULL) "; } if ($checkDepartmentsAccess) { $sWhere .= ' AND (t.departmentid IS NULL OR EXISTS(SELECT * FROM {operatordepartment} od WHERE od.operatorid=:currentoperatorid AND od.departmentid=t.departmentid)) '; $query_params['currentoperatorid'] = $currentoperatorid; } if (!$show_empty) { $sWhere .= ' AND t.visitormessagecount > 0 '; } if ($start_date !== null) { $query_params['start_date'] = $start_date; $sWhere .= ' AND unix_timestamp(t.created) >= :start_date'; } if ($end_date !== null) { $query_params['end_date'] = $end_date; $sWhere .= ' AND unix_timestamp(t.created) < :end_date'; } if ($operatorid !== null) { $query_params['operatorid'] = $operatorid; $sWhere .= ' AND (:operatorid IS NULL OR t.operatorid=:operatorid)'; } if (!empty($departmentid)) { $query_params['departmentid'] = $departmentid; $sWhere .= ' AND t.departmentid = :departmentid '; } if (!empty($locale)) { $query_params['locale'] = $locale; $sWhere .= ' AND t.locale = :locale '; } if ($offline !== null) { $query_params['offline'] = $offline; $sWhere .= ' AND t.offline=:offline'; } $sql .= $sWhere . " ORDER BY t.created DESC LIMIT {$nOffset}, {$nLimit}"; try { $this->db->query($sql, $query_params); $result = $this->db->getArrayOfRows(); } catch (Exception $e) { return array(); } foreach ($result as $k => $v) { $geodata = GeoIPLookup::getGeoDataByIP($v['remote']); //for testing purpose //$geodata = GeoIPLookup::getGeoDataByIP('89.113.218.99'); if ($geodata == null) { $geodata = array('city' => null, 'country' => null, 'lat' => null, 'lng' => null); } $result[$k] = array_merge($v, $geodata); $result[$k]['created'] = date(getDateTimeFormat(), $v['created']); $result[$k]['modified'] = date(getDateTimeFormat(), $v['modified']); $result[$k]['diff'] = webim_date_diff($v['modified'] - $v['created']); } return $result; }