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

ac_common.php

Go to the documentation of this file.
00001 <?
00002 
00003 /*
00004  *   This file is part of PhpCompta.
00005  *
00006  *   PhpCompta is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   PhpCompta is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with PhpCompta; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00026 include_once("debug.php");
00027 include_once("constant.php");
00036 function echo_error      ($p_log) {
00037         $fdebug=fopen("/tmp/phpcompta_error.log","a+");
00038         fwrite($fdebug,date("Ymd H:i:s").$p_log."\n");
00039         fclose($fdebug);
00040         echo_debug($p_log);
00041 }
00042 
00053 function cmpDate ($p_date,$p_date_oth) {
00054   $l_date=isDate($p_date);
00055   $l2_date=isDate($p_date_oth);
00056   if ($l_date == null || $l2_date == null ) {
00057     echo "erreur date";
00058     return null;
00059   }
00060   $l_adate=explode(".",$l_date);
00061   $l2_adate=explode(".",$l2_date);
00062   $l_mkdate=mktime(0,0,0,$l_adate[1],$l_adate[0],$l_adate[2]);
00063   $l2_mkdate=mktime(0,0,0,$l2_adate[1],$l2_adate[0],$l2_adate[2]);
00064   // si $p_date > $p_date_oth return > 0
00065   return $l_mkdate-$l2_mkdate;
00066 }
00076 function isNumber($p_int) {
00077   if ( strlen (trim($p_int)) == 0 ) return 0;
00078   $p_int=trim($p_int);
00079   if (! ereg ("^-{0,1}[0-9]+.{0,1}[0-9]*$",$p_int) ) {
00080     return 0;
00081   } else {
00082     return 1;
00083   }// !ereg
00084 }
00085 
00097 function isDate ( $p_date) {
00098   if ( strlen (trim($p_date)) == 0 ) return null;
00099   if (! ereg ("^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}",$p_date) ) {
00100 
00101     return null;
00102   } else {
00103     $l_date=explode(".",$p_date);
00104     if ( $l_date[2] > 2020 ) {
00105       return null;
00106     }
00107     echo_debug('ac_common.php',__LINE__,' date = '.var_export($l_date,true));
00108     if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) {
00109       return null;
00110     }
00111 
00112   }// !ereg
00113   return $p_date;
00114 }
00120 function formatDate($p_date) {
00121   if ( isDate($p_date)== null) return "null";
00122   return "'".$p_date."'";
00123 }
00133 function html_page_start($p_theme="",$p_script="",$p_script2="")
00134 {       
00135   include_once ("postgres.php");
00136  ini_set('magic_quotes_gpc','Off');
00137 
00138  $cn=DbConnect();
00139  if ( $p_theme != "") {
00140    $Res=ExecSql($cn,"select the_filestyle from theme
00141                    where the_name='".$p_theme."'");
00142     if (pg_NumRows($Res)==0) 
00143       $style="style.css";
00144     else {
00145       $s=pg_fetch_array($Res,0);
00146       $style=$s['the_filestyle'];
00147     }
00148  }else {
00149    $style="style.css";
00150  } // end if
00151  echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
00152  echo "<HTML>";
00153 
00154  if ( $p_script2 != "" )
00155    $p_script2='<script src="'.$p_script2.'" type="text/javascript"></script>';
00156 
00157  echo "<HEAD> 
00158       <TITLE>PhpCompta</TITLE>
00159       <META http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">
00160       <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
00161       <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">".
00162    $p_script2. "
00163         </HEAD><script src=\"scripts.js\" type=\"text/javascript\"></script>";
00164  echo "<BODY $p_script>";
00165 }
00170 function html_page_stop()
00171 {
00172         echo "</BODY>";
00173         echo "</HTML>";
00174 }
00182 function html_button_logout() {
00183         echo "<A class=\"mtitle\" HREF=logout.php> Logout </A>";
00184 }
00192 function NoAccess() 
00193 {
00194   echo "<script>";
00195   echo "alert ('Cette action ne vous est pas autorisée Contactez votre responsable');";
00196   echo "</script>";
00197   exit -1;
00198 }
00206 function FormatString($p_string) 
00207 {
00208   if ( !isset ($p_string) ) {
00209     echo_error("ac_common.php FormatString p_string empty");
00210     return null;
00211   }
00212   $p_string=trim($p_string);
00213   if (strlen($p_string) == 0 ) return null;
00214   $p_string=str_replace("\'","'",$p_string);
00215   $p_string=str_replace("''","'",$p_string);
00216   $p_string=str_replace("'","\'",$p_string);
00217   return $p_string;
00218 }
00219 
00222 /*           the content of p_array in a table */
00223 /*           used to display the menu */
00224 /* \param  array */
00225 /* \return : string */
00226 function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$default="",$p_extra="")
00227 {
00228   $ret="<TABLE $p_extra>";
00229   // direction Vertical
00230   if ( $p_dir == 'V') {
00231     foreach ($p_array as $all=>$href){
00232       $title="";
00233       if ( isset ($href[2] )) 
00234         $title=$href[2];
00235       $ret.='<TR><TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD></TR>';
00236     }
00237   }
00238       //direction Horizontal
00239   else if ( $p_dir == 'H' ) {
00240     $ret.="<TR>";
00241     foreach ($p_array as $all=>$href){
00242       $title="";
00243       if ( isset ($href[2] )) 
00244         $title=$href[2];
00245       if ( $default== $href[0]) {
00246       $ret.='<TD CLASS="selectedcell">'.$href[1].'</TD>';
00247 
00248       } else {
00249       $ret.='<TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD>';
00250       }
00251     }
00252     $ret.="</TR>";
00253   }
00254     $ret.="</TABLE>";
00255   return $ret;
00256 }
00267 function echo_warning($p_string) 
00268 {
00269   echo '<H2 class="info">'.$p_string."</H2>";
00270 }
00280 function make_array($p_cn,$p_sql,$p_null=0) {
00281   echo_debug('ac_common',__LINE__,$p_sql);
00282   $a=ExecSql($p_cn,$p_sql);
00283   $max=pg_NumRows($a);
00284   if ( $max==0) return null;
00285   for ($i=0;$i<$max;$i++) {
00286     $row=pg_fetch_row($a);
00287     $r[$i]['value']=$row[0];
00288     $r[$i]['label']=$row[1];
00289   }
00290   // add a blank item ?
00291   if ( $p_null == 1 ) {
00292   for ($i=$max;$i!=0;$i--) {
00293     $r[$i]['value']=    $r[$i-1]['value'];
00294     $r[$i]['label']=    $r[$i-1]['label'];
00295   }
00296   $r[0]['value']=-1;
00297   $r[0]['label']=" ";
00298   } //   if ( $p_null == 1 ) 
00299 
00300   return $r;
00301 }
00313 function getPeriodeName($p_cn,$p_id,$pos='p_start') {
00314   if ( $pos != 'p_start' and 
00315        $pos != 'p_end')
00316     echo_error('ac_common.php'."-".__LINE__.'  UNDEFINED PERIODE');
00317   $ret=execSql($p_cn,"select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
00318   if (pg_NumRows($ret) == 0) return null;
00319   $a=pg_fetch_array($ret,0);
00320   return $a['t'];
00321 }
00333 function getPeriodeFromMonth($p_cn,$p_date) {
00334   $R=ExecSql($p_cn,"select p_id from parm_periode where
00335               to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
00336   if ( pg_NumRows($R) == 0 ) 
00337     return -1;
00338   $a=pg_fetch_array($R,0);
00339 
00340   return $a['p_id'];
00341 }
00353 function getPeriodeFromDate($p_cn,$p_date) {
00354   $R=ExecSql($p_cn,"select p_id from parm_periode where
00355               p_start <= to_date('$p_date','DD.MM.YYYY')
00356            and p_end  >= to_date('$p_date','DD.MM.YYYY')
00357            ");
00358   if ( pg_NumRows($R) == 0 ) 
00359     return -1;
00360   $a=pg_fetch_array($R,0);
00361 
00362   return $a['p_id'];
00363 }
00369 function Decode($p_html){
00370   $p_html=str_replace('%0D','',$p_html);
00371   $p_html=str_replace('%0A','',$p_html);
00372   $p_html=urldecode($p_html);
00373   return $p_html;
00374 }
00375 ?>