Fixed: Bugs reported by scrutinizer

Fixed: Solve conflict between ->iban and ->iban_prefix.
This commit is contained in:
Laurent Destailleur 2014-11-22 16:57:08 +01:00
parent d8767bfbae
commit 671243e8f6
13 changed files with 23 additions and 352 deletions

View File

@ -25,12 +25,13 @@
*/
/**
* Classe permettant la gestion des comptes generaux de compta
* Class to manage accounting accounts
*/
class AccountingAccount
{
var $db;
var $error;
var $errors;
var $id;
var $rowid;
@ -126,6 +127,8 @@ class AccountingAccount
global $conf, $langs;
$error = 0;
$now=dol_now();
// Clean parameters
if (isset($this->fk_pcg_version))
$this->fk_pcg_version = trim($this->fk_pcg_version);

View File

@ -291,8 +291,6 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
//$object->note = trim($_POST["comment"]);
$object->morphy = $_POST["morphy"];
$object->amount = $_POST["amount"];
if (GETPOST('deletephoto')) $object->photo='';
elseif (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);

View File

@ -142,7 +142,7 @@ if ($action == 'edit') // Edit
print '</table><br>'."\n";
// Themes
show_theme('',1);
show_theme(null,1);
print '<br>';
// Liste des zone de recherche permanantes supportees
@ -323,7 +323,7 @@ else // Show
// Themes
show_theme('',0);
show_theme(null,0);
print '<br>';

View File

@ -63,8 +63,7 @@ if ($action == 'update' && ! $_POST["cancel"])
$account->number = trim($_POST["number"]);
$account->cle_rib = trim($_POST["cle_rib"]);
$account->bic = trim($_POST["bic"]);
$account->iban = trim($_POST["iban_prefix"]);
$account->iban_prefix = trim($_POST["iban_prefix"]); // deprecated
$account->iban = trim($_POST["iban"]);
$account->domiciliation = trim($_POST["domiciliation"]);
$account->proprio = trim($_POST["proprio"]);
$account->owner_address = trim($_POST["owner_address"]);
@ -246,7 +245,7 @@ if (($_GET["id"] || $_GET["ref"]) && $action != 'edit')
if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
print '<tr><td valign="top">'.$langs->trans($ibankey).'</td>';
print '<td colspan="3">'.$account->iban_prefix.'</td></tr>';
print '<td colspan="3">'.$account->iban.'</td></tr>';
print '<tr><td valign="top">'.$langs->trans($bickey).'</td>';
print '<td colspan="3">'.$account->bic.'</td></tr>';
@ -423,7 +422,7 @@ if ($_GET["id"] && $action == 'edit' && $user->rights->banque->configurer)
// IBAN
print '<tr><td valign="top">'.$langs->trans($ibankey).'</td>';
print '<td colspan="3"><input size="34" maxlength="34" type="text" class="flat" name="iban_prefix" value="'.$account->iban_prefix.'"></td></tr>';
print '<td colspan="3"><input size="34" maxlength="34" type="text" class="flat" name="iban" value="'.$account->iban.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans($bickey).'</td>';
print '<td colspan="3"><input size="11" maxlength="11" type="text" class="flat" name="bic" value="'.$account->bic.'"></td></tr>';

View File

@ -135,7 +135,7 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
$account->number = trim($_POST["number"]);
$account->cle_rib = trim($_POST["cle_rib"]);
$account->bic = trim($_POST["bic"]);
$account->iban_prefix = trim($_POST["iban_prefix"]);
$account->iban = trim($_POST["iban"]);
$account->domiciliation = trim($_POST["domiciliation"]);
$account->proprio = trim($_POST["proprio"]);

View File

@ -59,7 +59,7 @@ class Account extends CommonObject
//! BIC/SWIFT number
var $bic;
//! IBAN number (International Bank Account Number)
var $iban_prefix;
var $iban; // stored into iban_prefix field into database
var $proprio;
var $owner_address;
@ -642,7 +642,6 @@ class Account extends CommonObject
$this->cle_rib = $obj->cle_rib;
$this->bic = $obj->bic;
$this->iban = $obj->iban;
$this->iban_prefix = $obj->iban; // deprecated
$this->domiciliation = $obj->domiciliation;
$this->proprio = $obj->proprio;
$this->owner_address = $obj->owner_address;
@ -1011,7 +1010,6 @@ class Account extends CommonObject
$this->cle_rib = 50;
$this->bic = 'AA12';
$this->iban = 'FR999999999';
$this->iban_prefix = 'FR'; // deprecated
$this->domiciliation = 'The bank addresse';
$this->proprio = 'Owner';
$this->owner_address = 'Owner address';

View File

@ -79,7 +79,7 @@ class box_comptes extends ModeleBoxes
if ($user->rights->banque->lire)
{
$sql = "SELECT rowid, ref, label, bank, number, courant, clos, rappro, url,";
$sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix,";
$sql.= " code_banque, code_guichet, cle_rib, bic, iban_prefix as iban,";
$sql.= " domiciliation, proprio, owner_address,";
$sql.= " account_number, currency_code,";
$sql.= " min_allowed, min_desired, comment";

View File

@ -2179,331 +2179,6 @@ abstract class CommonObject
}
}
<<<<<<< HEAD
=======
/**
* Function to get extra fields of a member into $this->array_options
* This method is in most cases called by method fetch of objects but you can call it separately.
*
* @param int $rowid Id of line
* @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label()
* @return int <0 if error, 0 if no optionals to find nor found, 1 if a line is found and optional loaded
*/
function fetch_optionals($rowid,$optionsArray='')
{
if (! is_array($optionsArray))
{
// optionsArray not already loaded, so we load it
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
$optionsArray = $extrafields->fetch_name_optionals_label($this->table_element);
}
// Request to get complementary values
if (count($optionsArray) > 0)
{
$sql = "SELECT rowid";
foreach ($optionsArray as $name => $label)
{
$sql.= ", ".$name;
}
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields";
$sql.= " WHERE fk_object = ".$rowid;
dol_syslog(get_class($this)."::fetch_optionals sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$numrows=$this->db->num_rows($resql);
if ($numrows)
{
$tab = $this->db->fetch_array($resql);
foreach ($tab as $key => $value)
{
// Test fetch_array ! is_int($key) because fetch_array result is a mix table with some key as alpha and some key as int (depend db engine)
if ($key != 'rowid' && $key != 'tms' && ! is_int($key))
{
// we can add this attribute to object properties
$this->array_options["options_".$key]=$value;
}
}
}
$this->db->free($resql);
if ($numrows) return $numrows;
else return 0;
}
else
{
dol_print_error($this->db);
return -1;
}
}
return 0;
}
/**
* Delete all extra fields values for the current object.
*
* @return int <0 if KO, >0 if OK
*/
function deleteExtraFields()
{
global $langs;
$error=0;
$this->db->begin();
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
dol_syslog(get_class($this)."::deleteExtraFields delete sql=".$sql_del);
$resql=$this->db->query($sql_del);
if (! $resql)
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::deleteExtraFields ".$this->error,LOG_ERR);
$this->db->rollback();
return -1;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Add/Update all extra fields values for the current object.
* All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd')
*
* @return int -1=error, O=did nothing, 1=OK
*/
function insertExtraFields()
{
global $conf,$langs;
$error=0;
if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used
if (! empty($this->array_options))
{
// Check parameters
$langs->load('admin');
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafields = new ExtraFields($this->db);
$optionsArray = $extrafields->fetch_name_optionals_label($this->table_element);
foreach($this->array_options as $key => $value)
{
$attributeKey = substr($key,8); // Remove 'options_' prefix
$attributeType = $extrafields->attribute_type[$attributeKey];
$attributeSize = $extrafields->attribute_size[$attributeKey];
$attributeLabel = $extrafields->attribute_label[$attributeKey];
switch ($attributeType)
{
case 'int':
if (!is_numeric($value) && $value!='')
{
$error++; $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
return -1;
}
elseif ($value=='')
{
$this->array_options[$key] = null;
}
break;
case 'price':
$this->array_options[$key] = price2num($this->array_options[$key]);
break;
case 'date':
$this->array_options[$key]=$this->db->idate($this->array_options[$key]);
break;
case 'datetime':
$this->array_options[$key]=$this->db->idate($this->array_options[$key]);
break;
}
}
$this->db->begin();
$sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id;
dol_syslog(get_class($this)."::insertExtraFields delete sql=".$sql_del);
$this->db->query($sql_del);
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object";
foreach($this->array_options as $key => $value)
{
$attributeKey = substr($key,8); // Remove 'options_' prefix
// Add field of attribut
if (isset($extrafields->attribute_type[$attributeKey]) && $extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate
$sql.=",".$attributeKey;
}
$sql .= ") VALUES (".$this->id;
foreach($this->array_options as $key => $value)
{
$attributeKey = substr($key,8); // Remove 'options_' prefix
// Add field o fattribut
if(isset($extrafields->attribute_type[$attributeKey]) && $extrafields->attribute_type[$attributeKey] != 'separate') // Only for other type of separate)
{
if ($this->array_options[$key] != '')
{
$sql.=",'".$this->db->escape($this->array_options[$key])."'";
}
else
{
$sql.=",null";
}
}
}
$sql.=")";
dol_syslog(get_class($this)."::insertExtraFields insert sql=".$sql);
$resql = $this->db->query($sql);
if (! $resql)
{
$this->error=$this->db->lasterror();
dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
$this->db->rollback();
return -1;
}
else
{
$this->db->commit();
return 1;
}
}
else return 0;
}
/**
* Function to show lines of extrafields with output datas
*
* @param object $extrafields Extrafield Object
* @param string $mode Show output (view) or input (edit) for extrafield
* @param array $params Optionnal parameters
* @param string $keyprefix Prefix string to add into name and id of field (can be used to avoid duplicate names)
*
* @return string
*/
function showOptionals($extrafields, $mode='view', $params=0, $keyprefix='')
{
global $_POST, $conf;
$out = '';
if (count($extrafields->attribute_label) > 0)
{
$out .= "\n";
$out .= '<!-- showOptionalsInput --> ';
$out .= "\n";
$e = 0;
foreach($extrafields->attribute_label as $key=>$label)
{
if (is_array($params) && count($params)>0) {
if (array_key_exists('colspan',$params)) {
$colspan=$params['colspan'];
}
}else {
$colspan='3';
}
switch($mode) {
case "view":
$value=$this->array_options["options_".$key];
break;
case "edit":
$value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$this->array_options["options_".$key]);
break;
}
if ($extrafields->attribute_type[$key] == 'separate')
{
$out .= $extrafields->showSeparator($key);
}
else
{
$csstyle='';
if (is_array($params) && count($params)>0) {
if (array_key_exists('style',$params)) {
$csstyle=$params['style'];
}
}
if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0)
{
$out .= '<tr '.$csstyle.'>';
$colspan='0';
}
else
{
$out .= '<tr '.$csstyle.'>';
}
// Convert date into timestamp format
if (in_array($extrafields->attribute_type[$key],array('date','datetime')))
{
$value = isset($_POST["options_".$key])?dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]):$this->db->jdate($this->array_options['options_'.$key]);
}
if($extrafields->attribute_required[$key])
$label = '<span class="fieldrequired">'.$label.'</span>';
$out .= '<td>'.$label.'</td>';
$out .='<td'.($colspan?' colspan="'.$colspan.'"':'').'>';
switch($mode) {
case "view":
$out .= $extrafields->showOutputField($key,$value);
break;
case "edit":
$out .= $extrafields->showInputField($key,$value,'',$keyprefix);
break;
}
$out .= '</td>'."\n";
if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>';
else $out .= '</tr>';
$e++;
}
}
$out .= "\n";
$out .= '<!-- /showOptionalsInput --> ';
$out .= '
<script type="text/javascript">
jQuery(document).ready(function() {
function showOptions(child_list, parent_list)
{
var val = $("select[name=\"options_"+parent_list+"\"]").val();
var parentVal = parent_list + ":" + val;
if(val > 0) {
$("select[name=\""+child_list+"\"] option[parent]").hide();
$("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
} else {
$("select[name=\""+child_list+"\"] option").show();
}
}
function setListDependencies() {
jQuery("select option[parent]").parent().each(function() {
var child_list = $(this).attr("name");
var parent = $(this).find("option[parent]:first").attr("parent");
var infos = parent.split(":");
var parent_list = infos[0];
$("select[name=\"options_"+parent_list+"\"]").change(function() {
showOptions(child_list, parent_list);
});
});
}
setListDependencies();
});
</script>';
}
return $out;
}
>>>>>>> refs/remotes/origin/3.6
/**
* Function to check if an object is used by others.
* Check is done into this->childtables. There is no check into llx_element_element.

View File

@ -242,7 +242,7 @@ function entity_prepare_head($object, $aEntities)
/**
* Show list of themes. Show all thumbs of themes
*
* @param User $fuser User concerned or '' for global theme
* @param User $fuser User concerned or null for global theme
* @param int $edit 1 to add edit form
* @param boolean $foruserprofile Show for user profile view
* @return void
@ -265,7 +265,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false)
$selected_theme='';
if (empty($foruserprofile)) $selected_theme=$conf->global->MAIN_THEME;
else $selected_theme=empty($fuser->conf->MAIN_THEME)?'':$fuser->conf->MAIN_THEME;
else $selected_theme=((is_object($fuser) && ! empty($fuser->conf->MAIN_THEME))?$fuser->conf->MAIN_THEME:'');
$colspan=2;
if ($foruserprofile) $colspan=4;

View File

@ -38,7 +38,7 @@ create table llx_bank_account
number varchar(255),
cle_rib varchar(5),
bic varchar(11),
iban_prefix varchar(34), -- 34 according to ISO 13616
iban_prefix varchar(34), -- full iban. 34 according to ISO 13616
country_iban varchar(2), -- deprecated
cle_iban varchar(2),
domiciliation varchar(255),

View File

@ -32,7 +32,7 @@ create table llx_societe_rib
number varchar(255), -- account number
cle_rib varchar(5), -- key of bank account
bic varchar(20), -- 11 according to ISO 9362 (we keep 20 for backward compatibility)
iban_prefix varchar(34), -- 34 according to ISO 13616
iban_prefix varchar(34), -- full iban. 34 according to ISO 13616
domiciliation varchar(255),
proprio varchar(60),
owner_address varchar(255),

View File

@ -45,7 +45,6 @@ class CompanyBankAccount extends Account
var $cle_rib;
var $bic;
var $iban;
var $iban_prefix; // deprecated
var $proprio;
var $owner_address;
var $default_rib;
@ -141,7 +140,7 @@ class CompanyBankAccount extends Account
$sql .= ",number='".$this->number."'";
$sql .= ",cle_rib='".$this->cle_rib."'";
$sql .= ",bic='".$this->bic."'";
$sql .= ",iban_prefix = '".$this->iban_prefix."'";
$sql .= ",iban_prefix = '".$this->iban."'";
$sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
$sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
$sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'";
@ -196,7 +195,6 @@ class CompanyBankAccount extends Account
$this->cle_rib = $obj->cle_rib;
$this->bic = $obj->bic;
$this->iban = $obj->iban;
$this->iban_prefix = $obj->iban; // deprecated
$this->domiciliation = $obj->domiciliation;
$this->proprio = $obj->proprio;
$this->owner_address = $obj->owner_address;

View File

@ -71,7 +71,7 @@ if ($action == 'update' && ! $_POST["cancel"])
$account->number = $_POST["number"];
$account->cle_rib = $_POST["cle_rib"];
$account->bic = $_POST["bic"];
$account->iban_prefix = $_POST["iban_prefix"];
$account->iban = $_POST["iban"];
$account->domiciliation = $_POST["domiciliation"];
$account->proprio = $_POST["proprio"];
$account->owner_address = $_POST["owner_address"];
@ -129,7 +129,7 @@ if ($action == 'add' && ! $_POST["cancel"])
$account->number = $_POST["number"];
$account->cle_rib = $_POST["cle_rib"];
$account->bic = $_POST["bic"];
$account->iban_prefix = $_POST["iban_prefix"];
$account->iban = $_POST["iban"];
$account->domiciliation = $_POST["domiciliation"];
$account->proprio = $_POST["proprio"];
$account->owner_address = $_POST["owner_address"];
@ -292,7 +292,7 @@ if ($socid && $action != 'edit' && $action != "create")
}
print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4">'.$account->iban_prefix.'</td></tr>';
print '<td colspan="4">'.$account->iban.'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
print '<td colspan="4">'.$account->bic.'</td></tr>';
@ -476,13 +476,13 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
// IBAN
print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4"><input size="30" type="text" name="iban_prefix" value="'.$account->iban_prefix.'"></td></tr>';
print '<td colspan="4"><input size="30" type="text" name="iban" value="'.$account->iban.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
print '<td colspan="4"><input size="12" type="text" name="bic" value="'.$account->bic.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
print "<textarea name=\"domiciliation\" rows=\"4\" cols=\"40\">";
print '<textarea name="domiciliation" rows="4" cols="40">';
print $account->domiciliation;
print "</textarea></td></tr>";
@ -556,7 +556,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
// IBAN
print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4"><input size="30" type="text" name="iban_prefix" value="'.GETPOST('iban_prefix').'"></td></tr>';
print '<td colspan="4"><input size="30" type="text" name="iban" value="'.GETPOST('iban').'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
print '<td colspan="4"><input size="12" type="text" name="bic" value="'.GETPOST('bic').'"></td></tr>';