<?php
/****************************************************************************************
SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV

Copyright (C) 2006  Sylvain FATOME

This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; 
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program
(in the directory docs); 
if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
Boston, MA  02110-1301, USA.

Contact : galawa@free.fr
****************************************************************************************/

include ("../inc/config.inc.php");
?>
<?php require ("../inc/func.inc.php") ?>
<?php require ("../inc/func_log.inc.php") ?>
<?php require ("../inc/fic.inc.php") ?>
<?PHP
	Archivelog(@$HTTP_SESSION_VARS["code_log"]);
?>
<?php
	$td = strip_tags(trim(@$_GET['td']));
	$codecli = strip_tags(trim(@$_GET['cc']));
	$pointeur = strip_tags(trim(@$_GET["page"]));
	$pointeur--;
		
	if ($codecli <> "")
	{
		$row = lit_enr_cli($codecli);
		extract ($row);
		
		if ($td == "add")
		{
			$tab_ccli_id[] = 0;
			$tab_ccli_codecli[] = $codecli;
			$tab_ccli_telf[] = $cli_telf;
			$tab_ccli_fax[] = $cli_fax;
			$tab_ccli_maild[] = 0;
			$tab_ccli_mailc[] = 0;
			$tab_ccli_mailt[] = 0;

			$titre = "CREATION CONTACT";
		}

		if ($td == "edit")
		{
			$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
			mysql_select_db(DBNAME);
			$rech = "SELECT * FROM " .TBCCLI. " WHERE ccli_codecli = '$codecli'";
			$rs = mysql_query($rech)or die(mysql_error());
			$totalccli = mysql_num_rows($rs);
			if ($totalccli == 0)
			{
				echo "Aucun résultat";
			}
			else
			{
				 while ($row = mysql_fetch_array($rs))
				{
					extract ($row);
	
					$tab_ccli_id[] = $ccli_id;
					$tab_ccli_codecli[] = $ccli_codecli;
					$tab_ccli_func[] = $ccli_func;
					$tab_ccli_civilite[] = $ccli_civilite;
					$tab_ccli_prenom[] = $ccli_prenom;
					$tab_ccli_nom[] = $ccli_nom;
					$tab_ccli_telf[] = $ccli_telf;
					$tab_ccli_fax[] = $ccli_fax;
					$tab_ccli_telp[] = $ccli_telp;
					$tab_ccli_email[] = $ccli_email;
					$tab_ccli_mess[] = $ccli_mess;
					$tab_ccli_nota[] = $ccli_nota;
					$tab_ccli_maild[] = $ccli_maild;
					$tab_ccli_mailc[] = $ccli_mailc;
					$tab_ccli_mailt[] = $ccli_mailt;
				}
			}
			mysql_free_result($rs);
			mysql_close($conn);

			$titre = "EDITER CONTACTS";
		}
	}			
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SMI - ESPACE PRIVE : Contact Client</title>

<!-- Feuille de style pour les affichages courants -->
<link href="../inc/smi.css" rel="stylesheet" type="text/css">

<!-- Feuille de style & Script pour le menu -->
<link href="../inc/menu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="../coolmenus/coolmenus4.js"></script>

<!-- Scripts Javascript pour validation des formulaires -->
<script language="JavaScript" src="../inc/validator.js"></script>

<!-- Scripts Javascript pour affichages -->
<script language="JavaScript" src="../inc/aff.js"></script>

</head>

<body>

<p align="center"> <span class="titrepage"><?PHP echo $titre ?></span></p>
<p align="center"><span class="titre_gras">Pour le client : <?php echo $cli_ste; ?> </span></p>

<?PHP
			$ccli_id = $tab_ccli_id[$pointeur];
			$ccli_codecli = $tab_ccli_codecli[$pointeur];
			$ccli_func = $tab_ccli_func[$pointeur];
			$ccli_civilite = $tab_ccli_civilite[$pointeur];
			$ccli_prenom = $tab_ccli_prenom[$pointeur];
			$ccli_nom = $tab_ccli_nom[$pointeur];
			$ccli_telf = $tab_ccli_telf[$pointeur];
			$ccli_fax = $tab_ccli_fax[$pointeur];
			$ccli_telp = $tab_ccli_telp[$pointeur];
			$ccli_email = $tab_ccli_email[$pointeur];
			$ccli_mess = $tab_ccli_mess[$pointeur];
			$ccli_nota = $tab_ccli_nota[$pointeur];
			$ccli_maild = $tab_ccli_maild[$pointeur];
			$ccli_mailc = $tab_ccli_mailc[$pointeur];
			$ccli_mailt = $tab_ccli_mailt[$pointeur];
?>
<form name="ccli_maj" method="post" action="ccli_enr.php" onsubmit="return v.exec()">
    <input name="titre" type="hidden" id="titre" value="<?PHP echo $titre ?>">
    <input name="idccli" type="hidden" id="idccli" value="<?PHP echo $ccli_id ?>">
    <input name="code" type="hidden" id="code" value="<?PHP echo $ccli_codecli ?>">
  <table width="580"  border="0">
    <tr>
      <td width="33%">
	  <?PHP if ($td == "edit")
	  {
	  	echo ($pointeur+1)." / ".$totalccli;
	  }
	  else
	  { ?>
		&nbsp;
	  <?PHP } ?>
	  </td>
	  <?PHP
	  		$url_deb = $_SERVER["PHP_SELF"]."?td=".@$_GET["td"]."&cc=".@$_GET["cc"]."&page=1";
	  		if ((@$_GET["page"]-1) <=0)
				$npp = $totalccli;
			else
				$npp = @$_GET["page"]-1;
	  		$url_prec = $_SERVER["PHP_SELF"]."?td=".@$_GET["td"]."&cc=".@$_GET["cc"]."&page=".$npp;
			if ((@$_GET["page"]+1) > $totalccli)
				$nps = 1;
			else
				$nps = @$_GET["page"]+1;
	  		$url_suiv = $_SERVER["PHP_SELF"]."?td=".@$_GET["td"]."&cc=".@$_GET["cc"]."&page=".$nps;
	  		$url_fin = $_SERVER["PHP_SELF"]."?td=".@$_GET["td"]."&cc=".@$_GET["cc"]."&page=".$totalccli;
	  ?>
      <td width="33%"><div align="center"><span class="annot_std_it">(<img src="../img/oblig.gif" width="10" height="11"> : Saisie obligatoire) </span></div></td>
      <td width="33%">
	    <div align="right">
		  <?PHP if ($td == "edit")
		  {
		  ?>
		  <a href="<?PHP echo $url_deb; ?>"><img src="../img/deb.gif" width="22" height="22" border="0"></a> 
		  <a href="<?PHP echo $url_prec; ?>"><img src="../img/prec.png" width="22" height="22" border="0"></a>
		  <a href="<?PHP echo $url_suiv; ?>"><img src="../img/suiv.png" width="22" height="22" border="0"></a>
		  <a href="<?PHP echo $url_fin; ?>"><img src="../img/fin.gif" width="22" height="22" border="0"></a>
		  <?PHP
		  }
		  ?>
	    </div>
	  </td>
    </tr>
  </table>
  <table width="600"  border="0">
    <tr>
      <td width="20%" class="tfvNormal" id="f_func"><div align="right">Fonction</div></td>
      <td><input name="fonction" type="text" id="fonction" value="<?PHP echo $ccli_func ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_civil"><div align="right">Civilit&eacute;</div></td>
      <td width="84%"><select name="civil" size="1" id="civil">
          <?PHP

				// Création de la liste des civilités

				$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
				mysql_select_db(DBNAME);
				$rs = mysql_query("SELECT * FROM ".TBCIV." ORDER BY civ_desc");
				while ($resultat = mysql_fetch_array($rs)) 
				{
					extract($resultat);
					if ($ccli_civilite == $civ_code)
					{
						echo '<option value="'.$civ_code.'" selected>'.$civ_desc.'</option>';
					}
					else
					{
						echo '<option value="'.$civ_code.'">'.$civ_desc.'</option>';
					}
				}
				mysql_free_result($rs);
				mysql_close($conn);
				?>
        </select>
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_prenom"><div align="right">Pr&eacute;nom</div></td>
      <td><input name="prenom" type="text" id="prenom" value="<?PHP echo $ccli_prenom ?>" size="50" maxlength="50">
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_nom"><div align="right">Nom</div></td>
      <td><input name="nom" type="text" id="nom" value="<?PHP echo $ccli_nom ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toUpperCase();">
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_telf"><div align="right">T&eacute;l. Fixe </div></td>
      <td><input name="telf" type="text" id="telf" value="<?PHP echo $ccli_telf ?>" size="20" maxlength="20">
          <img src="../img/oblig.gif" width="10" height="11"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_fax"><div align="right">T&eacute;l&eacute;copieur</div></td>
      <td><input name="fax" type="text" id="fax" value="<?PHP echo $ccli_fax ?>" size="20" maxlength="20"></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_telp"><div align="right">Portable</div></td>
      <td><input name="telp" type="text" id="telp" value="<?PHP echo $ccli_telp ?>" size="20" maxlength="20">
      </td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_email"><div align="right">Email</div></td>
      <td><input name="email" type="text" id="email" value="<?PHP echo $ccli_email ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();">
		<?PHP if ($td == "edit") { ?>
      	<a href="mailto:<?PHP echo $ccli_email ?>"><img src="../img/mail.png" width="22" height="22" title="Envoyer e-mail" border ="0" align="absmiddle"></a></td>
		<?PHP } ?>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_mess"><div align="right">Messagerie</div></td>
      <td><input name="mess" type="text" id="mess" value="<?PHP echo $ccli_mess ?>" size="50" maxlength="50" onChange="javascript:this.value=this.value.toLowerCase();"></td>
    </tr>
    <tr>
      <td class="tfvNormal" id="f_mess"><div align="right">Accepte les emails... </div></td>
      <td>
	  <?PHP if ($ccli_mailc == "0") {
	  ?>
        <input type="checkbox" name="cpta" style="background : #FFFFFF;" value="cpta">Comptabilité 
	  <?PHP } else { ?>
        <input type="checkbox" name="cpta" style="background : #FFFFFF;" checked value="cpta">Comptabilité 
	  <?PHP } ?>
	  <?PHP if ($ccli_maild == "0") {
	  ?>
        <input type="checkbox" name="dir" style="background : #FFFFFF;" value="dir">Direction 
	  <?PHP } else { ?>
        <input type="checkbox" name="dir" style="background : #FFFFFF;" checked value="dir">Direction 
	  <?PHP } ?>
	  <?PHP if ($ccli_mailt == "0") {
	  ?>
        <input type="checkbox" name="tec" style="background : #FFFFFF;" value="tec">Technique 
	  <?PHP } else { ?>
        <input type="checkbox" name="tec" style="background : #FFFFFF;" checked value="tec">Technique 
	  <?PHP } ?>
	    <br>
        <span class="annot_std_it">(Vous pouvez choisir plusieurs possibilit&eacute;s pour recevoir les emails)</span></td>
    </tr>
    <tr>
      <td width="20%" class="tfvNormal" id="f_nota"><div align="right">Notes</div></td>
      <td><textarea name="nota" cols="50" id="nota"><?PHP echo $ccli_nota ?></textarea></td>
    </tr>
  </table>
  <p align="center">
    <?PHP if ($td == "add") { ?>
    <input name="RAZ" type="reset" id="RAZ" value="R&eacute;initialiser">
    <input name="enr" type="submit" id="enr" value="Enregistrer">
    <input name="annul" type="button" id="annul" value="Quitter" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">
	<br>
	<br>
    <input name="edit" type="button" id="edit" value="Passer en mode &eacute;dition/visualisation" onClick="javascript:; window.location=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&td=edit&page=1');">
    <?PHP } ?>
    <?PHP if ($td == "edit") { ?>
    <input name="mod" type="submit" id="mod" value="Modifier">
    <input name="del" type="submit" id="del" value="Supprimer">
    <input name="annul" type="button" id="annul" value="Quitter" onClick="javascript:; window.opener.location.reload(); self.close('fscomp');">
	<br>
	<br>
    <input name="add" type="button" id="add" value="Saisir un nouveau contact" onClick="javascript:; window.location=('ccli_maj.php?cc=<?PHP echo $codecli; ?>&td=add&page=1');">
    <?PHP } ?>
  </p>
</form>

<script>
// form fields description structure
var a_fields = {
	'fonction':{'l':'Fonction','r':false,'t':'f_func'},
	'civil':{'l':'Civilité','r':true,'f':'alpha','t':'f_civil'},
	'prenom':{'l':'Prénom','r':true,'t':'f_prenom','mx':50},
	'nom':{'l':'Nom','r': true,'t':'f_nom','mx':50},
	'telf':{'l':'Téléphone','r':true,'f':'unsigned','t':'f_telf','mx':20},
	'fax':{'l':'Télécopie','r':false,'f':'unsigned','t':'f_fax'},
	'telp':{'l':'Portable','r':false,'f':'unsigned','t':'f_telp'},
	'email':{'l':'E-mail','r':false,'f':'email','t':'f_email','mx':50},
	'mess':{'l':'Messagerie','r':false,'f':'email','t':'f_mess','mx':50},
	'nota':{'l':'Notes','r':false,'t':'f_nota'}
},

o_config = {
	'to_disable' : ['submit', 'RAZ'],
	'alert' : 1
}

// validator constructor call
var v = new validator('ccli_maj', a_fields, o_config);

</script>

</body>
</html>
