<?php

/**
 * $Id: ajax_graph_user_agents.php 24464 2014-08-19 08:59:53Z kgrisel $
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 24464 $
 */
CCanDo::checkRead();
$user_agent_id = CValue::get("user_agent_id");
$ua = new CUserAgent();
if ($user_agent_id) {
    $ua->load($user_agent_id);
    if ($ua->_id) {
        $ua->countBackRefs("user_authentications");
    }
}
$smarty = new CSmartyDP();
$smarty->assign("_user_agent", $ua);
$smarty->display("inc_vw_user_agents_line.tpl");
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 24464 $
 */
CCanDo::checkRead();
$start = CValue::get("start", 0);
$min_date = CValue::get("_min_date");
$max_date = CValue::get("_max_date");
CValue::setSession("ua_min_date", $min_date);
CValue::setSession("ua_max_date", $max_date);
CView::enforceSlave();
$auth = new CUserAuthentication();
$ua = new CUserAgent();
$ds = $ua->getDS();
$ljoin = array();
$ljoin["user_authentication"] = "`user_authentication`.`user_agent_id` = `user_agent`.`user_agent_id`";
$where = array();
if ($min_date) {
    $where[] = $ds->prepare("`datetime_login` >= %", $min_date);
}
if ($max_date) {
    $where[] = $ds->prepare("`datetime_login` <= %", $max_date);
}
$where["platform_name"] = $ds->prepare("!= 'unknown'");
$total = $ua->countMultipleList($where, null, "`user_agent`.`user_agent_id`", $ljoin);
$total = count($total);
$browsers = $ua->countMultipleList($where, null, "browser_name", $ljoin, "browser_name");
$versions = $ua->countMultipleList($where, null, "browser_name, browser_version", $ljoin, "browser_name, browser_version");
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
$start = CValue::get("start", 0);
$date_min = CValue::getOrSession("date_min", CMbDT::dateTime("-2 MONTH"));
$date_max = CValue::getOrSession("date_max");
$user_id = CValue::getOrSession("user_id");
$user_agent_id = CValue::get("user_agent_id");
$ua = new CUserAgent();
if ($user_agent_id) {
    $ua->load($user_agent_id);
}
$smarty = new CSmartyDP();
$smarty->assign("start", $start);
$smarty->assign("date_min", $date_min);
$smarty->assign("date_max", $date_max);
$smarty->assign("user_id", $user_id);
$smarty->assign("user_agent_id", $user_agent_id);
$smarty->assign("ua", $ua);
$smarty->display("vw_user_authentications.tpl");
 /**
  * Log user authentication
  *
  * @param CUser $user The user logging-in
  *
  * @return void
  */
 static function logAuth(CUser $user)
 {
     if (!self::authReady() || $user->dont_log_connection) {
         return;
     }
     global $rootName;
     $session_name = preg_replace("/[^a-z0-9]/i", "", $rootName);
     $app = CAppUI::$instance;
     $auth = new self();
     $auth->user_id = $user->_id;
     $auth->previous_user_id = null;
     $auth->auth_method = $app->auth_method;
     $auth->datetime_login = CMbDT::dateTime();
     $auth->id_address = $app->ip;
     $auth->session_id = session_id();
     // Screen size
     $cookie = CValue::cookie("{$session_name}-uainfo");
     $uainfo = stripslashes($cookie);
     if ($uainfo) {
         $uainfo = json_decode($uainfo, true);
         if (isset($uainfo["screen"])) {
             $screen = $uainfo["screen"];
             $auth->screen_width = (int) $screen[0];
             $auth->screen_height = (int) $screen[1];
         }
     }
     // User agent
     $user_agent_string = CValue::read($_SERVER, "HTTP_USER_AGENT");
     if ($user_agent_string) {
         $user_agent = CUserAgent::createFromUA($user_agent_string);
         $auth->user_agent_id = $user_agent->_id;
     }
     $auth->store();
 }