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

jrn_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.26 $ */
00025 require_once ("ac_common.php");
00026 require_once ("postgres.php");
00027 require_once("user_common.php");
00028 /* Admin. Dossier */
00029 $rep=DbConnect();
00030 include_once ("class_user.php");
00031 $User=new cl_user($rep);
00032 $User->Check();
00033 
00034 
00035 html_page_start($User->theme,"onLoad='window.focus();'");
00036 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00037   echo "You must choose a Dossier ";
00038   phpinfo();
00039   exit -2;
00040 }
00041 // Javascript
00042 echo JS_CONCERNED_OP;
00043 if ( isset( $p_jrn )) {
00044   $p_jrn=$p_jrn;
00045   $_SESSION[ "p_jrn"]=$p_jrn;
00046 
00047 }
00048 if (isset ($_GET['p_ctl'])) $p_ctl=$_GET['p_ctl'];
00049 if (isset($_POST['p_ctl'])) $p_ctl=$_POST['p_ctl'];
00050 $opt='<OPTION VALUE="="> =';
00051 $opt.='<OPTION VALUE="<="> <=';
00052 $opt.='<OPTION VALUE="<"> <';
00053 $opt.='<OPTION VALUE=">"> >';
00054 $opt.='<OPTION VALUE=">="> >=';
00055 $opt_date=$opt;
00056 $opt_montant=$opt;
00057 $c_comment="";
00058 $c_montant="";
00059 $c_internal="";
00060 $c_date="";
00061 $condition="";
00062 $part=" where ";
00063 $cn=DbConnect($_SESSION['g_dossier']);
00064 // if search then build the condition
00065 if ( isset ($_GET["search"]) ) {
00066   $c1=0;
00067   foreach( $_GET as $key=>$element){
00068     echo_debug('jrn_search.php',__LINE__,"$key = $element");
00069     ${"$key"}=$element;
00070   }
00071 
00072   if ( strlen(trim($p_comment)) != 0 ) {
00073     $c_comment=" $part upper(jr_comment) like upper('%$p_comment%')";
00074     $part=" and ";
00075   }
00076   if ( strlen($p_montant) != 0 && (ereg ("^[0-9]*\.[0-9]*$",$p_montant) ||
00077                                    ereg ("^[0-9]*$",$p_montant)) )
00078       { 
00079     $c_montant=sprintf(" $part jr_montant %s %s",$p_montant_sel,$p_montant);
00080     $opt_montant.='<OPTION VALUE="'.$p_montant_sel.'" SELECTED>'.$p_montant_sel;
00081     $part="  and ";
00082     }
00083   if ( strlen(trim($p_date)) != 0 ) {
00084       $c_date=sprintf(" $part j_date %s to_date('%s','DD.MM.YYYY')",$p_date_sel,$p_date);
00085       $part=" and ";
00086       $opt_date.='<OPTION VALUE="'.$p_date_sel.'" SELECTED>'.$p_date_sel;
00087   }
00088   if ( strlen(trim($p_internal)) != 0 ) {
00089     $c_internal=$part." jr_internal like  ('%".$p_internal."%')";
00090     $part=" and ";
00091 
00092   }
00093 
00094 $condition=$c_comment.$c_montant.$c_date.$c_internal;
00095 echo_debug('jrn_search.php',__LINE__,"condition = $condition");
00096 }
00097 $condition=$condition." ".$part;
00098 
00099 // If the usr is admin he has all right
00100 if ( $User->admin != 1 ) {
00101   $condition.="  uj_priv in ('W','R') and uj_login='".$User->id."'" ;
00102 } else {
00103   $condition.=" uj_login='".$User->id."' ";
00104 }
00105 ?>
00106 <div style="font-size:11px;">
00107 <?
00108 echo '<FORM ACTION="jrn_search.php" METHOD="GET">';
00109 echo '<TABLE>';
00110 echo '<TR>';
00111 if ( ! isset ($p_date)) $p_date="";
00112 if ( ! isset ($p_montant)) $p_montant="";
00113 if ( ! isset ($p_comment)) $p_comment="";
00114 if ( ! isset ($p_internal)) $p_internal="";
00115 echo '<input type="hidden" name="p_ctl" value="'.$p_ctl.'">';
00116 echo '<TD> Date </TD>';
00117 echo '<TD> <SELECT NAME="p_date_sel">'.$opt_date.' </TD>';
00118 echo '<TD> <INPUT TYPE="text" name="p_date" VALUE="'.$p_date.'"></TD>';
00119 
00120 echo '<TD> Montant </TD>';
00121 echo '<TD> <SELECT NAME="p_montant_sel">'.$opt_montant.' </TD>';
00122 echo '<TD> <INPUT TYPE="text" name="p_montant" VALUE="'.$p_montant.'"></TD>';
00123 echo '</TR><TR>';
00124 echo '<TD> Commentaire </TD>';
00125 echo '<TD> contient </TD>';
00126 echo '<TD> <INPUT TYPE="text" name="p_comment" VALUE="'.$p_comment.'"></TD>';
00127 ?>
00128 </TR><TR>
00129 <TD> Code interne </TD><TD>comme </TD>
00130 <?
00131 echo '<TD> <INPUT TYPE="text" name="p_internal" VALUE="'.$p_internal.'"></TD>';
00132 echo "</TR>";
00133 
00134 echo '</TABLE>';
00135 echo '<INPUT TYPE="submit" name="search" value="cherche">';
00136 echo '</FORM>';
00137 
00138 // if a search is asked otherwise don't show all the rows
00139 if ( isset ($_GET["search"]) ) {
00140   $sql="select j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
00141                  j_montant,j_poste,j_debit,j_tech_per,jr_id,jr_comment,j_grpt,pcm_lib,jr_internal from jrnx inner join 
00142                  jrn on jr_grpt_id=j_grpt inner join tmp_pcmn on j_poste=pcm_val ".
00143     " inner join user_sec_jrn on uj_jrn_id=j_jrn_def".
00144     $condition." order by jr_date,jr_id,j_debit desc";
00145   $Res=ExecSql($cn,$sql);
00146 
00147   $MaxLine=pg_NumRows($Res);
00148   $offset=(isset($_GET['offset']))?$_GET['offset']:0;
00149   $limit=$_SESSION['g_pagesize'];
00150   $sql_limit="";
00151   $sql_offset="";
00152   $bar="";
00153   if ( $limit != -1) {
00154     $page=(isset($_GET['page']))?$_GET['page']:0;
00155     $sql_limit=" LIMIT $limit ";
00156     $sql_offset=" OFFSET $offset ";
00157     $bar=jrn_navigation_bar($offset,$MaxLine,$limit,$page);
00158 
00159   }
00160   $sql.=$sql_limit.$sql_offset;
00161    if ( $MaxLine==0) { 
00162      html_page_stop();
00163      return;
00164    }
00165   $Res=ExecSql($cn,$sql);
00166   $MaxLine=pg_NumRows($Res);
00167 
00168   $col_vide="<TD></TD>";
00169   echo $bar;
00170   echo '<TABLE ALIGN="center" BORDER="0" CELLSPACING="O">';
00171   $l_id="";
00172 //   if ( $MaxLine > 250 ) {
00173 //     echo "Trop de lignes redéfinir la recherche";
00174 //     html_page_stop();
00175 //     return;
00176 //   }
00177   for ( $i=0; $i < $MaxLine; $i++) {
00178     $l_line=pg_fetch_array($Res,$i);
00179     if ( $l_id == $l_line['j_grpt'] ) {
00180       echo $col_vide.$col_vide;
00181     } else {
00182       echo "<TR><TD>";
00183       echo '<INPUT TYPE="CHECKBOX" onClick="GetIt(\''.$p_ctl.'\',\''.$l_line['jr_id']."')\" >";
00184       echo "</TD>";
00185 
00186       echo "<TD>";
00187       echo $l_line['j_date'];
00188       echo "</TD>";
00189       
00190       echo "<TD>";
00191       echo $l_line['jr_internal'];
00192       echo "</TD>";
00193       $l_id=$l_line['j_grpt'];
00194       echo '<TD COLSPAN="4">'.$l_line['jr_comment'].'</TD></TR>';
00195     }
00196     if ( $l_line['j_debit'] == 't' ) {
00197       echo '<TR style="background-color:#E7FBFF;">';
00198     }
00199     else {
00200       echo '<TR style="background-color:#E7FFEB;">';
00201     }
00202     echo $col_vide;
00203     if ( $l_line['j_debit']=='f')
00204       echo $col_vide;
00205 
00206     echo '<TD>';
00207     echo $l_line['j_poste'];
00208     echo '</TD>';
00209 
00210     if ( $l_line['j_debit']=='t')
00211       echo $col_vide;
00212 
00213     echo '<TD>';
00214     echo $l_line['pcm_lib'];
00215     echo '</TD>';
00216 
00217     if ( $l_line['j_debit']=='f')
00218       echo $col_vide;
00219 
00220     echo '<TD>';
00221     echo $l_line['j_montant'];
00222     echo '</TD>';
00223 
00224     echo "</TR>";
00225 
00226   }
00227   
00228   echo '</TABLE>';
00229   echo $bar;
00230 }// if $_POST [search]
00231 ?>
00232 </div>
00233 <?
00234 html_page_stop();
00235 ?>