From 580b9db3e7f3e9829cd9a32f5ac8fbc875306b1f Mon Sep 17 00:00:00 2001
From: Matt Sidnell <54064522+pstructures@users.noreply.github.com>
Date: Wed, 8 Jul 2020 14:20:59 +0100
Subject: [PATCH 1/2] Updated Hook in showOptionals function to allow the
manipulation of optional fields on cards etc...
---
htdocs/core/class/commonobject.class.php | 1009 ++++++++++++++--------
1 file changed, 648 insertions(+), 361 deletions(-)
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index f9a78a321ee..d6e8314155f 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -717,7 +717,8 @@ abstract class CommonObject
{
if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
$out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
- } else {
+ }
+ else {
$out .= ($outdone ? ' - ' : '').$this->state;
}
$outdone++;
@@ -844,8 +845,10 @@ abstract class CommonObject
$this->errors = $ecmfile->errors;
}
*/
- } else return '';
- } elseif (empty($ecmfile->share))
+ }
+ else return '';
+ }
+ elseif (empty($ecmfile->share))
{
// Add entry into index
if ($initsharekey)
@@ -853,7 +856,8 @@ abstract class CommonObject
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$ecmfile->share = getRandomPassword(true);
$ecmfile->update($user);
- } else return '';
+ }
+ else return '';
}
// Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@@ -875,7 +879,9 @@ abstract class CommonObject
if ($relativelink)
{
$linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : '');
- } else {
+ }
+ else
+ {
$linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
}
@@ -922,7 +928,9 @@ abstract class CommonObject
if (is_numeric($type_contact))
{
$id_type_contact = $type_contact;
- } else {
+ }
+ else
+ {
// We look for id type_contact
$sql = "SELECT tc.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
@@ -985,14 +993,18 @@ abstract class CommonObject
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error = $this->db->errno();
$this->db->rollback();
echo 'err rollback';
return -2;
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
@@ -1047,7 +1059,9 @@ abstract class CommonObject
if ($resql)
{
return 0;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
@@ -1083,7 +1097,9 @@ abstract class CommonObject
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -1119,7 +1135,9 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
@@ -1179,7 +1197,9 @@ abstract class CommonObject
'nom'=>$obj->lastname, // For backward compatibility
'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact,
'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact);
- } else {
+ }
+ else
+ {
$tab[$i] = $obj->id;
}
@@ -1187,7 +1207,9 @@ abstract class CommonObject
}
return $tab;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
dol_print_error($this->db);
return -1;
@@ -1221,7 +1243,9 @@ abstract class CommonObject
$result = $this->update_contact($rowid, $newstatut);
$this->db->free($resql);
return $result;
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
dol_print_error($this->db);
return -1;
@@ -1273,7 +1297,9 @@ abstract class CommonObject
$i++;
}
return $tab;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
//dol_print_error($this->db);
return null;
@@ -1354,7 +1380,9 @@ abstract class CommonObject
}
}
return $tab;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return null;
}
@@ -1414,7 +1442,9 @@ abstract class CommonObject
$result[$i] = $obj->fk_socpeople;
$i++;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
return null;
}
@@ -1424,15 +1454,15 @@ abstract class CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Load object contact with id=$this->contact_id into $this->contact
+ * Load object contact with id=$this->contactid into $this->contact
*
- * @param int $contactid Id du contact. Use this->contact_id if empty.
+ * @param int $contactid Id du contact. Use this->contactid if empty.
* @return int <0 if KO, >0 if OK
*/
public function fetch_contact($contactid = null)
{
// phpcs:enable
- if (empty($contactid)) $contactid = $this->contact_id;
+ if (empty($contactid)) $contactid = $this->contactid;
if (empty($contactid)) return 0;
@@ -1475,7 +1505,8 @@ abstract class CommonObject
}
return $result;
- } else return -1;
+ } else
+ return -1;
}
@@ -1545,7 +1576,9 @@ abstract class CommonObject
$this->barcode_type_label = $obj->label;
$this->barcode_type_coder = $obj->coder;
return 1;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -1752,7 +1785,9 @@ abstract class CommonObject
if (empty($this->fields) && method_exists($this, 'fetch'))
{
$result = $this->fetch($id);
- } else {
+ }
+ else
+ {
$result = $this->fetchCommon($id);
}
if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors
@@ -1764,11 +1799,15 @@ abstract class CommonObject
if (property_exists($this, $field)) $this->$field = $value;
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
return -2;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -1813,10 +1852,11 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
- } elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
+ }
+ elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
- $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
+ $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
if (!empty($filter))
@@ -1827,7 +1867,8 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ' AND te.'.$tmparray[0].' = '.($tmparray[1] == 'societe' ? 's' : 'parenttable').'.rowid'; // If we need to link to this table to limit select to entity
- } elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
+ }
+ elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1868,7 +1909,7 @@ abstract class CommonObject
elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
- $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
+ $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
if (!empty($filter))
@@ -1925,7 +1966,7 @@ abstract class CommonObject
while ($i < $num)
{
if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
- else $contactAlreadySelected[$i] = $tab[$i]['id'];
+ else $contactAlreadySelected[$i] = $tab[$i]['id'];
$i++;
}
return $contactAlreadySelected;
@@ -1952,12 +1993,14 @@ abstract class CommonObject
if ($projectid) $sql .= ' SET fk_project = '.$projectid;
else $sql .= ' SET fk_project = NULL';
$sql .= ' WHERE rowid = '.$this->id;
- } elseif ($this->table_element == 'actioncomm') // Special case for actioncomm
+ }
+ elseif ($this->table_element == 'actioncomm') // Special case for actioncomm
{
if ($projectid) $sql .= ' SET fk_project = '.$projectid;
else $sql .= ' SET fk_project = NULL';
$sql .= ' WHERE id = '.$this->id;
- } else // Special case for old architecture objects
+ }
+ else // Special case for old architecture objects
{
if ($projectid) $sql .= ' SET fk_projet = '.$projectid;
else $sql .= ' SET fk_projet = NULL';
@@ -1969,7 +2012,9 @@ abstract class CommonObject
{
$this->fk_project = $projectid;
return 1;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -2001,12 +2046,16 @@ abstract class CommonObject
// for supplier
if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id;
return 1;
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2038,12 +2087,16 @@ abstract class CommonObject
if ($rate) $this->setMulticurrencyRate($rate, 2);
return 1;
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2142,12 +2195,16 @@ abstract class CommonObject
}
return 1;
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2181,12 +2238,16 @@ abstract class CommonObject
if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id;
$this->cond_reglement = $id; // for compatibility
return 1;
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2215,12 +2276,16 @@ abstract class CommonObject
{
$this->retained_warranty_fk_cond_reglement = $id;
return 1;
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- } else {
+ }
+ else
+ {
dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2246,7 +2311,9 @@ abstract class CommonObject
{
$this->fk_delivery_address = $id;
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error);
return -1;
@@ -2370,7 +2437,9 @@ abstract class CommonObject
{
$this->modelpdf = $modelpdf;
return 1;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return 0;
}
@@ -2412,7 +2481,9 @@ abstract class CommonObject
dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
$this->error = $this->db->lasterror();
$error++;
- } else {
+ }
+ else
+ {
if (!$notrigger)
{
// Call trigger
@@ -2426,7 +2497,9 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->fk_account = ($fk_account == 'NULL') ?null:$fk_account;
$this->db->commit();
return 1;
@@ -2473,7 +2546,8 @@ abstract class CommonObject
{
$row = $this->db->fetch_row($resql);
$nl = $row[0];
- } else dol_print_error($this->db);
+ }
+ else dol_print_error($this->db);
if ($nl > 0)
{
// The goal of this part is to reorder all lines, with all children lines sharing the same
@@ -2515,7 +2589,9 @@ abstract class CommonObject
$this->updateRangOfLine($row, ($key + 1));
}
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
}
@@ -2525,11 +2601,10 @@ abstract class CommonObject
/**
* Get children of line
*
- * @param int $id Id of parent line
- * @param int $includealltree 0 = 1st level child, 1 = All level child
- * @return array Array with list of children lines id
+ * @param int $id Id of parent line
+ * @return array Array with list of children lines id
*/
- public function getChildrenOfLine($id, $includealltree = 0)
+ public function getChildrenOfLine($id)
{
$rows = array();
@@ -2542,13 +2617,16 @@ abstract class CommonObject
$resql = $this->db->query($sql);
if ($resql)
{
- if ($this->db->num_rows($resql) > 0) {
- while ($row = $this->db->fetch_row($resql)) {
- $rows[] = $row[0];
- if (!empty($includealltree)) $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
- }
+ $i = 0;
+ $num = $this->db->num_rows($resql);
+ while ($i < $num)
+ {
+ $row = $this->db->fetch_row($resql);
+ $rows[$i] = $row[0];
+ $i++;
}
}
+
return $rows;
}
@@ -2659,7 +2737,9 @@ abstract class CommonObject
{
dol_print_error($this->db);
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
}
@@ -2691,7 +2771,9 @@ abstract class CommonObject
{
dol_print_error($this->db);
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
}
}
@@ -2764,13 +2846,16 @@ abstract class CommonObject
if (!empty($row[0]))
{
return $row[0];
- } else {
+ }
+ else
+ {
return $this->getRangOfLine($fk_parent_line);
}
}
}
// If not, search the last rang of element
- else {
+ else
+ {
$sql = 'SELECT max('.$positionfield.') FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2809,7 +2894,9 @@ abstract class CommonObject
{
$this->ref_ext = $ref_ext;
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
return -1;
}
@@ -2854,12 +2941,15 @@ abstract class CommonObject
{
if ($suffix == '_public') $this->note_public = $note;
elseif ($suffix == '_private') $this->note_private = $note;
- else {
+ else
+ {
$this->note = $note; // deprecated
$this->note_private = $note;
}
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
@@ -3124,10 +3214,14 @@ abstract class CommonObject
if (!$error)
{
return 1;
- } else {
+ }
+ else
+ {
return -1;
}
- } else {
+ }
+ else
+ {
dol_print_error($this->db, 'Bad request in update_price');
return -1;
}
@@ -3172,7 +3266,9 @@ abstract class CommonObject
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->db->rollback();
return 0;
@@ -3245,12 +3341,15 @@ abstract class CommonObject
{
$sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'";
if ($withtargettype) $sql .= " AND targettype = '".$targettype."'";
- } elseif ($justtarget)
+ }
+ elseif ($justtarget)
{
$sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'";
if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'";
}
- } else {
+ }
+ else
+ {
$sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')";
$sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')";
}
@@ -3270,11 +3369,14 @@ abstract class CommonObject
if ($justsource)
{
$this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
- } elseif ($justtarget)
+ }
+ elseif ($justtarget)
{
$this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
}
- } else {
+ }
+ else
+ {
if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype)
{
$this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
@@ -3305,23 +3407,32 @@ abstract class CommonObject
// To work with non standard classpath or module name
if ($objecttype == 'facture') {
$classpath = 'compta/facture/class';
- } elseif ($objecttype == 'facturerec') {
+ }
+ elseif ($objecttype == 'facturerec') {
$classpath = 'compta/facture/class'; $module = 'facture';
- } elseif ($objecttype == 'propal') {
+ }
+ elseif ($objecttype == 'propal') {
$classpath = 'comm/propal/class';
- } elseif ($objecttype == 'supplier_proposal') {
+ }
+ elseif ($objecttype == 'supplier_proposal') {
$classpath = 'supplier_proposal/class';
- } elseif ($objecttype == 'shipping') {
+ }
+ elseif ($objecttype == 'shipping') {
$classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon';
- } elseif ($objecttype == 'delivery') {
+ }
+ elseif ($objecttype == 'delivery') {
$classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon';
- } elseif ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
+ }
+ elseif ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
$classpath = 'fourn/class'; $module = 'fournisseur';
- } elseif ($objecttype == 'fichinter') {
+ }
+ elseif ($objecttype == 'fichinter') {
$classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter';
- } elseif ($objecttype == 'subscription') {
+ }
+ elseif ($objecttype == 'subscription') {
$classpath = 'adherents/class'; $module = 'adherent';
- } elseif ($objecttype == 'contact') {
+ }
+ elseif ($objecttype == 'contact') {
$module = 'societe';
}
@@ -3330,17 +3441,23 @@ abstract class CommonObject
if ($objecttype == 'order') {
$classfile = 'commande'; $classname = 'Commande';
- } elseif ($objecttype == 'invoice_supplier') {
+ }
+ elseif ($objecttype == 'invoice_supplier') {
$classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur';
- } elseif ($objecttype == 'order_supplier') {
+ }
+ elseif ($objecttype == 'order_supplier') {
$classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur';
- } elseif ($objecttype == 'supplier_proposal') {
+ }
+ elseif ($objecttype == 'supplier_proposal') {
$classfile = 'supplier_proposal'; $classname = 'SupplierProposal';
- } elseif ($objecttype == 'facturerec') {
+ }
+ elseif ($objecttype == 'facturerec') {
$classfile = 'facture-rec'; $classname = 'FactureRec';
- } elseif ($objecttype == 'subscription') {
+ }
+ elseif ($objecttype == 'subscription') {
$classfile = 'subscription'; $classname = 'Subscription';
- } elseif ($objecttype == 'project' || $objecttype == 'projet') {
+ }
+ elseif ($objecttype == 'project' || $objecttype == 'projet') {
$classpath = 'projet/class'; $classfile = 'project'; $classname = 'Project';
}
@@ -3364,13 +3481,17 @@ abstract class CommonObject
}
}
}
- } else {
+ }
+ else
+ {
unset($this->linkedObjectsIds[$objecttype]);
}
}
}
return 1;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -3401,7 +3522,8 @@ abstract class CommonObject
$sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'";
$sql .= " WHERE fk_target = ".$this->id;
$sql .= " AND targettype = '".$this->db->escape($this->element)."'";
- } elseif ($updatetarget)
+ }
+ elseif ($updatetarget)
{
$sql .= "fk_target = ".$targetid;
$sql .= ", targettype = '".$this->db->escape($targettype)."'";
@@ -3413,7 +3535,9 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
return -1;
}
@@ -3448,16 +3572,21 @@ abstract class CommonObject
if ($rowid > 0)
{
$sql .= " rowid = ".$rowid;
- } else {
+ }
+ else
+ {
if ($deletesource)
{
$sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'";
$sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'";
- } elseif ($deletetarget)
+ }
+ elseif ($deletetarget)
{
$sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'";
$sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'";
- } else {
+ }
+ else
+ {
$sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')";
$sql .= " OR";
$sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')";
@@ -3468,7 +3597,9 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -3545,12 +3676,16 @@ abstract class CommonObject
}
return 1;
- } else {
+ }
+ else
+ {
$this->db->rollback();
dol_syslog(get_class($this)."::setStatut ".$this->error, LOG_ERR);
return -1;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -3589,8 +3724,11 @@ abstract class CommonObject
{
$this->canvas = $obj->canvas;
return 1;
- } else return 0;
- } else {
+ }
+ else return 0;
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -3663,13 +3801,16 @@ abstract class CommonObject
if (is_numeric($elementname)) // old usage
{
$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
- } else // new usage: $elementname=Translation key
+ }
+ else // new usage: $elementname=Translation key
{
$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
}
break; // We found at least one, we stop here
}
- } else {
+ }
+ else
+ {
$this->errors[] = $this->db->lasterror();
return -1;
}
@@ -3678,7 +3819,8 @@ abstract class CommonObject
{
$this->errors[] = "ErrorRecordHasChildren";
return $haschild;
- } else return 0;
+ }
+ else return 0;
}
/**
@@ -3770,7 +3912,8 @@ abstract class CommonObject
{
if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is ''
$totalToShip += $line->qty_shipped; // defined for shipment only
- } elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
+ }
+ elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
{
if (empty($totalToShip)) $totalToShip = 0;
$totalToShip += $line->qty; // defined for reception only
@@ -3780,7 +3923,8 @@ abstract class CommonObject
if ($this->element == 'shipping') {
// for shipments
$qty = $line->qty_shipped ? $line->qty_shipped : 0;
- } else {
+ }
+ else {
$qty = $line->qty ? $line->qty : 0;
}
@@ -3807,7 +3951,8 @@ abstract class CommonObject
{
$trueWeightUnit = pow(10, $weightUnit);
$totalWeight += $weight * $qty * $trueWeightUnit;
- } else {
+ }
+ else {
if ($weight_units == 99) {
// conversion 1 Pound = 0.45359237 KG
$trueWeightUnit = 0.45359237;
@@ -3816,7 +3961,8 @@ abstract class CommonObject
// conversion 1 Ounce = 0.0283495 KG
$trueWeightUnit = 0.0283495;
$totalWeight += $weight * $qty * $trueWeightUnit;
- } else {
+ }
+ else {
$totalWeight += $weight * $qty; // This may be wrong if we mix different units
}
}
@@ -3826,7 +3972,9 @@ abstract class CommonObject
$trueVolumeUnit = pow(10, $volumeUnit);
//print $line->volume;
$totalVolume += $volume * $qty * $trueVolumeUnit;
- } else {
+ }
+ else
+ {
$totalVolume += $volume * $qty; // This may be wrong if we mix different units
}
}
@@ -3857,7 +4005,9 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
@@ -3908,10 +4058,14 @@ abstract class CommonObject
{
$res = $this->db->fetch_object($resql);
return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
- } else {
+ }
+ else
+ {
return '';
}
- } else {
+ }
+ else
+ {
$this->errors[] = $this->db->lasterror();
return false;
}
@@ -3947,11 +4101,14 @@ abstract class CommonObject
$this->label_incoterms = $obj->libelle;
}
return 1;
- } else {
+ }
+ else
+ {
$this->errors[] = $this->db->lasterror();
return -1;
}
- } else return -1;
+ }
+ else return -1;
}
@@ -3992,7 +4149,9 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_create.tpl.php');
- } else {
+ }
+ else
+ {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_create.tpl.php';
}
@@ -4057,7 +4216,9 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_title.tpl.php');
- } else {
+ }
+ else
+ {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_title.tpl.php';
}
if (empty($conf->file->strict_mode)) {
@@ -4084,7 +4245,9 @@ abstract class CommonObject
{
$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element);
$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- } else {
+ }
+ else
+ {
$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line);
$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
@@ -4165,7 +4328,9 @@ abstract class CommonObject
}
$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label;
- } else {
+ }
+ else
+ {
$label = $line->product_label;
}
@@ -4184,7 +4349,9 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_view.tpl.php');
- } else {
+ }
+ else
+ {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_view.tpl.php';
}
@@ -4213,7 +4380,9 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php');
- } else {
+ }
+ else
+ {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_edit.tpl.php';
}
@@ -4273,7 +4442,9 @@ abstract class CommonObject
$action = '';
$hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
- } else {
+ }
+ else
+ {
$this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
}
@@ -4303,14 +4474,18 @@ abstract class CommonObject
if (!empty($line->date_start))
{
$date_start = $line->date_start;
- } else {
+ }
+ else
+ {
$date_start = $line->date_debut_prevue;
if ($line->date_debut_reel) $date_start = $line->date_debut_reel;
}
if (!empty($line->date_end))
{
$date_end = $line->date_end;
- } else {
+ }
+ else
+ {
$date_end = $line->date_fin_prevue;
if ($line->date_fin_reel) $date_end = $line->date_fin_reel;
}
@@ -4325,7 +4500,8 @@ abstract class CommonObject
$discount = new DiscountAbsolute($this->db);
$discount->fk_soc = $this->socid;
$this->tpl['label'] .= $discount->getNomUrl(0, 'discount');
- } elseif (!empty($line->fk_product))
+ }
+ elseif (!empty($line->fk_product))
{
$productstatic = new Product($this->db);
$productstatic->id = $line->fk_product;
@@ -4343,7 +4519,9 @@ abstract class CommonObject
{
$this->tpl['label'] .= get_date_range($date_start, $date_end);
}
- } else {
+ }
+ else
+ {
$this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product')));
if (!empty($line->desc)) {
$this->tpl['label'] .= $line->desc;
@@ -4365,25 +4543,32 @@ abstract class CommonObject
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
- } elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object
+ }
+ elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
- } elseif ($line->desc == '(EXCESS RECEIVED)')
+ }
+ elseif ($line->desc == '(EXCESS RECEIVED)')
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
- } elseif ($line->desc == '(EXCESS PAID)')
+ }
+ elseif ($line->desc == '(EXCESS PAID)')
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
- } else {
+ }
+ else
+ {
$this->tpl['description'] = dol_trunc($line->desc, 60);
}
- } else {
+ }
+ else
+ {
$this->tpl['description'] = ' ';
}
@@ -4410,7 +4595,9 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/originproductline.tpl.php');
- } else {
+ }
+ else
+ {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/originproductline.tpl.php';
}
@@ -4461,7 +4648,9 @@ abstract class CommonObject
{
$this->db->commit();
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->db->rollback();
return 0;
@@ -4495,7 +4684,9 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
if (!$notrigger)
{
$result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user);
@@ -4658,7 +4849,9 @@ abstract class CommonObject
{
$arrayofrecords = array(); // The write_file of templates of adherent class need this var
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams);
- } else {
+ }
+ else
+ {
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
}
// After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index.
@@ -4726,7 +4919,9 @@ abstract class CommonObject
if ($result < 0) {
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
}
- } else {
+ }
+ else
+ {
$ecmfile->entity = $conf->entity;
$ecmfile->filepath = $rel_dir;
$ecmfile->filename = $filename;
@@ -4765,7 +4960,9 @@ abstract class CommonObject
}
}
}
- } else {
+ }
+ else
+ {
dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
}
@@ -4773,7 +4970,9 @@ abstract class CommonObject
dol_meta_create($this);
return 1;
- } else {
+ }
+ else
+ {
$outputlangs->charset_output = $sav_charset_output;
dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors);
return -1;
@@ -4788,7 +4987,8 @@ abstract class CommonObject
}
return -1;
}
- } else return $reshook;
+ }
+ else return $reshook;
}
/**
@@ -4893,7 +5093,9 @@ abstract class CommonObject
if (!empty($this->errors))
{
$this->errors = array_unique(array_merge($this->errors, $interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice.
- } else {
+ }
+ else
+ {
$this->errors = $interface->errors;
}
}
@@ -4954,7 +5156,9 @@ abstract class CommonObject
if (preg_match('/date/', $type))
{
$this->array_languages[$key][$codelang] = $this->db->jdate($value);
- } else {
+ }
+ else
+ {
$this->array_languages[$key][$codelang] = $value;
}
@@ -4966,7 +5170,9 @@ abstract class CommonObject
if ($numrows) return $numrows;
else return 0;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -5015,12 +5221,14 @@ abstract class CommonObject
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime(0, 0, 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
- } elseif (in_array($key_type, array('datetime')))
+ }
+ elseif (in_array($key_type, array('datetime')))
{
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime($_POST[$postfieldkey."hour"], $_POST[$postfieldkey."min"], 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
- } elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
+ }
+ elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
{
$value_arr = GETPOST($postfieldkey, 'array'); // check if an array
if (!empty($value_arr)) {
@@ -5028,11 +5236,14 @@ abstract class CommonObject
} else {
$value_key = '';
}
- } elseif (in_array($key_type, array('price', 'double')))
+ }
+ elseif (in_array($key_type, array('price', 'double')))
{
$value_arr = GETPOST($postfieldkey, 'alpha');
$value_key = price2num($value_arr);
- } else {
+ }
+ else
+ {
$value_key = GETPOST($postfieldkey);
if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = '';
}
@@ -5112,7 +5323,9 @@ abstract class CommonObject
$extrafields->fetch_name_optionals_label($this->table_element);
}
$optionsArray = (!empty($extrafields->attributes[$this->table_element]['label']) ? $extrafields->attributes[$this->table_element]['label'] : null);
- } else {
+ }
+ else
+ {
global $extrafields;
dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
}
@@ -5153,7 +5366,9 @@ abstract class CommonObject
{
//var_dump($extrafields->attributes[$this->table_element]['type'][$key]);
$this->array_options["options_".$key] = $this->db->jdate($value);
- } else {
+ }
+ else
+ {
$this->array_options["options_".$key] = $value;
}
@@ -5177,7 +5392,9 @@ abstract class CommonObject
if ($numrows) return $numrows;
else return 0;
- } else {
+ }
+ else
+ {
dol_print_error($this->db);
return -1;
}
@@ -5210,7 +5427,9 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
@@ -5285,7 +5504,9 @@ abstract class CommonObject
$value = dol_eval($attrfieldcomputed, 1, 0);
dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG);
$new_array_options[$key] = $value;
- } else {
+ }
+ else
+ {
$new_array_options[$key] = null;
}
}
@@ -5297,7 +5518,8 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value == '')
+ }
+ elseif ($value == '')
{
$new_array_options[$key] = null;
}
@@ -5309,7 +5531,8 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value == '')
+ }
+ elseif ($value == '')
{
$new_array_options[$key] = null;
}
@@ -5340,16 +5563,21 @@ abstract class CommonObject
if ($this->array_options[$key] == $this->oldcopy->array_options[$key]) // If old value crypted in database is same than submited new value, it means we don't change it, so we don't update.
{
$new_array_options[$key] = $this->array_options[$key]; // Value is kept
- } else {
+ }
+ else
+ {
// var_dump($algo);
$newvalue = dol_hash($this->array_options[$key], $algo);
$new_array_options[$key] = $newvalue;
}
- } else {
+ }
+ else
+ {
$new_array_options[$key] = $this->array_options[$key]; // Value is kept
}
}
- } else // Common usage
+ }
+ else // Common usage
{
$new_array_options[$key] = $this->array_options[$key];
}
@@ -5376,20 +5604,24 @@ abstract class CommonObject
if ($value == '-1') // -1 is key for no defined in combo list of objects
{
$new_array_options[$key] = '';
- } elseif ($value)
+ }
+ elseif ($value)
{
$object = new $InfoFieldList[0]($this->db);
if (is_numeric($value)) $res = $object->fetch($value);
else $res = $object->fetch('', $value);
if ($res > 0) $new_array_options[$key] = $object->id;
- else {
+ else
+ {
$this->error = "Id/Ref '".$value."' for object '".$object->element."' not found";
$this->db->rollback();
return -1;
}
}
- } else {
+ }
+ else
+ {
dol_syslog('Error bad setup of extrafield', LOG_WARNING);
}
break;
@@ -5436,7 +5668,9 @@ abstract class CommonObject
if ($new_array_options[$key] != '' || $new_array_options[$key] == '0')
{
$sql .= ",'".$this->db->escape($new_array_options[$key])."'";
- } else {
+ }
+ else
+ {
$sql .= ",null";
}
}
@@ -5477,11 +5711,14 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
- } else return 0;
+ }
+ else return 0;
}
/**
@@ -5524,7 +5761,8 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraLanguageHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value == '')
+ }
+ elseif ($value == '')
{
$new_array_languages[$key] = null;
}
@@ -5536,7 +5774,8 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraLanguageHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraLanguageHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value == '')
+ }
+ elseif ($value == '')
{
$new_array_languages[$key] = null;
}
@@ -5595,18 +5834,21 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
- } else return 0;
+ }
+ else return 0;
}
/**
* Update an extra field value for the current object.
* Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
*
- * @param string $key Key of the extrafield to update (without starting 'options_')
+ * @param string $key Key of the extrafield (without starting 'options_')
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
* @param User $userused Object user
* @return int -1=error, O=did nothing, 1=OK
@@ -5647,7 +5889,8 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value === '')
+ }
+ elseif ($value === '')
{
$this->array_options["options_".$key] = null;
}
@@ -5659,7 +5902,8 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- } elseif ($value === '')
+ }
+ elseif ($value === '')
{
$this->array_options["options_".$key] = null;
}
@@ -5720,11 +5964,14 @@ abstract class CommonObject
dol_syslog(__METHOD__.$this->error, LOG_ERR);
$this->db->rollback();
return -1;
- } else {
+ }
+ else
+ {
$this->db->commit();
return 1;
}
- } else return 0;
+ }
+ else return 0;
}
/**
@@ -5837,30 +6084,39 @@ abstract class CommonObject
if (empty($morecss) && !empty($val['css']))
{
$morecss = $val['css'];
- } elseif (empty($morecss))
+ }
+ elseif (empty($morecss))
{
if ($type == 'date')
{
$morecss = 'minwidth100imp';
- } elseif ($type == 'datetime' || $type == 'link') // link means an foreign key to another primary id
+ }
+ elseif ($type == 'datetime' || $type == 'link') // link means an foreign key to another primary id
{
$morecss = 'minwidth200imp';
- } elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
+ }
+ elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
{
$morecss = 'maxwidth75';
} elseif ($type == 'url') {
$morecss = 'minwidth400';
- } elseif ($type == 'boolean')
+ }
+ elseif ($type == 'boolean')
{
$morecss = '';
- } else {
+ }
+ else
+ {
if (round($size) < 12)
{
$morecss = 'minwidth100';
- } elseif (round($size) <= 48)
+ }
+ elseif (round($size) <= 48)
{
$morecss = 'minwidth200';
- } else {
+ }
+ else
+ {
$morecss = 'minwidth400';
}
}
@@ -5878,44 +6134,56 @@ abstract class CommonObject
// TODO Must also support $moreparam
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
- } elseif (in_array($type, array('duration')))
+ }
+ elseif (in_array($type, array('duration')))
{
$out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1);
- } elseif (in_array($type, array('int', 'integer')))
+ }
+ elseif (in_array($type, array('int', 'integer')))
{
$tmp = explode(',', $size);
$newsize = $tmp[0];
$out = '';
- } elseif (in_array($type, array('real')))
+ }
+ elseif (in_array($type, array('real')))
{
$out = '';
- } elseif (preg_match('/varchar/', $type))
+ }
+ elseif (preg_match('/varchar/', $type))
{
$out = '';
- } elseif (in_array($type, array('mail', 'phone', 'url')))
+ }
+ elseif (in_array($type, array('mail', 'phone', 'url')))
{
$out = '';
- } elseif ($type == 'text')
+ }
+ elseif ($type == 'text')
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%');
$out = $doleditor->Create(1);
- } else {
+ }
+ else
+ {
$out = '';
}
- } elseif ($type == 'html')
+ }
+ elseif ($type == 'html')
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%');
$out = $doleditor->Create(1);
- } else {
+ }
+ else
+ {
$out = '';
}
- } elseif ($type == 'boolean')
+ }
+ elseif ($type == 'boolean')
{
$checked = '';
if (!empty($value)) {
@@ -5924,19 +6192,22 @@ abstract class CommonObject
$checked = ' value="1" ';
}
$out = '';
- } elseif ($type == 'price')
+ }
+ elseif ($type == 'price')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value);
}
$out = ' '.$langs->getCurrencySymbol($conf->currency);
- } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
+ }
+ elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value);
}
$out = ' ';
- } elseif ($type == 'select')
+ }
+ elseif ($type == 'select')
{
$out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -5957,7 +6228,8 @@ abstract class CommonObject
$out .= '>'.$val.'';
}
$out .= '';
- } elseif ($type == 'sellist')
+ }
+ elseif ($type == 'sellist')
{
$out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -6024,10 +6296,14 @@ abstract class CommonObject
{
$sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra';
$sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4];
- } else {
+ }
+ else
+ {
$sqlwhere .= ' WHERE '.$InfoFieldList[4];
}
- } else {
+ }
+ else
+ {
$sqlwhere .= ' WHERE 1=1';
}
// Some tables may have field, some other not. For the moment we disable it.
@@ -6062,7 +6338,9 @@ abstract class CommonObject
{
$labeltoshow .= $obj->$field_toshow.' ';
}
- } else {
+ }
+ else
+ {
$labeltoshow = $obj->{$InfoFieldList[1]};
}
$labeltoshow = dol_trunc($labeltoshow, 45);
@@ -6079,13 +6357,16 @@ abstract class CommonObject
}
}
$out .= '';
- } else {
+ }
+ else
+ {
if (!$notrans)
{
$translabel = $langs->trans($obj->{$InfoFieldList[1]});
if ($translabel != $obj->{$InfoFieldList[1]}) {
$labeltoshow = dol_trunc($translabel, 18);
- } else {
+ }
+ else {
$labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
}
}
@@ -6109,16 +6390,19 @@ abstract class CommonObject
$i++;
}
$this->db->free($resql);
- } else {
+ }
+ else {
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
';
}
}
$out .= '';
- } elseif ($type == 'checkbox')
+ }
+ elseif ($type == 'checkbox')
{
$value_arr = explode(',', $value);
$out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
- } elseif ($type == 'radio')
+ }
+ elseif ($type == 'radio')
{
$out = '';
foreach ($param['options'] as $keyopt => $val)
@@ -6129,11 +6413,13 @@ abstract class CommonObject
$out .= ($value == $keyopt ? 'checked' : '');
$out .= '/>
';
}
- } elseif ($type == 'chkbxlst')
+ }
+ elseif ($type == 'chkbxlst')
{
if (is_array($value)) {
$value_arr = $value;
- } else {
+ }
+ else {
$value_arr = explode(',', $value);
}
@@ -6271,7 +6557,8 @@ abstract class CommonObject
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
';
}
}
- } elseif ($type == 'link')
+ }
+ elseif ($type == 'link')
{
$param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter]]'
$param_list_array = explode(':', $param_list[0]);
@@ -6296,11 +6583,13 @@ abstract class CommonObject
$out .= '';
}
}
- } elseif ($type == 'password')
+ }
+ elseif ($type == 'password')
{
// If prefix is 'search_', field is used as a filter, we use a common text field.
$out = '';
- } elseif ($type == 'array')
+ }
+ elseif ($type == 'array')
{
$newval = $val;
$newval['type'] = 'varchar(256)';
@@ -6379,7 +6668,8 @@ abstract class CommonObject
{
$type = 'varchar'; // convert varchar(xx) int varchar
$size = $reg[1];
- } elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
+ }
+ elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
if (is_array($val['arrayofkeyval'])) $type = 'select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link';
@@ -6395,7 +6685,8 @@ abstract class CommonObject
{
$type = 'link';
$param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]);
- } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
+ }
+ elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4] => 'N');
$type = 'sellist';
}
@@ -6420,26 +6711,35 @@ abstract class CommonObject
if ($type == 'date')
{
$morecss = 'minwidth100imp';
- } elseif ($type == 'datetime' || $type == 'timestamp')
+ }
+ elseif ($type == 'datetime' || $type == 'timestamp')
{
$morecss = 'minwidth200imp';
- } elseif (in_array($type, array('int', 'double', 'price')))
+ }
+ elseif (in_array($type, array('int', 'double', 'price')))
{
$morecss = 'maxwidth75';
- } elseif ($type == 'url')
+ }
+ elseif ($type == 'url')
{
$morecss = 'minwidth400';
- } elseif ($type == 'boolean')
+ }
+ elseif ($type == 'boolean')
{
$morecss = '';
- } else {
+ }
+ else
+ {
if (round($size) < 12)
{
$morecss = 'minwidth100';
- } elseif (round($size) <= 48)
+ }
+ elseif (round($size) <= 48)
{
$morecss = 'minwidth200';
- } else {
+ }
+ else
+ {
$morecss = 'minwidth400';
}
}
@@ -6455,49 +6755,59 @@ abstract class CommonObject
} else {
$value = '';
}
- } elseif ($type == 'datetime' || $type == 'timestamp')
+ }
+ elseif ($type == 'datetime' || $type == 'timestamp')
{
if (!empty($value)) {
$value = dol_print_date($value, 'dayhour');
} else {
$value = '';
}
- } elseif ($type == 'duration')
+ }
+ elseif ($type == 'duration')
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (!is_null($value) && $value !== '') {
$value = convertSecondToTime($value, 'allhourmin');
}
- } elseif ($type == 'double' || $type == 'real')
+ }
+ elseif ($type == 'double' || $type == 'real')
{
if (!is_null($value) && $value !== '') {
$value = price($value);
}
- } elseif ($type == 'boolean')
+ }
+ elseif ($type == 'boolean')
{
$checked = '';
if (!empty($value)) {
$checked = ' checked ';
}
$value = '';
- } elseif ($type == 'mail')
+ }
+ elseif ($type == 'mail')
{
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
- } elseif ($type == 'url')
+ }
+ elseif ($type == 'url')
{
$value = dol_print_url($value, '_blank', 32, 1);
- } elseif ($type == 'phone')
+ }
+ elseif ($type == 'phone')
{
$value = dol_print_phone($value, '', 0, 0, '', ' ', 1);
- } elseif ($type == 'price')
+ }
+ elseif ($type == 'price')
{
if (!is_null($value) && $value !== '') {
$value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
}
- } elseif ($type == 'select')
+ }
+ elseif ($type == 'select')
{
$value = $param['options'][$value];
- } elseif ($type == 'sellist')
+ }
+ elseif ($type == 'sellist')
{
$param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
@@ -6558,7 +6868,9 @@ abstract class CommonObject
$value .= $obj->$field_toshow.' ';
}
}
- } else {
+ }
+ else
+ {
$translabel = '';
if (!empty($obj->{$InfoFieldList[1]})) {
$translabel = $langs->trans($obj->{$InfoFieldList[1]});
@@ -6569,11 +6881,14 @@ abstract class CommonObject
$value = $obj->{$InfoFieldList[1]};
}
}
- } else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
- } elseif ($type == 'radio')
+ }
+ else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
+ }
+ elseif ($type == 'radio')
{
$value = $param['options'][$value];
- } elseif ($type == 'checkbox')
+ }
+ elseif ($type == 'checkbox')
{
$value_arr = explode(',', $value);
$value = '';
@@ -6585,7 +6900,8 @@ abstract class CommonObject
}
$value = '
'.implode(' ', $toprint).'
';
}
- } elseif ($type == 'chkbxlst')
+ }
+ elseif ($type == 'chkbxlst')
{
$value_arr = explode(',', $value);
@@ -6652,7 +6968,8 @@ abstract class CommonObject
} else {
dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
}
- } elseif ($type == 'link')
+ }
+ elseif ($type == 'link')
{
$out = '';
@@ -6674,18 +6991,24 @@ abstract class CommonObject
$object->fetch($value);
$value = $object->getNomUrl($getnomurlparam);
}
- } else {
+ }
+ else
+ {
dol_syslog('Error bad setup of extrafield', LOG_WARNING);
return 'Error bad setup of extrafield';
}
- } else $value = '';
- } elseif ($type == 'text' || $type == 'html')
+ }
+ else $value = '';
+ }
+ elseif ($type == 'text' || $type == 'html')
{
$value = dol_htmlentitiesbr($value);
- } elseif ($type == 'password')
+ }
+ elseif ($type == 'password')
{
$value = preg_replace('/./i', '*', $value);
- } elseif ($type == 'array')
+ }
+ elseif ($type == 'array')
{
$value = implode('
', $value);
}
@@ -6711,10 +7034,13 @@ abstract class CommonObject
*/
public function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0)
{
- global $db, $conf, $langs, $action, $form;
-
+ global $db, $conf, $langs, $action, $form, $hookmanager;
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('ShowExtraFields',$parameters,$this,$action); // See description below
+ // Note that $action and $object may have been modified by hook
+ if (empty($reshook))
+ {
if (!is_object($form)) $form = new Form($db);
-
$out = '';
if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
@@ -6763,11 +7089,13 @@ abstract class CommonObject
if (is_array($params) && count($params) > 0) {
if (array_key_exists('cols', $params)) {
$colspan = $params['cols'];
- } elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
+ }
+ elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
$reg = array();
if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
$colspan = $reg[1];
- } else {
+ }
+ else {
$colspan = $params['colspan'];
}
}
@@ -6813,7 +7141,9 @@ abstract class CommonObject
}
$out .= $extrafields->showSeparator($key, $this, ($colspan + 1));
- } else {
+ }
+ else
+ {
$class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
$csstyle = '';
if (is_array($params) && count($params) > 0) {
@@ -6832,6 +7162,8 @@ abstract class CommonObject
$html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
+ $out .= '';
$return .= '';
- } elseif ($nbbyrow < 0) $return .= '';
+ }
+ elseif ($nbbyrow < 0) $return .= ' ';
$return .= "\n";
@@ -7192,20 +7531,26 @@ abstract class CommonObject
{
$return .= '';
$return .= ' .') ';
- } else {
+ }
+ else {
$return .= '';
$return .= ' .') ';
}
- } else {
+ }
+ else
+ {
$return .= '';
$return .= '  ';
}
- } else {
+ }
+ else
+ {
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
{
$return .= '';
$return .= ' .') ';
- } else {
+ }
+ else {
$return .= '';
$return .= ' .') ';
}
@@ -7240,7 +7585,8 @@ abstract class CommonObject
{
$return .= ' | ';
if (($nbphoto % $nbbyrow) == 0) $return .= '
';
- } elseif ($nbbyrow < 0) $return .= '';
+ }
+ elseif ($nbbyrow < 0) $return .= '';
}
if (empty($size)) { // Format origine
@@ -7329,7 +7675,8 @@ abstract class CommonObject
{
if (isset($info['type']) && ($info['type'] == 'duration')) return true;
else return false;
- } else return false;
+ }
+ else return false;
}
/**
@@ -7344,7 +7691,8 @@ abstract class CommonObject
{
if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
else return false;
- } else return false;
+ }
+ else return false;
}
/**
@@ -7448,10 +7796,13 @@ abstract class CommonObject
if (empty($this->{$field}))
{
$queryarray[$field] = null;
- } else {
+ }
+ else
+ {
$queryarray[$field] = $this->db->idate($this->{$field});
}
- } elseif ($this->isArray($info))
+ }
+ elseif ($this->isArray($info))
{
if (!empty($this->{$field})) {
if (!is_array($this->{$field})) {
@@ -7461,22 +7812,28 @@ abstract class CommonObject
} else {
$queryarray[$field] = null;
}
- } elseif ($this->isDuration($info))
+ }
+ elseif ($this->isDuration($info))
{
// $this->{$field} may be null, '', 0, '0', 123, '123'
if ($this->{$field} != '' || !empty($info['notnull'])) $queryarray[$field] = (int) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
else $queryarray[$field] = null;
- } elseif ($this->isInt($info) || $this->isFloat($info))
+ }
+ elseif ($this->isInt($info) || $this->isFloat($info))
{
if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity;
- else {
+ else
+ {
// $this->{$field} may be null, '', 0, '0', 123, '123'
if ($this->{$field} != '' || !empty($info['notnull'])) {
if ($this->isInt($info)) $queryarray[$field] = (int) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
if ($this->isFloat($info)) $queryarray[$field] = (double) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
- } else $queryarray[$field] = null;
+ }
+ else $queryarray[$field] = null;
}
- } else {
+ }
+ else
+ {
$queryarray[$field] = $this->{$field};
}
@@ -7501,7 +7858,8 @@ abstract class CommonObject
{
if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
else $this->{$field} = strtotime($obj->{$field});
- } elseif ($this->isArray($info))
+ }
+ elseif ($this->isArray($info))
{
if (!empty($obj->{$field})) {
$this->{$field} = @unserialize($obj->{$field});
@@ -7510,15 +7868,19 @@ abstract class CommonObject
} else {
$this->{$field} = array();
}
- } elseif ($this->isInt($info))
+ }
+ elseif ($this->isInt($info))
{
if ($field == 'rowid') $this->id = (int) $obj->{$field};
- else {
+ else
+ {
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
- } else {
+ }
+ else
+ {
if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (int) $obj->{$field};
} else {
@@ -7526,20 +7888,25 @@ abstract class CommonObject
}
}
}
- } elseif ($this->isFloat($info))
+ }
+ elseif ($this->isFloat($info))
{
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
- } else {
+ }
+ else
+ {
if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (double) $obj->{$field};
} else {
$this->{$field} = null;
}
}
- } else {
+ }
+ else
+ {
$this->{$field} = $obj->{$field};
}
}
@@ -7735,10 +8102,7 @@ abstract class CommonObject
{
if (empty($id) && empty($ref) && empty($morewhere)) return -1;
- $fieldlist = $this->getFieldList();
- if (empty($fieldlist)) return 0;
-
- $sql = 'SELECT '.$fieldlist;
+ $sql = 'SELECT '.$this->getFieldList();
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
if (!empty($id)) $sql .= ' WHERE rowid = '.$id;
@@ -7755,16 +8119,15 @@ abstract class CommonObject
if ($obj)
{
$this->setVarsFromFetchObj($obj);
-
- // Retreive all extrafield
- // fetch optionals attributes and labels
- $this->fetch_optionals();
-
return $this->id;
- } else {
+ }
+ else
+ {
return 0;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -7812,7 +8175,9 @@ abstract class CommonObject
}
return 1;
- } else {
+ }
+ else
+ {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -7939,7 +8304,8 @@ abstract class CommonObject
return -1;
}
}
- } elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables.
+ }
+ elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables.
{
$objectisused = $this->isObjectUsed($this->id);
if (!empty($objectisused))
@@ -8192,7 +8558,9 @@ abstract class CommonObject
$this->db->rollback();
return -1;
}
- } else {
+ }
+ else
+ {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
@@ -8270,89 +8638,8 @@ abstract class CommonObject
}
}
- /* Part for categories/tags */
-
/**
- * Sets object to given categories.
- *
- * Deletes object from existing categories not supplied.
- * Adds it to non existing supplied categories.
- * Existing categories are left untouch.
- *
- * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
- * @return int Array of category objects or < 0 if KO
- */
- public function getCategoriesCommon($type_categ)
- {
- require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
-
- // Get current categories
- $c = new Categorie($this->db);
- $existing = $c->containing($this->id, $type_categ, 'id');
-
- return $existing;
- }
-
- /**
- * Sets object to given categories.
- *
- * Deletes object from existing categories not supplied.
- * Adds it to non existing supplied categories.
- * Existing categories are left untouch.
- *
- * @param int[]|int $categories Category ID or array of Categories IDs
- * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
- * @return int <0 if KO, >0 if OK
- */
- public function setCategoriesCommon($categories, $type_categ)
- {
- require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
-
- // Handle single category
- if (!is_array($categories)) {
- $categories = array($categories);
- }
-
- // Get current categories
- $c = new Categorie($this->db);
- $existing = $c->containing($this->id, $type_categ, 'id');
-
- // Diff
- if (is_array($existing)) {
- $to_del = array_diff($existing, $categories);
- $to_add = array_diff($categories, $existing);
- } else {
- $to_del = array(); // Nothing to delete
- $to_add = $categories;
- }
-
- $error = 0;
-
- // Process
- foreach ($to_del as $del) {
- if ($c->fetch($del) > 0) {
- $c->del_type($this, $type_categ);
- }
- }
- foreach ($to_add as $add) {
- if ($c->fetch($add) > 0)
- {
- $result = $c->add_type($this, $type_categ);
- if ($result < 0)
- {
- $error++;
- $this->error = $c->error;
- $this->errors = $c->errors;
- break;
- }
- }
- }
-
- return $error ? -1 : 1;
- }
-
- /**
- * Copy related categories to another object
+ * copy related categories to another object
*
* @param int $fromId Id object source
* @param int $toId Id object cible
From 39104009ef2c2ac0748fa64ab77da9bd87b0bd55 Mon Sep 17 00:00:00 2001
From: Matt Sidnell <54064522+pstructures@users.noreply.github.com>
Date: Wed, 8 Jul 2020 14:25:37 +0100
Subject: [PATCH 2/2] Updated to match inline with code received from fork
---
htdocs/core/class/commonobject.class.php | 1402 +++++++++-------------
1 file changed, 560 insertions(+), 842 deletions(-)
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index d6e8314155f..6045e4232c2 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -717,8 +717,7 @@ abstract class CommonObject
{
if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
$out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state;
- }
- else {
+ } else {
$out .= ($outdone ? ' - ' : '').$this->state;
}
$outdone++;
@@ -845,10 +844,8 @@ abstract class CommonObject
$this->errors = $ecmfile->errors;
}
*/
- }
- else return '';
- }
- elseif (empty($ecmfile->share))
+ } else return '';
+ } elseif (empty($ecmfile->share))
{
// Add entry into index
if ($initsharekey)
@@ -856,8 +853,7 @@ abstract class CommonObject
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
$ecmfile->share = getRandomPassword(true);
$ecmfile->update($user);
- }
- else return '';
+ } else return '';
}
// Define $urlwithroot
$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
@@ -879,9 +875,7 @@ abstract class CommonObject
if ($relativelink)
{
$linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : '');
- }
- else
- {
+ } else {
$linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : '');
}
@@ -928,9 +922,7 @@ abstract class CommonObject
if (is_numeric($type_contact))
{
$id_type_contact = $type_contact;
- }
- else
- {
+ } else {
// We look for id type_contact
$sql = "SELECT tc.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc";
@@ -993,18 +985,14 @@ abstract class CommonObject
$this->db->commit();
return 1;
- }
- else
- {
+ } else {
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error = $this->db->errno();
$this->db->rollback();
echo 'err rollback';
return -2;
- }
- else
- {
+ } else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
@@ -1059,9 +1047,7 @@ abstract class CommonObject
if ($resql)
{
return 0;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
return -1;
}
@@ -1097,9 +1083,7 @@ abstract class CommonObject
$this->db->commit();
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -1135,9 +1119,7 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
return -1;
}
@@ -1197,9 +1179,7 @@ abstract class CommonObject
'nom'=>$obj->lastname, // For backward compatibility
'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact,
'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact);
- }
- else
- {
+ } else {
$tab[$i] = $obj->id;
}
@@ -1207,9 +1187,7 @@ abstract class CommonObject
}
return $tab;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
dol_print_error($this->db);
return -1;
@@ -1243,9 +1221,7 @@ abstract class CommonObject
$result = $this->update_contact($rowid, $newstatut);
$this->db->free($resql);
return $result;
- }
- else
- {
+ } else {
$this->error = $this->db->error();
dol_print_error($this->db);
return -1;
@@ -1297,9 +1273,7 @@ abstract class CommonObject
$i++;
}
return $tab;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
//dol_print_error($this->db);
return null;
@@ -1380,9 +1354,7 @@ abstract class CommonObject
}
}
return $tab;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
return null;
}
@@ -1442,9 +1414,7 @@ abstract class CommonObject
$result[$i] = $obj->fk_socpeople;
$i++;
}
- }
- else
- {
+ } else {
$this->error = $this->db->error();
return null;
}
@@ -1454,15 +1424,15 @@ abstract class CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
- * Load object contact with id=$this->contactid into $this->contact
+ * Load object contact with id=$this->contact_id into $this->contact
*
- * @param int $contactid Id du contact. Use this->contactid if empty.
+ * @param int $contactid Id du contact. Use this->contact_id if empty.
* @return int <0 if KO, >0 if OK
*/
public function fetch_contact($contactid = null)
{
// phpcs:enable
- if (empty($contactid)) $contactid = $this->contactid;
+ if (empty($contactid)) $contactid = $this->contact_id;
if (empty($contactid)) return 0;
@@ -1505,8 +1475,7 @@ abstract class CommonObject
}
return $result;
- } else
- return -1;
+ } else return -1;
}
@@ -1576,9 +1545,7 @@ abstract class CommonObject
$this->barcode_type_label = $obj->label;
$this->barcode_type_coder = $obj->coder;
return 1;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -1785,9 +1752,7 @@ abstract class CommonObject
if (empty($this->fields) && method_exists($this, 'fetch'))
{
$result = $this->fetch($id);
- }
- else
- {
+ } else {
$result = $this->fetchCommon($id);
}
if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors
@@ -1799,15 +1764,11 @@ abstract class CommonObject
if (property_exists($this, $field)) $this->$field = $value;
$this->db->commit();
return 1;
- }
- else
- {
+ } else {
$this->db->rollback();
return -2;
}
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -1852,11 +1813,10 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
- }
- elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
+ } elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
- $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
+ $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
if (!empty($filter))
@@ -1867,8 +1827,7 @@ abstract class CommonObject
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
$tmparray = explode('@', $this->ismultientitymanaged);
$sql .= ' AND te.'.$tmparray[0].' = '.($tmparray[1] == 'societe' ? 's' : 'parenttable').'.rowid'; // If we need to link to this table to limit select to entity
- }
- elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
+ } elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
@@ -1909,7 +1868,7 @@ abstract class CommonObject
elseif ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid
elseif ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid
if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc";
- $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
+ $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid=='rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists)
if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)';
if (!empty($filter))
@@ -1966,7 +1925,7 @@ abstract class CommonObject
while ($i < $num)
{
if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid'];
- else $contactAlreadySelected[$i] = $tab[$i]['id'];
+ else $contactAlreadySelected[$i] = $tab[$i]['id'];
$i++;
}
return $contactAlreadySelected;
@@ -1993,14 +1952,12 @@ abstract class CommonObject
if ($projectid) $sql .= ' SET fk_project = '.$projectid;
else $sql .= ' SET fk_project = NULL';
$sql .= ' WHERE rowid = '.$this->id;
- }
- elseif ($this->table_element == 'actioncomm') // Special case for actioncomm
+ } elseif ($this->table_element == 'actioncomm') // Special case for actioncomm
{
if ($projectid) $sql .= ' SET fk_project = '.$projectid;
else $sql .= ' SET fk_project = NULL';
$sql .= ' WHERE id = '.$this->id;
- }
- else // Special case for old architecture objects
+ } else // Special case for old architecture objects
{
if ($projectid) $sql .= ' SET fk_projet = '.$projectid;
else $sql .= ' SET fk_projet = NULL';
@@ -2012,9 +1969,7 @@ abstract class CommonObject
{
$this->fk_project = $projectid;
return 1;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -2046,16 +2001,12 @@ abstract class CommonObject
// for supplier
if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id;
return 1;
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2087,16 +2038,12 @@ abstract class CommonObject
if ($rate) $this->setMulticurrencyRate($rate, 2);
return 1;
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2195,16 +2142,12 @@ abstract class CommonObject
}
return 1;
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2238,16 +2181,12 @@ abstract class CommonObject
if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id;
$this->cond_reglement = $id; // for compatibility
return 1;
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2276,16 +2215,12 @@ abstract class CommonObject
{
$this->retained_warranty_fk_cond_reglement = $id;
return 1;
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms Erreur '.$sql.' - '.$this->db->error());
$this->error = $this->db->error();
return -1;
}
- }
- else
- {
+ } else {
dol_syslog(get_class($this).'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
$this->error = 'Status of the object is incompatible '.$this->statut;
return -2;
@@ -2311,9 +2246,7 @@ abstract class CommonObject
{
$this->fk_delivery_address = $id;
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->error();
dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error);
return -1;
@@ -2437,9 +2370,7 @@ abstract class CommonObject
{
$this->modelpdf = $modelpdf;
return 1;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return 0;
}
@@ -2481,9 +2412,7 @@ abstract class CommonObject
dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error());
$this->error = $this->db->lasterror();
$error++;
- }
- else
- {
+ } else {
if (!$notrigger)
{
// Call trigger
@@ -2497,9 +2426,7 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->fk_account = ($fk_account == 'NULL') ?null:$fk_account;
$this->db->commit();
return 1;
@@ -2546,8 +2473,7 @@ abstract class CommonObject
{
$row = $this->db->fetch_row($resql);
$nl = $row[0];
- }
- else dol_print_error($this->db);
+ } else dol_print_error($this->db);
if ($nl > 0)
{
// The goal of this part is to reorder all lines, with all children lines sharing the same
@@ -2589,9 +2515,7 @@ abstract class CommonObject
$this->updateRangOfLine($row, ($key + 1));
}
}
- }
- else
- {
+ } else {
dol_print_error($this->db);
}
}
@@ -2601,10 +2525,11 @@ abstract class CommonObject
/**
* Get children of line
*
- * @param int $id Id of parent line
- * @return array Array with list of children lines id
+ * @param int $id Id of parent line
+ * @param int $includealltree 0 = 1st level child, 1 = All level child
+ * @return array Array with list of children lines id
*/
- public function getChildrenOfLine($id)
+ public function getChildrenOfLine($id, $includealltree = 0)
{
$rows = array();
@@ -2617,16 +2542,13 @@ abstract class CommonObject
$resql = $this->db->query($sql);
if ($resql)
{
- $i = 0;
- $num = $this->db->num_rows($resql);
- while ($i < $num)
- {
- $row = $this->db->fetch_row($resql);
- $rows[$i] = $row[0];
- $i++;
+ if ($this->db->num_rows($resql) > 0) {
+ while ($row = $this->db->fetch_row($resql)) {
+ $rows[] = $row[0];
+ if (!empty($includealltree)) $rows = array_merge($rows, $this->getChildrenOfLine($row[0]), $includealltree);
+ }
}
}
-
return $rows;
}
@@ -2737,9 +2659,7 @@ abstract class CommonObject
{
dol_print_error($this->db);
}
- }
- else
- {
+ } else {
dol_print_error($this->db);
}
}
@@ -2771,9 +2691,7 @@ abstract class CommonObject
{
dol_print_error($this->db);
}
- }
- else
- {
+ } else {
dol_print_error($this->db);
}
}
@@ -2846,16 +2764,13 @@ abstract class CommonObject
if (!empty($row[0]))
{
return $row[0];
- }
- else
- {
+ } else {
return $this->getRangOfLine($fk_parent_line);
}
}
}
// If not, search the last rang of element
- else
- {
+ else {
$sql = 'SELECT max('.$positionfield.') FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql .= ' WHERE '.$this->fk_element.' = '.$this->id;
@@ -2894,9 +2809,7 @@ abstract class CommonObject
{
$this->ref_ext = $ref_ext;
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->error();
return -1;
}
@@ -2941,15 +2854,12 @@ abstract class CommonObject
{
if ($suffix == '_public') $this->note_public = $note;
elseif ($suffix == '_private') $this->note_private = $note;
- else
- {
+ else {
$this->note = $note; // deprecated
$this->note_private = $note;
}
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
return -1;
}
@@ -3214,14 +3124,10 @@ abstract class CommonObject
if (!$error)
{
return 1;
- }
- else
- {
+ } else {
return -1;
}
- }
- else
- {
+ } else {
dol_print_error($this->db, 'Bad request in update_price');
return -1;
}
@@ -3266,9 +3172,7 @@ abstract class CommonObject
{
$this->db->commit();
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return 0;
@@ -3341,15 +3245,12 @@ abstract class CommonObject
{
$sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'";
if ($withtargettype) $sql .= " AND targettype = '".$targettype."'";
- }
- elseif ($justtarget)
+ } elseif ($justtarget)
{
$sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'";
if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'";
}
- }
- else
- {
+ } else {
$sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')";
$sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')";
}
@@ -3369,14 +3270,11 @@ abstract class CommonObject
if ($justsource)
{
$this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
- }
- elseif ($justtarget)
+ } elseif ($justtarget)
{
$this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
}
- }
- else
- {
+ } else {
if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype)
{
$this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
@@ -3407,32 +3305,23 @@ abstract class CommonObject
// To work with non standard classpath or module name
if ($objecttype == 'facture') {
$classpath = 'compta/facture/class';
- }
- elseif ($objecttype == 'facturerec') {
+ } elseif ($objecttype == 'facturerec') {
$classpath = 'compta/facture/class'; $module = 'facture';
- }
- elseif ($objecttype == 'propal') {
+ } elseif ($objecttype == 'propal') {
$classpath = 'comm/propal/class';
- }
- elseif ($objecttype == 'supplier_proposal') {
+ } elseif ($objecttype == 'supplier_proposal') {
$classpath = 'supplier_proposal/class';
- }
- elseif ($objecttype == 'shipping') {
+ } elseif ($objecttype == 'shipping') {
$classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon';
- }
- elseif ($objecttype == 'delivery') {
+ } elseif ($objecttype == 'delivery') {
$classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon';
- }
- elseif ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
+ } elseif ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
$classpath = 'fourn/class'; $module = 'fournisseur';
- }
- elseif ($objecttype == 'fichinter') {
+ } elseif ($objecttype == 'fichinter') {
$classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter';
- }
- elseif ($objecttype == 'subscription') {
+ } elseif ($objecttype == 'subscription') {
$classpath = 'adherents/class'; $module = 'adherent';
- }
- elseif ($objecttype == 'contact') {
+ } elseif ($objecttype == 'contact') {
$module = 'societe';
}
@@ -3441,23 +3330,17 @@ abstract class CommonObject
if ($objecttype == 'order') {
$classfile = 'commande'; $classname = 'Commande';
- }
- elseif ($objecttype == 'invoice_supplier') {
+ } elseif ($objecttype == 'invoice_supplier') {
$classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur';
- }
- elseif ($objecttype == 'order_supplier') {
+ } elseif ($objecttype == 'order_supplier') {
$classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur';
- }
- elseif ($objecttype == 'supplier_proposal') {
+ } elseif ($objecttype == 'supplier_proposal') {
$classfile = 'supplier_proposal'; $classname = 'SupplierProposal';
- }
- elseif ($objecttype == 'facturerec') {
+ } elseif ($objecttype == 'facturerec') {
$classfile = 'facture-rec'; $classname = 'FactureRec';
- }
- elseif ($objecttype == 'subscription') {
+ } elseif ($objecttype == 'subscription') {
$classfile = 'subscription'; $classname = 'Subscription';
- }
- elseif ($objecttype == 'project' || $objecttype == 'projet') {
+ } elseif ($objecttype == 'project' || $objecttype == 'projet') {
$classpath = 'projet/class'; $classfile = 'project'; $classname = 'Project';
}
@@ -3481,17 +3364,13 @@ abstract class CommonObject
}
}
}
- }
- else
- {
+ } else {
unset($this->linkedObjectsIds[$objecttype]);
}
}
}
return 1;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -3522,8 +3401,7 @@ abstract class CommonObject
$sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'";
$sql .= " WHERE fk_target = ".$this->id;
$sql .= " AND targettype = '".$this->db->escape($this->element)."'";
- }
- elseif ($updatetarget)
+ } elseif ($updatetarget)
{
$sql .= "fk_target = ".$targetid;
$sql .= ", targettype = '".$this->db->escape($targettype)."'";
@@ -3535,9 +3413,7 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
return -1;
}
@@ -3572,21 +3448,16 @@ abstract class CommonObject
if ($rowid > 0)
{
$sql .= " rowid = ".$rowid;
- }
- else
- {
+ } else {
if ($deletesource)
{
$sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'";
$sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'";
- }
- elseif ($deletetarget)
+ } elseif ($deletetarget)
{
$sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'";
$sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'";
- }
- else
- {
+ } else {
$sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')";
$sql .= " OR";
$sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')";
@@ -3597,9 +3468,7 @@ abstract class CommonObject
if ($this->db->query($sql))
{
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -3676,16 +3545,12 @@ abstract class CommonObject
}
return 1;
- }
- else
- {
+ } else {
$this->db->rollback();
dol_syslog(get_class($this)."::setStatut ".$this->error, LOG_ERR);
return -1;
}
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
@@ -3724,11 +3589,8 @@ abstract class CommonObject
{
$this->canvas = $obj->canvas;
return 1;
- }
- else return 0;
- }
- else
- {
+ } else return 0;
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -3801,16 +3663,13 @@ abstract class CommonObject
if (is_numeric($elementname)) // old usage
{
$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
- }
- else // new usage: $elementname=Translation key
+ } else // new usage: $elementname=Translation key
{
$this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
}
break; // We found at least one, we stop here
}
- }
- else
- {
+ } else {
$this->errors[] = $this->db->lasterror();
return -1;
}
@@ -3819,8 +3678,7 @@ abstract class CommonObject
{
$this->errors[] = "ErrorRecordHasChildren";
return $haschild;
- }
- else return 0;
+ } else return 0;
}
/**
@@ -3912,8 +3770,7 @@ abstract class CommonObject
{
if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is ''
$totalToShip += $line->qty_shipped; // defined for shipment only
- }
- elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
+ } elseif ($line->element == 'commandefournisseurdispatch' && isset($line->qty))
{
if (empty($totalToShip)) $totalToShip = 0;
$totalToShip += $line->qty; // defined for reception only
@@ -3923,8 +3780,7 @@ abstract class CommonObject
if ($this->element == 'shipping') {
// for shipments
$qty = $line->qty_shipped ? $line->qty_shipped : 0;
- }
- else {
+ } else {
$qty = $line->qty ? $line->qty : 0;
}
@@ -3951,8 +3807,7 @@ abstract class CommonObject
{
$trueWeightUnit = pow(10, $weightUnit);
$totalWeight += $weight * $qty * $trueWeightUnit;
- }
- else {
+ } else {
if ($weight_units == 99) {
// conversion 1 Pound = 0.45359237 KG
$trueWeightUnit = 0.45359237;
@@ -3961,8 +3816,7 @@ abstract class CommonObject
// conversion 1 Ounce = 0.0283495 KG
$trueWeightUnit = 0.0283495;
$totalWeight += $weight * $qty * $trueWeightUnit;
- }
- else {
+ } else {
$totalWeight += $weight * $qty; // This may be wrong if we mix different units
}
}
@@ -3972,9 +3826,7 @@ abstract class CommonObject
$trueVolumeUnit = pow(10, $volumeUnit);
//print $line->volume;
$totalVolume += $volume * $qty * $trueVolumeUnit;
- }
- else
- {
+ } else {
$totalVolume += $volume * $qty; // This may be wrong if we mix different units
}
}
@@ -4005,9 +3857,7 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->db->commit();
return 1;
}
@@ -4058,14 +3908,10 @@ abstract class CommonObject
{
$res = $this->db->fetch_object($resql);
return 'Incoterm : '.$res->code.' - '.$this->location_incoterms;
- }
- else
- {
+ } else {
return '';
}
- }
- else
- {
+ } else {
$this->errors[] = $this->db->lasterror();
return false;
}
@@ -4101,14 +3947,11 @@ abstract class CommonObject
$this->label_incoterms = $obj->libelle;
}
return 1;
- }
- else
- {
+ } else {
$this->errors[] = $this->db->lasterror();
return -1;
}
- }
- else return -1;
+ } else return -1;
}
@@ -4149,9 +3992,7 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_create.tpl.php');
- }
- else
- {
+ } else {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_create.tpl.php';
}
@@ -4216,9 +4057,7 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_title.tpl.php');
- }
- else
- {
+ } else {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_title.tpl.php';
}
if (empty($conf->file->strict_mode)) {
@@ -4245,9 +4084,7 @@ abstract class CommonObject
{
$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element);
$reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
- }
- else
- {
+ } else {
$parameters = array('line'=>$line, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'table_element_line'=>$line->table_element, 'fk_parent_line'=>$line->fk_parent_line);
$reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
@@ -4328,9 +4165,7 @@ abstract class CommonObject
}
$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label;
- }
- else
- {
+ } else {
$label = $line->product_label;
}
@@ -4349,9 +4184,7 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_view.tpl.php');
- }
- else
- {
+ } else {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_view.tpl.php';
}
@@ -4380,9 +4213,7 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php');
- }
- else
- {
+ } else {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/objectline_edit.tpl.php';
}
@@ -4442,9 +4273,7 @@ abstract class CommonObject
$action = '';
$hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
}
- }
- else
- {
+ } else {
$this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines);
}
@@ -4474,18 +4303,14 @@ abstract class CommonObject
if (!empty($line->date_start))
{
$date_start = $line->date_start;
- }
- else
- {
+ } else {
$date_start = $line->date_debut_prevue;
if ($line->date_debut_reel) $date_start = $line->date_debut_reel;
}
if (!empty($line->date_end))
{
$date_end = $line->date_end;
- }
- else
- {
+ } else {
$date_end = $line->date_fin_prevue;
if ($line->date_fin_reel) $date_end = $line->date_fin_reel;
}
@@ -4500,8 +4325,7 @@ abstract class CommonObject
$discount = new DiscountAbsolute($this->db);
$discount->fk_soc = $this->socid;
$this->tpl['label'] .= $discount->getNomUrl(0, 'discount');
- }
- elseif (!empty($line->fk_product))
+ } elseif (!empty($line->fk_product))
{
$productstatic = new Product($this->db);
$productstatic->id = $line->fk_product;
@@ -4519,9 +4343,7 @@ abstract class CommonObject
{
$this->tpl['label'] .= get_date_range($date_start, $date_end);
}
- }
- else
- {
+ } else {
$this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product')));
if (!empty($line->desc)) {
$this->tpl['label'] .= $line->desc;
@@ -4543,32 +4365,25 @@ abstract class CommonObject
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
- }
- elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object
+ } elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
- }
- elseif ($line->desc == '(EXCESS RECEIVED)')
+ } elseif ($line->desc == '(EXCESS RECEIVED)')
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
- }
- elseif ($line->desc == '(EXCESS PAID)')
+ } elseif ($line->desc == '(EXCESS PAID)')
{
$discount = new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
$this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
- }
- else
- {
+ } else {
$this->tpl['description'] = dol_trunc($line->desc, 60);
}
- }
- else
- {
+ } else {
$this->tpl['description'] = ' ';
}
@@ -4595,9 +4410,7 @@ abstract class CommonObject
if (!empty($module))
{
$tpl = dol_buildpath($reldir.'/originproductline.tpl.php');
- }
- else
- {
+ } else {
$tpl = DOL_DOCUMENT_ROOT.$reldir.'/originproductline.tpl.php';
}
@@ -4648,9 +4461,7 @@ abstract class CommonObject
{
$this->db->commit();
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->db->rollback();
return 0;
@@ -4684,9 +4495,7 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
if (!$notrigger)
{
$result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user);
@@ -4849,9 +4658,7 @@ abstract class CommonObject
{
$arrayofrecords = array(); // The write_file of templates of adherent class need this var
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams);
- }
- else
- {
+ } else {
$resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
}
// After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index.
@@ -4919,9 +4726,7 @@ abstract class CommonObject
if ($result < 0) {
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
}
- }
- else
- {
+ } else {
$ecmfile->entity = $conf->entity;
$ecmfile->filepath = $rel_dir;
$ecmfile->filename = $filename;
@@ -4960,9 +4765,7 @@ abstract class CommonObject
}
}
}
- }
- else
- {
+ } else {
dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
}
@@ -4970,9 +4773,7 @@ abstract class CommonObject
dol_meta_create($this);
return 1;
- }
- else
- {
+ } else {
$outputlangs->charset_output = $sav_charset_output;
dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors);
return -1;
@@ -4987,8 +4788,7 @@ abstract class CommonObject
}
return -1;
}
- }
- else return $reshook;
+ } else return $reshook;
}
/**
@@ -5093,9 +4893,7 @@ abstract class CommonObject
if (!empty($this->errors))
{
$this->errors = array_unique(array_merge($this->errors, $interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice.
- }
- else
- {
+ } else {
$this->errors = $interface->errors;
}
}
@@ -5156,9 +4954,7 @@ abstract class CommonObject
if (preg_match('/date/', $type))
{
$this->array_languages[$key][$codelang] = $this->db->jdate($value);
- }
- else
- {
+ } else {
$this->array_languages[$key][$codelang] = $value;
}
@@ -5170,9 +4966,7 @@ abstract class CommonObject
if ($numrows) return $numrows;
else return 0;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -5221,14 +5015,12 @@ abstract class CommonObject
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime(0, 0, 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
- }
- elseif (in_array($key_type, array('datetime')))
+ } elseif (in_array($key_type, array('datetime')))
{
// Clean parameters
// TODO GMT date in memory must be GMT so we should add gm=true in parameters
$value_key = dol_mktime($_POST[$postfieldkey."hour"], $_POST[$postfieldkey."min"], 0, $_POST[$postfieldkey."month"], $_POST[$postfieldkey."day"], $_POST[$postfieldkey."year"]);
- }
- elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
+ } elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
{
$value_arr = GETPOST($postfieldkey, 'array'); // check if an array
if (!empty($value_arr)) {
@@ -5236,14 +5028,11 @@ abstract class CommonObject
} else {
$value_key = '';
}
- }
- elseif (in_array($key_type, array('price', 'double')))
+ } elseif (in_array($key_type, array('price', 'double')))
{
$value_arr = GETPOST($postfieldkey, 'alpha');
$value_key = price2num($value_arr);
- }
- else
- {
+ } else {
$value_key = GETPOST($postfieldkey);
if (in_array($key_type, array('link')) && $value_key == '-1') $value_key = '';
}
@@ -5323,9 +5112,7 @@ abstract class CommonObject
$extrafields->fetch_name_optionals_label($this->table_element);
}
$optionsArray = (!empty($extrafields->attributes[$this->table_element]['label']) ? $extrafields->attributes[$this->table_element]['label'] : null);
- }
- else
- {
+ } else {
global $extrafields;
dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
}
@@ -5366,9 +5153,7 @@ abstract class CommonObject
{
//var_dump($extrafields->attributes[$this->table_element]['type'][$key]);
$this->array_options["options_".$key] = $this->db->jdate($value);
- }
- else
- {
+ } else {
$this->array_options["options_".$key] = $value;
}
@@ -5392,9 +5177,7 @@ abstract class CommonObject
if ($numrows) return $numrows;
else return 0;
- }
- else
- {
+ } else {
dol_print_error($this->db);
return -1;
}
@@ -5427,9 +5210,7 @@ abstract class CommonObject
$this->error = $this->db->lasterror();
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->db->commit();
return 1;
}
@@ -5504,9 +5285,7 @@ abstract class CommonObject
$value = dol_eval($attrfieldcomputed, 1, 0);
dol_syslog($langs->trans("Extrafieldcomputed")." sur ".$attributeLabel."(".$value.")", LOG_DEBUG);
$new_array_options[$key] = $value;
- }
- else
- {
+ } else {
$new_array_options[$key] = null;
}
}
@@ -5518,8 +5297,7 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value == '')
+ } elseif ($value == '')
{
$new_array_options[$key] = null;
}
@@ -5531,8 +5309,7 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value == '')
+ } elseif ($value == '')
{
$new_array_options[$key] = null;
}
@@ -5563,21 +5340,16 @@ abstract class CommonObject
if ($this->array_options[$key] == $this->oldcopy->array_options[$key]) // If old value crypted in database is same than submited new value, it means we don't change it, so we don't update.
{
$new_array_options[$key] = $this->array_options[$key]; // Value is kept
- }
- else
- {
+ } else {
// var_dump($algo);
$newvalue = dol_hash($this->array_options[$key], $algo);
$new_array_options[$key] = $newvalue;
}
- }
- else
- {
+ } else {
$new_array_options[$key] = $this->array_options[$key]; // Value is kept
}
}
- }
- else // Common usage
+ } else // Common usage
{
$new_array_options[$key] = $this->array_options[$key];
}
@@ -5604,24 +5376,20 @@ abstract class CommonObject
if ($value == '-1') // -1 is key for no defined in combo list of objects
{
$new_array_options[$key] = '';
- }
- elseif ($value)
+ } elseif ($value)
{
$object = new $InfoFieldList[0]($this->db);
if (is_numeric($value)) $res = $object->fetch($value);
else $res = $object->fetch('', $value);
if ($res > 0) $new_array_options[$key] = $object->id;
- else
- {
+ else {
$this->error = "Id/Ref '".$value."' for object '".$object->element."' not found";
$this->db->rollback();
return -1;
}
}
- }
- else
- {
+ } else {
dol_syslog('Error bad setup of extrafield', LOG_WARNING);
}
break;
@@ -5668,9 +5436,7 @@ abstract class CommonObject
if ($new_array_options[$key] != '' || $new_array_options[$key] == '0')
{
$sql .= ",'".$this->db->escape($new_array_options[$key])."'";
- }
- else
- {
+ } else {
$sql .= ",null";
}
}
@@ -5711,14 +5477,11 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->db->commit();
return 1;
}
- }
- else return 0;
+ } else return 0;
}
/**
@@ -5761,8 +5524,7 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraLanguageHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value == '')
+ } elseif ($value == '')
{
$new_array_languages[$key] = null;
}
@@ -5774,8 +5536,7 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraLanguageHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraLanguageHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value == '')
+ } elseif ($value == '')
{
$new_array_languages[$key] = null;
}
@@ -5834,21 +5595,18 @@ abstract class CommonObject
{
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->db->commit();
return 1;
}
- }
- else return 0;
+ } else return 0;
}
/**
* Update an extra field value for the current object.
* Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
*
- * @param string $key Key of the extrafield (without starting 'options_')
+ * @param string $key Key of the extrafield to update (without starting 'options_')
* @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY)
* @param User $userused Object user
* @return int -1=error, O=did nothing, 1=OK
@@ -5889,8 +5647,7 @@ abstract class CommonObject
{
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value === '')
+ } elseif ($value === '')
{
$this->array_options["options_".$key] = null;
}
@@ -5902,8 +5659,7 @@ abstract class CommonObject
dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
$this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
return -1;
- }
- elseif ($value === '')
+ } elseif ($value === '')
{
$this->array_options["options_".$key] = null;
}
@@ -5964,14 +5720,11 @@ abstract class CommonObject
dol_syslog(__METHOD__.$this->error, LOG_ERR);
$this->db->rollback();
return -1;
- }
- else
- {
+ } else {
$this->db->commit();
return 1;
}
- }
- else return 0;
+ } else return 0;
}
/**
@@ -6084,39 +5837,30 @@ abstract class CommonObject
if (empty($morecss) && !empty($val['css']))
{
$morecss = $val['css'];
- }
- elseif (empty($morecss))
+ } elseif (empty($morecss))
{
if ($type == 'date')
{
$morecss = 'minwidth100imp';
- }
- elseif ($type == 'datetime' || $type == 'link') // link means an foreign key to another primary id
+ } elseif ($type == 'datetime' || $type == 'link') // link means an foreign key to another primary id
{
$morecss = 'minwidth200imp';
- }
- elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
+ } elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
{
$morecss = 'maxwidth75';
} elseif ($type == 'url') {
$morecss = 'minwidth400';
- }
- elseif ($type == 'boolean')
+ } elseif ($type == 'boolean')
{
$morecss = '';
- }
- else
- {
+ } else {
if (round($size) < 12)
{
$morecss = 'minwidth100';
- }
- elseif (round($size) <= 48)
+ } elseif (round($size) <= 48)
{
$morecss = 'minwidth200';
- }
- else
- {
+ } else {
$morecss = 'minwidth400';
}
}
@@ -6134,56 +5878,44 @@ abstract class CommonObject
// TODO Must also support $moreparam
$out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
- }
- elseif (in_array($type, array('duration')))
+ } elseif (in_array($type, array('duration')))
{
$out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1);
- }
- elseif (in_array($type, array('int', 'integer')))
+ } elseif (in_array($type, array('int', 'integer')))
{
$tmp = explode(',', $size);
$newsize = $tmp[0];
$out = '';
- }
- elseif (in_array($type, array('real')))
+ } elseif (in_array($type, array('real')))
{
$out = '';
- }
- elseif (preg_match('/varchar/', $type))
+ } elseif (preg_match('/varchar/', $type))
{
$out = '';
- }
- elseif (in_array($type, array('mail', 'phone', 'url')))
+ } elseif (in_array($type, array('mail', 'phone', 'url')))
{
$out = '';
- }
- elseif ($type == 'text')
+ } elseif ($type == 'text')
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%');
$out = $doleditor->Create(1);
- }
- else
- {
+ } else {
$out = '';
}
- }
- elseif ($type == 'html')
+ } elseif ($type == 'html')
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%');
$out = $doleditor->Create(1);
- }
- else
- {
+ } else {
$out = '';
}
- }
- elseif ($type == 'boolean')
+ } elseif ($type == 'boolean')
{
$checked = '';
if (!empty($value)) {
@@ -6192,22 +5924,19 @@ abstract class CommonObject
$checked = ' value="1" ';
}
$out = '';
- }
- elseif ($type == 'price')
+ } elseif ($type == 'price')
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value);
}
$out = ' '.$langs->getCurrencySymbol($conf->currency);
- }
- elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
+ } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
{
if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
$value = price($value);
}
$out = ' ';
- }
- elseif ($type == 'select')
+ } elseif ($type == 'select')
{
$out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -6228,8 +5957,7 @@ abstract class CommonObject
$out .= '>'.$val.'';
}
$out .= '';
- }
- elseif ($type == 'sellist')
+ } elseif ($type == 'sellist')
{
$out = '';
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
@@ -6296,14 +6024,10 @@ abstract class CommonObject
{
$sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra';
$sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4];
- }
- else
- {
+ } else {
$sqlwhere .= ' WHERE '.$InfoFieldList[4];
}
- }
- else
- {
+ } else {
$sqlwhere .= ' WHERE 1=1';
}
// Some tables may have field, some other not. For the moment we disable it.
@@ -6338,9 +6062,7 @@ abstract class CommonObject
{
$labeltoshow .= $obj->$field_toshow.' ';
}
- }
- else
- {
+ } else {
$labeltoshow = $obj->{$InfoFieldList[1]};
}
$labeltoshow = dol_trunc($labeltoshow, 45);
@@ -6357,16 +6079,13 @@ abstract class CommonObject
}
}
$out .= '';
- }
- else
- {
+ } else {
if (!$notrans)
{
$translabel = $langs->trans($obj->{$InfoFieldList[1]});
if ($translabel != $obj->{$InfoFieldList[1]}) {
$labeltoshow = dol_trunc($translabel, 18);
- }
- else {
+ } else {
$labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
}
}
@@ -6390,19 +6109,16 @@ abstract class CommonObject
$i++;
}
$this->db->free($resql);
- }
- else {
+ } else {
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
';
}
}
$out .= '';
- }
- elseif ($type == 'checkbox')
+ } elseif ($type == 'checkbox')
{
$value_arr = explode(',', $value);
$out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
- }
- elseif ($type == 'radio')
+ } elseif ($type == 'radio')
{
$out = '';
foreach ($param['options'] as $keyopt => $val)
@@ -6413,13 +6129,11 @@ abstract class CommonObject
$out .= ($value == $keyopt ? 'checked' : '');
$out .= '/>
';
}
- }
- elseif ($type == 'chkbxlst')
+ } elseif ($type == 'chkbxlst')
{
if (is_array($value)) {
$value_arr = $value;
- }
- else {
+ } else {
$value_arr = explode(',', $value);
}
@@ -6557,8 +6271,7 @@ abstract class CommonObject
print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
';
}
}
- }
- elseif ($type == 'link')
+ } elseif ($type == 'link')
{
$param_list = array_keys($param['options']); // $param_list='ObjectName:classPath[:AddCreateButtonOrNot[:Filter]]'
$param_list_array = explode(':', $param_list[0]);
@@ -6583,13 +6296,11 @@ abstract class CommonObject
$out .= '';
}
}
- }
- elseif ($type == 'password')
+ } elseif ($type == 'password')
{
// If prefix is 'search_', field is used as a filter, we use a common text field.
$out = '';
- }
- elseif ($type == 'array')
+ } elseif ($type == 'array')
{
$newval = $val;
$newval['type'] = 'varchar(256)';
@@ -6668,8 +6379,7 @@ abstract class CommonObject
{
$type = 'varchar'; // convert varchar(xx) int varchar
$size = $reg[1];
- }
- elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
+ } elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
if (is_array($val['arrayofkeyval'])) $type = 'select';
if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link';
@@ -6685,8 +6395,7 @@ abstract class CommonObject
{
$type = 'link';
$param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]);
- }
- elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
+ } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
$param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4] => 'N');
$type = 'sellist';
}
@@ -6711,35 +6420,26 @@ abstract class CommonObject
if ($type == 'date')
{
$morecss = 'minwidth100imp';
- }
- elseif ($type == 'datetime' || $type == 'timestamp')
+ } elseif ($type == 'datetime' || $type == 'timestamp')
{
$morecss = 'minwidth200imp';
- }
- elseif (in_array($type, array('int', 'double', 'price')))
+ } elseif (in_array($type, array('int', 'double', 'price')))
{
$morecss = 'maxwidth75';
- }
- elseif ($type == 'url')
+ } elseif ($type == 'url')
{
$morecss = 'minwidth400';
- }
- elseif ($type == 'boolean')
+ } elseif ($type == 'boolean')
{
$morecss = '';
- }
- else
- {
+ } else {
if (round($size) < 12)
{
$morecss = 'minwidth100';
- }
- elseif (round($size) <= 48)
+ } elseif (round($size) <= 48)
{
$morecss = 'minwidth200';
- }
- else
- {
+ } else {
$morecss = 'minwidth400';
}
}
@@ -6755,59 +6455,49 @@ abstract class CommonObject
} else {
$value = '';
}
- }
- elseif ($type == 'datetime' || $type == 'timestamp')
+ } elseif ($type == 'datetime' || $type == 'timestamp')
{
if (!empty($value)) {
$value = dol_print_date($value, 'dayhour');
} else {
$value = '';
}
- }
- elseif ($type == 'duration')
+ } elseif ($type == 'duration')
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if (!is_null($value) && $value !== '') {
$value = convertSecondToTime($value, 'allhourmin');
}
- }
- elseif ($type == 'double' || $type == 'real')
+ } elseif ($type == 'double' || $type == 'real')
{
if (!is_null($value) && $value !== '') {
$value = price($value);
}
- }
- elseif ($type == 'boolean')
+ } elseif ($type == 'boolean')
{
$checked = '';
if (!empty($value)) {
$checked = ' checked ';
}
$value = '';
- }
- elseif ($type == 'mail')
+ } elseif ($type == 'mail')
{
$value = dol_print_email($value, 0, 0, 0, 64, 1, 1);
- }
- elseif ($type == 'url')
+ } elseif ($type == 'url')
{
$value = dol_print_url($value, '_blank', 32, 1);
- }
- elseif ($type == 'phone')
+ } elseif ($type == 'phone')
{
$value = dol_print_phone($value, '', 0, 0, '', ' ', 1);
- }
- elseif ($type == 'price')
+ } elseif ($type == 'price')
{
if (!is_null($value) && $value !== '') {
$value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
}
- }
- elseif ($type == 'select')
+ } elseif ($type == 'select')
{
$value = $param['options'][$value];
- }
- elseif ($type == 'sellist')
+ } elseif ($type == 'sellist')
{
$param_list = array_keys($param['options']);
$InfoFieldList = explode(":", $param_list[0]);
@@ -6868,9 +6558,7 @@ abstract class CommonObject
$value .= $obj->$field_toshow.' ';
}
}
- }
- else
- {
+ } else {
$translabel = '';
if (!empty($obj->{$InfoFieldList[1]})) {
$translabel = $langs->trans($obj->{$InfoFieldList[1]});
@@ -6881,14 +6569,11 @@ abstract class CommonObject
$value = $obj->{$InfoFieldList[1]};
}
}
- }
- else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
- }
- elseif ($type == 'radio')
+ } else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
+ } elseif ($type == 'radio')
{
$value = $param['options'][$value];
- }
- elseif ($type == 'checkbox')
+ } elseif ($type == 'checkbox')
{
$value_arr = explode(',', $value);
$value = '';
@@ -6900,8 +6585,7 @@ abstract class CommonObject
}
$value = ''.implode(' ', $toprint).'
';
}
- }
- elseif ($type == 'chkbxlst')
+ } elseif ($type == 'chkbxlst')
{
$value_arr = explode(',', $value);
@@ -6968,8 +6652,7 @@ abstract class CommonObject
} else {
dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
}
- }
- elseif ($type == 'link')
+ } elseif ($type == 'link')
{
$out = '';
@@ -6991,24 +6674,18 @@ abstract class CommonObject
$object->fetch($value);
$value = $object->getNomUrl($getnomurlparam);
}
- }
- else
- {
+ } else {
dol_syslog('Error bad setup of extrafield', LOG_WARNING);
return 'Error bad setup of extrafield';
}
- }
- else $value = '';
- }
- elseif ($type == 'text' || $type == 'html')
+ } else $value = '';
+ } elseif ($type == 'text' || $type == 'html')
{
$value = dol_htmlentitiesbr($value);
- }
- elseif ($type == 'password')
+ } elseif ($type == 'password')
{
$value = preg_replace('/./i', '*', $value);
- }
- elseif ($type == 'array')
+ } elseif ($type == 'array')
{
$value = implode('
', $value);
}
@@ -7035,246 +6712,241 @@ abstract class CommonObject
public function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0)
{
global $db, $conf, $langs, $action, $form, $hookmanager;
+
+ if (!is_object($form)) $form = new Form($db);
+
$parameters=array();
- $reshook=$hookmanager->executeHooks('ShowExtraFields',$parameters,$this,$action); // See description below
- // Note that $action and $object may have been modified by hook
+ $reshook=$hookmanager->executeHooks('showOptionals',$parameters,$this,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
- if (!is_object($form)) $form = new Form($db);
- $out = '';
+ $out = '';
- if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
- {
- $out .= "\n";
- $out .= ' ';
- $out .= "\n";
-
- $extrafields_collapse_num = '';
- $e = 0;
- foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
+ if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0)
{
- // Show only the key field in params
- if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
+ $out .= "\n";
+ $out .= ' ';
+ $out .= "\n";
- // @todo Add test also on 'enabled' (different than 'list' that is 'visibility')
- $enabled = 1;
- if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key]))
+ $extrafields_collapse_num = '';
+ $e = 0;
+ foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label)
{
- $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1);
- }
- if (empty($enabled)) continue;
+ // Show only the key field in params
+ if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
- $visibility = 1;
- if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key]))
- {
- $visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1);
- }
+ // @todo Add test also on 'enabled' (different than 'list' that is 'visibility')
+ $enabled = 1;
+ if ($enabled && isset($extrafields->attributes[$this->table_element]['enabled'][$key]))
+ {
+ $enabled = dol_eval($extrafields->attributes[$this->table_element]['enabled'][$key], 1);
+ }
+ if (empty($enabled)) continue;
- $perms = 1;
- if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key]))
- {
- $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
- }
-
- if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
- elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
- elseif ($mode == 'view' && empty($visibility)) continue;
- if (empty($perms)) continue;
- // Load language if required
- if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
- $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
- }
-
- $colspan = '';
- if (is_array($params) && count($params) > 0) {
- if (array_key_exists('cols', $params)) {
- $colspan = $params['cols'];
+ $visibility = 1;
+ if ($visibility && isset($extrafields->attributes[$this->table_element]['list'][$key]))
+ {
+ $visibility = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1);
}
- elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
- $reg = array();
- if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
- $colspan = $reg[1];
- }
- else {
- $colspan = $params['colspan'];
- }
+
+ $perms = 1;
+ if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key]))
+ {
+ $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1);
}
- }
- switch ($mode) {
- case "view":
- $value = $this->array_options["options_".$key.$keysuffix];
- break;
- case "create":
- case "edit":
- $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values.
- // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
- if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix))
- {
- if (is_array($getposttemp)) {
- // $getposttemp is an array but following code expects a comma separated string
- $value = implode(",", $getposttemp);
- } else {
- $value = $getposttemp;
- }
- } else {
- $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object.
- }
- //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value);
- break;
- }
+ if (($mode == 'create') && abs($visibility) != 1 && abs($visibility) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list
+ elseif (($mode == 'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list and <> 4 = not visible at the creation
+ elseif ($mode == 'view' && empty($visibility)) continue;
+ if (empty($perms)) continue;
+ // Load language if required
+ if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) {
+ $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]);
+ }
- if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate')
- {
- $extrafields_collapse_num = '';
- $extrafield_param = $extrafields->attributes[$this->table_element]['param'][$key];
- if (!empty($extrafield_param) && is_array($extrafield_param)) {
- $extrafield_param_list = array_keys($extrafield_param['options']);
-
- if (count($extrafield_param_list) > 0) {
- $extrafield_collapse_display_value = intval($extrafield_param_list[0]);
-
- if ($extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2) {
- $extrafields_collapse_num = $extrafields->attributes[$this->table_element]['pos'][$key];
- }
- }
- }
-
- $out .= $extrafields->showSeparator($key, $this, ($colspan + 1));
- }
- else
- {
- $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : '');
- $csstyle = '';
+ $colspan = '';
if (is_array($params) && count($params) > 0) {
- if (array_key_exists('class', $params)) {
- $class .= $params['class'].' ';
- }
- if (array_key_exists('style', $params)) {
- $csstyle = $params['style'];
+ if (array_key_exists('cols', $params)) {
+ $colspan = $params['cols'];
+ } elseif (array_key_exists('colspan', $params)) { // For backward compatibility. Use cols instead now.
+ $reg = array();
+ if (preg_match('/colspan="(\d+)"/', $params['colspan'], $reg)) {
+ $colspan = $reg[1];
+ } else {
+ $colspan = $params['colspan'];
+ }
}
}
- // add html5 elements
- $domData = ' data-element="extrafield"';
- $domData .= ' data-targetelement="'.$this->element.'"';
- $domData .= ' data-targetid="'.$this->id.'"';
-
- $html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
-
- $out .= '';
- else $out .= '';
- $e++;
- }
- }
- $out .= "\n";
- // Add code to manage list depending on others
- if (!empty($conf->use_javascript_ajax)) {
- $out .= '
- '."\n";
- $out .= ' '."\n";
- }
- }
- return $out;
+ // add html5 elements
+ $domData = ' data-element="extrafield"';
+ $domData .= ' data-targetelement="'.$this->element.'"';
+ $domData .= ' data-targetid="'.$this->id.'"';
- } //end Hook
+ $html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id);
+
+ if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; }
+
+ if ($action == 'selectlines') { $colspan++; }
+
+ // Convert date into timestamp format (value in memory must be a timestamp)
+ if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
+ {
+ $datenotinstring = $this->array_options['options_'.$key];
+ if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility
+ {
+ $datenotinstring = $this->db->jdate($datenotinstring);
+ }
+ $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring;
+ }
+ // Convert float submited string into real php numeric (value in memory must be a php numeric)
+ if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double')))
+ {
+ $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key];
+ }
+ // HTML, select, integer and text add default value
+ if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('html', 'text', 'select', 'int')))
+ {
+ if ($action == 'create') $value = $extrafields->attributes[$this->table_element]['default'][$key];
+ else $value = $this->array_options['options_'.$key];
+ }
+
+ $labeltoshow = $langs->trans($label);
+ $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]);
+
+ $out .= '';
+ else $out .= '';
+ $e++;
+ }
+ }
+ $out .= "\n";
+ // Add code to manage list depending on others
+ if (!empty($conf->use_javascript_ajax)) {
+ $out .= '
+ '."\n";
+ $out .= ' '."\n";
+ }
+ }
+ return $out;
+ } // end of hook manager
}
@@ -7342,9 +7014,7 @@ abstract class CommonObject
if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false
{
$buyPrice = $unitPrice * (1 - $discountPercent / 100);
- }
- else
- {
+ } else {
// Get cost price for margin calculation
if (!empty($fk_product))
{
@@ -7361,13 +7031,11 @@ abstract class CommonObject
if ($product->cost_price > 0)
{
$buyPrice = $product->cost_price;
- }
- elseif ($product->pmp > 0)
+ } elseif ($product->pmp > 0)
{
$buyPrice = $product->pmp;
}
- }
- elseif (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')
+ } elseif (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp')
{
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
$product = new Product($this->db);
@@ -7390,8 +7058,7 @@ abstract class CommonObject
if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0)
{
$buyPrice = $productFournisseur->fourn_unitprice;
- }
- elseif ($result < 0)
+ } elseif ($result < 0)
{
$this->errors[] = $productFournisseur->error;
return -2;
@@ -7504,8 +7171,7 @@ abstract class CommonObject
if ($nbphoto % $nbbyrow == 1) $return .= '';
$return .= '';
- }
- elseif ($nbbyrow < 0) $return .= '';
+ } elseif ($nbbyrow < 0) $return .= ' ';
$return .= "\n";
@@ -7531,26 +7197,20 @@ abstract class CommonObject
{
$return .= '';
$return .= ' .') ';
- }
- else {
+ } else {
$return .= '';
$return .= ' .') ';
}
- }
- else
- {
+ } else {
$return .= '';
$return .= '  ';
}
- }
- else
- {
+ } else {
if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight)
{
$return .= '';
$return .= ' .') ';
- }
- else {
+ } else {
$return .= '';
$return .= ' .') ';
}
@@ -7585,8 +7245,7 @@ abstract class CommonObject
{
$return .= ' | ';
if (($nbphoto % $nbbyrow) == 0) $return .= '
';
- }
- elseif ($nbbyrow < 0) $return .= '';
+ } elseif ($nbbyrow < 0) $return .= '';
}
if (empty($size)) { // Format origine
@@ -7675,8 +7334,7 @@ abstract class CommonObject
{
if (isset($info['type']) && ($info['type'] == 'duration')) return true;
else return false;
- }
- else return false;
+ } else return false;
}
/**
@@ -7691,8 +7349,7 @@ abstract class CommonObject
{
if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
else return false;
- }
- else return false;
+ } else return false;
}
/**
@@ -7796,13 +7453,10 @@ abstract class CommonObject
if (empty($this->{$field}))
{
$queryarray[$field] = null;
- }
- else
- {
+ } else {
$queryarray[$field] = $this->db->idate($this->{$field});
}
- }
- elseif ($this->isArray($info))
+ } elseif ($this->isArray($info))
{
if (!empty($this->{$field})) {
if (!is_array($this->{$field})) {
@@ -7812,28 +7466,22 @@ abstract class CommonObject
} else {
$queryarray[$field] = null;
}
- }
- elseif ($this->isDuration($info))
+ } elseif ($this->isDuration($info))
{
// $this->{$field} may be null, '', 0, '0', 123, '123'
if ($this->{$field} != '' || !empty($info['notnull'])) $queryarray[$field] = (int) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
else $queryarray[$field] = null;
- }
- elseif ($this->isInt($info) || $this->isFloat($info))
+ } elseif ($this->isInt($info) || $this->isFloat($info))
{
if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity;
- else
- {
+ else {
// $this->{$field} may be null, '', 0, '0', 123, '123'
if ($this->{$field} != '' || !empty($info['notnull'])) {
if ($this->isInt($info)) $queryarray[$field] = (int) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
if ($this->isFloat($info)) $queryarray[$field] = (double) $this->{$field}; // If '0', it may be set to null later if $info['notnull'] == -1
- }
- else $queryarray[$field] = null;
+ } else $queryarray[$field] = null;
}
- }
- else
- {
+ } else {
$queryarray[$field] = $this->{$field};
}
@@ -7858,8 +7506,7 @@ abstract class CommonObject
{
if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
else $this->{$field} = strtotime($obj->{$field});
- }
- elseif ($this->isArray($info))
+ } elseif ($this->isArray($info))
{
if (!empty($obj->{$field})) {
$this->{$field} = @unserialize($obj->{$field});
@@ -7868,19 +7515,15 @@ abstract class CommonObject
} else {
$this->{$field} = array();
}
- }
- elseif ($this->isInt($info))
+ } elseif ($this->isInt($info))
{
if ($field == 'rowid') $this->id = (int) $obj->{$field};
- else
- {
+ else {
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
- }
- else
- {
+ } else {
if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (int) $obj->{$field};
} else {
@@ -7888,25 +7531,20 @@ abstract class CommonObject
}
}
}
- }
- elseif ($this->isFloat($info))
+ } elseif ($this->isFloat($info))
{
if ($this->isForcedToNullIfZero($info))
{
if (empty($obj->{$field})) $this->{$field} = null;
else $this->{$field} = (double) $obj->{$field};
- }
- else
- {
+ } else {
if (!is_null($obj->{$field}) || (isset($info['notnull']) && $info['notnull'] == 1)) {
$this->{$field} = (double) $obj->{$field};
} else {
$this->{$field} = null;
}
}
- }
- else
- {
+ } else {
$this->{$field} = $obj->{$field};
}
}
@@ -8102,7 +7740,10 @@ abstract class CommonObject
{
if (empty($id) && empty($ref) && empty($morewhere)) return -1;
- $sql = 'SELECT '.$this->getFieldList();
+ $fieldlist = $this->getFieldList();
+ if (empty($fieldlist)) return 0;
+
+ $sql = 'SELECT '.$fieldlist;
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
if (!empty($id)) $sql .= ' WHERE rowid = '.$id;
@@ -8119,15 +7760,16 @@ abstract class CommonObject
if ($obj)
{
$this->setVarsFromFetchObj($obj);
+
+ // Retreive all extrafield
+ // fetch optionals attributes and labels
+ $this->fetch_optionals();
+
return $this->id;
- }
- else
- {
+ } else {
return 0;
}
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -8175,9 +7817,7 @@ abstract class CommonObject
}
return 1;
- }
- else
- {
+ } else {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
return -1;
@@ -8304,8 +7944,7 @@ abstract class CommonObject
return -1;
}
}
- }
- elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables.
+ } elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables.
{
$objectisused = $this->isObjectUsed($this->id);
if (!empty($objectisused))
@@ -8558,9 +8197,7 @@ abstract class CommonObject
$this->db->rollback();
return -1;
}
- }
- else
- {
+ } else {
$this->error = $this->db->error();
$this->db->rollback();
return -1;
@@ -8638,8 +8275,89 @@ abstract class CommonObject
}
}
+ /* Part for categories/tags */
+
/**
- * copy related categories to another object
+ * Sets object to given categories.
+ *
+ * Deletes object from existing categories not supplied.
+ * Adds it to non existing supplied categories.
+ * Existing categories are left untouch.
+ *
+ * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
+ * @return int Array of category objects or < 0 if KO
+ */
+ public function getCategoriesCommon($type_categ)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+
+ // Get current categories
+ $c = new Categorie($this->db);
+ $existing = $c->containing($this->id, $type_categ, 'id');
+
+ return $existing;
+ }
+
+ /**
+ * Sets object to given categories.
+ *
+ * Deletes object from existing categories not supplied.
+ * Adds it to non existing supplied categories.
+ * Existing categories are left untouch.
+ *
+ * @param int[]|int $categories Category ID or array of Categories IDs
+ * @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
+ * @return int <0 if KO, >0 if OK
+ */
+ public function setCategoriesCommon($categories, $type_categ)
+ {
+ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+
+ // Handle single category
+ if (!is_array($categories)) {
+ $categories = array($categories);
+ }
+
+ // Get current categories
+ $c = new Categorie($this->db);
+ $existing = $c->containing($this->id, $type_categ, 'id');
+
+ // Diff
+ if (is_array($existing)) {
+ $to_del = array_diff($existing, $categories);
+ $to_add = array_diff($categories, $existing);
+ } else {
+ $to_del = array(); // Nothing to delete
+ $to_add = $categories;
+ }
+
+ $error = 0;
+
+ // Process
+ foreach ($to_del as $del) {
+ if ($c->fetch($del) > 0) {
+ $c->del_type($this, $type_categ);
+ }
+ }
+ foreach ($to_add as $add) {
+ if ($c->fetch($add) > 0)
+ {
+ $result = $c->add_type($this, $type_categ);
+ if ($result < 0)
+ {
+ $error++;
+ $this->error = $c->error;
+ $this->errors = $c->errors;
+ break;
+ }
+ }
+ }
+
+ return $error ? -1 : 1;
+ }
+
+ /**
+ * Copy related categories to another object
*
* @param int $fromId Id object source
* @param int $toId Id object cible