From b712539fe768829aeda4143040e45d20be498ca1 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Mon, 2 Oct 2017 20:49:10 +0200 Subject: [PATCH] CFGSEC : the ledgers are now updated thanks an inplace class --- html/ajax_misc.php | 6 + include/ajax/ajax_ledger_security.php | 173 ++++++++++++++++++++ include/class/acc_ledger.class.php | 2 +- include/class/acc_ledger_purchase.class.php | 2 +- include/class/acc_payment.class.php | 26 +-- include/lib/html_input.class.php | 15 ++ include/lib/inplace_edit.class.php | 26 ++- include/lib/iselect.class.php | 20 ++- include/param_sec.inc.php | 145 ++++++++-------- scenario/inplace_edit.test.php | 23 ++- 10 files changed, 350 insertions(+), 88 deletions(-) create mode 100644 include/ajax/ajax_ledger_security.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 82749d116..f3b4dd086 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -109,6 +109,12 @@ $path = array( "account"=>"ajax_poste", "card"=>"ajax_card", "ledger"=>"ajax_ledger", + // Manage ledger access + "ledger_access"=>"ajax_ledger_security", + // Manage user profile + "profile"=>"ajax_ledger_security", + // Update in once all the ledgers + "ledger_access_all"=>"ajax_ledger_security", "todo_list"=>"ajax_todo_list", "history"=>"ajax_history", "pcmn_update"=>"ajax_pcmn_update", diff --git a/include/ajax/ajax_ledger_security.php b/include/ajax/ajax_ledger_security.php new file mode 100644 index 000000000..142396214 --- /dev/null +++ b/include/ajax/ajax_ledger_security.php @@ -0,0 +1,173 @@ + + +if (!defined('ALLOWED')) + die('Appel direct ne sont pas permis'); + + +require_once NOALYSS_INCLUDE.'/lib/itext.class.php'; +require_once NOALYSS_INCLUDE.'/lib/iselect.class.php'; +require_once NOALYSS_INCLUDE.'/lib/inum.class.php'; +require_once NOALYSS_INCLUDE.'/lib/inplace_edit.class.php'; + +/** + * @file + * @brief Manage the security of a ledger , from CFGSEC module + * + */ + +$n_dossier_id=Dossier::id(); +//----------------------------------------------------------------------------- +// Manage the user's access to ledgers +//----------------------------------------------------------------------------- +if ($op=="ledger_access") +{ + $input=$http->request("input"); + $action=$http->request("ieaction", "string", "display"); + $user_id=$http->post("user_id", "numeric"); + $jrn_def_id=$http->post("jrn_def_id", "numeric"); + if ($action=="display") + { + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("jrn_def_id", $jrn_def_id); + $ie_input->add_json_param("op", "ledger_access"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("user_id", $user_id); + echo $ie_input->ajax_input(); + return; + } + if ($action=="ok") + { + $value=$http->post("value"); + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("jrn_def_id", $jrn_def_id); + $ie_input->add_json_param("op", "ledger_access"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("user_id", $user_id); + $ie_input->set_value($value); + $sec_User=new User($cn, $user_id); + $count=$cn->get_value('select count(*) from user_sec_jrn where uj_login=$1 '. + ' and uj_jrn_id=$2', array($sec_User->login, $jrn_def_id)); + if ($count==0) + { + $cn->exec_sql('insert into user_sec_jrn (uj_login,uj_jrn_id,uj_priv)'. + ' values ($1,$2,$3)', + array($sec_User->login, $jrn_def_id, $value)); + } + else + { + $cn->exec_sql('update user_sec_jrn set uj_priv=$1 where uj_login=$2 and uj_jrn_id=$3', + array($value, $sec_User->login, $jrn_def_id)); + } + echo $ie_input->value(); + return; + } + if ($action=="cancel") + { + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("jrn_def_id", $jrn_def_id); + $ie_input->add_json_param("op", "ledger_access"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("user_id", $user_id); + echo $ie_input->value(); + return; + } +} +//----------------------------------------------------------------------------- +// Set the user's profile +//----------------------------------------------------------------------------- +if ( $op == "profile") +{ + $input=$http->request("input"); + $action=$http->request("ieaction", "string", "display"); + $user_id=$http->post("user_id", "numeric"); + $profile_id=$http->post("profile_id","numeric"); + if ($action=="display") + { + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("profile_id", $profile_id); + $ie_input->add_json_param("op", "profile"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("user_id", $user_id); + echo $ie_input->ajax_input(); + return; + } + if ($action=="ok") + { + $value=$http->post("value"); + // save profile + $sec_User=new User($cn,$user_id); + $sec_User->save_profile($value); + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("op", "profile"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("user_id", $user_id); + $ie_input->set_value($value); + + echo $ie_input->value(); + return; + } + if ($action=="cancel") + { + $ie_input=Inplace_Edit::build($input); + $ie_input->set_callback("ajax_misc.php"); + $ie_input->add_json_param("op", "profile"); + $ie_input->add_json_param("gDossier", $n_dossier_id); + $ie_input->add_json_param("profile_id", $profile_id); + $ie_input->add_json_param("user_id", $user_id); + echo $ie_input->value(); + return; + } +} +//------------------------------------------------------------------------------ +// Update in once all the ledger access for an user +//------------------------------------------------------------------------------ +if ( $op == 'ledger_access_all') { + // Find the login + $user_id=$http->post("user_id","numeric"); + $access=$http->post("access"); + if ( $access != "W" && $access != "X" && $access !="R") die("Invalid access"); + $sec_User=new User($cn, $user_id); + // Insert all the existing ledgers to user_sec_jrn + $sql="insert into user_sec_jrn( + uj_jrn_id, + uj_login, + uj_priv + ) select jrn_def_id,$1,'X' + from + jrn_def + where + not exists(select 1 + from + user_sec_jrn + where + uj_jrn_id = jrn_def_id + and uj_login = $1 + )"; + $cn->exec_sql($sql,array($sec_User->login)); + $cn->exec_sql('update user_sec_jrn set uj_priv=$1 where uj_login=$2',array($access,$sec_User->login)); + return; +} \ No newline at end of file diff --git a/include/class/acc_ledger.class.php b/include/class/acc_ledger.class.php index 6a0239919..bbb9dcfa1 100644 --- a/include/class/acc_ledger.class.php +++ b/include/class/acc_ledger.class.php @@ -3653,7 +3653,7 @@ class Acc_Ledger extends jrn_def_sql { $r = ''; $r.='
'; - $r.='

' . _('Payé par') . '

'; + $r.='

' . _('Payement') . '

'; $mp = new Acc_Payment($this->db); $mp->set_parameter('ledger_source', $this->id); $r.=$mp->select($p_selected); diff --git a/include/class/acc_ledger_purchase.class.php b/include/class/acc_ledger_purchase.class.php index 8edd3f629..438f8178b 100644 --- a/include/class/acc_ledger_purchase.class.php +++ b/include/class/acc_ledger_purchase.class.php @@ -874,7 +874,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger /* insert into jrn */ $acc_pay->mt=$mt; - $acc_pay->desc=(!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement; + $acc_pay->desc=(!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement; $mp_jr_id=$acc_pay->insert_jrn(); $acjrn->grpt_id=$acseq; $acjrn->update_internal_code($acinternal); diff --git a/include/class/acc_payment.class.php b/include/class/acc_payment.class.php index 4c8498154..b24b006e0 100644 --- a/include/class/acc_payment.class.php +++ b/include/class/acc_payment.class.php @@ -277,6 +277,8 @@ class Acc_Payment } /*!\brief show several lines with radio button to select the payment *method we want to use, the $_POST['e_mp'] will be set + * \todo this class is used only for storage of the defined payment method, not the payment itself, + * it must be moved to another class 'Operation_Payment' *\param $p_selected if the id choose *\return html string */ @@ -287,20 +289,24 @@ class Acc_Payment $r.=HtmlInput::hidden('gDossier',dossier::id()); if ( empty($array)==false ) { + $date_pay=new IDate('mp_date'); + + $r.=sprintf(_("Date %s"), + $date_pay->input()); $acompte=new INum('acompte'); $acompte->value=0; $r.=_(" Acompte à déduire"); $r.=$acompte->input(); - $r.='

'; - $e_comm_paiement=new IText('e_comm_paiement'); - $e_comm_paiement->table = 0; - $e_comm_paiement->setReadOnly(false); - $e_comm_paiement->size = 60; - $e_comm_paiement->tabindex = 3; - $r.=_(" Libellé du paiement"); - $r.=$e_comm_paiement->input(); - $r.='

'; - } + $r.='

'; + $e_comm_paiement=new IText('e_comm_paiement'); + $e_comm_paiement->table = 0; + $e_comm_paiement->setReadOnly(false); + $e_comm_paiement->size = 60; + $e_comm_paiement->tabindex = 3; + $r.=_(" Libellé du paiement"); + $r.=$e_comm_paiement->input(); + $r.='

'; + } $r.='
    '; $r.='
  1. '._('Paiement encodé plus tard'); diff --git a/include/lib/html_input.class.php b/include/lib/html_input.class.php index 0a3e5109a..f005b6de6 100755 --- a/include/lib/html_input.class.php +++ b/include/lib/html_input.class.php @@ -100,6 +100,21 @@ class HtmlInput $this->attribute[]=array($p_name,$p_value); $this->$p_name=$p_value; } + /** + * Set the value of input (IText, INum,...) + * @param type $p_string + */ + function set_value($p_string) + { + $this->value=$p_string; + } + /** + * Return the value of input (IText, INum,...) + */ + function get_value() + { + return $this->value; + } /** *@brief you can add attribute to this in javascript * this function is a wrapper and create a script (in js) to modify diff --git a/include/lib/inplace_edit.class.php b/include/lib/inplace_edit.class.php index 18414c5b8..522a59922 100644 --- a/include/lib/inplace_edit.class.php +++ b/include/lib/inplace_edit.class.php @@ -38,12 +38,14 @@ class Inplace_Edit { - ///< HtmlInput object + /// HtmlInput object private $input; - ///< Json object to pass to JavaScript + /// Json object to pass to JavaScript private $json; - ///< Php file which answered the ajax + /// Php file which answered the ajax private $callback; + /// Message to display if value is empty + private $message; /** * Create a Inplace_Edit, initialise JSON and fullfill the default json value: * input which is the HtmlInput object serialized @@ -53,6 +55,7 @@ class Inplace_Edit $this->input=$p_input; $x["input"]=serialize($p_input); $this->json=json_encode($x, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK); + $this->message=_("Faites un choix"); } ///@brief build a Inplace_Edit object from /// a serialized string (ajax json parameter = input) @@ -105,7 +108,9 @@ EOF; */ function value() { - echo $this->input->value, + $v=$this->input->get_value(); + $v=(trim($v)=="")?$this->message:$v; + echo $v, "