<?php

/**
 * $Id: ajax_vw_user_authentications.php 25142 2014-10-07 12:16:51Z phenxdesign $
 *
 * @category Admin
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision: 25142 $
 * @link     http://www.mediboard.org
 */
CCanDo::checkEdit();
// Récuperation de l'utilisateur sélectionné
$user_id = CValue::get("user_id");
$start = CValue::get("start");
$user = new CUser();
$user->load($user_id);
$user->countConnections();
$user_authentication = new CUserAuthentication();
$ds = $user_authentication->getDS();
$where = array("user_id" => $ds->prepare("= ?", $user_id));
$limit = intval($start) . ", 30";
$list = $user_authentication->loadList($where, "datetime_login DESC", $limit);
$smarty = new CSmartyDP();
$smarty->assign("list", $list);
$smarty->assign("user", $user);
$smarty->display("inc_vw_user_authentications.tpl");
$user_id = CValue::getOrSession("user_id");
$user_agent_id = CValue::get("user_agent_id");
$auth = new CUserAuthentication();
$ua = new CUserAgent();
$where = array("datetime_login" => ">= '{$date_min}'");
if ($date_max) {
    $where[] = "datetime_login <= '{$date_min}'";
}
if ($user_id) {
    $where["user_id"] = "<= '{$user_id}'";
}
if ($user_agent_id) {
    $where["user_agent_id"] = "= '{$user_agent_id}'";
    $ua->load($user_agent_id);
}
$limit = (int) $start . ",100";
$total = $auth->countList($where);
/** @var CUserAuthentication[] $auth_list */
$auth_list = $auth->loadList($where, "datetime_login DESC", $limit);
foreach ($auth_list as $_auth) {
    $_auth->loadRefUser()->loadRefMediuser()->loadRefFunction();
}
$smarty = new CSmartyDP();
$smarty->assign("start", $start);
$smarty->assign("total", $total);
$smarty->assign("date_min", $date_min);
$smarty->assign("date_max", $date_max);
$smarty->assign("user_id", $user_id);
$smarty->assign("auth_list", $auth_list);
$smarty->assign("ua", $ua);
$smarty->display("inc_vw_list_user_authentications.tpl");