<?php
// $Id: recherche.php,v 1.11 2008-04-23 14:33:04 fgiva Exp $
     $type_rech="materiel";
     if (isset ($_GET['typerech']))
        $type_rech=$_GET['typerech'];

     echo "<div>";

     echo "<FORM action='../scr/tdb.php?typerech=$type_rech' method=POST  name=f1 >";
     echo "<table class='global' border='0' cellpadding='5'  cellspacing='5'>";
     echo "<tr>";
     if ($type_rech=="materiel")
        echo "<td colspan='3'><b>Recherche Globale MATERIEL</b></td></tr>";
     else
        echo "<td colspan='3'><b>Recherche Globale INTERVENTIONS EN COURS</b></td></tr>";
     echo "<tr>";
     echo "<td>";

     echo "<input type='image' alt='Tout' align='top' vspace='3'"; // onclick='f1.recherche.value=\"\"'
     if(file_exists("../dyn/custom/img/loupe.png")) {
        echo " src='../dyn/custom/img/loupe.png' border='0' hspace='4' align='middle'>";  //<img
     }else {
        echo " src='../img/loupe.png'  border='0' hspace='4' align='middle'>";
     }
     echo "<input type='text' name='recherche' value='".$recherche."' class='champFormulaire' >";
     echo "<input type='submit' name='s1' value='Rechercher' style=".$styleBouton."' >";
     echo "<img src='../img/fleche_droite.png' align='bottom'  border='0'>";
     if ($type_rech=="materiel")
        echo "<a href='../scr/tdb.php?recherche=$recherche&typerech=interventions'> INTERVENTIONS EN COURS </a>";
     else
        echo "<a href='../scr/tdb.php?recherche=$recherche'> MATERIEL </a>";

     echo "<br>";

     include ("../sql/".$dsn['phptype']."/tdb.inc");
     $ntab=0;
     foreach($soustableau as $stab) {
        if ($typerech[$ntab]==$type_rech) {
           $nat=$sousnature[$ntab];
           include ("../sql/".$dsn['phptype']."/".$stab.".inc");
           if ($recherche) {
               $sqlw="";
               foreach($champRecherche as $elem) {
                   if (substr($elem,0,1)!='*') {
                       if (!get_magic_quotes_gpc()) { // magic_quotes_gpc = Off
                           $sqlw = $sqlw." ".$elem." like '%".AddSlashes($recherche)."%' or ";
                       }else{  // magic_quotes_gpc = On
                           $sqlw = $sqlw." ".$elem." like '%".$recherche."%' or ";
                       }
                   }
               }
               $sqlw=substr($sqlw,0,strlen($sqlw)-3).")";
               if ($selection!="")
                   $sqlC="select count(*) from ".$table." ".$selection." and (".$sqlw;
               else
                   $sqlC="select count(*) from ".$table." where (".$sqlw;
           } else {
               if ($selection!="")
                   $sqlC="select count(*) from ".$table." ".$selection;
               else
                   $sqlC="select count(*) from ".$table;
           }
           $nbligne=$db->getOne($sqlC);
           if ($nbligne>0) {
               if ($type_rech=='interventions')
                   $urltype="&typerech=$type_rech";
               else
                   $urltype="";
               if ($recherche) {
                   echo "<div><a href='../scr/tab.php?obj=$stab&nat=$nat&recherche=$recherche$urltype'><img src=$ico alt='' title='' /> $ent [$recherche]</a> --- $nbligne occurrence(s)</div>";
               } else {
                   echo "<div><a href='../scr/tab.php?obj=$stab&nat=$nat$urltype'><img src=$ico alt='' title='' /> $ent</a> --- $nbligne occurrence(s)</div>";
               }
               echo "<br>";
           }
        }
        $ntab++;
     }
     echo "<br>";

     echo "</td>";
     echo "</tr>";
     echo "</table>";
     echo "</form>";
     echo "</div>";
?>