00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00065 return $l_mkdate-$l2_mkdate;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
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 }
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 if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) {
00108 return null;
00109 }
00110
00111 }
00112 return $p_date;
00113 }
00119 function formatDate($p_date) {
00120 if ( isDate($p_date)== null) return "null";
00121 return "'".$p_date."'";
00122 }
00132 function html_page_start($p_theme="",$p_script="",$p_script2="")
00133 {
00134 include_once ("postgres.php");
00135 ini_set('magic_quotes_gpc','Off');
00136
00137 $cn=DbConnect();
00138 if ( $p_theme != "") {
00139 $Res=ExecSql($cn,"select the_filestyle from theme
00140 where the_name='".$p_theme."'");
00141 if (pg_NumRows($Res)==0)
00142 $style="style.css";
00143 else {
00144 $s=pg_fetch_array($Res,0);
00145 $style=$s['the_filestyle'];
00146 }
00147 }else {
00148 $style="style.css";
00149 }
00150 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">';
00151 echo "<HTML>";
00152
00153 if ( $p_script2 != "" )
00154 $p_script2='<script src="'.$p_script2.'" type="text/javascript"></script>';
00155
00156 echo "<HEAD>
00157 <TITLE>PhpCompta</TITLE>
00158 <META http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">
00159 <LINK REL=\"stylesheet\" type=\"text/css\" href=\"$style\" media=\"screen\">
00160 <link rel=\"stylesheet\" type=\"text/css\" href=\"style-print.css\" media=\"print\">".
00161 $p_script2. "
00162 </HEAD><script src=\"scripts.js\" type=\"text/javascript\"></script>";
00163 echo "<BODY $p_script>";
00164 }
00169 function html_page_stop()
00170 {
00171 echo "</BODY>";
00172 echo "</HTML>";
00173 }
00181 function html_button_logout() {
00182 echo "<A class=\"mtitle\" HREF=logout.php> Logout </A>";
00183 }
00191 function NoAccess() {
00192 echo "<BR><BR><BR><BR><BR><BR>";
00193 echo "<P ALIGN=center><BLINK>
00194 <FONT size=+12 COLOR=RED>
00195 You haven't access
00196 </FONT></BLINK></P></BODY></HTML>";
00197
00198 exit -1;
00199 }
00207 function FormatString($p_string)
00208 {
00209 if ( !isset ($p_string) ) {
00210 echo_error("ac_common.php FormatString p_string empty");
00211 return null;
00212 }
00213 $p_string=trim($p_string);
00214 if (strlen($p_string) == 0 ) return null;
00215 $p_string=str_replace("\'","'",$p_string);
00216 $p_string=str_replace("''","'",$p_string);
00217 $p_string=str_replace("'","\'",$p_string);
00218 return $p_string;
00219 }
00220
00223
00224
00225
00226
00227 function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$default="",$p_extra="")
00228 {
00229 $ret="<TABLE $p_extra>";
00230
00231 if ( $p_dir == 'V') {
00232 foreach ($p_array as $all=>$href){
00233 $title="";
00234 if ( isset ($href[2] ))
00235 $title=$href[2];
00236 $ret.='<TR><TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD></TR>';
00237 }
00238 }
00239
00240 else if ( $p_dir == 'H' ) {
00241 $ret.="<TR>";
00242 foreach ($p_array as $all=>$href){
00243 $title="";
00244 if ( isset ($href[2] ))
00245 $title=$href[2];
00246 if ( $default== $href[0]) {
00247 $ret.='<TD CLASS="selectedcell">'.$href[1].'</TD>';
00248
00249 } else {
00250 $ret.='<TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD>';
00251 }
00252 }
00253 $ret.="</TR>";
00254 }
00255 $ret.="</TABLE>";
00256 return $ret;
00257 }
00268 function echo_warning($p_string)
00269 {
00270 echo '<H2 class="info">'.$p_string."</H2>";
00271 }
00281 function make_array($p_cn,$p_sql,$p_null=0) {
00282
00283 $a=pg_exec($p_cn,$p_sql);
00284 $max=pg_NumRows($a);
00285 if ( $max==0) return null;
00286 for ($i=0;$i<$max;$i++) {
00287 $row=pg_fetch_row($a);
00288 $r[$i]['value']=$row[0];
00289 $r[$i]['label']=$row[1];
00290 }
00291
00292 if ( $p_null == 1 ) {
00293 for ($i=$max;$i!=0;$i--) {
00294 $r[$i]['value']= $r[$i-1]['value'];
00295 $r[$i]['label']= $r[$i-1]['label'];
00296 }
00297 $r[0]['value']=-1;
00298 $r[0]['label']=" ";
00299 }
00300
00301 return $r;
00302 }
00314 function getPeriodeName($p_cn,$p_id,$pos='p_start') {
00315 if ( $pos != 'p_start' and
00316 $pos != 'p_end')
00317 echo_error('ac_common.php'."-".__LINE__.' UNDEFINED PERIODE');
00318 $ret=execSql($p_cn,"select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
00319 if (pg_NumRows($ret) == 0) return null;
00320 $a=pg_fetch_array($ret,0);
00321 return $a['t'];
00322 }
00334 function getPeriodeFromMonth($p_cn,$p_date) {
00335 $R=ExecSql($p_cn,"select p_id from parm_periode where
00336 to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
00337 if ( pg_NumRows($R) == 0 )
00338 return -1;
00339 $a=pg_fetch_array($R,0);
00340
00341 return $a['p_id'];
00342 }
00354 function getPeriodeFromDate($p_cn,$p_date) {
00355 $R=ExecSql($p_cn,"select p_id from parm_periode where
00356 p_start <= to_date('$p_date','DD.MM.YYYY')
00357 and p_end >= to_date('$p_date','DD.MM.YYYY')
00358 ");
00359 if ( pg_NumRows($R) == 0 )
00360 return -1;
00361 $a=pg_fetch_array($R,0);
00362
00363 return $a['p_id'];
00364 }
00365
00366 ?>