<?php
include "checklog.php";
$clid = $HTTP_GET_VARS["clid"];
$query = "select * from clienti where cust_id=$clid";
$res = mysql_query($query,$conn);
if ($res) {
	$row = mysql_fetch_array($res);
	if ($row["cust_id"] == $clid) {
		$sel = array(" "," "," "," "," "," "," "," "," "," "," ");
		$sel[$row["list"]] = " selected ";
		$listino = "<select size=\"1\" name=\"list\" class=\"pulsante\">\n";
		for ($n=0;$n<10;$n++) {
			$n1 = $n + 1;
    		$listino .= "<option $sel[$n] value=\"$n\">$n1</option>\n";
		}
    	$listino .= "</select>\n";
?>
<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 EliminaCl() {
	sMsg = "ATTENZIONE: L'operazione, se confermata, è irreversibile.\n\n";
	sMsg = sMsg + "Si desidera eliminare il cliente?";
	if (confirm(sMsg)) {
		return true;
	} else {
		return false;
	}
}
//-->
</script>
</head>

<body topmargin="0" leftmargin="4" marginwidth="4" marginheight="0" class="pagina">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="50%"><span class="titolo">Gestione Clienti</span><span class="sottotitolo"> 
      - Dettaglio profilo cliente</span></td>
    <td width="25%"><span class="sottotitolo"><a href="boclsearch.php" target="_self">&gt;&gt;Ricerca</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="edit" method="post" action="boclupdate.php">
  <table width="100%" border="0" cellspacing="0" cellpadding="10">
    <tr> 
      <td align="left" valign="top" class="testomin"> 
        <table border="0" class="form">
          <tr> 
            <td><b>Nome utente: </b></td>
            <td> 
              <?php echo  htmlentities($row["user"]); ?>
            </td>
          </tr>
          <tr> 
            <td><b>Password: </b></td>
            <td> 
              <input type="text" name="pw" value="<?php echo  MakeClean($row["pw"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td><b>Listino: </b></td>
            <td> 
              <?php echo  $listino; ?>
            </td>
          </tr>
          <tr>
            <td><b>Sconto cliente: </b></td>
            <td>
              <input type="text" name="sconto_cl" value="<?php echo  MakeClean($row["sconto_cl"]); ?>" class="pulsante" size="10">
              <b>%</b> </td>
          </tr>
          <tr> 
            <td><b>Nome e cognome: </b></td>
            <td> 
              <input type="text" name="full_name" maxlength="100" value="<?php echo  MakeClean($row["full_name"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>Ragione sociale: </td>
            <td> 
              <input type="text" name="corp" maxlength="100" value="<?php echo  MakeClean($row["corp"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>P.iva / CF: </td>
            <td> 
              <input type="text" name="cf_piva" maxlength="100" value="<?php echo  MakeClean($row["cf_piva"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>Indirizzo: </td>
            <td> 
              <input type="text" name="addr" maxlength="100" value="<?php echo  MakeClean($row["addr"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>C.A.P: </td>
            <td> 
              <input type="text" name="zip" maxlength="100" value="<?php echo  MakeClean($row["zip"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>Localit&agrave; (prov): </td>
            <td> 
              <input type="text" name="city" maxlength="100" value="<?php echo  MakeClean($row["city"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <hr>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <p><b>Indirizzo spedizione (se differente):</b></p>
            </td>
          </tr>
          <tr> 
            <td>Denominazione: </td>
            <td> 
              <input type="text" name="del_name" maxlength="100" value="<?php echo  MakeClean($row["del_name"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>Indirizzo: </td>
            <td> 
              <input type="text" name="del_addr" maxlength="100" value="<?php echo  MakeClean($row["del_addr"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>C.A.P.: </td>
            <td> 
              <input type="text" name="del_zip" maxlength="100" value="<?php echo  MakeClean($row["del_zip"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td> Localit&agrave; (prov): </td>
            <td> 
              <input type="text" name="del_city" maxlength="100" value="<?php echo  MakeClean($row["del_city"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <hr>
            </td>
          </tr>
          <tr> 
            <td>Stato: </td>
            <td> 
              <input type="text" name="country" maxlength="100" value="<?php echo  MakeClean($row["country"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td><b>E-mail: </b></td>
            <td> 
              <input type="text" name="email" maxlength="100" value="<?php echo  MakeClean($row["email"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td>Telefono: </td>
            <td> 
              <input type="text" name="phone" maxlength="100" value="<?php echo  MakeClean($row["phone"]); ?>" class="pulsante" size="40">
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <hr>
            </td>
          </tr>
          <tr> 
            <td>Note: </td>
            <td> 
              <textarea name="notes" cols="35" rows="3" class="pulsante"><?php echo  $row["notes"]; ?></textarea>
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <hr>
            </td>
          </tr>
          <tr> 
            <td>Newsletter:</td>
            <td> 
              <input type="checkbox" <?php if($row["news"] == "1") {echo "checked";} ?> name="news" value="1">
            </td>
          </tr>
<?php
	if ($row["edisplay"] != "") {
?>
<tr> 
            <td colspan="2"> 
              <hr>
            </td>
          </tr>
          <tr> 
            <td valign="top">Campi aggiuntivi:</td>
            <td valign="top"> 
              <?php echo nl2br(htmlentities($row["edisplay"])); ?>
            </td>
          </tr>
<?php
	}
?>
          <tr> 
            <td>&nbsp;</td>
            <td> 
              <input type="hidden" name="usr" value="<?php echo MakeClean($row["cust_id"]); ?>">
            </td>
          </tr>
          <tr> 
            <td colspan="2"> 
              <div align="center"> 
                <input type="submit" name="Submit" value="Salva" class="pulsante">
              </div>
            </td>
          </tr>
        </table>
      </td>
      <td align="center" valign="top" class="testomin"> 
<?php
$haordini = 0;
$sql = "SELECT ordini.codice, ordini.ID, DATE_FORMAT(ordini.data, '%d/%m/%Y %H.%i') AS data2 FROM ordini WHERE ordini.cliente = $clid ORDER BY ordini.ID DESC";
$result = mysql_query($sql);
if (mysql_num_rows($result) >0) {
	$haordini = 1;
?>
        <table border="1" cellspacing="1" cellpadding="2" bordercolor="#333399">
          <tr> 
            <td colspan="2" class="intestazione" nowrap><b class="testomin">Ordini 
              effettuati</b></td>
          </tr>
<?php
	while ($row = mysql_fetch_array($result)) {
		$codice = $row['codice'];
		$ordid = $row['ID'];
		$data = $row['data2'];
?>
          <tr> 
            <td class="tooltip"><b><a href="boordedit.php?ordid=<?=$ordid?>" target="_self"><?=$codice?></a></b></td>
            <td class="tooltip"><?=$data?></td>
          </tr>
<?php
	}
?>
        </table>
<?php
}
?>
        <p>&nbsp;</p>
      </td>
    </tr>
  </table>
  </form>
<form name="delete" class="form" action="bocldelete.php" method="POST" onSubmit="return EliminaCl();">
  <p>
    <input type="hidden" name="clid" value="<?php echo $clid; ?>">
    <input type="submit" name="Submit" value="Elimina cliente" class="pulsanteRosso">
    <?php
	if ($haordini == 1) {
?>
  </p>
  <p class="form">Modalit&agrave; cancellazione:<br>
    <input type="radio" name="eliminaordini" value="0" checked>
    Elimina solo il cliente (conserva i suoi ordini)<br>
    <input type="radio" name="eliminaordini" value="1">
    Elimina anche gli ordini di questo cliente senza aggiornare la disponibilit&agrave; 
    degli articoli<br>
    <input type="radio" name="eliminaordini" value="2">
    Elimina anche gli ordini di questo cliente e aggiorna la disponibilit&agrave; 
    degli articoli<br> </p>
    <?php
	  }
?>
</form>
<form name="help"><input type="hidden" name="pagina" value="clienti.htm"></form>
</body>
</html>

<?php
	} else {
		die(Output("Cliente non trovato"));
	}
} else {
	die(Output("Cliente non trovato"));
}
?>