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

poste_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.16 $ */
00024 include_once ("ac_common.php");
00025 html_page_start($_SESSION['g_theme'],"onLoad='window.focus();'");
00026 include_once ("postgres.php");
00027 include_once("jrn.php");
00028 /* Admin. Dossier */
00029 $rep=DbConnect();
00030 include_once ("class_user.php");
00031 $User=new cl_user($rep);
00032 $User->Check();
00033 
00034 echo JS_SEARCH_POSTE;
00035 
00036 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00037   echo "You must choose a Dossier ";
00038   exit -2;
00039 }
00040 
00041 $c_comment="";
00042 $c_class="";
00043 
00044 $condition="";
00045 $cn=DbConnect($_SESSION['g_dossier']);
00046 if ( isset($_POST['search']) ) {
00047   $c1=0;
00048   foreach( $HTTP_POST_VARS as $key=>$element){
00049     ${"$key"}=$element;
00050   }
00051   if ( strlen(trim($p_comment)) != 0 ) {
00052     $c_comment=" where upper(pcm_lib) like upper('%$p_comment%')";
00053     $c1=1;
00054   }
00055   if ( strlen(trim($p_class)) != 0 &&
00056        (string) $p_class == (int)(string) $p_class) {
00057     if ($c1==1) 
00058       $clause=" and ";
00059     else
00060       $clause = " where ";
00061     $c_class=sprintf(" %s pcm_val::text like '%s%%'",$clause,$p_class);
00062 
00063     }
00064   
00065 
00066   $condition=$c_comment.$c_class;
00067 }
00068 $url="";
00069 // Filter ???
00070 if ( isset($_GET['filter'])) {
00071   $url="?filter=1";
00072   // There is a filter, the value of the filter is the journal id, we
00073   // have to find what account are available
00074   $SqlCred="";
00075   // Load the property
00076   $l_line=GetJrnProperty($cn,$_GET['p_jrn']);
00077   if ( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 ) {
00078     $valid_cred=split(" ",$l_line['jrn_def_class_cred']);
00079 
00080     // Creation query
00081     foreach ( $valid_cred as $item_cred) {
00082       if ( strlen (trim($item_cred))) {
00083         echo_debug('poste_search.php',__LINE__,"l_line[jrn_def_class_cred] $l_line[jrn_def_class_cred] item_cred $item_cred");
00084         if ( strstr($item_cred,"*") == true ) {
00085           $item_cred=strtr($item_cred,"*","%");
00086           $Sql=" pcm_val like '$item_cred' or";
00087         } else {
00088           $Sql=" pcm_val = '$item_cred' or";
00089         }
00090         $SqlCred=$SqlCred.$Sql;
00091       }
00092     }//foreach
00093    
00094   }
00095   if ( strlen(trim ($l_line['jrn_def_class_deb']) ) > 0 ) {
00096     $valid_deb=split(" ",$l_line['jrn_def_class_deb']);
00097 
00098     // Creation query
00099     foreach ( $valid_deb as $item_deb) {
00100       if ( strlen (trim($item_deb))) {
00101         echo_debug('poste_search.php',__LINE__,"l_line[jrn_def_class_deb] $l_line[jrn_def_class_deb] item_deb $item_deb");
00102         if ( strstr($item_deb,"*") == true ) {
00103           $item_cred=strtr($item_deb,"*","%");
00104           $Sql=" pcm_val like '$item_deb' or";
00105         } else {
00106           $Sql=" pcm_val = '$item_deb' or";
00107         }
00108         $SqlCred=$SqlCred.$Sql;
00109       }
00110     }//foreach
00111        
00112   }
00113   if ( $condition=="") {
00114     $condition .= ($SqlCred=="")?"":" where  ".substr($SqlCred,0,strlen($SqlCred)-2);
00115   } else {
00116     $condition .= ($SqlCred=="")?"":" and (  ".substr($SqlCred,0,strlen($SqlCred)-2)." ) ";
00117   }
00118 }// if (isset($_GET['filter']))
00119 if ( isset($_GET['p_ctl'])) {
00120   $p_ctl=$_GET['p_ctl'];
00121 }
00122 if ( isset($_POST['p_ctl'])) {
00123   $p_ctl=$_POST['p_ctl'];
00124 }
00125 
00126 echo_debug('poste_search.php',__LINE__,"condition = $condition");
00127 
00128 echo '<FORM ACTION="poste_search.php'.$url.'" METHOD="POST">';
00129 if ( isset($p_ctl) ) {
00130   if ($p_ctl != 'not')   echo '<INPUT TYPE="hidden" name="p_ctl" value="'.$p_ctl.'">';
00131 }
00132 echo '<TABLE>';
00133 echo '<TR>';
00134 
00135 echo '<TD>Poste Comptable Commence par  </TD>';
00136 
00137 if ( ! isset ($p_class) ) $p_class="";
00138 $opt=" <INPUT TYPE=\"text\" value=\"$p_class\" name=\"st_with\">";
00139 echo '<TD> <INPUT TYPE="text" name="p_class" VALUE="'.$p_class.'"></TD>';
00140 
00141 echo '<TD> Libellé </TD>';
00142 echo '<TD> contient </TD>';
00143 if ( ! isset ($p_comment) ) $p_comment="";
00144 echo '<TD> <INPUT TYPE="text" name="p_comment" VALUE="'.$p_comment.'"></TD></TR>';
00145 echo '</TABLE>';
00146 echo '<INPUT TYPE="submit" name="search" value="cherche">';
00147 echo '</FORM>';
00148 
00149 // if request search
00150 if ( isset($_POST['search']) or isset($_GET['filter']) ) {
00151   $Res=ExecSql($cn,"select * from tmp_pcmn $condition order by pcm_val::text");
00152   
00153   $MaxLine=pg_NumRows($Res);
00154   if ( $MaxLine==0) { 
00155     html_page_stop();
00156     return;
00157   }
00158   echo '<TABLE BORDER="0">';
00159   $l_id="";
00160   
00161   for ( $i=0; $i < $MaxLine; $i++) {
00162     $l_line=pg_fetch_array($Res,$i);
00163     echo "<TR>";
00164     // if p_ctl is set we need to be able to return the value
00165     if (isset($p_ctl) and $p_ctl != 'not' ){
00166       echo '<TD>';
00167       echo '<input type="checkbox" onClick="SetItChild(\''.$p_ctl.'\',\''.$l_line['pcm_val'].'\')">';
00168       echo '</td>';
00169     }
00170     echo '<TD>';
00171     echo $l_line['pcm_val'];
00172     echo '</TD>';
00173 
00174     echo '<TD>';
00175     echo $l_line['pcm_lib'];
00176     echo '</TD>';
00177     echo "</TR>";
00178 
00179   }
00180   
00181   echo '</TABLE>';
00182 }
00183 echo '<INPUT TYPE="BUTTON" Value="Close" onClick=\'GetIt()\'>';
00184 html_page_stop();
00185 ?>