<?php
include "checklog.php";

$confr = "WHERE 1 = 1";
foreach($HTTP_GET_VARS as $k=>$v) {
	if (strtolower($k) != "submit" && $v != "") {
		$testo = addslashes(trim($v));
		$testo = str_replace("%","\\%",$testo);
		$testo = str_replace("_","\\_",$testo);
		$confr .= " AND $k LIKE '%$testo%'";
	}
}

if ($confr == "WHERE 1 = 1" || $confr == "") {
	$confr = "WHERE 1 = 0";
}

$rpp = 25;

$sql = "SELECT COUNT(cust_id) AS no FROM clienti $confr";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$no = $row["no"];
$no1 = $no;
if ($no1 < 1) {$no1 = 1;}

$maxp = intval(($no1 - 1) / $rpp) + 1;
if (!isset($HTTP_COOKIE_VARS["boclisearch_pagina"])) {
	$actp = 1;
} else {
	$actp = $HTTP_COOKIE_VARS["boclisearch_pagina"];
}
$actp = intval($actp);
if ($actp > $maxp || $actp < 1) {$actp = 1;}
$lolim = ($actp -1) * $rpp;

?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<base target="_self">
<link rel="stylesheet" href="backoffice.css" type="text/css">

<script language="JavaScript">
<!--
function EditCl(id) {
	document.view.clid.value = id;
	document.view.submit();
}

function PageGoTo(np) {
	if (np < 1) {
		selnum = document.navigazione.pagina.selectedIndex;
		np = document.navigazione.pagina.options[selnum].value;
	}
	np = parseInt(np);
	document.cookie = "boclisearch_pagina=" + np;
	self.location = self.location;
}

function MarcaRefer() {
	document.cookie = "bocli_ref=boclresults.php" + location.search;
}
//-->
</script>
</head>

<body topmargin="0" leftmargin="4" marginwidth="4" marginheight="0" class="pagina" onLoad="MarcaRefer()">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="50%"><span class="titolo">Gestione Clienti</span><span class="sottotitolo"> 
      - Risultati ricerca </span></td>
    <td width="25%"><span class="sottotitolo"><a href="boclienti.php" target="_self">&gt;&gt;Elenco 
      clienti </a></span></td>
    <td width="25%"><span class="sottotitolo"><a href="bocladd.php" target="_self">&gt;&gt;Aggiungi</a></span></td>
  </tr>
</table>

<form name="navigazione" method="get" action="">
  <table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr> 
      <td class="intestazione" nowrap> 
        <?php
if ($actp > 1) {
?>
        <input type="button" name="back" value="|<<" class="pulsante" onClick="PageGoTo(1);">
        <input type="button" name="back" value="<" class="pulsante" onClick="PageGoTo(<?=$actp?> - 1);">
        <?php
}
?>
      </td>
      <td class="intestazione" nowrap>&nbsp;&nbsp;Pagina: 
        <?=$actp?>
        / 
        <?=$maxp?>
        &nbsp;&nbsp; </td>
      <td class="intestazione" nowrap> 
        <?php
if ($actp < $maxp) {
?>
        <input type="button" name="forward" value=">" class="pulsante" onClick="PageGoTo(<?=$actp?> + 1);">
        <input type="button" name="forward" value=">>|" class="pulsante" onClick="PageGoTo(<?=$maxp?>);">
        <?php
}
?>
      </td>
      <td class="intestazione" nowrap> &nbsp;&nbsp;Vai a pagina:</td>
      <td class="intestazione" nowrap> 
        <select name="pagina" class="pulsante" onChange="PageGoTo(0);">
          <?php
for ($i=1; $i <= $maxp; $i++) {
	$sel = "";
	if ($actp == $i) {$sel="selected";}
	echo "<option $sel value=$i>$i</option>";
}
?>
        </select>
      </td>
      <td class="intestazione" nowrap width="100%" align="right">Clienti trovati: 
        <?=$no?>
      </td>
    </tr>
  </table>
</form>

<form name="view" method="GET" action="bocledit.php">
  <input type="hidden" name="pagina" value="0">
  <input type="hidden" name="clid">
  <table width="100%" border="0" cellspacing="1" cellpadding="2">
    <tr> 
      <td class="intestazione" nowrap>Data iscrizione</td>
      <td class="intestazione" nowrap>Nome utente</td>
      <td class="intestazione" nowrap>Nome e cognome</td>
      <td class="intestazione" width="100%" nowrap>Ragione sociale</td>
      <td class="intestazione" nowrap>E-mail</td>
      <td class="intestazione">Listino</td>
      <td>&nbsp;</td>
    </tr>
<?php
$sql = "SELECT *, DATE_FORMAT(subsc_date, '%d/%m/%Y %H.%i') AS data2 FROM clienti $confr LIMIT $lolim, $rpp";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
	$clid = $row["cust_id"];
	$data = $row["data2"];
	$user = htmlentities($row["user"]);
	$fullname = htmlentities($row["full_name"]);
	$corp = htmlentities($row["corp"]);
	$email = $row["email"];
	$list = $row["list"] + 1;
	if ($rowclass == "row1") {
		$rowclass = "row2";
	} else {
		$rowclass = "row1";
	}
?>
    <tr> 
      <td class="<?=$rowclass?>" align="center" nowrap>
        <?=$data?>
      </td>
      <td class="<?=$rowclass?>" nowrap>
        <?=$user?>
      </td>
      <td class="<?=$rowclass?>" nowrap>
        <?=$fullname?>
      </td>
      <td class="<?=$rowclass?>"><?=$corp?></td>
      <td class="<?=$rowclass?>"><a href="mailto:<?=$email?>"><?=$email?></a></td>
      <td class="<?=$rowclass?>" align="center">
        <?=$list?>
      </td>
      <td class="<?=$rowclass?>">
        <input type="button" value="Dettagli" class="pulsante" onClick="EditCl(<?=$clid?>);">
      </td>
    </tr>
<?php
}
?>
  </table>
</form>
<form name="help"><input type="hidden" name="pagina" value="clienti.htm"></form>
</body>
</html>