<?php
  function Affecte_Resultat_Article($ligne,$NoClient)
  {
    $no_type_rabais = 0;
      if($ligne2=Client::getClientByNoClient($NoClient))
      {
        $no_type_rabais=$ligne2['TypeRabais'];
      }
    $niv=0;
    $ligneb=$ligne;
    $noArticleRR = $ligneb['Description'];
    if (Stock::getStockByNoArticleRR(addslashes($noArticleRR)))
    { // stock existe
      $resultata = Article::getArticleStockByNoArticleRR(addslashes($noArticleRR));
    }
    else
    { // pas de stock
        $resultata=Article::getPasDeStockArticle(addslashes($noArticleRR));;
    }
    // TODO should we pass by reference ?
    foreach($resultata as $lignea) // on suit le chainage
    {
      $noArticleRR = $ligneb['Description'];
      if (Stock::getStockByNoArticleRR(addslashes($noArticleRR)))
      { // stock existe
        $resultata = Article::getArticleStockByNoArticleRR(addslashes($noArticleRR));
      }
      else
      { // pas de stock
        $resultata = Article::getArticleStockByNoArticleRR(addslashes($noArticleRR));
      }
        $ligneb=$lignea;
    }
    $result = "document.info.NoArticle.value='" . addslashes($ligneb['NoArticle']) . "';";
	if (isset($ligneb['DescriptionPerso']) && strlen($ligneb['DescriptionPerso'])!=0)
	{
      $result .= "document.info.Description.value='" . addslashes($ligneb['DescriptionPerso']) . "';";
	}
	else
	{
      $result .= "document.info.Description.value='" . addslashes($ligneb['Description']) . "';";
	}
    $result .= "document.info.TVA.value = '" . $ligneb['TVA']  . "';";
  	$result .= "document.info.GM.value = '" . $ligneb['GroupeMarchandise'] . "';";
    $result .= "document.info.Stock.value = '" . round($ligneb['EnStock']) . "';";
    if( (isset($ligneb['LieuxStock']) && strlen($ligneb['LieuxStock'])!= 0)) {
      $result .= "document.info.LieuxStock.value = '" . $ligneb['LieuxStock'] . "';";
    }
	$result .= "document.getElementById('Stock').innerText = '" . round($ligneb['EnStock']) . "';";
	if (isset($ligneb['LieuxStock']) && strlen($ligneb['LieuxStock'])!= 0)
	{
	  $result .= "document.getElementById('LieuxStock').innerText = ' (" . $ligneb['LieuxStock'] . ")';";
	}
	else
	{
	  $result .= "document.getElementById('LieuxStock').innerText = '';";
	}
	$focus_prix = false;
    if ($GLOBALS["Commande"]==1)
    {
  	  $result .= "document.info.Rabais.value = '-" . $ligneb['Rabais'] . "';";
      $result .= "document.info.Prix.value ='" . $ligneb['PrixImportateur']  . "';";
    }
  	else
  	{
  	  $result .= "document.info.Rabais.value = '" . $ligneb['RabaisType'.$no_type_rabais] . "';";
      if($ligneb['PrixPropre']!=0)
      {
        $result .= "document.info.Prix.value ='" . $ligneb['PrixPropre']  . "';";
      }
      else
      {
        $result .= "document.info.Prix.value ='" . $ligneb['PrixImportateur']  . "';";
		if ($ligneb['PrixImportateur'] == 0)
		{
		  $focus_prix = true;
		}
      }
  	}
  	if(isset($GLOBALS["NbArticles"]) && $GLOBALS["NbArticles"] != 0)
  	{
  	  $result .= "document.info.Quantite.value = '".$GLOBALS["NbArticles"]."';";
  	}
  	else
    {
  	  $result .= "document.info.Quantite.value = '1.00';";
	  if ($focus_prix)
	  {
  	    $result .= "document.info.Prix.select();";
	  }
	  else
	  {
  	    $result .= "document.info.Quantite.select();";
	  }
  	}
    return $result;
  }
  function Affecte_Resultat_Client($ligne,$Mode)
  {
    $result = "";
    if($Mode==5)
    {
      $result .= "document.info.NoClient2.value = '".$ligne['NoClient']."';";
      $result .= "document.info.Nom2.value = '".addslashes($ligne['Nom'])."';";
      $result .= "document.info.Prenom2.value = '".addslashes($ligne['Prenom'])."';";
    }
    else
    {
      $result .= "document.info.NoClient.value = '".$ligne['NoClient']."';";
      $result .= "document.info.Nom.value = '".addslashes($ligne['Nom'])."';";
      $result .= "document.info.Prenom.value = '".addslashes($ligne['Prenom'])."';";
    }
  	if($Mode<3)
  	{
   	  if(!empty($ligne['Natel']))
   	  {
   	    $result .= "document.info.Telephone.value = '".Format_Telephone($ligne['Natel'])."';";
   	  }
   	  else if(!empty($ligne['TelPriv']))
   	  {
   	    $result .= "document.info.Telephone.value = '".Format_Telephone($ligne['TelPriv'])."';";
   	  }
   	  else if(!empty($ligne['TelProf']))
   	  {
   		$result .= "document.info.Telephone.value = '".Format_Telephone($ligne['TelProf'])."';";
   	  }
   	  else
   	  {
   		$result .= "document.info.Telephone.value = '';";
   	  }
    }
    switch ($Mode)
    {
      case 2:
        $result .= "efface_vhc();";
        $result .= "recherche_alerte_ajax(".$ligne['NoClient'].",'');";
        $result .= "recherche_vhc_ajax(0);";
        break;
      case 4:
        $result .= "recherche_alerte_ajax(".$ligne['NoClient'].",'');";
        $result .= "recherche_vhc_ajax(1);";
        break;
    }
    return $result;
  }
  function Affecte_Resultat_Vehicule($ligne,$Mode)
  {
    $result = "";
    if($Mode==1)
    {
      $result .= "recherche_alerte_ajax(".$ligne['Client'].",'".$ligne["NoChasis"]."');";
	  $result .= "document.info.NoChasis.value = '".addslashes($ligne['NoChasis'])."';";
	  $result .= "document.info.Marque.value = '".addslashes($ligne['MarqueModel'])."';";
	  $result .= "document.info.Model.value = '".addslashes($ligne['Model'])."';";
	  $result .= "document.info.Km.value = '".addslashes($ligne['Km'])."';";
	  $result .= "document.info.NoPlaque.value = '".addslashes($ligne['NoPlaque'])."';";
    }
    else if($Mode==2)
    {
      $result .= "document.info.NoChasisAchat.value = '".addslashes($ligne['NoChasis'])."';";
    }
    else 
    {
      $result .= "recherche_alerte_ajax(".$ligne['Client'].",'".$ligne["NoChasis"]."');";
	  $result .= "document.info.NoChasis.value = '".addslashes($ligne['NoChasis'])."';";
	  $result .= "document.info.Vehicule.value = '".addslashes($ligne['Model'])."';";
	  $result .= "document.info.Km.value = '".addslashes($ligne['Km'])."';";
	  $result .= "document.forms['info'].service.options.length = 1;";
	  $result .= "document.forms['info'].service.selectedIndex = 0;";
      if ($ligne2 = ChassisModel::getChassisModelByNoChassis($ligne['NoChasis']))
      {
	    $result .= "document.info.vhc.value = '".$ligne2["Id"]."';";
		$resultat3 = ServiceVHC::getServiceVHCByVhc($ligne2["Id"]);
		$pos = 0;
		$pos_service = 0;
		$arr_km = array();
		$km_pos = array();
	    foreach ($resultat3 as $ligne3)
	    {
	      $pos++;
		  switch ($ligne2['Type_Service'])
		  {
		    case "Texte":
	        $result .= "add_service_option('".$ligne3['Id']."','".$ligne3['Nom']."','".$ligne3['Duree']."');";
			$pospar = strpos($ligne3['Nom'], '(');
			if ($pospar === false) { }
			else
			{
			  $kms = substr($ligne3["Nom"], $pospar);
			  $kms = str_replace("(", "", $kms);
			  $kms = str_replace(")", "", $kms);
        $kmsarr = explode("-", $kms);
			  foreach ($kmsarr as $km)
			  {
          array_push($arr_km, intval($km));
          $km_pos[intval($km)] = $pos;
          //$result .= "alert('".$km."');";
		    }
		    }
			break;
			default:
	        $result .= "add_service_option('".$ligne3['Id']."','Service ".$ligne3['Km']."','".$ligne3['Duree']."');";
	        if (($pos_service == 0)&&($ligne['Km'] + 500 < $ligne3['Km']))
	        {
	          $pos_service = $pos;
            }
			break;
		  }
	    }
		sort($arr_km);
	    foreach ($arr_km as $km)
		{
	      if (($pos_service == 0)&&(intval($ligne['Km']) + 500 < $km))
	      {
		    //$result .= "alert('".$km."');";
	        $pos_service = $km_pos[$km];
          }
		}
		$resultat3 = VHCOptions::getVHCOptionsAndServiceOptionsByVhc($ligne2["Id"]);
		$pos = 0;
		//$pos_service = 0;
		foreach ($resultat3 as $ligne3)
		{
		  $result .= "add_service_option_item('".$ligne3["Id"]."','".$ligne3["Nom_court"]."','".$ligne3["Duree"]."');";
		  // TODO
		}
	    if ($pos_service != 0)
	    {
		  $GLOBALS["Special"] = $pos_service;
		  //$GLOBALS["Special"] = "if (confirm('Service ?'))";
		  //$GLOBALS["Special"] .= "{";
	      //$GLOBALS["Special"] .= "window.opener.document.forms['info'].service.selectedIndex = $pos_service;";
		  //$GLOBALS["Special"] .= "window.opener.duree_service();";
		  //$GLOBALS["Special"] .= "}";
		  //$result .= "if (confirm('Service ?'))";
		  //$result .= "{";
	      //$result .= "document.forms['info'].service.selectedIndex = $pos_service;";
		  //$result .= "duree_service();";
		  //$result .= "}";
	      
	    }
      }
      else 
      {
	    $result .= "document.info.vhc.value = '0';";
      }
      $result .= "document.info.Temps.focus();";
    }
    return $result;
  }
  function Requette_Recherche($champ, $type, $data, $special=0)
  {
    $type_interne=$type%100;
    $out = "";
    switch($type_interne)
    {
      case 0: /* texte */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 1: /* chiffre */
        if($special==0)
        {
          if((!empty($data[0]))&&(!empty($data[1])))
          {
            $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
          }
          else if(!empty($data[0]))
          {
            $out="$champ = '" . $data[0] . "'";
          }
        }
        else
        {
          if((!empty($data[0]))&&(!empty($data[1])))
          {
            $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
          }
          else if(!empty($data[0]))
          {
            $out="$champ != '" . $data[0] . "'";
          }
        }
      break;
      case 2: /* date */
        $erreur=0;
        $out="";
        $date1="";
        $date2="";
		
        if(!empty($data[0]))
		{
		  $date1 = substr($data[0],6,4)."-".substr($data[0],3,2)."-".substr($data[0],0,2);
		}
        if(!empty($data[1]))
		{
		  $date2 = substr($data[1],6,4)."-".substr($data[1],3,2)."-".substr($data[1],0,2);
		}

		
		
        /*if((!empty($data[0]))and(!empty($data[1]))and(!empty($data[2])))
        {
          $tmp1=$data[2];
          $tmp2=$data[1];
          $tmp3=$data[0];
          if (strlen($tmp1)<4)
          {
            $tmp1 = substr("2000",0,4-strlen($tmp1)). $tmp1;
          }
    		  else if (strlen($tmp1)>4)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp2)<2)
          {
            $tmp2 = substr("01",0,2-strlen($tmp2)). $tmp2;
          }
    		  else if (strlen($tmp2)>2)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp3)<2)
          {
            $tmp3 = substr("01",0,2-strlen($tmp3)). $tmp3;
          }
    		  else if (strlen($tmp3)>2)
    		  {
    		  	$erreur=1;
    		  }
    		  $date1 .= $tmp1 . "-" . $tmp2 . "-" . $tmp3;
    		}
        if((!empty($data[3]))and(!empty($data[4]))and(!empty($data[5])))
        {
          $tmp1=$data[5];
          $tmp2=$data[4];
          $tmp3=$data[3];
          if (strlen($tmp1)<4)
          {
            $tmp1 = substr("2000",0,4-strlen($tmp1)). $tmp1;
          }
    		  else if (strlen($tmp1)>4)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp2)<2)
          {
            $tmp2 = substr("01",0,2-strlen($tmp2)). $tmp2;
          }
    		  else if (strlen($tmp2)>2)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp3)<2)
          {
            $tmp3 = substr("01",0,2-strlen($tmp3)). $tmp3;
          }
    		  else if (strlen($tmp3)>2)
    		  {
    		  	$erreur=1;
    		  }
    		  $date2 .= $tmp1 . "-" . $tmp2 . "-" . $tmp3;
    		}*/
    		if ($erreur==1)
    		{
    		  $out="";
    		}
    		else
    		{
          if($special==0)
          {
    		    if((!empty($date1))and(!empty($date2)))
    		    {
              $out="$champ >= '" . $date1 . "' AND $champ <= '" . $date2 . "'";
    		    }
    		    else if(!empty($date1))
    		    {
              $out="$champ = '" . $date1 . "'";
    		    }
          }
          else
          {
    		    if((!empty($date1))and(!empty($date2)))
    		    {
              $out="$champ >= '" . $date1 . "' AND $champ <= '" . $date2 . "'";
    		    }
    		    else if(!empty($date1))
    		    {
              $out="$champ != '" . $date1 . "'";
    		    }
    		  }
    		}
			//echo $out;
      break;
      case 3: /* type allocution */
      break;
      case 4: /* NPA */
        if($special==0)
        {
	      if((!empty($data[0]))&&(!empty($data[1])))
          {
            $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
    		  }
    		  else if(!empty($data[0]))
    		  {
    		    $out="$champ = '" . $data[0] . "'";
    		  }
        }
        else
        {
	      if((!empty($data[0]))&&(!empty($data[1])))
          {
            $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
    		  }
    		  else if(!empty($data[0]))
    		  {
    		    $out="$champ != '" . $data[0] . "'";
    		  }
        }
      break;
      case 5: /* Localite */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 6: /* Pays */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 7: /* Telephone */
        //$out=addslashes($data);
		if (!empty($data))
		{
	      $tel=$data;
		  $tel=str_replace(" ", "", $tel);
		  $tel=str_replace("/", "", $tel);
		  $tel=str_replace(".", "", $tel);
		  $tel=str_replace("+", "00", $tel);
		  if (strpos($tel, '%') !== false)
		  {
		    $out="$champ LIKE '%".addslashes($tel)."%'";
		  }
		  else
		  {
		  if (strlen($tel) >= 2)
		  {
		    if (substr($tel, 0, 2) == "00")
		    {
		    }
		    else if (substr($tel, 0, 1) == "0")
		    {
		      $tel = "0041" . substr($tel, 1);
		    }
			else
			{
			  $tel = "004122" . $tel;
			}
		  }
		  //echo $tel;
          $out="$champ = '".addslashes($tel)."'";
		  }
		}
		//$out=Compare_Sans_Accents($champ,addslashes($data));
      break;
      case 8: /* Email */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 9: /* Langue */
        $out=$data;
      break;
      case 10: /* Type client */
      break;
      case 11: /* Code rabais */
      break;
      case 12: /* Moyen de payement */
        if(!empty($data))
        {
    		  $out="$champ = $data";
        }
      break;
      case 13: /* Long texte */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents_Multiple($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 14: /* Client */
        if(!empty($data[0]))
        {
          if(is_numeric($data[0]))
          {
  	        if((!empty($data[0]))&&(!empty($data[1])))
            {
              if($champ == "NoClient" && $special != 2)
              {
                $out="(($champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "') OR (NoClient2 >= '" . $data[0] . "' AND NoClient2 <= '" . $data[1] . "'))";
              }
              else
              {
                $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
              }
    		    }
    		    else if(!empty($data[0]))
    		    {
              if($champ == "NoClient" && $special != 2)
              {
      		      $out="($champ = '" . $data[0] . "' OR NoClient2 = '" . $data[0] . "')";
              }
              else
              {
      		      $out="$champ = '" . $data[0] . "'";
              }
            }
          }
          else
          {
            if(!empty($data[1]))
            {
              $resultats=Client::getClientByNoms($data[0], $data[1]);
              $nb_resultats=0;
              $listerech="";
              foreach($resultats as $lignes)
              {
                if($nb_resultats!=0)
                {
                  $listerech.=", ";
                }
                $listerech.=$lignes['NoClient'];
                $nb_resultats++;
              }
              if($nb_resultats!=0)
                if($champ == "NoClient" && $special != 2)
                {
                  $out="($champ IN ($listerech) OR NoClient2 IN ($listerech))";
                }
                else
                {
                  $out="$champ IN ($listerech)";
                }
              else
                $out="1=0";
            }
            else
            {
              $requettes="SELECT NoClient FROM clients WHERE ".Compare_Sans_Accents("Nom",addslashes($data[0]));
              $resultats=Connection::executeRawQueryWithfetchAll($requettes);
              $nb_resultats=0;
              $listerech="";
              foreach($resultats as $lignes)
              {
                if($nb_resultats!=0)
                {
                  $listerech.=", ";
                }
                $listerech.=$lignes['NoClient'];
                $nb_resultats++;
              }
              if($nb_resultats!=0)
                if($champ == "NoClient" && $special != 2)
                {
                  $out="($champ IN ($listerech) OR NoClient2 IN ($listerech))";
                }
                else
                {
                  $out="$champ IN ($listerech)";
                }
              else
                $out="1=0";
            }
          }
        }
      break;
      case 15: /* Type Rabais */
        $out=$data;
      break;
      case 16: /* Type Rabais base articles */
        $out=addslashes($data);
      break;
      case 17: /* No Matricule */
        if((!empty($data[0]))and(!empty($data[1]))and(!empty($data[2])))
        {
          $out="$champ = '".$data[0].$data[1].$data[2]."'";
    		}
      break;
      case 18: /* Date et heure */
        $erreur=0;
        $out="";
        $date1="";
        $date2="";
        if(!empty($data[0]))
        {
          $date1 = substr($data[0],6,4)."-".substr($data[0],3,2)."-".substr($data[0],0,2);
        }
        if(!empty($data[1]))
        {
          $date2 = substr($data[1],6,4)."-".substr($data[1],3,2)."-".substr($data[1],0,2);
        }
        /*if((!empty($data[0]))and(!empty($data[1]))and(!empty($data[2])))
        {
          $tmp1=$data[2];
          $tmp2=$data[1];
          $tmp3=$data[0];
          if (strlen($tmp1)<4)
          {
            $tmp1 = substr("2000",0,4-strlen($tmp1)). $tmp1;
          }
    		  else if (strlen($tmp1)>4)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp2)<2)
          {
            $tmp2 = substr("01",0,2-strlen($tmp2)). $tmp2;
          }
    		  else if (strlen($tmp2)>2)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp3)<2)
          {
            $tmp3 = substr("01",0,2-strlen($tmp3)). $tmp3;
          }
    		  else if (strlen($tmp3)>2)
    		  {
    		  	$erreur=1;
    		  }
    		  $date1 .= $tmp1 . "-" . $tmp2 . "-" . $tmp3;
    		}
        if((!empty($data[3]))and(!empty($data[4]))and(!empty($data[5])))
        {
          $tmp1=$data[5];
          $tmp2=$data[4];
          $tmp3=$data[3];
          if (strlen($tmp1)<4)
          {
            $tmp1 = substr("2000",0,4-strlen($tmp1)). $tmp1;
          }
    		  else if (strlen($tmp1)>4)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp2)<2)
          {
            $tmp2 = substr("01",0,2-strlen($tmp2)). $tmp2;
          }
    		  else if (strlen($tmp2)>2)
    		  {
    		  	$erreur=1;
    		  }
          if (strlen($tmp3)<2)
          {
            $tmp3 = substr("01",0,2-strlen($tmp3)). $tmp3;
          }
    		  else if (strlen($tmp3)>2)
    		  {
    		  	$erreur=1;
    		  }
    		  $date2 .= $tmp1 . "-" . $tmp2 . "-" . $tmp3;
    		}*/
    		if ($erreur==1)
    		{
    		  $out="";
    		}
    		else
    		{
    		  if((!empty($date1))and(!empty($date2)))
    		  {
                $out="$champ >= '" . $date1 . " 00:00:00' AND $champ <= '" . $date2 . " 23:59:59'";
    		  }
    		  else if(!empty($date1))
    		  {
                $out="$champ >= '" . $date1 . " 00:00:00' AND $champ <= '" . $date1 . " 23:59:59'";
    		  }
    		}
      break;
      case 19: /* Decimal */
        if($special==0)
        {
  	    if((strlen($data[0])!=0)&&(strlen($data[1])!=0))
        {
          $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
    		}
    		else if(strlen($data[0])!=0)
    		{
    		  $out="$champ = '" . $data[0] . "'";
    		}
    		else
    		{
    		}
	   }
	   else
	   {
    		if(strlen($data[0])!=0)
    		{
    		  $out="$champ != '" . $data[0] . "'";
    		}
	   }
      break;
      case 20: /* Texte avec recherche sans espace nom+RR */
        if(!empty($data))
        {
        	$out="articles.".$champ . "RR LIKE '" . addslashes(Texte_Sans_Espace($data)) . "%'";
        }
      break;
      case 21: /* Type facture */
        if($special==0)
        {
          if(!empty($data))
          {
    		    $out="$champ = '$data'";
          }
        }
        else
        {
          if(!empty($data))
          {
    		    $out="$champ != '$data'";
          }
    		}
      break;
      case 22: /* Genre facture */
        if($special==0)
        {
          if(!empty($data))
          {
    		    $out="$champ = '$data'";
          }
        }
        else
        {
          if(!empty($data))
          {
    		    $out="$champ != '$data'";
          }
    		}
      break;
      case 23: /* Type vehicule */
        if($special==0)
        {
          if(!empty($data))
          {
    		    $out="$champ = '$data'";
          }
        }
        else
        {
          if(!empty($data))
          {
    		    $out="$champ != '$data'";
          }
    		}
      break;
      case 24: /* Status vehicule */
        if($special==0)
        {
          if(!empty($data))
          {
    		    $out="$champ = '$data'";
          }
        }
        else
        {
          if(!empty($data))
          {
    		    $out="$champ != '$data'";
          }
    		}
      break;
      case 25: /* NoChasis */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 26: /* Vendu */
      break;
      case 27: /* Description */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 28: /* Vehicule */
	    $arr = str_split($data);
		$str = "%".implode("%", $arr);
	    $out = "T.NoClient IN (SELECT V.Client FROM vehicules AS V WHERE V.Model LIKE '".addslashes($data)."%')";
      break;
      case 29: /* No plaques */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
      break;
      case 30: /* Status atelier */
        if($special==0)
        {
          $len=strlen($data);
          if($len>0)
          {
    		    $out="$champ = $data";
          }
        }
        else
        {
          $len=strlen($data);
          if($len>0)
          {
    		    $out="$champ != $data";
          }
    		}
      break;
      case 31: /* Vendeur */
        if(!empty($data))
        {
    		  $out="$champ = $data";
        }
      break;
      case 32: /* NoCommande */
      break;
      case 33: /* Commande ouverte, envoyée, reçue */
        switch($data)
        {
          case "O":
            $out="NoFourniseur = ''";
          break;
          case "E":
            $out="NoFourniseur != '' AND Recu != 'O'";
          break;
          case "R":
            $out="NoFourniseur != '' AND Recu = 'O'";
          break;
    		}
      break;
      case 34: /* texte majuscules */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
    		}
      break;
      case 35: /* Texte Sans Espaces */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
    		}
  	  break;
      case 36: /* Categories Articles */
        $out=$data;
      break;
      case 38: /* No chassis cle primaire */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
    		}
  	  break;
	  case 39: /* NbStock ou NbTransfert Dans un autre table par garage */
  	    if((strlen($data[0])!=0)&&(strlen($data[1])!=0))
        {
          $out="$champ >= '" . $data[0] . "' AND $champ <= '" . $data[1] . "'";
    		}
    		else if(strlen($data[0])!=0)
    		{
    		  $out="$champ = '" . $data[0] . "'";
    		}
    		else
    		{
    		}
  	  break;
	  case 40: /* LieuxStoquage Dans un autre table par garage */
        if($special==0)
        {
          if(!empty($data))
          {
            $out=Compare_Sans_Accents($champ,addslashes($data));
          }
        }
        else
        {
          if(!empty($data))
          {
            $out=Diff_Sans_Accents($champ,addslashes($data));
          }
        }
  	  break;
      case 41: /* Allocution */
        if(!empty($data))
        {
    		  $out="$champ = '$data'";
        }
      break;
      case 42: /* Boolean */
        if(!empty($data) && $data == "1")
        {
    		  $out="$champ = 1";
        }
		else
		{
    		  $out="$champ = 0";
		}
      break;
      case 43: /* Types client */
        if(!empty($data))
        {
    		  $out="$champ = '$data'";
        }
  	  break;
      case 44: /* Impression entete */
        if(!empty($data))
        {
    		  $out="$champ = '$data'";
        }
  	  break;
      case 45: /* Type garantie */
        if(!empty($data))
        {
    		  $out="$champ = '$data'";
        }
  	  break;
      case 46: /* Type vehicule */
        if(!empty($data))
        {
    		  $out="$champ = '$data'";
        }
  	  break;
  	}
   	return $out;
  }

?>