diff --git a/include/class_acc_ledger_fin.php b/include/class_acc_ledger_fin.php index 66c155cc2..fdbc2a662 100644 --- a/include/class_acc_ledger_fin.php +++ b/include/class_acc_ledger_fin.php @@ -45,15 +45,25 @@ class Acc_Ledger_Fin extends Acc_Ledger $this->type = 'FIN'; } - /**\brief verify that the data are correct before inserting or confirming - * \param an array (usually $_POST) - * \return String - * \throw Exception on error occurs + /** + * Verify that the data are correct before inserting or confirming + * @brief verify the data + * @param an array (usually $_POST) + * @return String + * @throw Exception on error occurs */ public function verify($p_array) { global $g_user; + if (is_array($p_array ) == false || empty($p_array)) + throw new Exception ("Array empty"); + /* + * Check needed value + */ + check_parameter($p_array,'p_jrn'); + + extract($p_array); /* check for a double reload */ if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0) diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index 923e4bd76..bbd46d3d7 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -61,7 +61,17 @@ class Acc_Ledger_Sold extends Acc_Ledger { public function verify($p_array) { global $g_parameter, $g_user; + + if (is_array($p_array ) == false || empty($p_array)) + throw new Exception ("Array empty"); + extract($p_array); + + /* + * Check needed value + */ + check_parameter($p_array,'p_jrn,e_date,e_client'); + /* check for a double reload */ if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0) throw new Exception(_('Double Encodage'), 5); @@ -918,7 +928,10 @@ class Acc_Ledger_Sold extends Acc_Ledger { return $r; } - /* !\brief update the payment + /** + * @brief update the payment + * @deprecated + * */ function show_unpaid() { diff --git a/include/user_common.php b/include/user_common.php index 6b0d56ae2..a1ed734f8 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -226,4 +226,20 @@ function toNumber($p_num) $p_num=str_replace(',','.',$p_num); return $p_num; } +/** + * Check that all the index are in the array, used by function to check if + * the array contains the needed variables before an extract + * @param type $p_array array to check + * @param type $needed string containing variable separated by comma + * @throws Exception + */ +function check_parameter($p_array,$p_needed) +{ + $needed = split(',',$p_needed); + for ($e=0;$e<$needed;$e++) { + if ( ! isset($p_array[$needed[$e]])) { + throw new Exception (_('Paramètre manquant')." ".$needed[$e]); + } + } +} ?>