/* * This file is part of PhpCompta. * * PhpCompta is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * PhpCompta is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PhpCompta; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr /*! \file * \brief common utilities for a lot of procedure, classe */ include_once("debug.php"); include_once("constant.php"); /*! * \brief log error into the /tmp/phpcompta_error.log it doesn't work on windows * * \param log message * * \return nothing * */ function echo_error ($p_log) { $fdebug=fopen("/tmp/phpcompta_error.log","a+"); fwrite($fdebug,date("Ymd H:i:s").$p_log."\n"); fclose($fdebug); echo_debug($p_log); } /*! * \brief Compare 2 dates * \param date * \param date2 * * \return * - == 0 les dates sont identiques * - > 0 date1 > date2 * - < 0 date1 < date2 */ function cmpDate ($p_date,$p_date_oth) { $l_date=isDate($p_date); $l2_date=isDate($p_date_oth); if ($l_date == null || $l2_date == null ) { echo "erreur date"; return null; } $l_adate=explode(".",$l_date); $l2_adate=explode(".",$l2_date); $l_mkdate=mktime(0,0,0,$l_adate[1],$l_adate[0],$l_adate[2]); $l2_mkdate=mktime(0,0,0,$l2_adate[1],$l2_adate[0],$l2_adate[2]); // si $p_date > $p_date_oth return > 0 return $l_mkdate-$l2_mkdate; } /*! * \brief check if the argument is a number * * \param $p_int number to test * * \return * - 1 it's a number * - 0 it is not */ function isNumber($p_int) { if ( strlen (trim($p_int)) == 0 ) return 0; $p_int=trim($p_int); if (! ereg ("^-{0,1}[0-9]+.{0,1}[0-9]*$",$p_int) ) { return 0; } else { return 1; }// !ereg } /*! * \brief Verifie qu'une date est bien formaté * en d.m.y et est valable * \param $p_date * * \return * - null si la date est invalide ou malformaté * - $p_date si tout est bon * */ function isDate ( $p_date) { if ( strlen (trim($p_date)) == 0 ) return null; if (! ereg ("^[0-9]{1,2}\.[0-9]{1,2}\.20[0-9]{2}",$p_date) ) { return null; } else { $l_date=explode(".",$p_date); if ( $l_date[2] > 2020 ) { return null; } echo_debug('ac_common.php',__LINE__,' date = '.var_export($l_date,true)); if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) { return null; } }// !ereg return $p_date; } /*! * \brief call cmpDate * * \return the date or the quoted string null */ function formatDate($p_date) { if ( isDate($p_date)== null) return "null"; return "'".$p_date."'"; } /*! * \brief Default page header for each page * * \param default theme * \param $p_script * \param $p_script2 another js script * * \return none */ function html_page_start($p_theme="",$p_script="",$p_script2="") { include_once ("postgres.php"); ini_set('magic_quotes_gpc','Off'); $cn=DbConnect(); if ( $p_theme != "") { $Res=ExecSql($cn,"select the_filestyle from theme where the_name='".$p_theme."'"); if (pg_NumRows($Res)==0) $style="style.css"; else { $s=pg_fetch_array($Res,0); $style=$s['the_filestyle']; } }else { $style="style.css"; } // end if echo ''; echo ""; if ( $p_script2 != "" ) $p_script2=''; echo "