Task #1078 - Bug opération prédéfinie pour les opérations diverses

To fix the bug, we implement a safer way to get data from _POST, the function Pre_Op_Advance::get_post was not correct

 if the name is already used than a new one is computed
This commit is contained in:
Dany De Bontridder 2015-01-02 19:04:20 +01:00
parent d8e596da74
commit e7e409c5f1
4 changed files with 41 additions and 18 deletions

View file

@ -57,11 +57,16 @@ echo HtmlInput::button('close', _('Annuler'), 'onclick="removeDiv(\'mod_predf_op
echo '</form>';
$html = ob_get_contents();
$html1 = ob_get_contents();
ob_end_clean();
$html = escape_xml($html);
//echo $html;exit();
header('Content-type: text/xml; charset=UTF-8');
$html = escape_xml($html1);
if (headers_sent() )
{
echo $html1;
}
else {
header('Content-type: text/xml; charset=UTF-8');
}
echo <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>

View file

@ -25,14 +25,20 @@
*/
if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
if ($g_user->check_module('PREDOP') == 0) exit();
if ( trim($_POST['opd_name']) != '')
$name=HtmlInput::default_value_post("opd_name", "");
if ( trim($name) != '')
{
$cn->exec_sql('delete from op_predef where od_id=$1',
array($_POST['od_id']));
$od_id=HtmlInput::default_value_post("od_id", -1);
var_dump($_POST);
$cn->exec_sql("delete from op_predef_detail where od_id=$1",array($_POST['od_id']));
switch ($_POST['jrn_type']) {
if ( $od_id == -1 ||isNumber($od_id) == 0) return;
$cn->exec_sql('delete from op_predef where od_id=$1',
array($od_id));
$cn->exec_sql("delete from op_predef_detail where od_id=$1",array($od_id));
$jrn_type=HtmlInput::default_value_post("jrn_type", null);
switch ($jrn_type) {
case 'ACH':
$operation=new Pre_op_ach($cn);
break;
@ -42,6 +48,8 @@ if ( trim($_POST['opd_name']) != '')
case 'ODS':
$operation=new Pre_Op_Advanced($cn);
break;
default :
throw new Exception(_('Type de journal invalide'));
}
$operation->get_post();
$operation->save();

View file

@ -43,12 +43,21 @@ class Pre_Op_Advanced extends Pre_operation_detail
for ($i=0;$i<$this->operation->nb_item;$i++)
{
if ( ! isset ($_POST['poste'.$i]) && ! isset ($_POST['qc_'.$i]))
continue;
if (isset ($this->{'poste'.$i}))
$this->{'poste'.$i}=(trim($_POST['qc_'.$i]) != "" )?$_POST['qc_'.$i]:$_POST['poste'.$i];
if ( isset($this->{'qc'.$i}))
$poste=HtmlInput::default_value_post("poste".$i, null);
$qcode=HtmlInput::default_value_post("qc_".$i, null);
if ( $poste == null && $qcode == null ) continue;
if ($poste != null && trim ($poste) != "")
{
$this->{'poste'.$i}=$poste;
$this->{'isqc'.$i}='f';
}
if ( $qcode != null && trim ($qcode) != "") {
$this->{'isqc'.$i}=(trim($_POST['qc_'.$i]) != "")?'t':'f';
$this->{'poste'.$i}=trim ($qcode);
}
$this->{"amount".$i}=$_POST['amount'.$i];
$this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
@ -62,9 +71,9 @@ class Pre_Op_Advanced extends Pre_operation_detail
{
try
{
$this->db->start();
if ($this->operation->save() == false )
return;
$this->db->start();
// save the selling
for ($i=0;$i<$this->operation->nb_item;$i++)
{
@ -85,6 +94,8 @@ class Pre_Op_Advanced extends Pre_operation_detail
$this->db->exec_sql($sql);
}
$this->db->commit();
}
catch (Exception $e)
{

View file

@ -101,8 +101,7 @@ class Pre_operation
"and jrn_def_id=".$this->p_jrn)
!= 0 )
{
echo "<span class=\"notice\"> Ce modèle d' op&eacute;ration a d&eacute;j&agrave; &eacute;t&eacute; sauv&eacute;</span>";
return false;
$this->name="copy_".$this->name."_".microtime(true);
}
if ( $this->count() > MAX_PREDEFINED_OPERATION )
{