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

ac_common.php File Reference

common utilities for a lot of procedure, classe More...

Go to the source code of this file.

Functions

 echo_error ($p_log)
 log error into the /tmp/phpcompta_error.log it doesn't work on windows
 cmpDate ($p_date, $p_date_oth)
 Compare 2 dates.
 isNumber ($p_int)
 check if the argument is a number
 isDate ($p_date)
 Verifie qu'une date est bien formaté en d.m.y et est valable.
 formatDate ($p_date)
 call cmpDate
 html_page_start ($p_theme="", $p_script="", $p_script2="")
 Default page header for each page.
 html_page_stop ()
 end tag
 html_button_logout ()
 Button logout.
 NoAccess ()
 Echo no access and stop.
 FormatString ($p_string)
 Fix the problem with the quote char for the database.
 ShowItem ($p_array, $p_dir='V', $class="mtitle", $class_ref="mtitle", $default="", $p_extra="")
 store the string which print
 echo_warning ($p_string)
 warns
 make_array ($p_cn, $p_sql, $p_null=0)
 make a array with the sql
 getPeriodeName ($p_cn, $p_id, $pos='p_start')
 Show the periode which found thanks its id.
 getPeriodeFromMonth ($p_cn, $p_date)
 Return the period corresponding to the date.
 getPeriodeFromDate ($p_cn, $p_date)
 Return the period corresponding to the date.
 Decode ($p_html)
 Decode the html for the widegt richtext and remove newline.


Detailed Description

common utilities for a lot of procedure, classe

Definition in file ac_common.php.


Function Documentation

cmpDate p_date,
p_date_oth
 

Compare 2 dates.

Parameters:
date 
date2 
Returns:
  • == 0 les dates sont identiques
  • > 0 date1 > date2
  • < 0 date1 < date2

Definition at line 53 of file ac_common.php.

References isDate().

Referenced by VerifData(), and VerifyOperationDate().

00053                                        {
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 }

Decode p_html  ) 
 

Decode the html for the widegt richtext and remove newline.

Parameters:
$p_html string to decode
Returns:
the html code without new line

Definition at line 369 of file ac_common.php.

00369                         {
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 }

echo_error p_log  ) 
 

log error into the /tmp/phpcompta_error.log it doesn't work on windows

Parameters:
log message
Returns:
nothing

Definition at line 36 of file ac_common.php.

References echo_debug().

Referenced by AddFiche(), AddForm(), AddModele(), CheckPoste(), DeleteRapt(), EncodeFiche(), ExecSql(), form_verify_input(), FormAchInput(), FormAchView(), FormatString(), FormFin(), FormODS(), FormVenInput(), FormVenteView(), GetFicheJrn(), getPeriodeName(), GetTvaPoste(), Imp(), InsertRapt(), isValid(), Remove(), Document_modele::Save(), save_upload_document(), fiche::update(), UpdateFiche(), UpdateJrn(), UpdateModele(), VerifData(), and VerifyOperationDate().

00036                                   {
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 }

echo_warning p_string  ) 
 

warns

Parameters:
: 
  • string gen :
  • none
Returns:
:
  • none

Definition at line 267 of file ac_common.php.

Referenced by GetFicheJrn(), and IsFicheOfJrn().

00268 {
00269   echo '<H2 class="info">'.$p_string."</H2>";
00270 }

formatDate p_date  ) 
 

call cmpDate

Returns:
the date or the quoted string null

Definition at line 120 of file ac_common.php.

References isDate().

00120                              {
00121   if ( isDate($p_date)== null) return "null";
00122   return "'".$p_date."'";
00123 }

FormatString p_string  ) 
 

Fix the problem with the quote char for the database.

Parameters:
$p_string 
Returns:
a string which won't let strange char for the database

Definition at line 206 of file ac_common.php.

References echo_error().

Referenced by AddFiche(), AddForm(), AddModele(), action::Confirm(), fiche::CountByDef(), action::Display(), fiche::GetByQCode(), fiche::insert(), InsertJrn(), ListJrn(), RecordFin(), RecordInvoice(), RecordSell(), Remove(), parm_code::Save(), Document_modele::Save(), action::SaveStage2(), ShowActionList(), Supplier::Summary(), Customer::Summary(), contact::Summary(), Admin::Summary(), fiche::update(), action::Update(), UpdateComment(), UpdateFiche(), UpdateForm(), Own::UpdateRow(), and ViewJrn().

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 }

getPeriodeFromDate p_cn,
p_date
 

Return the period corresponding to the date.

Parameters:
: 
  • p_cn database connection
  • the date 'DD.MM.YYYY'
    Returns:
    : parm_periode.p_id

Definition at line 353 of file ac_common.php.

References $a, and ExecSql().

00353                                            {
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 }

getPeriodeFromMonth p_cn,
p_date
 

Return the period corresponding to the date.

Parameters:
p_cn database connection
the month + year 'MM.YYYY'
Returns:
: parm_periode.p_id

Definition at line 333 of file ac_common.php.

References $a, and ExecSql().

Referenced by ParseFormula().

00333                                             {
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 }

getPeriodeName p_cn,
p_id,
pos = 'p_start'
 

Show the periode which found thanks its id.

Parameters:
$p_cn database connection
p_id 
Start or end
Returns:
: string

Definition at line 313 of file ac_common.php.

References $a, $ret, and echo_error().

00313                                                     {
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 }

html_button_logout  ) 
 

Button logout.

Returns:
nothing

Definition at line 182 of file ac_common.php.

00182                               {
00183         echo "<A class=\"mtitle\" HREF=logout.php> Logout </A>";
00184 }

html_page_start p_theme = "",
p_script = "",
p_script2 = ""
 

Default page header for each page.

Parameters:
default theme
$p_script 
$p_script2 another js script
Returns:
none

Definition at line 133 of file ac_common.php.

References $cn, $Res, $style, DbConnect(), and ExecSql().

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 }

html_page_stop  ) 
 

end tag

Definition at line 170 of file ac_common.php.

00171 {
00172         echo "</BODY>";
00173         echo "</HTML>";
00174 }

isDate p_date  ) 
 

Verifie qu'une date est bien formaté en d.m.y et est valable.

Parameters:
$p_date 
Returns:
  • null si la date est invalide ou malformaté
  • $p_date si tout est bon

Definition at line 97 of file ac_common.php.

References echo_debug().

Referenced by cmpDate(), action::Confirm(), form_verify_input(), formatDate(), ListJrn(), VerifData(), VerifyOperationDate(), and ViewJrn().

00097                            {
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 }

isNumber p_int  ) 
 

check if the argument is a number

Parameters:
$p_int number to test
Returns:
  • 1 it's a number
  • 0 it is not

Definition at line 76 of file ac_common.php.

Referenced by AddFiche(), AddModele(), ComputeTotalVat(), ComputeVat(), DeleteRapt(), form_verify_input(), FormAchInput(), FormAchView(), FormODS(), FormVenInput(), FormVenteView(), fiche::insert(), InsertRapt(), RecordFin(), RecordInvoice(), RecordODS(), RecordSell(), Remove(), Document_modele::Save(), and fiche::update().

00076                           {
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 }

make_array p_cn,
p_sql,
p_null = 0
 

make a array with the sql

Parameters:
$cn dbatabase connection
$sql related sql
Returns:
: a double array [value,label]

Definition at line 280 of file ac_common.php.

References $a, $i, $r, $row, echo_debug(), ExecSql(), label, and value.

Referenced by action::Confirm(), action::Display(), Document_modele::form(), FormAchInput(), FormVenInput(), FormVenteView(), and ShowFormTransfert().

00280                                             {
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 }

NoAccess  ) 
 

Echo no access and stop.

Returns:
nothing

Definition at line 192 of file ac_common.php.

References exit.

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 }

ShowItem p_array,
p_dir = 'V',
class = "mtitle",
class_ref = "mtitle",
default = "",
p_extra = ""
 

store the string which print

/*

Definition at line 226 of file ac_common.php.

References $ret.

Referenced by MenuAdmin(), ShowJrn(), ShowMenuAdvanced(), ShowMenuCompta(), ShowMenuDocument(), and ShowMenuParam().

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 }