Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

fiche_search.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00020 /* $Revision: 1.19 $ */
00025 include_once ("ac_common.php");
00026 include_once ("poste.php");
00027 include_once ("postgres.php");
00028 include_once("jrn.php");
00029 /* Admin. Dossier */
00030 $rep=DbConnect();
00031 include_once ("class_user.php");
00032 $User=new cl_user($rep);
00033 $User->Check();
00034 
00035 //determine focus:
00036 if ( isset ( $_POST['search']) )
00037 {
00038   html_page_start($User->theme,"onLoad=\"window.focus();SetFocus('select0',0)\"");
00039 } else
00040 {
00041   html_page_start($User->theme,"onLoad=\"window.focus();SetFocus('fic_search',0)\"");
00042 }
00043 
00044 
00045 
00046 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00047   echo "You must choose a Dossier ";
00048   exit -2;
00049 }
00050 
00051 include_once ("check_priv.php");
00052 $cn=DbConnect($_SESSION['g_dossier']);
00053 // Get The priv on the selected folder
00054 if ( $User->CheckAction($cn,FICHE_READ) == 0 ){
00055     /* Cannot Access */
00056     echo '<h2 class="error"> Vous n\' avez pas accès</h2>';
00057     return;
00058 }
00059 
00060 function get_list_fiche($p_cn,$get,$p_jrn)
00061 {
00062   $sql="select $get as fiche from jrn_def where jrn_def_id=$p_jrn";
00063   $Res=ExecSql($p_cn,$sql);
00064 
00065   // fetch it
00066   $Max=pg_NumRows($Res);
00067   if ( $Max==0) {
00068     echo_warning("No rows");
00069     exit();
00070   }
00071   // Normally Max must be == 1
00072   $list=pg_fetch_array($Res,0);
00073   if ( $list['fiche']=="") {
00074     echo_warning("Journal mal paramètré");
00075     exit();
00076   }
00077   $list_fiche=$list['fiche'];
00078   return $list_fiche;
00079 }
00080 ?>
00081 <script language="javascript">
00082 function SetData (name_ctl,value,value_2,value_3,value_4,value_5,value_6) {
00083   self.opener.SetData(name_ctl,value,value_2,value_3,value_4,value_5,value_6);
00084   window.close();
00085 }
00086 </script>
00087 <?
00088 $cn=DbConnect($_SESSION['g_dossier']);
00089 $r="";
00090 
00091 foreach ($HTTP_GET_VARS as $key=>$element) {
00092   // The value are e_name e_type e_PHPSESSID
00093   ${"e_$key"}=$element;
00094   echo_debug('fiche_search.php',__LINE__,"e_$key =$element<br>");
00095 
00096 }
00097 $e_fic_search=(isset ($_POST['fic_search']))?$_POST['fic_search']:"";
00098 
00099 $r.="<FORM METHOD=\"POST\" ACTION=\"".$_SERVER['REQUEST_URI']."\">";
00100 $r.="Recherche : ".'<INPUT TYPE="TEXT" NAME="fic_search" VALUE="'.$e_fic_search.'">';
00101 $r.='<INPUT TYPE="submit" name="search" value="Go">';
00102 //$r.="</FORM>";
00103 $r.="<div>";
00104 echo $r;
00105 $r="";
00106 
00107 // Show result of the search 
00108 if ( isset ( $_POST['search']) )  {
00109 
00110   // Get the field from database
00111   if ( $e_type == 'deb' ) {
00112     $get='jrn_def_fiche_deb';
00113     $list_fiche=get_list_fiche($cn,$get,$_GET['p_jrn']);
00114     $sql="select * from vw_fiche_attr where fd_id in ( $list_fiche )";
00115   }
00116   elseif ( $e_type == 'cred' ) {
00117     $get='jrn_def_fiche_cred';
00118     $list_fiche=get_list_fiche($cn,$get,$_GET['p_jrn']);
00119     $sql="select * from vw_fiche_attr where fd_id in ( $list_fiche )";
00120   }
00124   elseif ( $e_type == 'all' ) {
00125     $sql="select * from vw_fiche_attr where true";
00126   }
00127   // if e_type contains a list of value for filtering on fiche_def_ref.frd_id
00128   else{
00129     $list_fiche=$e_type;
00130     $sql="select * from vw_fiche_attr where frd_id in ( $list_fiche )";
00131     //    $sql="select * from vw_fiche_attr ";
00132   }
00133 // e_fic_search contains the pattern
00134 
00135   if (strlen(trim($e_fic_search) ) == 0 ) {
00136     $Res=ExecSql($cn,$sql); 
00137   } else {
00138     $Res=ExecSql($cn,"$sql and upper(vw_name) like upper('%$e_fic_search%')"); 
00139   }
00140 
00141   // Test whether rows are returned
00142  if ( ($Max = pg_NumRows($Res) ) == 0 ) {
00143    echo_warning("Pas de fiche trouvée");
00144    return;
00145  } 
00146  // Show the cards
00147  for ( $i=0; $i < $Max; $i++)  {
00148 
00149   //set focus on first "Select" button.
00150    
00151   $row=pg_fetch_array($Res,$i);
00152   // if quick code is empty pass ( it not used for the contact)
00153   if (trim($row['quick_code']) == "")
00154     continue;
00155 
00156 
00157   if ( $i %2  == 0 ) 
00158     $class="even";
00159   else
00160     $class="odd";
00161   $text=FormatString($row['vw_name']);
00162   $r.="<span class=\"$class\">";
00163   $qcode=    $row['quick_code'] ;
00164 
00165   $r.=sprintf ('<input name="%s" type="button" onClick="'."SetData('%s','%s','%s','%s','%s','%s','%s')".'" value="%s">',
00166         "select" . $i,
00167               $e_name,
00168               $row['quick_code'] ,
00169               $text, 
00170               $row['vw_sell'], 
00171               $row['vw_buy'], 
00172               $row['tva_id'], 
00173                $row['tva_label']  ,
00174                $qcode
00175                );
00176   $r.="&nbsp;".$row['vw_name'];
00177   if ( $row['vw_addr'] !="")
00178     $r.="<br><font size=-1>Adresse:&nbsp;".$row['vw_addr']."&nbsp;".$row['vw_cp']."</font>";
00179   $r.="</span>";
00180  }
00181 }
00182 $r.="</div>";
00183 $r.="</FORM>";
00184 echo $r;
00185 
00186 ?>
00187 
00188 <?
00189 
00190 html_page_stop();
00191 ?>