diff --git a/include/ac_common.php b/include/ac_common.php new file mode 100644 index 000000000..af0cd89a9 --- /dev/null +++ b/include/ac_common.php @@ -0,0 +1,145 @@ + 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; +} +/* function isDate + * Purpose : Verifie qu'une date est bien formaté + * en d.m.y et est valable + * parm : + * - $p_date + * gen : + * - rien + * 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; + } + if ( checkdate ($l_date[1],$l_date[0],$l_date[2]) == false) { + return null; + } + + }// !ereg + return $p_date; +} +function formatDate($p_date) { + if ( isDate($p_date)== null) return "null"; + return "'".$p_date."'"; +} +function html_page_start($p_first=0,$p_script="") +{ + global $user,$pass,$IsValid; + if ($p_first == 1 ) { + echo_debug("Start session explicit"); + session_start(); + } + session_register("user"); + session_register("pass"); + session_register("IsValid"); + + echo_debug("user = ".$user." pass=".$pass." IsValid = $IsValid"); + echo ''; + echo ""; + echo " + Gnu Accountancy + + "; + echo ""; +} +function html_page_stop() +{ + echo ""; + echo ""; +} +function html_button_logout() { + echo " Logout "; +} +function NoAccess() { + // echo ''; + echo "





"; + echo "

+ + You haven't access +

"; + + exit -1; +} +function FormatString($p_string) +{ + if ( !isset ($p_string) ) { + echo_error("ac_common.php FormatString p_string empty"); + return null; + } + $p_string=trim($p_string); + if (strlen($p_string) == 0 ) return null; + $p_string=str_replace("'","\'",$p_string); + return $p_string; +} +?> diff --git a/include/central_inc.php b/include/central_inc.php new file mode 100644 index 000000000..c41570891 --- /dev/null +++ b/include/central_inc.php @@ -0,0 +1,71 @@ + diff --git a/include/check_priv.php b/include/check_priv.php new file mode 100644 index 000000000..ba34f3020 --- /dev/null +++ b/include/check_priv.php @@ -0,0 +1,154 @@ + droit par défaut = W + return 2; + } + $Priv=pg_fetch_array($Res2,0); + + if ( $Priv['uj_priv'] == "X" ) return 0; + if ( $Priv['uj_priv'] == "R" ) return 1; + if ( $Priv['uj_priv'] == "W" ) return 2; + echo '

Undefined right

'; + echo_debug ("Droit Journal $Priv[uj_priv]"); + return 0; + } + if ( $Def['priv_priv'] == "R") { + // Si droit pas défaut == Lire + if ( $PrivJrn == 0 ) { + // Pas de droit spécifique sur jrn => droit par défaut = Lire + return 1; + } + $Priv=pg_fetch_array($Res2,0); + + if ( $Priv['uj_priv'] == "X" ) return 0; + if ( $Priv['uj_priv'] == "R" ) return 1; + if ( $Priv['uj_priv'] == "W" ) return 2; + echo_debug ("Droit Journal $Priv[uj_priv]"); + echo '

Undefined right

'; + return 0; + } + echo '

Undefined default right

'; + return 0; + +} +/* function CheckAction + * Purpose : Check if an user is allowed to do an action + * + * parm : + * - p_dossier dossier id + * - p_login user's login + * - p_action_id + * gen : + * - + * return: + * - 0 no priv + * - 1 priv granted + * + */ +function CheckAction ( $p_dossier,$p_login,$p_action_id) +{ + if ( CheckIsAdmin ($p_login) ) return 1; + $l_Db=sprintf("dossier%d",$p_dossier); + $cn=DbConnect($l_Db); + $Res=ExecSql($cn,"select * from user_sec_act where ua_login='$p_login' and ua_act_id=$p_action_id"); + $Count=pg_NumRows($Res); + if ( $Count == 0 ) return 0; + if ( $Count == 1 ) return 1; + echo "

Invalid action !!!

"; +} +/* function CheckIsAdmin + * Purpose : Check if an user is an administrator + * + * parm : + * - $p_user user login + * gen : + * - + * return: + * - 0 if no + * - 1 if yes + * + */ +function CheckIsAdmin($p_user) +{ + if ( $p_user == 'webcompta') return 1; + $sql="select use_id from ac_users where use_login='$p_user' + and use_active=1 and use_admin=1 "; + $cn=DbConnect(); + + $isAdmin=CountSql($cn,$sql); + + + return $isAdmin; + +} +?> diff --git a/include/constant.php b/include/constant.php new file mode 100644 index 000000000..a0143cb0f --- /dev/null +++ b/include/constant.php @@ -0,0 +1,67 @@ + diff --git a/include/debug.php b/include/debug.php new file mode 100644 index 000000000..d922dd2ad --- /dev/null +++ b/include/debug.php @@ -0,0 +1,33 @@ + diff --git a/include/facture_inc.php b/include/facture_inc.php new file mode 100644 index 000000000..59104113d --- /dev/null +++ b/include/facture_inc.php @@ -0,0 +1,51 @@ + diff --git a/include/fiche_inc.php b/include/fiche_inc.php new file mode 100644 index 000000000..ed05140fd --- /dev/null +++ b/include/fiche_inc.php @@ -0,0 +1,543 @@ +$element){ + ${"p_$key"}=$element; + echo_debug("p_$key=$element;"); + } + $base=GetBaseFiche($p_cn,$p_type); + $num=GetNextFiche($p_cn,$base); + $sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) + values (%s,'%s',%d)", + $num, + $p_nom0, + $base); + echo_debug($sql); + $Res=ExecSql($p_cn,$sql); + $sql=sprintf("insert into fiche ( f_id,f_label,f_fd_id) values (%d,'%s',%d)", + $num,$p_nom0,$p_type); + $Res=ExecSql($p_cn,$sql); + for ( $i = 1; $i < $p_inc;$i++) { + $sql=sprintf("insert into isupp (is_f_id,is_isd_id,is_value) values ( + %d,%d,'%s')", + $num, ${"p_isd_id$i"},${"p_nom$i"}); + echo_debug($sql); + $Res=ExecSql($p_cn,$sql); + } + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function EncodeFiche($p_cn,$p_type,$p_array=null) { + echo_debug("function EncodeFiche($p_cn,$p_type) "); + $ch_col=""; + $ch_li=''; + echo '
'; + echo ''; + + echo ""; + if ($p_array == null) { + $p_f_id=""; + echo_debug("Array is null"); + $sql="select isd_id,isd_label from isupp_def where isd_fd_id=".$p_type; + + $Res=ExecSql($p_cn,$sql); + $Max=pg_NumRows($Res); + + echo ''; + for ($i=0;$i < $Max;$i++) { + $l_line=pg_fetch_array($Res,$i); + $Hid=sprintf('', + $i,$l_line['isd_id']); + printf ('', + $l_line['isd_label'], $i,$Hid); + } + echo ''; + echo '
%s %s
'; + echo ''; + echo ''; + echo '
'; + }else { + $sql="select f_label,f_fd_id from fiche where f_id=".$p_type; + $Res=ExecSql($p_cn,$sql); + $Max=pg_NumRows($Res); + if ( $Max == 0 ) return; + $l_line=pg_fetch_array($Res,0); + printf('
', + $l_line['f_label']); + echo ''; + + $sql="select isd_fd_id,isd_id,isd_label,is_value,is_id,is_f_id from isupp left join isupp_def on isd_id=is_isd_id where is_f_id=".$p_type; + + $Res=ExecSql($p_cn,$sql); + $Max=pg_NumRows($Res); + echo_debug("Max ==== $Max"); + echo ''; + + echo ''; + for ($i=0;$i < $Max;$i++) { + $l_line=pg_fetch_array($Res,$i); + + + $Hid=sprintf('', + $i,$l_line['is_id']); + printf (' %s %s', + $l_line['isd_label'], $i, $l_line['is_value'],$Hid); + } + echo ''; + echo ''; + echo ''; + echo ''; + } +} + +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetBaseFiche($p_cn,$p_type) { + $base=null; + $Res=ExecSql($p_cn,"select fd_class_base from fichedef where fd_id=".$p_type); + if ( pg_NumRows($Res) == 0 ) return; + $base=pg_fetch_array($Res,0); + return $base['fd_class_base']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function ViewFiche($p_cn,$p_type) { + $Res=ExecSql($p_cn,"select f_id,f_label from fiche where f_fd_id='".$p_type."' order by f_id"); + $Max=pg_NumRows($Res); + + for ( $i = 0; $i < $Max; $i++) { + $l_line=pg_fetch_array($Res,$i); + $div="
"; + $span_mod=' Modifie'; + $span_del=''. + ' delete'; + $span_id=''.$l_line['f_id'].""; + if ( $i %2 == 0 ) + $div='
'; + echo $div.$span_del.' '.' '.' '.' '.' '.' '. + $span_mod." "." "." ".$span_id." "." "." ".$l_line['f_label']."
"; + } + echo '
'; + echo ''; + echo ''; + echo '
'; + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetNextFiche($p_cn,$p_base) { + $Res=ExecSql($p_cn,"select max(pcm_val) as maxcode from tmp_pcmn where pcm_val_parent = $p_base"); + $Max=pg_NumRows($Res); + echo_debug("$Max=pg_NumRows"); + $l_line=pg_fetch_array($Res,0); + $ret=$l_line['maxcode']; + if ( $ret == "" ) { + $ret=sprintf("%d%04d",$p_base,0); + return $ret+1; + + } + + echo_debug("ret $ret"); + return $ret+1; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetDataFiche($p_cn,$p_fiche_id) { + +} + +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function ViewFicheDetail($p_cn,$p_id) { +$sql="insert into isupp (is_f_id,is_isd_id) select". + " '".$p_id."',isd_id from isupp_def ". + " where isd_id not in ". + "(select is_isd_id from isupp where is_f_id=".$p_id.") ". + " and isd_fd_id=(select distinct f_fd_id from fiche ". + " where f_id=".$p_id.")"; + $Res=ExecSql($p_cn,$sql); + EncodeFiche ($p_cn,$p_id,1); +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function UpdateFiche($p_cn,$p_array) { + foreach ( $p_array as $key=> $element) { + echo_debug("$key => $element"); + ${"$key"}=$element; + } + $sql=sprintf("update tmp_pcmn set pcm_lib='%s' where pcm_val=%s", + $f_label, + $f_id); + echo_debug($sql); + $Res=ExecSql($p_cn,$sql); + $sql=sprintf("update fiche set f_label='%s' where f_id=%s", + $f_label, + $f_id); + echo_debug($sql); + $Res=ExecSql($p_cn,$sql); + for ( $i =0 ; $i < $max ; $i++) { + $sql=sprintf("update isupp set is_value='%s' where is_id=%d", + ${"nom$i"}, + ${"is_id$i"}); + echo_debug($sql); + $Res=ExecSql($p_cn,$sql); + } +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function EncodeModele($p_js) +{ + echo '

Ajout d\'un modèle

'; + echo '
'; + echo '
Libellé '; + echo '
Classe de base '; + echo $p_js; + echo ''; + echo '
'; + echo '
'; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function DefModele ($p_js,$p_array=null,$p_ligne=1) +{ + echo_debug("DefModele ($p_array,$p_ligne=1) "); + for ($i=0; $i < $p_ligne; $i++) { + ${"p_LABEL$i"}=""; + ${"p_inform$i"}=""; + ${"p_isd_id$i"}=""; + } + if ($p_array != null) { + foreach ( $p_array as $key => $element){ + ${"p_$key"}=$element; + echo_debug ("p_$key $element"); + }//foreach + }else { + $p_nom_mod=""; + $p_class_base=""; + } + + echo '
'; + echo ''; + // echo ''; + echo '
Label'; + echo '
classe'.$p_js; + + if ( isset($p_fd_id) ) { + echo ''; + } + for ( $i=0; $i < $p_ligne ; $i++ ) { + if ( isset($p_fd_id) ) { + echo ''; + } + printf( '
Libellé ', + $i, + ${"p_LABEL$i"} + ); + if ( ${"p_inform$i"} == "on" || ${"p_inform$i"}=='t' ) { + $val="checked"; + } else { + $val=""; + } + printf('Dans les formulaires ', + $i, + $val + ); + } + echo '
'; + if ( isset($p_fd_id) ){ + echo '
'; + }else { + echo '
'; + }//if isset p_fd_id else + + echo ''; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function AddModele($p_cn,$p_array) { + echo_debug("AddModele"); + $p_ligne=$p_array['inc']; + for ($i=0; $i < $p_ligne; $i++) { + ${"p_inform$i"}=""; + } + + foreach ( $p_array as $key=>$element ) { + echo_debug("p_$key $element"); + ${"p_$key"}=$element; + } + $p_nom_mod=FormatString($p_nom_mod); + $p_class_base=FormatString($p_class_base); + $sql=sprintf("insert into fichedef(fd_label,fd_class_base) values ('%s','%s')", + $p_nom_mod,$p_class_base); + $Res=ExecSql($p_cn,$sql); + + $f_id=GetSequence($p_cn,"s_fdef"); + + for ( $i=0; $i < $p_inc; $i++) { + if ( ${"p_inform$i"} == "on" ) { + $valform="true"; + }else { + $valform="false"; + } + ${"p_LABEL$i"}=FormatString(${"p_LABEL$i"}); + if ( ${"p_LABEL$i"} != null ) { + $sql=sprintf("insert into isupp_def(isd_label,isd_fd_id,isd_form) values ('%s',%d,%s)", + ${"p_LABEL$i"},$f_id,$valform); + $Res=ExecSql($p_cn,$sql); + } + } +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function UpdateModele($p_cn,$p_fiche,$p_js) { + $array=GetDataModele($p_cn,$p_fiche); + if ($array==null) { + echo_error ("fiche_inc:UpdateModele Fiche non trouvée"); + return; + } + foreach ( $array as $key=>$element) echo_debug("$key => $element"); + DefModele($p_js,$array,$array['ligne']); + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetDataModele($p_cn,$p_fiche) { + $Res=ExecSql($p_cn,"select fd_id,fd_label,fd_class_base, + isd_id,isd_label,isd_form + from fichedef inner join isupp_def on isd_fd_id=fd_id + where fd_id=$p_fiche"); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + for ($i=0; $i < $Max;$i++) { + $line=pg_fetch_array($Res,$i); + if ($i == 0 ) { + $array["nom_mod"]=$line['fd_label']; + $array["class_base"]=$line['fd_class_base']; + $array["fd_id"]=$line['fd_id']; + }//if $i == 0 + //inform + $text=sprintf("inform%d",$i); + $array[$text]=$line['isd_form']; + //Label + $text=sprintf("LABEL%d",$i); + $array[$text]=$line['isd_label']; + //isd_id + $text=sprintf("isd_id%d",$i); + $array[$text]=$line['isd_id']; + + }//for + $array['ligne']=$Max; + return $array; +} + +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function SaveModele($p_cn,$p_array) { + for ($i=0; $i < $p_array['inc']; $i++) { + ${"inform$i"}=""; + } + + foreach ($p_array as $key=>$element){ + echo_debug("$key => $element"); + ${"$key"}=$element; + }//foreach + $nom_mod=FormatString($nom_mod); + $class_base=FormatString($class_base); + if ( $nom_mod != null ) { + $sql=sprintf("update fichedef set fd_label='%s', fd_class_base='%s' where fd_id=%d", + $nom_mod,$class_base,$fd_id); + $Res=ExecSql($p_cn,$sql); + } + for ($i=1;$i<$inc;$i++){ + if ( ${"inform$i"} != null) { + $valform='true'; + }else { + $valform='false'; + } //if ( ${"inform$d") != null) + + if ( ${"isd_id$i"} != null ) { + ${"LABEL$i"}=FormatString(${"LABEL$i"}); + if ( ${"LABEL$i"} != null ) { + $sql=sprintf("update isupp_def set isd_label='%s',isd_form=%s where isd_id=%d", + ${"LABEL$i"},$valform,${"isd_id$i"}); + } + } // if ( ${"p_isd_id$i"} != null ) + else { + ${"LABEL$i"}=FormatString(${"LABEL$i"}); + if ( ${"LABEL$i"} != null ) { + $sql=sprintf("insert into isupp_def( isd_label,isd_fd_id,isd_form) + values ('%s',%d,%s)", + ${"LABEL$i"},$fd_id,$valform); + }// if ( ${"LABEL$i"} != null ) + }//else if ( ${"p_isd_id$i"} != null ) + $Res=ExecSql($p_cn,$sql); + }//for +} +function Remove ($p_cn, $p_fid) { + if ( ! isset ($p_cn) || + ! isset ($p_fid) ) { + echo_error ("Remove Missing Parameter p_cn = $p_cn p_fid=$p_fid"); + return; + } + if ( CountSql($p_cn,"select * from jrnx where j_poste=$p_fid") == 0 ) { + $Res=ExecSql($p_cn,"delete from isupp where is_f_id=$p_fid"); + $Res=ExecSql($p_cn,"delete from fiche where f_id=$p_fid"); + } else { + echo ""; + } +} +?> diff --git a/include/form_inc.php b/include/form_inc.php new file mode 100644 index 000000000..4ec2fd5b9 --- /dev/null +++ b/include/form_inc.php @@ -0,0 +1,308 @@ +'; + $search='"; + for ( $i =0 ; $i <= $p_line; $i++) { + ${"text$i"}=""; + ${"form$i"}=""; + ${"pos$i"}=""; + } + if ( $p_array != null ) { + foreach ( $p_array as $key=> $element ) { + ${"$key"}=$element; + echo_debug ("EncodeForm $key = $element"); + + } + + } else { + $form_nom=""; + $text0=""; + $form0=""; + } + echo ""; + printf ("Nom du formulaire : ", + $form_nom); + printf (''; + echo ""; + if ( isset($fr_id) ) echo " Position "; + echo " Texte "; + echo " Formule"; + + echo ''; + for ( $i =0 ; $i < $p_line;$i++) { + echo ""; + // si fr_id != null alors les donnees viennent de + // GetDataForm: ce n'est pas un nouvel enregistrement + // + if ( isset($fr_id)) { + echo ""; + printf ('', + $i,${"pos$i"}); + echo ''; + } + + echo ""; + printf ('', + $i,${"text$i"}); + echo ''; + + echo ""; + printf ('', + $i,${"form$i"}); + echo $search; + echo ''; + + echo ""; + } + echo ""; + if ( isset($fr_id)){ + echo ''; + }else { + echo ''; + } + echo ''; + echo "
"; + +} +/* function ViewForm + * Purpose : Show the details of a form + * + * parm : + * - $p_cn connection + * - $p_id gives the formdef.fr_id + * - sessid for the search window + * gen : + * - none + * return: + * - none + * + */ +function ViewForm($p_cn,$p_sessid,$p_id) { + $array=GetDataForm($p_cn,$p_id); + $l_nom=GetFormName($p_cn,$p_id); + $array['form_nom']=$l_nom; + + $l_line=GetNumberLine($p_cn,$p_id); + EncodeForm($l_line,$p_sessid,$array); + +} +/* function GetDataForm + * Purpose : + * Get data from a form + * parm : + * - $p_cn connection + * - $p_id gives the formdef.fr_id + * - + * gen : + * - none + * return: + * - array + * + */ +function GetDataForm($p_cn,$p_id) { + $Res=ExecSql($p_cn,"select fo_id,fo_fr_id,fo_pos,fo_label,fo_formula from form where fo_fr_id=$p_id + order by fo_pos"); + $Max=pg_NumRows($Res); + for ( $i=0;$i<$Max;$i++){ + $l_line=pg_fetch_array($Res,$i); + + // get the fo_id + $text=sprintf("fo_id%d",$i); + $array[$text]=$l_line['fo_id']; + // get the fo_label + $text=sprintf("text%d",$i); + $array[$text]=$l_line['fo_label']; + // get the fo_formula + $text=sprintf("form%d",$i); + $array[$text]=$l_line['fo_formula']; + // get the pos + $text=sprintf("pos%d",$i); + $array[$text]=$l_line['fo_pos']; + } //for + $array["fr_id"]=$p_id; + return $array; +} +/* function GetNumberLine + * Purpose : Get the number of line of a form + * + * parm : + * - $p_cn connection + * - $p_id gives the formdef.fr_id + * - + * gen : + * - none + * return: + * - integer + * + */ +function GetNumberLine($p_cn,$p_id) { + $Res=ExecSql($p_cn,"select * from form where fo_fr_id=".$p_id); + $count=pg_NumRows($Res); + return $count; +} +/* function GetFormName + * Purpose : Get the name of the form + * + * parm : + * - $p_cn connection + * - $p_id formdef.fr_id + * gen : + * - none + * return: + * - string name + * + */ +function GetFormName($p_cn,$p_id) { + $Res=ExecSql($p_cn,"select fr_label from formdef where fr_id=".$p_id); + if ( pg_NumRows($Res) == 0 ) return null; + $name=pg_fetch_array($Res,0); + return $name['fr_label']; +} +/* function UpdateForm + * Purpose : + * + * parm : + * - $p_cn connexion + * - $array + * gen : + * - none + * return: + * - none + * + */ +function UpdateForm($p_cn,$p_array) { + foreach ($p_array as $key=>$element) { + echo_debug ("UpdateForm $key = $element"); + ${"$key"}=$element; + } + $Res=ExecSql($p_cn,"update formdef set fr_label='".$form_nom."' where fr_id=".$fr_id); + $Res=ExecSql($p_cn,"delete from form where fo_fr_id=".$fr_id); + // Test les positions + for ($i =0; $i <$line;$i++) { + echo_debug ("position =".${"pos$i"}); + if ( (string) ${"pos$i"} != (string) (int) ${"pos$i"}) { + ${"pos$i"}=$i+1; + } + if ( ${"pos$i"} > $line || ${"pos$i"} < 0) { + ${"pos$i"}=$i+1; + echo_debug("position trop grand max = $line+1 "); + } + } + for ($i =0; $i <$line;$i++) { + for ( $o=$i+1; $o < $line;$o++) { + if ( ${"pos$i"} == ${"pos$o"} ) { + ${"pos$o"}=$o+1; + } + } + } + for ( $i=0;$i<$line;$i++) { + if ( strlen(trim(${"text$i"})) != 0) { + ${"text$i"}=FormatString(${"text$i"}); + ${"form$i"}=FormatString(${"form$i"}); + if ( ${"text$i"} != null ) { + ${"form$i"}=(${"form$i"}==null)?${"form$i"}:"'".${"form$i"}."'"; + $sql=sprintf("insert into form (fo_fr_id, + fo_pos, + fo_label, + fo_formula) values + ( %d, + %d, + '%s', + %s)", + $fr_id,${"pos$i"},${"text$i"},${"form$i"} + ); + $Res=ExecSql($p_cn,$sql); + } + }//if + }//for + +} +/* function AddForm + * Purpose : + * + * parm : + * - $p_cn connexion + * - $array + * gen : + * - none + * return: + * - none + * + */ +function AddForm($p_cn,$p_array) { + foreach ($p_array as $key=>$element) { + echo_debug ("AddForm $key = $element"); + ${"$key"}=$element; + } + + if ( !isset ($form_nom) || + ! isset ($line) ) { + echo_error("Nom ou ligne non défini"); + return; + } + $sql="insert into formdef (fr_label) values ('".$form_nom."')"; + $Res=ExecSql($p_cn,$sql); + $n=GetSequence($p_cn,"s_formdef"); + + for ($i=0;$i < $line;$i++) { + ${"text$i"}=FormatString(${"text$i"}); + ${"form$i"}=FormatString(${"form$i"}); + if ( ${"text$i"} != null ) { + ${"form$i"}=(${"form$i"}==null)?${"form$i"}:"'".${"form$i"}."'"; + $sql=sprintf("insert into form (fo_fr_id, + fo_pos, + fo_label, + fo_formula) values + ( %d, + %d, + '%s', + %s)", + $n,$i+1,${"text$i"},${"form$i"} + ); + $Res=ExecSql($p_cn,$sql); + }//if + }//for $i +} + +?> diff --git a/include/impress_inc.php b/include/impress_inc.php new file mode 100644 index 000000000..a43fba670 --- /dev/null +++ b/include/impress_inc.php @@ -0,0 +1,593 @@ +$element) { + echo_debug("VIEWIMP $key $element"); + ${"$key"}=$element; + } + if ( ! isset($type) ) return; + + if ( $action=="viewhtml") echo '
'; + else { + if ( $type=="jrn") + echo ''; + if ( $type=="poste") + echo ''; + } + echo $periode; + echo ''; + echo ''; + if (isset ($central)) { + echo ''; + } + if ( isset($filter)) + echo ''; + if ( isset ($p_id)) { + echo ''; + } else { + include_once("poste.php"); + echo PosteForm($p_cn); + } + echo ''; + + echo '
'; + echo "
"; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function Imp($p_array,$p_cn) { + if ( ! isset($p_array['action'])) { + echo_error ("IMP no action specified"); return; + } + if ( $p_array['action']=="viewhtml") { + return ImpHtml($p_array,$p_cn); + } + echo_error ("IMP no action specified"); return; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function ImpHtml($p_array,$p_cn) +{ + foreach($p_array as $key=>$element) { + ${"$key"}=$element; + echo_debug("ImpHtml $key => $element"); + } + + + $colvide=""; + // formulaire + if ( $type == "form" ) { + if ( !isset ($periode)) return NO_PERIOD_SELECTED; + $cond=CreatePeriodeCond($periode); + $Res=ExecSql($p_cn,"select fo_id , + fo_fr_id, + fo_pos, + fo_label, + fo_formula, + fr_label from form + inner join formdef on fr_id=fo_fr_id + order by fo_pos"); + $Max=pg_NumRows($Res); + if ($Max==0) return $ret=""; + for ($i=0;$i<$Max;$i++) { + $l_line=pg_fetch_array($Res,$i); + $col=ParseFormula($p_cn, + $l_line['fo_label'], + $l_line['fo_formula'],$cond); + echo "
"; + foreach ($col as $key=> $element) { + echo "$element "; + } + echo "
"; + } //for ($i + + }//form + if ($type=="poste") { + if ( ! isset ( $poste )) return NO_POST_SELECTED; + if ( !isset ($periode)) return NO_PERIOD_SELECTED; + include_once("poste.php"); + $cond=CreatePeriodeCond($periode); + $ret="" ; + for ( $i =0;$i%d %s", + $poste[$i],GetPosteLibelle($p_cn,$poste[$i],1)); + $ret.=""; + list ($array,$tot_deb,$tot_cred)=GetDataPoste($p_cn,$poste[$i],$cond); + if ( $array == null) continue; + foreach ($array as $col=>$element) { + $ret.=""; + $ret.=sprintf("",$element['jr_internal']); + $ret.=sprintf("",$element['j_date']); + $ret.=sprintf("",$element['jrn_name']); + $ret.=sprintf("",$element['description']); + if ( $element['j_debit']=='t') { + $ret.=sprintf("",$element['montant']); + } else { + $ret.=sprintf(" $colvide ",$element['montant']); + + } + $ret.=""; + }//foreach + $ret.=sprintf("$colvide $colvide $colvide $colvide ". + "". + "", + $tot_deb, + $tot_cred); + $ret.="
%s%sjrn:%s%s debit % 8.2fcredit % 8.2f
% 8.2f% 8.2f
"; + $ret.="Total débit :".$tot_deb." Total Crédit:".$tot_cred; + }// for i + return $ret; + }//poste + if ($type=="jrn") { + + echo_debug("imp html journaux"); + $ret=""; + if (isset($filter)) { + $array=GetDataJrn($p_cn,$p_array,$filter); + } + $cass=""; + $c=0; + + foreach ($array as $a=>$e2) { + // echo_debug($ret); + + //cassure entre op + if ( $cass!=$e2['grp'] ) { + $cass=$e2['grp']; + $ret.=''.$e2['j_date'].""; + $ret.="".$e2['jr_internal']." ".$e2['comment'].""; + } + $ret.=""; + $ret.=$colvide; + + if ($e2['debit']=='f') $ret.=$colvide; + $ret.="".$e2['poste'].""; + if ($e2['debit']=='t') $ret.=$colvide; + $ret.="".$e2['description'].""; + if ($e2['debit']=='f') $ret.=$colvide; + $ret.="".$e2['montant'].""; + if ($e2['debit']=='t') $ret.=$colvide; + $ret.=""; + } + echo_debug($ret); + + return $ret ; + }//jrn + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetDataPoste($p_cn,$p_poste,$p_condition) +{ + $Res=ExecSql($p_cn,"select to_char(j_date,'DD.MM.YYYY') as j_date,". + "to_char(j_montant,'999999999.99') as montant,". + " j_text as description,jrn_def_name as jrn_name,". + "j_debit, jr_internal, ". + " case when j_debit='t' then 'debit' else 'credit' end as debit". + " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ". + " left join jrn on jr_grpt_id=j_grpt". + " where j_poste=".$p_poste." and ".$p_condition. + " order by j_date"); + $array=array(); + $tot_cred=0; + $tot_deb=0; + $Max=pg_NumRows($Res); + if ( $Max == 0 ) return null; + for ($i=0;$i<$Max;$i++) { + $array[]=pg_fetch_array($Res,$i); + if ($array[$i]['j_debit']=='t') { + $tot_deb+=$array[$i]['montant'] ; + } else { + $tot_cred+=$array[$i]['montant'] ; + } + } + return array($array,$tot_deb,$tot_cred); +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetDataJrn($p_cn,$p_array,$filter=YES) +{ + if ( !isset ($p_array['periode']) ) return NO_PERIOD_SELECTED; + $cond=CreatePeriodeCond($p_array['periode']); + if ( $filter==YES) { + $Res=ExecSql($p_cn,"select to_char(j_date,'DD.MM.YYYY') as j_date, + j_montant as montant,j_debit as debit,j_poste as poste,". + "j_text as description,j_grpt as grp,jr_comment as comment, + j_rapt as oc,jr_internal from jrnx left join jrn on ". + "jr_grpt_id=j_grpt where j_jrn_def=".$p_array['p_id']. + " and ".$cond." order by j_date,j_grpt,j_debit desc"); + } + if ( $filter == NO) { + if ( $p_array['central']=='no') { + $Res=ExecSql($p_cn,"select to_char(j_date,'DD.MM.YYYY') as j_date, + j_montant as montant,j_debit as debit,j_poste as poste,". + "j_text as description,j_grpt as grp,jr_comment as comment, + j_rapt as oc,jr_internal from jrnx left join jrn on ". + "jr_grpt_id=j_grpt where ". + $cond." order by j_date,j_grpt,j_debit desc"); + } else { + $cond=CreatePeriodeCond($p_array['periode'],"c_periode"); + + $Res=ExecSql($p_cn,"select to_char(c_date,'DD.MM.YYYY') as j_date, + c_montant as montant,c_debit as debit,c_poste as poste,". + "c_description as description,c_grp as grp,c_comment as comment, + c_rapt as oc,c_internal from centralized left join jrn on ". + "jr_grpt_id=c_grp where ". + $cond." order by c_id,c_date,c_grp,c_debit desc"); + + } + }// filter == no + $array=array(); + $Max=pg_NumRows($Res); + for ($i=0;$i<$Max;$i++) { + $array[]=pg_fetch_array($Res,$i); + } + return $array; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function CreatePeriodeCond($p_periode,$p_field=" j_tech_per") { + $cond_periode=" $p_field in ("; + + // condition periode + foreach ( $p_periode as $per) { + $cond_periode.=$per.","; + } + $cond_periode=substr($cond_periode,0,strlen($cond_periode)-1); + $cond_periode.=")"; +return $cond_periode; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetDataJrnPdf($p_cn,$p_array,$p_limit,$p_offset) +{ + if ( !isset ($p_array['periode']) ) return NO_PERIOD_SELECTED; + + if ( $p_array['filter']==YES) { + $cond=CreatePeriodeCond($p_array['periode']); + $Res=ExecSql($p_cn,"select j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + jr_internal, + case j_debit when 't' then j_montant::text else ' ' end as deb_montant, + case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, + j_debit as debit,j_poste as poste,". + "j_text as description,j_grpt as grp,jr_comment as comment, + j_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". + "jr_grpt_id=j_grpt where j_jrn_def=".$p_array['p_id']. + " and ".$cond." order by j_id,j_date,j_grpt,j_debit desc". + " limit ".$p_limit." offset ".$p_offset); + } else { + if ( $p_array['central']=='no' ) { + $cond=CreatePeriodeCond($p_array['periode']); + $Res=ExecSql($p_cn,"select j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + jr_internal, + case j_debit when 't' then j_montant::text else ' ' end as deb_montant, + case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, + j_debit as debit,j_poste as poste,". + "j_text as description,j_grpt as grp,jr_comment as comment, + j_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". + "jr_grpt_id=j_grpt where ". + " ".$cond." order by j_date,j_grpt,j_debit desc". + " limit ".$p_limit." offset ".$p_offset); + + } else { + $cond=CreatePeriodeCond($p_array['periode'],"c_periode"); + $Sql="select c_id as j_id, + c_j_id, + to_char (c_date,'DD.MM.YYYY') as j_date , + c_internal as jr_internal, + case c_debit when 't' then c_montant::text else ' ' end as deb_montant, + case c_debit when 'f' then c_montant::text else ' ' end as cred_montant, + c_debit as j_debit, + c_poste as j_poste, + c_description as description, + c_grp as grp, + c_comment as comment, + c_rapt as oc, + c_periode as periode + from centralized left join jrn on ". + "jr_grpt_id=c_grp where ". + $cond." order by c_id "; + $Res=ExecSql($p_cn,$Sql." limit ".$p_limit." offset ".$p_offset); + } // Grand Livre + } + + + $array=array(); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $case=""; + $tot_deb=0; + $tot_cred=0; + for ($i=0;$i<$Max;$i++) { + $line=pg_fetch_array($Res,$i); + $mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):""; + $mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):""; + $tot_deb+=$line['deb_montant']; + $tot_cred+=$line['cred_montant']; + if ( $case != $line['grp'] ) { + $case=$line['grp']; + $array[]=array ( + 'j_id'=>$line['j_id'], + 'j_date' => $line['j_date'], + 'internal'=>$line['jr_internal'], + 'deb_montant'=>$mont_deb, + 'cred_montant'=>$mont_cred, + 'description'=>$line['description'], + 'poste' => $line['poste'], + 'periode' => $line['periode'] + ); + + }else { + $array[]=array ( + 'j_id'=>$line['j_id'], + 'j_date' => '', + 'internal'=>'', + 'deb_montant'=>$mont_deb, + 'cred_montant'=>$mont_cred, + 'description'=>$line['description'], + 'poste' => $line['poste'], + 'periode' => $line['periode']); + + } + + + } + echo_debug("Total debit $tot_deb,credit $tot_cred"); + $a=array($array,$tot_deb,$tot_cred); + return $a; +} +function GetDataGrpt($p_cn,$p_array) +{ + if ( !isset ($p_array['periode']) ) return NO_PERIOD_SELECTED; + $cond=CreatePeriodeCond($p_array['periode']); + $Res=ExecSql($p_cn,"select distinct ". + " j_grpt as grp". + " from jrnx ". + " where j_jrn_def=".$p_array['p_id']. + " and ".$cond." order by j_grpt"); + $array=array(); + $Max=pg_NumRows($Res); + $case=""; + for ($i=0;$i<$Max;$i++) { + $array[]=pg_fetch_array($Res,$i); + } + return $array; +} + +/* function GetRappel + * Purpose : Get the amount on each page + * + * parm : + * - $p_cn + * - $p_jrnx_id jrnx.j_id + * - $p_jrn_id jrn.jr_id + * - $which LAST or FIRST + * - $p_type valeur JRN GL-CENTRAL GL-NOCENTRAL + * gen : + * - + * return: + * - array sum (deb) sum(cred) + * + */ + +function GetRappel($p_cn,$p_jrnx_id,$p_jrn_id,$p_exercice,$which,$p_type) +{ + include_once("preference.php"); + + if ( $which == LAST) + $cmp="<="; + else + $cmp="<"; + + if ( $p_type == 'JRN' ) { + $c_line=CountSql($p_cn,"select * from jrnx left join parm_periode on j_tech_per=p_id ". + "where j_jrn_def=$p_jrn_id and p_exercice='".$p_exercice."'". + " and j_id $cmp $p_jrnx_id "); + + if ($c_line == 0 ) { return array (0,0); } + $sql="select sum(j_montant) as tot_amount ". + " from jrnx ". + " left join parm_periode on j_tech_per=p_id ". + " where j_jrn_def=$p_jrn_id and ". + " p_exercice='".$p_exercice."'". + " and j_id $cmp $p_jrnx_id " ; + $Res=ExecSql($p_cn,$sql." and j_debit='t' "); + if ( pg_NumRows($Res) == 0 ) + $deb=0; + else { + $line=pg_fetch_array($Res,0); + $deb=$line['tot_amount']; + } + + $Res=ExecSql($p_cn,$sql." and j_debit='f' "); + if ( pg_NumRows($Res) == 0 ) + $cred=0; + else { + + $line=pg_fetch_array($Res,0); + $cred=$line['tot_amount']; + } + echo_debug("MONTANT $deb,$cred"); + $a=array($deb,$cred); + return $a; + } + if ($p_type=='GL-CENTRAL') { // Si Grand Livre, prendre donnée centralisée{ + $c_line=CountSql($p_cn,"select * from centralized left join parm_periode on c_periode=p_id ". + "where p_exercice='".$p_exercice."'". + " and c_id $cmp $p_jrnx_id "); + + if ($c_line == 0 ) { return array (0,0); } + $sql="select sum(c_montant) as tot_amount ". + " from centralized ". + " left join parm_periode on c_periode=p_id ". + " where ". + " p_exercice='".$p_exercice."'". + " and c_id $cmp $p_jrnx_id " ; + $Res=ExecSql($p_cn,$sql." and c_debit='t' "); + if ( pg_NumRows($Res) == 0 ) + $deb=0; + else { + $line=pg_fetch_array($Res,0); + $deb=$line['tot_amount']; + } + + $Res=ExecSql($p_cn,$sql." and c_debit='f' "); + if ( pg_NumRows($Res) == 0 ) + $cred=0; + else { + + $line=pg_fetch_array($Res,0); + $cred=$line['tot_amount']; + } + echo_debug("MONTANT $deb,$cred"); + $a=array($deb,$cred); + return $a; + } + if ($p_type=='GL-NOCENTRAL') { // Si Grand Livre, prendre donnée non centralisée{ + return array(0,0); + } + +} +/* function ParseFormula + * Purpose : Parse the formula contained in the fo_formula + * field and return a array containing all the columns + * + * parm : + * - $p_cn connexion + * - $p_label + * - $p_formula + * gen : + * - none + * return: + * - array + * + */ +function ParseFormula($p_cn,$p_label,$p_formula,$p_cond) +{ + $aret=array(); + $l_debit=0; + $l_credit=0; + // somme debit + $Res=ExecSql($p_cn,"select sum (j_montant) as montant from + jrnx where $p_cond and j_debit='t' and j_poste like '$p_formula'"); + if (pg_NumRows($Res)==0){ + $l_debit=0; + } else { + $l=pg_fetch_array($Res,0); + $l_debit=$l['montant']; + } + // somme credit + $Res=ExecSql($p_cn,"select sum (j_montant) as montant from + jrnx where $p_cond and j_debit='f' and j_poste like '$p_formula'"); + if (pg_NumRows($Res)==0) { + $l_credit=0; + } else { + $l=pg_fetch_array($Res,0); + $l_credit=$l['montant']; + } + + if ( $l_credit==$l_debit) { + $aret=array('desc' => $p_label, + 'montant' => '0'); + } + if ( $l_credit < $l_debit) { + $l2=sprintf("% .2f",$l_debit-$l_credit); + $aret=array('desc' => $p_label, + 'montant' => $l2); + } + if ( $l_credit>$l_debit) { + $l2=sprintf("(% .2f)",$l_credit-$l_debit); + $aret=array('desc' => $p_label, + 'montant' => $l2); + + } + return $aret; +} +?> diff --git a/include/jrn.php b/include/jrn.php new file mode 100644 index 000000000..f01a43c18 --- /dev/null +++ b/include/jrn.php @@ -0,0 +1,1072 @@ +$e) { + ${"e_$n"}= $e; + } + } + /* Get Jrn's properties */ + $l_line=GetJrnProp($p_dossier,$p_jrn); + if ( $l_line == null ) return; + + + echo '
'; + printf ('

%s %s

',$l_line['jrn_def_name'],$l_line['jrn_def_code']); + echo '
'; + echo ""; + echo ""; + // Date echeance - paiement + if ( $l_line['jrn_def_ech'] == 't' ) { + echo $l_line['jrn_def_ech_lib'].''; + } + echo '
'; + echo 'Date : '; + echo '

débit

'; + // Chargement comptes disponibles + if ( strlen(trim ($l_line['jrn_def_class_deb']) ) > 0 ) { + $valid_deb=split(" ",$l_line['jrn_def_class_deb']); + + // Creation query + $SqlDeb="select pcm_val,pcm_lib from tmp_pcmn where "; + foreach ( $valid_deb as $item_deb) { + if ( strlen (trim($item_deb))) { + echo_debug("l_line[jrn_def_class_deb] $l_line[jrn_def_class_deb] item_deb $item_deb"); + if ( strstr($item_deb,"*") == true ) { + $item_deb=strtr($item_deb,"*","%"); + $Sql=" pcm_val like '$item_deb' or"; + } else { + $Sql=" pcm_val = '$item_deb' or"; + } + $SqlDeb=$SqlDeb.$Sql; + } + } + $SqlDeb = substr($SqlDeb,0,strlen($SqlDeb)-2)." order by pcm_val::text"; + } else + { + $SqlDeb="select pcm_val,pcm_lib from tmp_pcmn order by pcm_val::text"; + } + echo_debug("SqlDeb $SqlDeb"); + $Res=ExecSql($cn,$SqlDeb); + $Count=pg_NumRows($Res); + + for ( $i=0;$i<$Count;$i++) { + $l2_line=pg_fetch_array($Res,$i); + $lib=substr($l2_line['pcm_lib'],0,35); + $poste [$l2_line['pcm_val']]= $lib; + } + + echo ""; + for ( $i=0;$i < $p_MaxDeb;$i++) { + echo ""; + echo "'); + printf('', + $i, + ${"e_text_deb$i"}); + + printf('', + $i,$i,${"e_mont_deb$i"},$i); + echo ""; + + } +if ( $p_update == 0 ) echo ""; + echo "
"; + printf ('"; + printf (' Montant :
"; + echo '
'; + + echo '
'; + echo '

crédit

'; + // Chargement comptes disponibles + if ( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 ) { + $valid_cred=split(" ",$l_line['jrn_def_class_cred']); + + // Creation query + $SqlCred="select pcm_val,pcm_lib from tmp_pcmn where "; + foreach ( $valid_cred as $item_cred) { + if ( strlen (trim($item_cred))) { + echo_debug("l_line[jrn_def_class_cred] $l_line[jrn_def_class_cred] item_cred $item_cred"); + if ( strstr($item_cred,"*") == true ) { + $item_cred=strtr($item_cred,"*","%"); + $Sql=" pcm_val like '$item_cred' or"; + } else { + $Sql=" pcm_val = '$item_cred' or"; + } + $SqlCred=$SqlCred.$Sql; + } + } + $SqlCred = substr($SqlCred,0,strlen($SqlCred)-2)." order by pcm_val::text" ; + } else + { + $SqlCred="select pcm_val,pcm_lib from tmp_pcmn order by pcm_val::text"; + } + echo_debug("SqlCred $SqlCred"); + $Res=ExecSql($cn,$SqlCred); + $Count=pg_NumRows($Res); + + echo ""; + for ( $i=0;$i<$Count;$i++) { + $l2_line=pg_fetch_array($Res,$i); + $lib=substr($l2_line['pcm_lib'],0,35); + $poste_c[$l2_line['pcm_val']]=$lib; + } + for ( $i=0;$i < $p_MaxCred;$i++) { + echo ""; + echo ""; + printf('', + $i, + ${"e_text_cred$i"}); + + printf ('', + $i,$i,${"e_mont_cred$i"}); + echo ""; + + } + + echo ""; + if ( isset ($_GET["PHPSESSID"]) ) { + $sessid=$_GET["PHPSESSID"]; + } + else { + $sessid=$_POST["PHPSESSID"]; + } + + $search='"; + echo_debug("search $search"); + echo ''; + echo "
"; + printf ('"; + echo " Montant :
rapprochement : '.$search.'
"; + echo '
'; + echo ''; + echo $e_comment; + echo ""; + + + if ( $p_update==0) { + echo ''; + } else { + echo ''; + } + echo ''; + // echo ''; + echo ''; + echo ''; + echo ''; + echo ""; + echo '
'; + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ + +function UpdateJrn($p_dossier,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array) +{ + include_once("postgres.php"); + echo_debug("function UpdateJrn($p_dossier,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array)"); + foreach ( $p_array as $n=>$e) { + ${"e_$n"}= $e; + echo_debug("e_$n= $e"); + } + /* Get Jrn's properties */ + $l_line=GetJrnProp($p_dossier,$p_jrn); + if ( $l_line == null ) return; + + $l_dossier=sprintf("dossier%d",$p_dossier); + $cn=DbConnect($l_dossier); + + echo '
'; + printf ('

%s (%s)

',$l_line['jrn_def_name'],$l_line['jrn_def_code']); + echo '
'; + echo ""; + echo ""; + echo ""; + // Date echeance - paiement + if ( $l_line['jrn_def_ech'] == 't' ) { + echo $l_line['jrn_def_ech_lib'].''; + } + echo '
'; + + echo '

débit

'; + // Chargement comptes disponibles + if ( strlen(trim ($l_line['jrn_def_class_deb']) ) > 0 ) { + $valid_deb=split(" ",$l_line['jrn_def_class_deb']); + + // Creation query + $SqlDeb="select pcm_val,pcm_lib from tmp_pcmn where "; + foreach ( $valid_deb as $item_deb) { + if ( strlen (trim($item_deb))) { + echo_debug("l_line[jrn_def_class_deb] $l_line[jrn_def_class_deb] item_deb $item_deb"); + if ( strstr($item_deb,"*") == true ) { + $item_deb=strtr($item_deb,"*","%"); + $Sql=" pcm_val like '$item_deb' or"; + } else { + $Sql=" pcm_val = '$item_deb' or"; + } + $SqlDeb=$SqlDeb.$Sql; + } + } + $SqlDeb = substr($SqlDeb,0,strlen($SqlDeb)-2)." order by pcm_val::text"; + } else + { + $SqlDeb="select pcm_val,pcm_lib from tmp_pcmn order by pcm_val::text"; + } + echo_debug("SqlDeb $SqlDeb"); + $Res=ExecSql($cn,$SqlDeb); + $Count=pg_NumRows($Res); + + for ( $i=0;$i<$Count;$i++) { + $l2_line=pg_fetch_array($Res,$i); + $lib=substr($l2_line['pcm_lib'],0,35); + $poste [$l2_line['pcm_val']]= $lib; + } + + echo ""; +echo '"; + + echo ""; + printf('', + $i, + ${"e_text_deb$i"}); + + printf ('', + $i,$i,${"e_mont_deb$i"},$i); + echo ""; + + } + echo "
Date : '; + for ( $i=0;$i < $p_MaxDeb;$i++) { + echo "
"; + printf('', + $i, + ${"e_op_deb$i"}); + + printf ('"; + echo " Montant :
"; + echo '
'; + + echo '
'; + echo '

crédit

'; + // Chargement comptes disponibles + if ( strlen(trim ($l_line['jrn_def_class_cred']) ) > 0 ) { + $valid_cred=split(" ",$l_line['jrn_def_class_cred']); + + // Creation query + $SqlCred="select pcm_val,pcm_lib from tmp_pcmn where "; + foreach ( $valid_cred as $item_cred) { + if ( strlen (trim($item_cred))) { + echo_debug("l_line[jrn_def_class_cred] $l_line[jrn_def_class_cred] item_cred $item_cred"); + if ( strstr($item_cred,"*") == true ) { + $item_cred=strtr($item_cred,"*","%"); + $Sql=" pcm_val like '$item_cred' or"; + } else { + $Sql=" pcm_val = '$item_cred' or"; + } + $SqlCred=$SqlCred.$Sql; + } + } + $SqlCred = substr($SqlCred,0,strlen($SqlCred)-2)." order by pcm_val::text" ; + } else + { + $SqlCred="select pcm_val,pcm_lib from tmp_pcmn order by pcm_val::text"; + } + echo_debug("SqlCred $SqlCred"); + $Res=ExecSql($cn,$SqlCred); + $Count=pg_NumRows($Res); + + echo ""; + for ( $i=0;$i<$Count;$i++) { + $l2_line=pg_fetch_array($Res,$i); + $lib=substr($l2_line['pcm_lib'],0,35); + $poste_c[$l2_line['pcm_val']]=$lib; + } + for ( $i=0;$i < $p_MaxCred;$i++) { + echo ""; + echo ""; + printf('', + $i, + ${"e_text_cred$i"}); + + printf ('', + $i,$i,${"e_mont_cred$i"}); + echo ""; + + } + if ( isset ($_GET["PHPSESSID"]) ) { + $sessid=$_GET["PHPSESSID"]; + } + else { + $sessid=$_POST["PHPSESSID"]; + } + + $search='"; + + echo ''; + echo "
"; + printf('', + $i, + ${"e_op_cred$i"}); + + printf ('"; + echo " Montant :
rapprochement : '.$search.'
"; + echo '
'; + echo ''; + echo $e_comment; + echo ""; + + $e_sum_deb=0; + $e_sum_cred=0; + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ""; + echo '
'; + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ + +function ViewRec($p_array = null) { + if ($p_array == null) { + echo_debug("p_array is null"); + }else { + foreach ( $p_array as $n=>$e) { + echo_debug("a[$n]= $e"); + } + + } +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function CorrectRecord($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array) +{ + + RecordJrn($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array); +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function ViewRecord ($p_dossier,$p_jrn,$p_id,$p_MaxDeb,$p_MaxCred,$p_array) +{ + echo_debug ("ViewRecord : $p_dossier"); + echo_debug("function ViewRecord ($p_dossier,$p_jrn,$p_id,$p_MaxCred,$p_MaxDeb,$p_array)"); + foreach ( $p_array as $key=>$element) { + ${"e_$key"}=$element; + echo_debug(" e_$key=$element;"); + + } + // Get Jrn's Prop + $l_prop=GetJrnProp($p_dossier,$p_jrn); + + include_once("poste.php"); + if ( $l_prop == null ) return; + $col_vide=""; + echo ''; + echo ''; + echo ""; + echo ""; + echo ""; + echo "
". $l_prop['jrn_def_name']."(".$l_prop['jrn_def_code'].") Date : $e_op_date
"; + + + echo ""; + echo ""; + for ($i = 0; $i < $p_MaxDeb;$i++) { + //Deb + if ( strlen(trim(${"e_mont_deb$i"})) > 0 && ${"e_mont_deb$i"} > 0 ) { + // $class=GetPosteLibelle($p_dossier,${"e_class_deb$i"}); + $class=${"e_text_deb$i"}; + echo '$col_vide$col_vide"; + } + } + + // Cred + for ($i = 0; $i < $p_MaxCred;$i++) { + if ( strlen(trim(${"e_mont_cred$i"})) > 0 && ${"e_mont_cred$i"} > 0 ) { + //$class=GetPosteLibelle($p_dossier,${"e_class_cred$i"}); + $class=${"e_text_cred$i"}; + echo ''.$col_vide.'$col_vide "; + } + } + echo ""; + echo $col_vide; + echo $col_vide; + echo ""; + echo ""; + echo "
operation $p_id
'.${"e_class_deb$i"}." $class ".${"e_mont_deb$i"}."
'.${"e_class_cred$i"}." $class ".${"e_mont_cred$i"}."
Total $e_sum_deb $e_sum_cred
"; + // Bouton again + echo ''; + echo '
'; + echo ' Ajouter'; + echo '
'; +} +/* function GetJrnProp + * Purpose : Get the properties of a journal + * + * parm : + * - p_dossier the folder id + * - p_jrn the jrn id + * gen : + * - none + * return: + * - an array containing properties + * + */ +function GetJrnProp($p_dossier,$p_jrn) +{ + $l_dossier=sprintf("dossier%d",$p_dossier); + $cn=DbConnect($l_dossier); + $Res=ExecSql($cn,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type, + jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code + from jrn_Def + where jrn_def_id=$p_jrn"); + $Count=pg_NumRows($Res); + if ( $Count == 0 ) { + echo '

Paramètres journaux non trouvés

'; + return null; + } + return pg_fetch_array($Res,0); +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetNextId($p_cn,$p_name) { + include_once("postgres.php"); + + $Res=ExecSql($p_cn,"select max($p_name) as result from jrnx"); + echo_debug("$Res=ExecSql($p_cn,"."select max($p_name) as result from jrnx"); + if (pg_NumRows($Res) == 0 ) + return 0; + $l_res=pg_fetch_array($Res,0); + return $l_res['result']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetNextJrnId($p_cn,$p_name) { + include_once("postgres.php"); + $Res=ExecSql($p_cn,"select max($p_name) as result from jrn "); + echo_debug("$Res=ExecSql($p_cn,"."select max($p_name) as result from jrn "); + + if (pg_NumRows($Res) == 0 ) + return 0; + $l_res=pg_fetch_array($Res,0); + return $l_res['result']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) { + echo_debug("function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) "); + $db=sprintf("dossier%d",$p_dossier); + $l_prop=GetJrnProp($p_dossier,$p_jrn); + echo $l_prop['jrn_def_name']."( ".$l_prop['jrn_def_code'].")"; + $cn=DbConnect($db); + if ( $p_array == null) { + include_once("preference.php"); + $l_periode=GetUserPeriode($cn,$p_user); + $Res=ExecSql($cn,"select j_id,jr_internal,j_text,to_char(j_date,'DD.MM.YYYY') as j_date, + j_montant,j_poste,pcm_lib,j_grpt,j_rapt,j_debit,j_centralized,j_tech_per + from jrnx inner join tmp_pcmn on j_poste=pcm_val + inner join jrn on jr_grpt_id=j_grpt + where + j_jrn_def=$p_jrn and j_tech_per=$l_periode + order by j_id,j_grpt,j_debit desc"); + } else { + // Construction Query + foreach ( $p_array as $key=>$element) { + ${"l_$key"}=$element; + echo_debug ("l_$key $element"); + } + $sql="select j_id,j_text,to_char(j_date,'DD.MM.YYYY') as j_date,j_montant,j_poste,pcm_lib,j_grpt,j_rapt,j_debit,j_centralized,j_tech_per,jr_internal + from jrnx inner join tmp_pcmn on j_poste=pcm_val + inner join jrn on jr_grpt_id=j_id + where + j_jrn_def=$p_jrn"; + $l_and="and "; + if ( (string) $l_s_montant == (string) (int) $l_s_montant ) { + $sql.=" and j_montant $l_mont_sel $l_s_montant"; + } + if ( isDate($l_date_start) != null ) { + $sql.=$l_and." j_date >='".$l_date_start."'"; + } + if ( isDate($l_date_end) != null ) { + $sql.=$l_and." j_date <='".$l_date_end."'"; + } + $l_s_comment=FormatString($l_s_comment); + if ( $l_s_comment != null ) { + $sql.=$l_and." ( upper(jr_comment) like upper('%".$l_s_comment."%') or + upper(j_text) like upper('%".$l_s_comment."%'))"; + } + + $sql.=" order by j_id,j_grpt,j_debit desc"; + echo_debug ("search query is $sql"); + $Res=ExecSql($cn,$sql); + } + $MaxLine=pg_NumRows($Res); + if ( $MaxLine == 0 ) return; + $col_vide=""; + echo ''; + $l_id=0; + for ( $i=0; $i < $MaxLine; $i++) { + $l_line=pg_fetch_array($Res,$i); + if ( $l_line['j_debit'] == 't' ) { + echo ''; + } + else { + echo ''; + } + if ( $l_id == $l_line['j_grpt'] ) { + echo $col_vide.$col_vide.$col_vide.$col_vide; + } else { + echo ""; + + + if ( $l_line['j_centralized'] == 'f' && isClosed($cn,$l_line['j_tech_per']) == false ) + { + echo ""; + echo '"; + }else { + echo ""; + echo '"; + echo ""; + + } + + // echo ""; + $l_id=$l_line['j_grpt']; + } + if ( $l_line['j_debit']=='f') + echo $col_vide; + + echo ''; + + if ( $l_line['j_debit']=='t') + echo $col_vide; + + echo ''; + + if ( $l_line['j_debit']=='f') + echo $col_vide; + + echo ''; + + if ( $l_line['j_debit']=='t') + echo $col_vide; + + echo ""; + + + } + echo '
"; + echo $l_line['j_date']; + echo ""; + list($z_type,$z_num,$num_op)=split("-",$l_line['jr_internal']); + echo $num_op; + echo "'; + echo ""; + echo "Modifier"; + echo ""; + if ( isset ($_GET["PHPSESSID"]) ) { + $sessid=$_GET["PHPSESSID"]; + } else { + $sessid=$_POST["PHPSESSID"]; + } + echo ""; + echo '"; + echo ""; + echo "'; + echo $l_line['jr_internal']; + echo ""; + echo '"; + echo "'; + echo $l_line['j_poste']; + echo ''; + echo $l_line['j_text']; + echo ''; + echo $l_line['j_montant']; + echo '
'; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function isClosed($p_cn,$p_period) { + return false; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetData ($p_cn,$p_grpt) { + $Res=ExecSql($p_cn,"select + to_char(j_date,'DD.MM.YYYY') as j_date, + j_text, + j_debit, + j_poste, + j_montant, + j_id, + jr_comment, + to_char(jr_date,'DD.MM.YYYY') as jr_date, + jr_rapt, jr_id,jr_internal + from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$p_grpt"); + $MaxLine=pg_NumRows($Res); + if ( $MaxLine == 0 ) return null; + $deb=0;$cred=0; + for ( $i=0; $i < $MaxLine; $i++) { + + $l_line=pg_fetch_array($Res,$i); + $l_array['op_date']=$l_line['j_date']; + if ( $l_line['j_debit'] == 't' ) { + $l_class=sprintf("class_deb%d",$deb); + $l_montant=sprintf("mont_deb%d",$deb); + $l_text=sprintf("text_deb%d",$deb); + $l_array[$l_class]=$l_line['j_poste']; + $l_array[$l_montant]=$l_line['j_montant']; + $l_array[$l_text]=$l_line['j_text']; + $l_id=sprintf("op_deb%d",$deb); + $l_array[$l_id]=$l_line['j_id']; + $deb++; + } + if ( $l_line['j_debit'] == 'f' ) { + $l_class=sprintf("class_cred%d",$cred); + $l_montant=sprintf("mont_cred%d",$cred); + $l_array[$l_class]=$l_line['j_poste']; + $l_array[$l_montant]=$l_line['j_montant']; + $l_id=sprintf("op_cred%d",$cred); + $l_array[$l_id]=$l_line['j_id']; + $l_text=sprintf("text_cred%d",$deb); + $l_array[$l_text]=$l_line['j_text']; + + $cred++; + } + $l_array['jr_internal']=$l_line['jr_internal']; + $l_array['comment']=$l_line['jr_comment']; + $l_array['ech']=$l_line['jr_date']; + $l_array['rapt']=$l_line['jr_rapt']; + $l_array['jr_id']=$l_line['jr_id']; + } + return array($l_array,$deb,$cred); +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - -1 si aucune valeur de trouvée + * + */ +function GetRapt($p_cn,$p_rappt) { + + $Res=ExecSql($p_cn,"select jr_id from jrn where jr_rapt='$p_rappt'"); + if ( pg_NumRows($Res) == 0 ) return -1; + $l_line=pg_fetch_array($Res); + return $l_line['jr_id']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - null si aucune valeur de trouvée + * + */ +function GetInternal($p_cn,$p_id) { + + $Res=ExecSql($p_cn,"select jr_internal from jrn where jr_id=$p_id"); + if ( pg_NumRows($Res) == 0 ) return null; + $l_line=pg_fetch_array($Res); + return $l_line['jr_internal']; +} + +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - -1 si aucune valeur de trouvée + * + */ +function GetRaptDest($p_cn,$p_rappt) { + + $Res=ExecSql($p_cn,"select jr_rapt from jrn where jr_internal='$p_rappt'"); + echo_debug("select jr_rapt from jrn where jr_id=$p_rappt"); + if ( pg_NumRows($Res) == 0 ) return -1; + $l_line=pg_fetch_array($Res); + if ( strlen (trim ($l_line['jr_rapt'])) == 0 ) return -1; + return $l_line['jr_rapt']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function GetAmount($p_cn,$p_id) { + $Res=ExecSql($p_cn,"select jr_montant from jrn where jr_internal='$p_id'"); + if (pg_NumRows($Res)==0) return -1; + $l_line=pg_fetch_array($Res,0); + return $l_line['jr_montant']; +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function VerifData($p_cn,$p_array,$p_user) +{ + if ( ! isset ($p_cn) || + ! isset ($p_array)|| + ! isset ($p_user)|| + $p_array == null ){ + echo_error("JRN.PHP VerifData missing parameter"); + return BADPARM; + } + // Montre ce qu'on a encodé et demande vérif + $next=""; + foreach ( $p_array as $name=>$element ) { + echo_debug("element $name -> $element "); + // Sauve les données dans des variables + ${"p_$name"}=$element; + } + // Verif Date + if ( isDate($p_op_date) == null) { + return BADDATE; + } + // userPref contient la periode par default + $userPref=GetUserPeriode($p_cn,$p_user); + list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$userPref); + + // Date dans la periode active + echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demandée $p_op_date"); + if ( cmpDate($p_op_date,$l_date_start)<0 || + cmpDate($p_op_date,$l_date_end)>0 ) + { + return NOTPERIODE; + } + // Periode fermée + if ( PeriodeClosed ($p_cn,$userPref)=='t' ) + { + return PERIODCLOSED; + } + $l_mont=0; + if ( ! isset ($p_ech) ) $p_ech=""; + + if ($p_ech!='' && isDate ( $p_ech) == null ){ + return INVALID_ECH; + } + + $tot_deb= 0; + $tot_cred= 0; + for ( $i = 0; $i < $p_MaxCred; $i++) { + if ( isset ( ${"p_mont_cred$i"} )) + $tot_cred+=${"p_mont_cred$i"}; + } + for ( $i = 0; $i < $p_MaxDeb; $i++) { + if ( isset ( ${"p_mont_deb$i"} )) + $tot_deb+=${"p_mont_deb$i"}; + } + echo_debug("Amont = $tot_deb $tot_cred"); + if ( round($tot_deb,2) != round($tot_cred,2) ) { + return DIFF_AMOUNT; + } + + $l_dest=-1; + // Rapprochement demandé et vérif + if ( strlen(trim($p_rapt)) != 0 ){ + $l_dest=GetRapt($p_cn,$p_rapt); + if ( $l_dest != -1 ) { + return RAPPT_ALREADY_USED; + } + // Get Amount + $l_mont=GetAmount($p_cn,$p_rapt); + if ( $l_mont == -1 ) { + return RAPPT_NOT_EXIST; + } + if ( $tot_deb != $l_mont) { + return RAPPT_NOMATCH_AMOUNT; + } + + } + return NOERROR; + +} +/* function GetJrnName + * Purpose : Return the name of the jrn + * + * parm : + * - p_cn connexion resource + * - jrn id + * gen : + * - none + * return: + * - string or null if not found + * + */ +function GetJrnName($p_cn,$p_id) { + $Res=ExecSql($p_cn,"select jrn_def_name from ". + " jrn_def where jrn_def_id=". + $p_id); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $ret=pg_fetch_array($Res,0); + return $ret['jrn_def_name']; +} +/* function NextJrn + * Purpose : + * Get the number of the next jrn + * from the jrn_def.jrn_code + * + * parm : + * - $p_cn connection + * - $p_type jrn type + * gen : + * - none + * return: + * - string containing the next code + * + */ +function NextJrn($p_cn,$p_type) +{ + $Ret=CountSql($p_cn,"select * from jrn_def where jrn_def_type='".$p_type."'"); + return $Ret+1; +} +/* function SetInternalCode + * Purpose : + * + * parm : + * - $p_cn connection + * - $p_id id in jr_id + * - $p_jrn jrn id jrn_def_id + * - $p_dossier dossier id + * gen : + * - + * return: + * - + * + */ +function SetInternalCode($p_cn,$p_id,$p_jrn,$p_dossier) +{ + $num=CountSql($p_cn,"select * from jrn where jr_def_id=$p_jrn"); + $atype=GetJrnProp($p_dossier,$p_jrn); + $type=$atype['jrn_def_code']; + $internal_code=sprintf("%s-%08d",$type,$num); + $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal_code."' where ". + " jr_id = ".$p_id); + return $internal_code; +} + + +?> diff --git a/include/poste.php b/include/poste.php new file mode 100644 index 000000000..3bba1a53b --- /dev/null +++ b/include/poste.php @@ -0,0 +1,102 @@ + Journal non trouvé "; + // return (3,3); + } + $l_line=pg_fetch_array($Res,0); + $l_deb=$l_line['jrn_deb_max_line']; + $l_cred=$l_line['jrn_cred_max_line']; + // return ($l_deb,$l_cred); + +} +/* function + * Purpose : + * + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function PosteForm($p_cn) { + $Res=ExecSql($p_cn,"select pcm_val,pcm_lib from tmp_pcmn order by pcm_val::text"); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $ret='"; + return $ret; +} +?> diff --git a/include/postgres.php b/include/postgres.php new file mode 100644 index 000000000..88b3739b9 --- /dev/null +++ b/include/postgres.php @@ -0,0 +1,354 @@ +'; + echo "





"; + echo "

+ + Invalid user
or
Invalid password +

"; + session_unset(); + + exit -1; + } else $IsValid=1; + + return $ret; + +} +/*++ + * function : ShowDossier + * Parameter : p_type string : all for all dossiers lim for only the + * dossier where we've got rights + * Return : nothing + * Description : + * Show the folder where user have access +++*/ +function ShowDossier($p_type,$p_first=0,$p_max=10,$p_Num=0) { + global $user; + if ( $p_max == 0 ) { + $l_step=""; + } else { + $l_step="LIMIT $p_max OFFSET $p_first"; + } + $cn=DbConnect(); + if ( $p_type == "all") { + $l_sql="select *, 'W' as priv_priv from ac_dossier ORDER BY dos_name "; + $p_Num=CountSql($cn,$l_sql); + } else { + $l_sql="select * from jnt_use_dos + natural join ac_dossier + natural join ac_users + inner join priv_user on priv_jnt=jnt_id where + use_login='".$user."' and priv_priv !='NO' + order by dos_name "; + $p_Num=CountSql($cn,$l_sql); + } + $l_sql=$l_sql.$l_step; + $p_res=ExecSql($cn,$l_sql); + + echo_debug("ShowDossier:".$p_res." Line = $p_Num"); + + $Max=pg_NumRows($p_res); + if ( $Max == 0 ) return null; + for ( $i=0;$i<$Max; $i++) { + // echo_debug ("i = $i"); + $row[]=pg_fetch_array($p_res,$i); + //echo $row[dossier]; + } + return $row; +} +/*++ + * function : CheckAccess + * Parameter : $p_right (user or admin) + * $p_database (name of the database) + * Return : 1 if ok + * Description : + * Check user's access right to the given database +++*/ +function CheckAccess($p_right,$p_database) +{ +// global $user,$pass; +// echo "User is $user"; +// $cn=pg_connect("host=127.0.0.1 dbname=$p_database user='webcompta' "); +// $ret=pg_exec($cn,"select name from ac_dossier where name='$user' and dossier='$p_database' and priv='$p_right'"); +// if ( pg_NumRows($ret) == 0 ) { +// /* echo '';*/ +// echo "





"; +// echo "

+// +// You haven't the right to connect +//

"; +// session_unset(); +// return 0; +// } + +// return $ret; + +} +// Check if the user has admin right +// to be complete +function CheckAdmin() { + global $user,$pass; + $res=0; + + if ( $user != 'webcompta') { + $pass5=md5($pass); + $sql="select use_id from ac_users where use_login='$user' + and use_active=1 and use_admin=1 and use_pass='$pass5'"; + + $cn=DbConnect(); + + $isAdmin=CountSql($cn,$sql); + } else $isAdmin=1; + + return $isAdmin; +} +function DbConnect($p_db="account_repository") { + $a=pg_connect("dbname=$p_db host=127.0.0.1 user='webcompta'"); + echo_debug ("connect to $p_db"); + return $a; +} +function ExecSql($p_connection, $p_string) { + echo_debug("SQL = $p_string"); + $ret=pg_exec($p_connection,$p_string); + if ( $ret == false ) { echo_error ("SQL ERROR ::: $p_string");} + return $ret; +} +/* + * GetAllUser + * Return all the users + * as an array + */ +function GetAllUser() { + echo_debug("GetUser"); + $cn=DbConnect(); + $sql="select * from ac_users where use_login!='webcompta'"; + echo_debug("ExecSql"); + $Res=ExecSql($cn,$sql); + $Num=pg_NumRows($Res); + if ( $Num == 0 ) return null; + for ($i=0;$i < $Num; $i++) { + $User[]=pg_fetch_array($Res,$i); + } + return $User; +} +/* GetUid + * Check if the User is valid + * and return an array with his property + */ +function GetUid($p_uid) { + $cn=DbConnect(); + $Res=ExecSql($cn,"select * from ac_users where use_id=".$p_uid); + $Num=pg_NumRows($Res); + if ( $Num == 0 ) { return false; } + for ($i=0;$i < $Num; $i++) { + $Prop[]=pg_fetch_array($Res,$i); + } + return $Prop; +} +/* + * GetPriv + * Get the privilege of an user on a folder + */ +function GetPriv($p_dossier,$p_login) +{ + $cn=DbConnect(); + $Res=ExecSql($cn,"select priv_priv + from priv_user left join jnt_use_dos on jnt_id=priv_jnt + inner join ac_users on ac_users.use_id=jnt_use_dos.use_id + where use_login='$p_login' and dos_id=$p_dossier"); + $Num=pg_NumRows($Res); + echo_debug("Found ".$Num." rows in GetPriv"); + if ( $Num==0) { return 0;} + for($i=0;$i < $Num;$i++) { + $Right=pg_fetch_array($Res,$i); + $Priv[]=$Right['priv_priv']; + } + return $Priv; +} +/* ExisteJnt + * Get the number of rows + * from table jnt_use_dos where $p_dossier = dos_id and + * use_id=$p_user + */ +function ExisteJnt($p_dossier,$p_user) +{ + $cn=DbConnect(); + $Res=ExecSql($cn,"select * from jnt_use_dos where dos_id=".$p_dossier." and use_id=".$p_user); + return pg_NumRows($Res); +} +/* ExistePriv + * + * + * + */ +function ExistePriv($p_jntid) +{ + $cn=DbConnect(); + $Res=ExecSql($cn,"select * from priv_user where priv_jnt=".$p_jntid); + return pg_NumRows($Res); +} +/* GetJnt + * Get the jnt + * + * + */ +function GetJnt($p_dossier,$p_user) +{ + $cn=DbConnect(); + $Res=ExecSql($cn,"select jnt_id from jnt_use_dos where dos_id=".$p_dossier." and use_id=".$p_user); + $R=pg_fetch_array($Res,0); + return $R['jnt_id']; +} +/* GetDbId + * Get the dos_id of a dossier + * parm: name of the folder + */ +function GetDbId($p_name) +{ + $cn=DbConnect(); + $r_sql=ExecSql($cn,"select dos_id from ac_dossier + where dos_name='".$p_name."'"); + $num=pg_NumRows($r_sql); + if ( $num == 0 ) { + return 0; + } else { + $l_db=pg_fetch_array($r_sql,0); + return $l_db['dos_id']; + } + +} +/* CountSql + * Count the number of row + * + * parm: p_conn connection handler + * p_sql sql string + */ + +function CountSql($p_conn,$p_sql) +{ + $r_sql=ExecSql($p_conn,$p_sql); + return pg_NumRows($r_sql); + +} +/* GetDossierName + * Param: id of a dossier + * return : Name of the dossier + */ +function GetDossierName($p_dossier) +{ + $cn=DbConnect(); + $Ret=ExecSql($cn,"select dos_name from ac_dossier where dos_id=".$p_dossier); + $r= pg_fetch_array($Ret,0); + return $r['dos_name']; +} +/* GetSequence + * get the current sequence + */ +function GetSequence($p_cn,$p_seq) +{ + $Res=ExecSql($p_cn,"select currval('$p_seq') as seq"); + $seq=pg_fetch_array($Res,0); + return $seq['seq']; +} +function StartSql($p_cn) { + $Res=ExecSql($p_cn,"start transaction"); +} +function EndSql($p_cn) { + $Res=ExecSql($p_cn,"end transaction"); +} +function Commit($p_cn) { + $Res=ExecSql($p_cn,"commit"); +} +function Rollback($p_cn) { + $Res=ExecSql($p_cn,"rollback"); +} +function AlterSequence($p_cn,$p_name,$p_value) { + + $Res=ExecSql($p_cn,"drop sequence $p_name"); + $Res=ExecSql($p_cn,"create sequence $p_name start $p_value"); +} +function GetLogin($p_uid) +{ + $cn=DbConnect(); + $Res=ExecSql($cn,"select use_login from ac_users where use_id=$p_uid"); + if ( pg_NumRows($Res) == 0 ) return null; + $a_login=pg_fetch_array($Res,0); + return $a_login['use_login']; +} + +/* function SyncRight + * Purpose : Synchronize les droits par défaut + * avec les journaux existants + * parm : + * - + * gen : + * - + * return: + * - + * + */ +function SyncRight($p_dossier,$p_user) { + $priv=GetPriv($p_dossier,$p_user); + $right=$priv[0]; + $ldb=sprintf("dossier%d",$p_dossier); + $cn=DbConnect($ldb); + + $sql="insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv) ". + "select '".$p_user."',jrn_def_id,'".$right."' from jrn_def ". + "where jrn_def_id not in ". + "(select uj_jrn_id from user_sec_jrn where uj_login='".$p_user."')"; + $Res=ExecSql($cn,$sql); +} +?> diff --git a/include/preference.php b/include/preference.php new file mode 100644 index 000000000..0ebe8c967 --- /dev/null +++ b/include/preference.php @@ -0,0 +1,350 @@ +'; + for ( $i = 0; $i < $Max;$i++) { + $l_line=pg_fetch_array($Res,$i); + $ret.=sprintf('