<?php

include("postget.php");
include_once("common.php");
checklevel(2, $_REQUEST['clientid']);
if ($active == 0) {
    $where = " WHERE active=0 ";
    $titulo = _INACTIVE_CLIENTS;
} elseif ($active == 1) {
    $where = " WHERE active=1 ";
    $titulo = _ACTIVE_CLIENTS;
} elseif ($active == -1) {
    $where = " WHERE active=-1 ";
    $titulo = _ELIMINATED_CLIENTS;
} elseif ($active == -2) {
    $where = " WHERE suspended=1 ";
    $titulo = _SUSPENDED_CLIENTS;
} elseif ($active == 9) {
    $where = "";
    $titulo = _ALL_CLIENTS;
} elseif ($active == -9) {
    $where = " WHERE promotionalmailing = 0 ";
    $titulo = _CLIENTS_NOT_SUBSCRIBED;
}
$pagetitle = $titulo;

$paging = new pagination;
if ($_REQUEST['orderby']) {
    $orderby = $_REQUEST['orderby'];
} else {
    $orderby = 'last';
}
$paging->mantenerVar('orderby', 'active');

include("head_template.php");
echo '
<div class="container">
	<div class="row">
';


$query = "SELECT * FROM hd_clients $where ORDER BY " . $orderby . "";

$paging->agregarConsulta($query);
$paging->porPagina($config[32][1]);
$paging->paginasAntes(3, 10, 20, 50);
$paging->paginasDespues(3, 10, 20, 50);
$paging->linkSeparador('&nbsp;');
$paging->linkSeparadorEspecial('...');
$paging->linkClase('pag');
$paging->mostrarActual("<span class=\"pagthis\">{n}</span>");

$paging->ejecutar();

echo "" . strtoupper($titulo) . " (" . $paging->numTotalRegistros() . " " . _RECORDS . ")";

if ($paging->numTotalPaginas() > 1) {
    echo "<div class='pagination'><b>" . ucfirst(_PAGES) . "</b>: " . $paging->fetchNavegacion() . "</div>";
}

echo '<table class="table table-striped">';

print("<thead><tr>
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=clientid&active=$active'>" . _ID . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=last&active=$active'>" . _LAST_NAME . ", " . _FIRST_NAME . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=company&active=$active'>" . _COMPANY . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=country&active=$active'>" . _COUNTRY . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=phone&active=$active'>" . _PHONE . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=email&active=$active'>" . _EMAIL . "</a></b></th> 
	<th><b><a href='" . $serverurl . "/clientslist.php?orderby=start&active=$active'>" . _START . "</a></b></th> 
	</tr></thead><tbody>");

$bgc = true;
while ($datos = $paging->fetchResultado()) {
    print("<TR>");
    print("<TD align='center'><a href='" . $serverurl . "/tickets.php?clientid=$datos[clientid]'>$datos[clientid]</a></TD>");
    print("<TD align='center' nowrap>");
    print("<a href='" . $serverurl . "/tickets.php?clientid=$datos[clientid]'>$datos[last], $datos[first]</a>");
    if ($datos[comments]) {
        print("<img class='sprites comment btip' src='images/transparent.gif' border='0' title='" . nl2br(substr($datos[comments], 1)) . "'>&nbsp;");
    }
    print("</TD>");
    print("<TD align='center'>$datos[company]&nbsp;</TD>");
    print("<TD align='center'>");
    bandera2($datos[country]);
    print("&nbsp;</TD>");
    print("<TD align='center'>$datos[phone]</TD>");
    print("<TD align='center'><a href=mailto:$datos[email]>$datos[email]</a></TD>");
    print("<TD align='center'>" . date($df, $datos[start]) . "</TD>");
    print("</TR>");
}

echo '
    </tbody</table>
</div>
</div>
';

include("foot_template.php");
?>