FIX error reported by scrutinizer

This commit is contained in:
Laurent Destailleur 2016-05-08 11:33:46 +02:00
parent eaa548124b
commit c8d98dbfdc
4 changed files with 129 additions and 134 deletions

View File

@ -76,19 +76,17 @@ if ($action == 'add') {
$res = $object->create($user);
if ($res == 0) {
} else {
if ($res == - 3) {
$error = 1;
$action = "create";
}
if ($res == - 4) {
$error = 2;
$action = "create";
}
if ($res == - 3) {
$error = 1;
$action = "create";
}
if ($res == - 4) {
$error = 2;
$action = "create";
}
}
Header("Location: account.php");
header("Location: account.php");
exit;
} else if ($action == 'edit') {
if (! GETPOST('cancel', 'alpha')) {
$result = $object->fetch($id);
@ -134,7 +132,8 @@ if ($action == 'add') {
$result = $object->delete($user);
if ($result > 0) {
Header("Location: account.php");
header("Location: account.php");
exit;
}
}

View File

@ -39,8 +39,6 @@ class FormAdvTargetEmailing extends Form
global $langs;
$this->db = $db;
return 1;
}
/**
@ -89,52 +87,53 @@ class FormAdvTargetEmailing extends Form
function multiselectCountry($htmlname = 'country_id', $selected_array=array()) {
global $conf, $langs;
$langs->load ( "dict" );
$langs->load("dict");
$maxlength = 0;
$out = '';
$countryArray = array ();
$countryArray = array();
$label = array ();
$options_array = array ();
$options_array = array();
$sql = "SELECT rowid, code as code_iso, label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_country";
$sql .= " WHERE active = 1 AND code<>''";
$sql .= " ORDER BY code ASC";
dol_syslog ( get_class ( $this ) . "::select_country sql=" . $sql );
$resql = $this->db->query ( $sql );
dol_syslog(get_class($this) . "::select_country sql=" . $sql);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows ( $resql );
$num = $this->db->num_rows($resql);
$i = 0;
if ($num) {
$foundselected = false;
while ( $i < $num ) {
while ($i < $num) {
$obj = $this->db->fetch_object ( $resql );
$countryArray [$i] ['rowid'] = $obj->rowid;
$countryArray [$i] ['code_iso'] = $obj->code_iso;
$countryArray [$i] ['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv ( "Country" . $obj->code_iso ) != "Country" . $obj->code_iso ? $langs->transnoentitiesnoconv ( "Country" . $obj->code_iso ) : ($obj->label != '-' ? $obj->label : ''));
$label [$i] = $countryArray [$i] ['label'];
$countryArray [$i] ['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country" . $obj->code_iso ) != "Country" . $obj->code_iso ? $langs->transnoentitiesnoconv ( "Country" . $obj->code_iso ) : ($obj->label != '-' ? $obj->label : ''));
$label[$i] = $countryArray[$i]['label'];
$i ++;
}
array_multisort ( $label, SORT_ASC, $countryArray );
array_multisort($label, SORT_ASC, $countryArray);
foreach ( $countryArray as $row ) {
$label = dol_trunc ( $row ['label'], $maxlength, 'middle' );
if ($row ['code_iso'])
$label .= ' (' . $row ['code_iso'] . ')';
foreach ($countryArray as $row) {
$label = dol_trunc($row['label'], $maxlength, 'middle');
if ($row['code_iso'])
$label .= ' (' . $row['code_iso'] . ')';
$options_array [$row ['rowid']] = $label;
$options_array[$row['rowid']] = $label;
}
}
} else {
dol_print_error ( $this->db );
dol_print_error($this->db);
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
/**
@ -151,7 +150,7 @@ class FormAdvTargetEmailing extends Form
$options_array = array ();
$sql_usr = '';
$sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login";
$sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
$sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")";
@ -197,10 +196,10 @@ class FormAdvTargetEmailing extends Form
foreach ($langs_available as $key => $value)
{
$label = $value;
$options_array [$key] = $label;
$options_array[$key] = $label;
}
asort($options_array);
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
/**
@ -247,16 +246,18 @@ class FormAdvTargetEmailing extends Form
$sql .= ' WHERE ' . $InfoFieldList [3];
}
}
if (! empty ( $InfoFieldList [1] ) && $key == 'ts_payeur') {
if (! empty($InfoFieldList[1])) {
$sql .= " ORDER BY nom";
}
// $sql.= ' WHERE entity = '.$conf->entity;
dol_syslog ( get_class ( $this ) . "::".__METHOD__,LOG_DEBUG);
$resql = $this->db->query ( $sql );
$options_array = array();
dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows ( $resql );
$num = $this->db->num_rows($resql);
$i = 0;
if ($num) {
while ( $i < $num ) {
@ -270,15 +271,15 @@ class FormAdvTargetEmailing extends Form
}
}
return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array );
return $this->advMultiselectarray($htmlname, $options_array, $selected_array);
}
/**
* Return combo list with people title
*
* @param string $htmlname Name of HTML select combo field
* @param array $selected_array array
* @return string HTML combo
* @param string $htmlname Name of HTML select combo field
* @param array $selected_array Array
* @return string HTML combo
*/
function multiselectCivility($htmlname='civilite_id',$selected_array = array())
{
@ -357,23 +358,21 @@ class FormAdvTargetEmailing extends Form
// Find if keys is in selected array value
if (is_array($selected_array) && count($selected_array)>0) {
$intersect_array = array_intersect_key ( $options_array, array_flip ( $selected_array ) );
$intersect_array = array_intersect_key($options_array, array_flip($selected_array));
} else {
$intersect_array=array();
}
if (count ( $options_array ) > 0) {
foreach ( $options_array as $keyoption => $valoption ) {
if (count($options_array) > 0) {
foreach ($options_array as $keyoption => $valoption) {
// If key is in intersect table then it have to e selected
if (count ( $intersect_array ) > 0) {
$selected = '';
if (count ( $intersect_array ) > 0) {
if (array_key_exists ( $keyoption, $intersect_array )) {
$selected = ' selected="selected" ';
} else {
$selected = '';
$selected = ' selected="selected"';
}
}
$return .= '<option ' . $selected . ' value="' . $keyoption . '">' . $valoption . '</option>';
$return .= '<option' . $selected . ' value="' . $keyoption . '">' . $valoption . '</option>';
}
}

View File

@ -52,7 +52,7 @@ class mailing_advthirdparties extends MailingTargets
*
* @param int $mailing_id Id of mailing. No need to use it.
* @param array $socid Array of id soc to add
* @param int $type_of_target define in advtargetemailing.class.php
* @param int $type_of_target Defined in advtargetemailing.class.php
* @param array $contactid Array of contact id to add
* @return int <0 if error, number of emails added if ok
*/
@ -73,47 +73,45 @@ class mailing_advthirdparties extends MailingTargets
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")";
$sql.= " AND s.rowid IN (".implode(',',$socid).")";
$sql.= " ORDER BY email";
}
dol_syslog(get_class($this)."::add_to_target societe sql=".$sql, LOG_DEBUG);
// Stock recipients emails into targets table
$result=$this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG);
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
'email' => $obj->email,
'fk_contact' => $obj->fk_contact,
'name' => $obj->name,
'firstname' => $obj->firstname,
'other' => '',
'source_url' => $this->url($obj->id,'thirdparty'),
'source_id' => $obj->id,
'source_type' => 'thirdparty'
);
}
}
$i++;
}
}
else
{
dol_syslog($this->db->error());
$this->error=$this->db->error();
return -1;
// Stock recipients emails into targets table
$result=$this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG);
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
'email' => $obj->email,
'fk_contact' => $obj->fk_contact,
'name' => $obj->name,
'firstname' => $obj->firstname,
'other' => '',
'source_url' => $this->url($obj->id,'thirdparty'),
'source_id' => $obj->id,
'source_type' => 'thirdparty'
);
}
}
$i++;
}
}
else
{
dol_syslog($this->db->error());
$this->error=$this->db->error();
return -1;
}
}
}
@ -131,47 +129,45 @@ class mailing_advthirdparties extends MailingTargets
$sql.= " AND socp.fk_soc IN (".implode(',',$socid).")";
}
$sql.= " ORDER BY email";
}
dol_syslog(get_class($this)."::add_to_target contact sql=".$sql);
// Stock recipients emails into targets table
$result=$this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
'email' => $obj->email,
'fk_contact' =>$obj->id,
'lastname' => $obj->lastname,
'firstname' => $obj->firstname,
'other' => '',
'source_url' => $this->url($obj->id,'contact'),
'source_id' => $obj->id,
'source_type' => 'contact'
);
}
}
$i++;
}
}
else
{
dol_syslog($this->db->error());
$this->error=$this->db->error();
return -1;
// Stock recipients emails into targets table
$result=$this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i = 0;
dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found");
$old = '';
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) {
if (!array_key_exists($obj->email, $cibles)) {
$cibles[$obj->email] = array(
'email' => $obj->email,
'fk_contact' =>$obj->id,
'lastname' => $obj->lastname,
'firstname' => $obj->firstname,
'other' => '',
'source_url' => $this->url($obj->id,'contact'),
'source_id' => $obj->id,
'source_type' => 'contact'
);
}
}
$i++;
}
}
else
{
dol_syslog($this->db->error());
$this->error=$this->db->error();
return -1;
}
}
}

View File

@ -3041,6 +3041,7 @@ class Product extends CommonObject
function get_sousproduits_arbo()
{
//$parent = $this->getParent();
$parent=array();
$parent[$this->label]=array(0 => $this->id);
foreach($parent as $key => $value) // key=label, value[0]=id