if ($result) {
     $tab = $db->fetch_array($res);
     foreach ($tab as $key => $value) {
         $return[$key] = $value;
     }
     $_SESSION['uid'] = $tab['rowid'];
     $_SESSION['uname'] = $username;
     $_SESSION['nom'] = $tab['lastname'];
     $_SESSION['prenom'] = $tab['firstname'];
     $_SESSION['TERMINAL_ID'] = $terminalid;
     dol_include_once('/pos/class/cash.class.php');
     $terminal = new Cash($db);
     $terminal->fetch($terminalid);
     $userstatic = new User($db);
     $userstatic->fetch($_SESSION['uid']);
     $terminal->set_used($userstatic);
     if ($terminal->is_closed) {
         $terminal->set_open($userstatic);
     }
     //var_dump($_SESSION);exit;
     if ($terminal->tactil == 2) {
         if (file_exists(dol_buildpath('/pos/frontend/movil.php'))) {
             header('Location: ' . dol_buildpath('/pos/frontend/movil.php', 1));
         } else {
             header('Location: ' . dol_buildpath('/pos/frontend/tpv.php', 1));
         }
     } else {
         header('Location: ' . dol_buildpath('/pos/frontend/tpv.php', 1));
     }
     exit;
 } else {
$pageprev = $page - 1;
$pagenext = $page + 1;
$langs->load("pos@pos");
/*
 * Actions
 */
//free terminal
if ($action == 'freeterminal') {
    $cash = new Cash($db);
    $cash->fetch(GETPOST('id', 'int'));
    $cash->set_unused($user);
}
if ($action == 'blockterminal') {
    $cash = new Cash($db);
    $cash->fetch(GETPOST('id', 'int'));
    $cash->set_used($user);
}
// Recherche
$mode = GETPOST('mode');
$modesearch = GETPOST('mode-search');
if ($mode == 'search') {
    $_POST["search_name"] = $cashname;
    $sql = "SELECT rowid";
    $sql .= " FROM " . MAIN_DB_PREFIX . "pos_cash";
    $sql .= " WHERE (";
    $sql .= " name like '%" . $db->escape($cashname) . "%'";
    $sql .= ")";
    $sql .= " AND entity = " . $conf->entity;
    if (!$user->rights->societe->client->voir && !$cash) {
        $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
    }