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 }
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 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 }
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 }
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 echo "<BR><BR><BR><BR><BR><BR>";
00194 echo "<P ALIGN=center><BLINK>
00195 <FONT size=+12 COLOR=RED>
00196 You haven't access
00197 </FONT></BLINK></P></BODY></HTML>";
00198
00199 exit -1;
00200 }
00208 function FormatString($p_string)
00209 {
00210 if ( !isset ($p_string) ) {
00211 echo_error("ac_common.php FormatString p_string empty");
00212 return null;
00213 }
00214 $p_string=trim($p_string);
00215 if (strlen($p_string) == 0 ) return null;
00216 $p_string=str_replace("\'","'",$p_string);
00217 $p_string=str_replace("''","'",$p_string);
00218 $p_string=str_replace("'","\'",$p_string);
00219 return $p_string;
00220 }
00221
00224
00225
00226
00227
00228 function ShowItem($p_array,$p_dir='V',$class="mtitle",$class_ref="mtitle",$default="",$p_extra="")
00229 {
00230 $ret="<TABLE $p_extra>";
00231
00232 if ( $p_dir == 'V') {
00233 foreach ($p_array as $all=>$href){
00234 $title="";
00235 if ( isset ($href[2] ))
00236 $title=$href[2];
00237 $ret.='<TR><TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD></TR>';
00238 }
00239 }
00240
00241 else if ( $p_dir == 'H' ) {
00242 $ret.="<TR>";
00243 foreach ($p_array as $all=>$href){
00244 $title="";
00245 if ( isset ($href[2] ))
00246 $title=$href[2];
00247 if ( $default== $href[0]) {
00248 $ret.='<TD CLASS="selectedcell">'.$href[1].'</TD>';
00249
00250 } else {
00251 $ret.='<TD CLASS="'.$class.'"><A class="'.$class_ref.'" HREF="'.$href[0].'" title="'.$title.'">'.$href[1].'</A></TD>';
00252 }
00253 }
00254 $ret.="</TR>";
00255 }
00256 $ret.="</TABLE>";
00257 return $ret;
00258 }
00269 function echo_warning($p_string)
00270 {
00271 echo '<H2 class="info">'.$p_string."</H2>";
00272 }
00282 function make_array($p_cn,$p_sql,$p_null=0) {
00283
00284 $a=pg_exec($p_cn,$p_sql);
00285 $max=pg_NumRows($a);
00286 if ( $max==0) return null;
00287 for ($i=0;$i<$max;$i++) {
00288 $row=pg_fetch_row($a);
00289 $r[$i]['value']=$row[0];
00290 $r[$i]['label']=$row[1];
00291 }
00292
00293 if ( $p_null == 1 ) {
00294 for ($i=$max;$i!=0;$i--) {
00295 $r[$i]['value']= $r[$i-1]['value'];
00296 $r[$i]['label']= $r[$i-1]['label'];
00297 }
00298 $r[0]['value']=-1;
00299 $r[0]['label']=" ";
00300 }
00301
00302 return $r;
00303 }
00315 function getPeriodeName($p_cn,$p_id,$pos='p_start') {
00316 if ( $pos != 'p_start' and
00317 $pos != 'p_end')
00318 echo_error('ac_common.php'."-".__LINE__.' UNDEFINED PERIODE');
00319 $ret=execSql($p_cn,"select to_char($pos,'Mon YYYY') as t from parm_periode where p_id=$p_id");
00320 if (pg_NumRows($ret) == 0) return null;
00321 $a=pg_fetch_array($ret,0);
00322 return $a['t'];
00323 }
00335 function getPeriodeFromMonth($p_cn,$p_date) {
00336 $R=ExecSql($p_cn,"select p_id from parm_periode where
00337 to_char(p_start,'DD.MM.YYYY') = '01.$p_date'");
00338 if ( pg_NumRows($R) == 0 )
00339 return -1;
00340 $a=pg_fetch_array($R,0);
00341
00342 return $a['p_id'];
00343 }
00355 function getPeriodeFromDate($p_cn,$p_date) {
00356 $R=ExecSql($p_cn,"select p_id from parm_periode where
00357 p_start <= to_date('$p_date','DD.MM.YYYY')
00358 and p_end >= to_date('$p_date','DD.MM.YYYY')
00359 ");
00360 if ( pg_NumRows($R) == 0 )
00361 return -1;
00362 $a=pg_fetch_array($R,0);
00363
00364 return $a['p_id'];
00365 }
00366
00367 ?>