44require_once DOL_DOCUMENT_ROOT.
'/core/class/doldeprecationhandler.class.php';
53 use DolDeprecationHandler;
55 const TRIGGER_PREFIX =
'';
91 public $errors = array();
96 private $validateFieldsErrors = array();
114 public $element_for_permission;
119 public $table_element;
124 public $table_element_line =
'';
130 public $ismultientitymanaged;
140 public $array_options = array();
146 public $fields = array();
153 public $array_languages =
null;
158 public $contacts_ids;
163 public $contacts_ids_internal;
168 public $linked_objects;
173 public $linkedObjectsIds;
178 public $linkedObjects;
183 private $linkedObjectsFullLoaded = array();
198 protected $table_ref_field =
'';
203 public $restrictiononfksoc = 0;
212 public $context = array();
324 private $commandeFournisseur;
340 public $ref_previous;
386 public $country_code;
429 public $barcode_type;
435 public $barcode_type_code;
441 public $barcode_type_label;
447 public $barcode_type_coder;
453 public $mode_reglement_id;
459 public $cond_reglement_id;
464 public $demand_reason_id;
470 public $transport_mode_id;
479 private $cond_reglement;
483 protected $depr_cond_reglement;
490 public $fk_delivery_address;
496 public $shipping_method_id;
502 public $shipping_method;
508 public $fk_multicurrency;
514 public $multicurrency_code;
520 public $multicurrency_tx;
525 public $multicurrency_total_ht;
530 public $multicurrency_total_tva;
535 public $multicurrency_total_localtax1;
540 public $multicurrency_total_localtax2;
545 public $multicurrency_total_ttc;
558 public $last_main_doc;
583 public $note_private;
608 public $total_localtax1;
614 public $total_localtax2;
631 public $actiontypecode;
637 public $comments = array();
663 public $civility_code;
669 public $date_creation;
674 public $date_validation;
679 public $date_modification;
693 private $date_update;
698 public $date_cloture;
710 public $user_creation;
715 public $user_creation_id;
727 public $user_validation;
732 public $user_validation_id;
737 public $user_closing_id;
743 public $user_modification;
748 public $user_modification_id;
754 public $fk_user_creat;
760 public $fk_user_modif;
766 public $next_prev_filter;
771 public $specimen = 0;
793 public $labelStatus = array();
798 public $labelStatusShort = array();
809 public $showphoto_on_popup;
814 public $nb = array();
829 public $extraparams = array();
834 protected $childtables = array();
841 protected $childtablesoncascade = array();
851 public $cond_reglement_supplier_id;
858 public $deposit_percent;
864 public $retained_warranty_fk_cond_reglement;
869 public $warehouse_id;
874 public $isextrafieldmanaged = 0;
887 'alreadypaid' =>
'totalpaid',
888 'cond_reglement' =>
'depr_cond_reglement',
890 'commandeFournisseur' =>
'origin_object',
891 'expedition' =>
'origin_object',
892 'fk_project' =>
'fk_project',
893 'livraison' =>
'origin_object',
894 'projet' =>
'project',
895 'statut' =>
'status',
914 $sql =
"SELECT rowid";
915 $sql .=
" FROM ".$db->prefix().$element;
916 $sql .=
" WHERE entity IN (".getEntity($element).
")";
919 $sql .=
" AND rowid = ".((int) $id);
921 $sql .=
" AND ref = '".$db->escape($ref).
"'";
922 } elseif ($ref_ext) {
923 $sql .=
" AND ref_ext = '".$db->escape($ref_ext).
"'";
925 $error =
'ErrorWrongParameters';
926 dol_syslog(get_class().
"::isExistingObject ".$error, LOG_ERR);
929 if ($ref || $ref_ext) {
930 $sql .=
" AND entity = ".((int)
$conf->entity);
933 dol_syslog(get_class().
"::isExistingObject", LOG_DEBUG);
934 $resql = $db->query($sql);
936 $num = $db->num_rows($resql);
953 return (empty($this->
id));
968 $this->errors = array_merge($this->errors,
$object->errors);
993 global $action, $extrafields, $langs, $hookmanager;
996 $MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP =
getDolGlobalInt(
'MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP', 3);
1002 if (!empty($extrafields->attributes[$this->table_element][
'label'])) {
1003 $data[
'opendivextra'] =
'<div class="centpercent wordbreak divtooltipextra">';
1004 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
1005 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
1008 if ($count >= abs($MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP)) {
1009 $data[
'more_extrafields'] =
'<br>...';
1013 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
1014 $enabled = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
1016 if ($enabled && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
1017 $enabled = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
1020 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
1021 $perms = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
1023 if (empty($enabled)) {
1026 if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
1029 if (empty($perms)) {
1032 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
1033 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
1035 $labelextra = $langs->trans((
string) $extrafields->attributes[$this->table_element][
'label'][$key]);
1036 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
1037 $data[$key] =
'<br><b><u>'. $labelextra .
'</u></b>';
1039 $value = (empty($this->array_options[
'options_' . $key]) ?
'' : $this->array_options[
'options_' . $key]);
1040 $data[$key] =
'<br><b>'. $labelextra .
':</b> ' . $extrafields->showOutputField($key, $value,
'', $this->table_element);
1044 $data[
'closedivextra'] =
'</div>';
1047 $hookmanager->initHooks(array($this->element .
'dao'));
1048 $parameters = array(
1049 'tooltipcontentarray' => &$data,
1050 'params' => $params,
1053 $hookmanager->executeHooks(
'getTooltipContent', $parameters, $this, $action);
1056 $label = implode($data);
1069 return $this->error.(is_array($this->errors) ? (($this->error !=
'' ?
', ' :
'').implode(
', ', $this->errors)) :
'');
1081 global $hookmanager;
1083 $parameters = array(
'objref' => $objref);
1085 $reshook = $hookmanager->executeHooks(
'getFormatedCustomerRef', $parameters, $this, $action);
1087 return $hookmanager->resArray[
'objref'];
1089 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
1100 global $hookmanager;
1102 $parameters = array(
'objref' => $objref);
1104 $reshook = $hookmanager->executeHooks(
'getFormatedSupplierRef', $parameters, $this, $action);
1106 return $hookmanager->resArray[
'objref'];
1108 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
1120 public function getFullAddress($withcountry = 0, $sep =
"\n", $withregion = 0, $extralangcode =
'')
1122 if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
1123 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
1124 $tmparray =
getCountry($this->country_id,
'all');
1125 $this->country_code = $tmparray[
'code'];
1126 $this->country = $tmparray[
'label'];
1129 if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) {
1130 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
1131 $tmparray =
getState($this->state_id,
'all',
null, 1);
1132 $this->state_code = $tmparray[
'code'];
1133 $this->state = $tmparray[
'label'];
1134 $this->region_code = $tmparray[
'region_code'];
1135 $this->region = $tmparray[
'region'];
1154 if (empty($this->last_main_doc)) {
1158 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1159 $ecmfile =
new EcmFiles($this->db);
1160 $result = $ecmfile->fetch(0,
'', $this->last_main_doc);
1162 $this->error = $ecmfile->error;
1163 $this->errors = $ecmfile->errors;
1167 if (empty($ecmfile->id)) {
1169 if ($initsharekey) {
1170 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1192 } elseif (empty($ecmfile->share)) {
1194 if ($initsharekey) {
1195 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1197 $ecmfile->update($user);
1203 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
1207 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1216 if (!empty($ecmfile->share)) {
1217 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$ecmfile->share;
1219 if ($forcedownload) {
1220 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
1223 if ($relativelink) {
1224 $linktoreturn =
'document.php'.($paramlink ?
'?'.$paramlink :
'');
1226 $linktoreturn = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
1230 return $linktoreturn;
1244 public function add_contact($fk_socpeople, $type_contact, $source =
'external', $notrigger = 0)
1247 global $user, $langs;
1249 dol_syslog(get_class($this).
"::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
1252 if ($fk_socpeople <= 0) {
1253 $langs->load(
"errors");
1254 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"1");
1255 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1258 if (!$type_contact) {
1259 $langs->load(
"errors");
1260 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"2");
1261 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1265 if ($this->restrictiononfksoc && property_exists($this,
'socid') && !empty($this->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
1266 $sql_allowed_contacts =
'SELECT COUNT(*) as cnt FROM '.$this->db->prefix().
'societe_commerciaux as sc';
1267 $sql_allowed_contacts.=
' WHERE sc.fk_soc = '.(int) $this->socid;
1268 $sql_allowed_contacts.=
' AND sc.fk_user = '.(int) $user->id;
1270 $resql_allowed_contacts = $this->db->query($sql_allowed_contacts);
1272 if (!$resql_allowed_contacts) {
1273 $this->errors[] = $this->db->lasterror();
1275 } elseif ($obj = $this->db->fetch_object($resql_allowed_contacts)) {
1276 if ($obj->cnt == 0) {
1277 $langs->load(
"companies");
1278 $this->error = $langs->trans(
"ErrorCommercialNotAllowedForThirdparty", $user->id);
1279 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1285 $id_type_contact = 0;
1286 if (is_numeric($type_contact)) {
1287 $id_type_contact = $type_contact;
1290 $sql =
"SELECT tc.rowid";
1291 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1292 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1293 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1294 $sql .=
" AND tc.code='".$this->db->escape($type_contact).
"' AND tc.active=1";
1296 $resql = $this->db->query($sql);
1298 $obj = $this->db->fetch_object($resql);
1300 $id_type_contact = $obj->rowid;
1304 if ($id_type_contact == 0) {
1305 dol_syslog(
"CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact.
"' does not exists or is not active for element ".$this->element.
", we can ignore it");
1313 $already_added =
false;
1314 if (is_array($TListeContacts) && !empty($TListeContacts)) {
1315 foreach ($TListeContacts as $array_contact) {
1316 if ($array_contact[
'status'] == 4 && $array_contact[
'id'] == $fk_socpeople && $array_contact[
'fk_c_type_contact'] == $id_type_contact) {
1317 $already_added =
true;
1323 if (!$already_added) {
1327 $sql =
"INSERT INTO ".$this->db->prefix().
"element_contact";
1328 $sql .=
" (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1329 $sql .=
" VALUES (".$this->id.
", ".((int) $fk_socpeople).
" , ";
1330 $sql .=
"'".$this->db->idate($datecreate).
"'";
1331 $sql .=
", 4, ".((int) $id_type_contact);
1334 $resql = $this->db->query($sql);
1337 $result = $this->
call_trigger(strtoupper($this->element).
'_ADD_CONTACT', $user);
1339 $this->db->rollback();
1344 $this->db->commit();
1347 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1348 $this->error = $this->db->errno();
1349 $this->db->rollback();
1352 $this->error = $this->db->lasterror();
1353 $this->db->rollback();
1373 $contacts = $objFrom->liste_contact(-1, $source);
1374 foreach ($contacts as $contact) {
1375 if ($this->
add_contact($contact[
'id'], $contact[
'fk_c_type_contact'], $contact[
'source']) < 0) {
1392 public function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0)
1396 $sql =
"UPDATE ".$this->db->prefix().
"element_contact set";
1397 $sql .=
" statut = ".((int) $statut);
1398 if ($type_contact_id) {
1399 $sql .=
", fk_c_type_contact = ".((int) $type_contact_id);
1401 if ($fk_socpeople) {
1402 $sql .=
", fk_socpeople = ".((int) $fk_socpeople);
1404 $sql .=
" where rowid = ".((int) $rowid);
1406 $resql = $this->db->query($sql);
1410 $this->error = $this->db->lasterror();
1432 if (!$error && empty($notrigger)) {
1434 $this->context[
'contact_id'] = ((int) $rowid);
1435 $result = $this->
call_trigger(strtoupper($this->element).
'_DELETE_CONTACT', $user);
1443 dol_syslog(get_class($this).
"::delete_contact", LOG_DEBUG);
1445 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1446 $sql .=
" WHERE rowid = ".((int) $rowid);
1448 $result = $this->db->query($sql);
1451 $this->errors[] = $this->db->lasterror();
1456 $this->db->commit();
1459 $this->error = $this->db->lasterror();
1460 $this->db->rollback();
1480 if (!empty($typeContact)) {
1481 foreach ($typeContact as $key => $value) {
1482 array_push($temp, $key);
1484 $listId = implode(
",", $temp);
1489 if (empty($listId)) {
1493 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1494 $sql .=
" WHERE element_id = ".((int) $this->
id);
1495 $sql .=
" AND fk_c_type_contact IN (".$this->db->sanitize($listId).
")";
1497 dol_syslog(get_class($this).
"::delete_linked_contact", LOG_DEBUG);
1498 if ($this->db->query($sql)) {
1501 $this->error = $this->db->lasterror();
1518 public function liste_contact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1, $arrayoftcids = array())
1525 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
1526 if ($source ==
'internal') {
1527 $sql .=
", '-1' as socid, t.statut as statuscontact, t.login, t.photo, t.gender, t.fk_country as country_id";
1529 if ($source ==
'external' || $source ==
'thirdparty') {
1530 $sql .=
", t.fk_soc as socid, t.statut as statuscontact, t.fk_pays as country_id";
1532 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email, t.address, t.zip, t.town";
1533 if (empty($arrayoftcids)) {
1534 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label, co.label as country";
1537 if (empty($arrayoftcids)) {
1538 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc,";
1540 $sql .=
" ".$this->db->prefix().
"element_contact as ec";
1541 if ($source ==
'internal') {
1542 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user as t on ec.fk_socpeople = t.rowid";
1543 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as co ON co.rowid = t.fk_country";
1545 if ($source ==
'external' || $source ==
'thirdparty') {
1546 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople as t on ec.fk_socpeople = t.rowid";
1547 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as co ON co.rowid = t.fk_pays";
1549 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
1550 if (empty($arrayoftcids)) {
1551 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1552 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1554 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1556 if ($source ==
'internal') {
1557 $sql .=
" AND tc.source = 'internal'";
1559 if ($source ==
'external' || $source ==
'thirdparty') {
1560 $sql .=
" AND tc.source = 'external'";
1562 $sql .=
" AND tc.active = 1";
1564 $sql .=
" AND ec.fk_c_type_contact IN (".$this->db->sanitize(implode(
',', $arrayoftcids)).
")";
1567 $sql .=
" AND t.statut = ".((int) $status);
1569 if ($statusoflink >= 0) {
1570 $sql .=
" AND ec.statut = ".((int) $statusoflink);
1572 $sql .=
" ORDER BY t.lastname ASC";
1574 dol_syslog(get_class($this).
"::liste_contact", LOG_DEBUG);
1575 $resql = $this->db->query($sql);
1577 $num = $this->db->num_rows($resql);
1580 $obj = $this->db->fetch_object($resql);
1583 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1584 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1586 'parentId' => $this->
id,
1587 'source' => $obj->source,
1588 'socid' => $obj->socid,
1590 'nom' => $obj->lastname,
1591 'civility' => $obj->civility,
1592 'lastname' => $obj->lastname,
1593 'firstname' => $obj->firstname,
1594 'email' => $obj->email,
1595 'address' => $obj->address,
1597 'town' => $obj->town,
1598 'country_id' => $obj->country_id,
1599 'country' => $obj->country,
1600 'login' => (empty($obj->login) ?
'' : $obj->login),
1601 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
1602 'gender' => (empty($obj->gender) ?
'' : $obj->gender),
1603 'statuscontact' => $obj->statuscontact,
1604 'rowid' => $obj->rowid,
1605 'code' => $obj->code,
1606 'libelle' => $libelle_type,
1607 'status' => (
int) $obj->statuslink,
1608 'fk_c_type_contact' => $obj->fk_c_type_contact
1611 $tab[$i] = $obj->id;
1619 $this->error = $this->db->lasterror();
1634 $sql =
"SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1635 $sql .=
" tc.code, tc.libelle as type_label";
1636 $sql .=
" FROM (".$this->db->prefix().
"element_contact as ec, ".$this->db->prefix().
"c_type_contact as tc)";
1637 $sql .=
" WHERE ec.rowid =".((int) $rowid);
1638 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1639 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1641 dol_syslog(get_class($this).
"::swapContactStatus", LOG_DEBUG);
1642 $resql = $this->db->query($sql);
1644 $obj = $this->db->fetch_object($resql);
1645 $newstatut = ($obj->statut == 4) ? 5 : 4;
1647 $this->db->free($resql);
1650 $this->error = $this->db->error();
1667 public function liste_type_contact($source =
'internal', $order =
'position', $option = 0, $activeonly = 0, $code =
'')
1672 if (empty($order)) {
1673 $order =
'position';
1675 if ($order ==
'position') {
1681 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position";
1682 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1683 $sql .=
" WHERE tc.element = '".$this->db->escape($this->element).
"'";
1684 if ($activeonly == 1) {
1685 $sql .=
" AND tc.active = 1";
1687 if (!empty($source) && $source !=
'all') {
1688 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1690 if (!empty($code)) {
1691 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1693 $sql .= $this->db->order($order,
'ASC');
1696 $resql = $this->db->query($sql);
1698 $this->error = $this->db->lasterror();
1703 $num = $this->db->num_rows($resql);
1706 $obj = $this->db->fetch_object($resql);
1708 $transkey =
"TypeContact_".$this->element.
"_".$source.
"_".$obj->code;
1709 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $langs->trans($obj->type_label));
1710 if (empty($option)) {
1711 $tab[$obj->rowid] = $libelle_type;
1712 } elseif ($option == 1) {
1713 $tab[$obj->code] = $libelle_type;
1715 $tab[$obj->rowid] = array(
'id' => $obj->rowid,
'code' => $obj->code,
'label' => $libelle_type);
1734 public function listeTypeContacts($source =
'internal', $option = 0, $activeonly = 0, $code =
'', $element =
'', $excludeelement =
'')
1738 $langs->loadLangs(array(
'bills',
'contracts',
'interventions',
'orders',
'projects',
'propal',
'ticket',
'agenda'));
1742 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position, tc.element, tc.module";
1743 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1745 $sqlWhere = array();
1746 if (!empty($element)) {
1747 $sqlWhere[] =
" tc.element='".$this->db->escape($element).
"'";
1749 if (!empty($excludeelement)) {
1750 $sqlWhere[] =
" tc.element <> '".$this->db->escape($excludeelement).
"'";
1753 if ($activeonly == 1) {
1754 $sqlWhere[] =
" tc.active=1";
1757 if (!empty($source) && $source !=
'all') {
1758 $sqlWhere[] =
" tc.source='".$this->db->escape($source).
"'";
1761 if (!empty($code)) {
1762 $sqlWhere[] =
" tc.code='".$this->db->escape($code).
"'";
1765 if (count($sqlWhere) > 0) {
1766 $sql .=
" WHERE ".implode(
' AND ', $sqlWhere);
1769 $sql .= $this->db->order(
'tc.element, tc.position',
'ASC');
1772 $resql = $this->db->query($sql);
1774 $num = $this->db->num_rows($resql);
1776 $langs->loadLangs(array(
"propal",
"orders",
"bills",
"suppliers",
"contracts",
"supplier_proposal"));
1778 while ($obj = $this->db->fetch_object($resql)) {
1779 $modulename = $obj->module ?? $obj->element;
1780 if (strpos($obj->element,
'project') !==
false) {
1781 $modulename =
'projet';
1782 } elseif ($obj->element ==
'contrat') {
1783 $element =
'contract';
1784 } elseif ($obj->element ==
'action') {
1785 $modulename =
'agenda';
1786 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1787 $modulename =
'fournisseur';
1789 if (isModEnabled($modulename)) {
1790 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1791 $tmpelement = $obj->element;
1792 $transkey =
"TypeContact_".$tmpelement.
"_".$source.
"_".$obj->code;
1793 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1794 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1800 $this->error = $this->db->lasterror();
1821 if (!
getDolGlobalInt(
'SHIPPING_USE_ITS_OWN_CONTACTS') && $this->element ==
'shipping' && $this->origin_id != 0) {
1822 $id = $this->origin_id;
1823 $element =
'commande';
1824 } elseif ($this->element ==
'reception' && $this->origin_id != 0) {
1825 $id = $this->origin_id;
1826 $element =
'order_supplier';
1829 $element = $this->element;
1832 $sql =
"SELECT ec.fk_socpeople";
1833 $sql .=
" FROM ".$this->db->prefix().
"element_contact as ec,";
1834 if ($source ==
'internal') {
1835 $sql .=
" ".$this->db->prefix().
"user as c,";
1837 if ($source ==
'external') {
1838 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
1840 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc";
1841 $sql .=
" WHERE ec.element_id = ".((int) $id);
1842 $sql .=
" AND ec.fk_socpeople = c.rowid";
1843 if ($source ==
'internal') {
1844 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
1846 if ($source ==
'external') {
1847 $sql .=
" AND c.entity IN (".getEntity(
'societe').
")";
1849 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1850 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1851 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1853 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1855 $sql .=
" AND tc.active = 1";
1857 $sql .=
" AND ec.statut = ".((int) $status);
1860 dol_syslog(get_class($this).
"::getIdContact", LOG_DEBUG);
1861 $resql = $this->db->query($sql);
1863 while ($obj = $this->db->fetch_object($resql)) {
1864 $result[$i] = $obj->fk_socpeople;
1868 $this->error = $this->db->error();
1885 if (empty($contactid)) {
1886 $contactid = $this->contact_id;
1889 if (empty($contactid)) {
1893 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1894 $contact =
new Contact($this->db);
1895 $result = $contact->fetch($contactid);
1896 $this->contact = $contact;
1911 if (empty($this->socid) && empty($this->fk_soc) && empty($force_thirdparty_id)) {
1915 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1917 $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : 0);
1918 if ($force_thirdparty_id) {
1919 $idtofetch = $force_thirdparty_id;
1923 $thirdparty =
new Societe($this->db);
1924 $result = $thirdparty->fetch($idtofetch);
1926 $this->errors = array_merge($this->errors, $thirdparty->errors);
1928 $this->thirdparty = $thirdparty;
1932 $this->thirdparty->price_level = 1;
1951 if (!$this->table_ref_field) {
1955 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
1956 $sql .=
" WHERE ".$this->table_ref_field.
" LIKE '".$this->db->escape($ref).
"'";
1959 $query = $this->db->query($sql);
1961 if (!$this->db->num_rows($query)) {
1965 $result = $this->db->fetch_object($query);
1967 if (method_exists($this,
'fetch')) {
1968 return $this->fetch($result->rowid);
1970 $this->error =
'Fetch method not implemented on '.get_class($this);
1971 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
1972 array_push($this->errors, $this->error);
2001 dol_syslog(get_class($this).
'::fetchBarCode this->element='.$this->element.
' this->barcode_type='.$this->barcode_type);
2003 $idtype = $this->barcode_type;
2004 if (empty($idtype) && $idtype !=
'0') {
2005 if ($this->element ==
'product' &&
getDolGlobalString(
'PRODUIT_DEFAULT_BARCODE_TYPE')) {
2007 } elseif ($this->element ==
'societe') {
2010 dol_syslog(
'Call fetchBarCode with barcode_type not defined and cannot be guessed', LOG_WARNING);
2015 if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
2016 $sql =
"SELECT rowid, code, libelle as label, coder";
2017 $sql .=
" FROM ".$this->db->prefix().
"c_barcode_type";
2018 $sql .=
" WHERE rowid = ".((int) $idtype);
2020 $resql = $this->db->query($sql);
2022 $obj = $this->db->fetch_object($resql);
2024 $this->barcode_type = $obj->rowid;
2025 $this->barcode_type_code = $obj->code;
2026 $this->barcode_type_label = $obj->label;
2027 $this->barcode_type_coder = $obj->coder;
2045 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2047 if (empty($this->fk_project) && !empty($this->fk_projet)) {
2048 $this->fk_project = $this->fk_projet;
2050 if (empty($this->fk_project)) {
2054 $project =
new Project($this->db);
2055 $result = $project->fetch($this->fk_project);
2057 $this->projet = $project;
2058 $this->project = $project;
2100 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
2103 if (empty($this->fk_product)) {
2107 $product =
new Product($this->db);
2109 $result = $product->fetch($this->fk_product);
2111 $this->product = $product;
2125 $user =
new User($this->db);
2126 $result = $user->fetch($userid);
2127 $this->
user = $user;
2141 $origin = $this->origin ? $this->origin : $this->origin_type;
2144 if ($origin ==
'shipping') {
2145 $origin =
'expedition';
2147 if ($origin ==
'delivery') {
2148 $origin =
'livraison';
2150 if ($origin ==
'order_supplier' || $origin ==
'supplier_order') {
2151 $origin =
'commandeFournisseur';
2154 $classname = ucfirst($origin);
2155 $this->origin_object =
new $classname($this->db);
2157 $this->origin_object->fetch($this->origin_id);
2175 $sql =
"SELECT rowid FROM ".$this->db->prefix().$table;
2176 $sql .=
" WHERE ".$field.
" = '".$this->db->escape($key).
"'";
2177 if (!empty($element)) {
2178 $sql .=
" AND entity IN (".getEntity($element).
")";
2180 $sql .=
" AND entity = ".((int)
$conf->entity);
2183 dol_syslog(get_class($this).
'::fetchObjectFrom', LOG_DEBUG);
2184 $resql = $this->db->query($sql);
2186 $obj = $this->db->fetch_object($resql);
2189 if (method_exists($this,
'fetch')) {
2190 $result = $this->fetch($obj->rowid);
2192 $this->error =
'fetch() method not implemented on '.get_class($this);
2193 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
2194 array_push($this->errors, $this->error);
2214 if (!empty($id) && !empty($field) && !empty($table)) {
2215 $sql =
"SELECT ".$field.
" FROM ".$this->db->prefix().$table;
2216 $sql .=
" WHERE rowid = ".((int) $id);
2218 dol_syslog(get_class($this).
'::getValueFrom', LOG_DEBUG);
2219 $resql = $this->db->query($sql);
2221 $row = $this->db->fetch_row($resql);
2244 public function setValueFrom($field, $value, $table =
'', $id =
null, $format =
'', $id_field =
'', $fuser =
null, $trigkey =
'', $fk_user_field =
'fk_user_modif')
2248 if (empty($table)) {
2249 $table = $this->table_element;
2254 if (empty($format)) {
2257 if (empty($id_field)) {
2258 $id_field =
'rowid';
2262 if ($table ==
'product' && $field ==
'note_private') {
2266 if (in_array($table, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
2267 $fk_user_field =
'fk_user_mod';
2269 if (in_array($table, array(
'prelevement_bons'))) {
2270 $fk_user_field =
'';
2275 $sql =
"SELECT " . $field;
2276 $sql .=
" FROM " . MAIN_DB_PREFIX . $table;
2277 $sql .=
" WHERE " . $id_field .
" = " . ((int) $id);
2279 $resql = $this->db->query($sql);
2281 if ($obj = $this->db->fetch_object($resql)) {
2282 if ($format ==
'date') {
2283 $oldvalue = $this->db->jdate($obj->$field);
2285 $oldvalue = $obj->$field;
2289 $this->error = $this->db->lasterror();
2300 $sql =
"UPDATE ".$this->db->prefix().$table.
" SET ";
2302 if ($format ==
'text') {
2303 $sql .= $field.
" = '".$this->db->escape($value).
"'";
2304 } elseif ($format ==
'int') {
2305 $sql .= $field.
" = ".((int) $value);
2306 } elseif ($format ==
'date') {
2307 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value).
"'" :
"null");
2308 } elseif ($format ==
'dategmt') {
2309 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value,
'gmt').
"'" :
"null");
2312 if ($fk_user_field) {
2313 if (!empty($fuser) && is_object($fuser)) {
2314 $sql .=
", ".$this->db->sanitize($fk_user_field).
" = ".((int) $fuser->id);
2315 } elseif (empty($fuser) || $fuser !=
'none') {
2316 $sql .=
", ".$this->db->sanitize($fk_user_field).
" = ".((int) $user->id);
2320 $sql .=
" WHERE ".$id_field.
" = ".((int) $id);
2322 $resql = $this->db->query($sql);
2326 if (method_exists($this,
'fetch')) {
2327 $result = $this->fetch($id);
2331 $this->oldcopy = clone $this;
2332 if (property_exists($this->oldcopy, $field)) {
2333 $this->oldcopy->$field = $oldvalue;
2337 $result = $this->
call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
2345 if (property_exists($this, $field)) {
2346 $this->$field = $value;
2348 $this->db->commit();
2351 $this->db->rollback();
2355 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2356 $this->error =
'DB_ERROR_RECORD_ALREADY_EXISTS';
2358 $this->error = $this->db->lasterror();
2360 $this->db->rollback();
2379 global
$conf, $user;
2381 if (!$this->table_element) {
2382 dol_print_error(
null, get_class($this).
"::load_previous_next_ref was called on object with property table_element not defined");
2385 if ($fieldid ==
'none') {
2390 if (in_array($this->table_element, array(
'facture_rec',
'facture_fourn_rec')) && $fieldid ==
'title') {
2396 if ($user->socid > 0) {
2397 $socid = $user->socid;
2402 $aliastablesociete =
's';
2403 if ($this->element ==
'societe') {
2404 $aliastablesociete =
'te';
2406 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2407 $sql =
"SELECT MAX(te.".$fieldid.
")";
2408 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2409 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2410 $tmparray = explode(
'@', $this->ismultientitymanaged);
2411 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2412 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2413 $sql .=
", ".$this->db->prefix().
"societe as s";
2414 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2415 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2417 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2418 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2420 if ($fieldid ==
'rowid') {
2421 $sql .=
" WHERE te.".$fieldid.
" < ".((int) $this->
id);
2423 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($this->
ref).
"'";
2425 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2426 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2428 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2429 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2432 $filtermax = $filter;
2437 if ($errormessage) {
2438 if (!preg_match(
'/^\s*AND/i', $filtermax)) {
2446 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2447 $tmparray = explode(
'@', $this->ismultientitymanaged);
2448 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2449 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2450 $sql .=
' AND te.fk_soc = s.rowid';
2452 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2453 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2454 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
2455 $sql .=
" AND te.entity IS NOT NULL";
2457 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2460 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2463 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2464 $tmparray = explode(
'@', $this->ismultientitymanaged);
2465 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2467 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2468 $sql .=
' AND te.fk_soc = '.((int) $socid);
2470 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2471 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2473 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2474 $sql .=
' AND te.rowid = '.((int) $socid);
2478 $result = $this->db->query($sql);
2480 $this->error = $this->db->lasterror();
2483 $row = $this->db->fetch_row($result);
2484 $this->ref_previous = $row[0];
2486 $sql =
"SELECT MIN(te.".$fieldid.
")";
2487 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2488 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2489 $tmparray = explode(
'@', $this->ismultientitymanaged);
2490 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2491 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2492 $sql .=
", ".$this->db->prefix().
"societe as s";
2493 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2494 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2496 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2497 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2499 if ($fieldid ==
'rowid') {
2500 $sql .=
" WHERE te.".$fieldid.
" > ".((int) $this->
id);
2502 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($this->
ref).
"'";
2504 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2505 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
2507 $userschilds = $user->getAllChildIds();
2508 $sql .=
" OR sc.fk_user IN (".$this->db->sanitize(implode(
',', $userschilds)).
")";
2512 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2513 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2516 $filtermin = $filter;
2521 if ($errormessage) {
2522 if (!preg_match(
'/^\s*AND/i', $filtermin)) {
2532 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2533 $tmparray = explode(
'@', $this->ismultientitymanaged);
2534 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2535 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2536 $sql .=
' AND te.fk_soc = s.rowid';
2538 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2539 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2540 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
2541 $sql .=
" AND te.entity IS NOT NULL";
2543 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2546 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2549 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2550 $tmparray = explode(
'@', $this->ismultientitymanaged);
2551 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2553 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2554 $sql .=
' AND te.fk_soc = '.((int) $socid);
2556 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2557 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2559 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2560 $sql .=
' AND te.rowid = '.((int) $socid);
2565 $result = $this->db->query($sql);
2567 $this->error = $this->db->lasterror();
2570 $row = $this->db->fetch_row($result);
2571 $this->ref_next = $row[0];
2586 $contactAlreadySelected = array();
2591 if ($source ==
'thirdparty') {
2592 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
2594 $contactAlreadySelected[$i] = $tab[$i][
'id'];
2598 return $contactAlreadySelected;
2614 if (!$this->table_element) {
2615 dol_syslog(get_class($this).
"::setProject was called on object with property table_element not defined", LOG_ERR);
2619 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2621 if (!empty($this->fields[
'fk_project'])) {
2623 $sql .=
" SET fk_project = ".((int) $projectid);
2625 $sql .=
" SET fk_project = NULL";
2627 $sql .=
' WHERE rowid = '.((int) $this->
id);
2628 } elseif ($this->table_element ==
'actioncomm') {
2630 $sql .=
" SET fk_project = ".((int) $projectid);
2632 $sql .=
" SET fk_project = NULL";
2634 $sql .=
' WHERE id = '.((int) $this->
id);
2637 $sql .=
' SET fk_projet = '.((int) $projectid);
2639 $sql .=
' SET fk_projet = NULL';
2641 $sql .=
" WHERE rowid = ".((int) $this->
id);
2646 dol_syslog(get_class($this).
"::setProject", LOG_DEBUG);
2647 if ($this->db->query($sql)) {
2648 $this->fk_project = ((int) $projectid);
2655 if (!$error && !$notrigger) {
2657 $result = $this->
call_trigger(strtoupper($this->element) .
'_MODIFY', $user);
2666 $this->db->rollback();
2669 $this->db->commit();
2687 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2689 if ($this->
status >= 0 || $this->element ==
'societe') {
2691 $fieldname =
'fk_mode_reglement';
2692 if ($this->element ==
'societe') {
2693 $fieldname =
'mode_reglement';
2695 if (get_class($this) ==
'Fournisseur') {
2696 $fieldname =
'mode_reglement_supplier';
2698 if (get_class($this) ==
'Tva') {
2699 $fieldname =
'fk_typepayment';
2701 if (get_class($this) ==
'Salary') {
2702 $fieldname =
'fk_typepayment';
2705 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2706 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2707 $sql .=
' WHERE rowid='.((int) $this->
id);
2709 if ($this->db->query($sql)) {
2710 $this->mode_reglement_id = $id;
2712 if (get_class($this) ==
'Fournisseur') {
2713 $this->mode_reglement_supplier_id = $id;
2716 if (!$error && !$notrigger) {
2718 if (get_class($this) ==
'Commande') {
2721 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
2730 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2731 $this->error = $this->db->error();
2735 dol_syslog(get_class($this).
'::setPaymentMethods, status of the object is incompatible');
2736 $this->error =
'Status of the object is incompatible '.$this->status;
2749 dol_syslog(get_class($this).
'::setMulticurrencyCode('.$code.
')');
2750 if ($this->
status >= 0 || $this->element ==
'societe') {
2751 $fieldname =
'multicurrency_code';
2753 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2754 $sql .=
" SET ".$fieldname.
" = '".$this->db->escape($code).
"'";
2755 $sql .=
' WHERE rowid='.((int) $this->
id);
2757 if ($this->db->query($sql)) {
2758 $this->multicurrency_code = $code;
2762 $this->setMulticurrencyRate($rate, 2);
2767 dol_syslog(get_class($this).
'::setMulticurrencyCode Error '.$sql.
' - '.$this->db->error());
2768 $this->error = $this->db->error();
2772 dol_syslog(get_class($this).
'::setMulticurrencyCode, status of the object is incompatible');
2773 $this->error =
'Status of the object is incompatible '.$this->status;
2785 public function setMulticurrencyRate($rate, $mode = 1)
2787 dol_syslog(get_class($this).
'::setMulticurrencyRate('.$rate.
', '.$mode.
')');
2788 if ($this->
status >= 0 || $this->element ==
'societe') {
2789 $fieldname =
'multicurrency_tx';
2791 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2792 $sql .=
" SET ".$this->db->sanitize($fieldname).
" = ".((float) $rate);
2793 $sql .=
' WHERE rowid='.((int) $this->
id);
2795 if ($this->db->query($sql)) {
2796 $this->multicurrency_tx = $rate;
2799 if (!empty($this->lines)) {
2800 foreach ($this->lines as &$line) {
2803 $line->subprice = 0;
2808 $line->multicurrency_subprice = 0;
2811 switch ($this->element) {
2815 '@phan-var-force Propal $this';
2816 '@phan-var-force PropaleLigne $line';
2821 $line->remise_percent,
2823 $line->localtax1_tx,
2824 $line->localtax2_tx,
2825 ($line->description ? $line->description : $line->desc),
2828 $line->special_code,
2829 $line->fk_parent_line,
2830 $line->skip_update_total,
2831 $line->fk_fournprice,
2834 $line->product_type,
2837 $line->array_options,
2839 $line->multicurrency_subprice
2845 '@phan-var-force Commande $this';
2846 '@phan-var-force OrderLine $line';
2849 ($line->description ? $line->description : $line->desc),
2852 $line->remise_percent,
2854 $line->localtax1_tx,
2855 $line->localtax2_tx,
2860 $line->product_type,
2861 $line->fk_parent_line,
2862 $line->skip_update_total,
2863 $line->fk_fournprice,
2866 $line->special_code,
2867 $line->array_options,
2869 $line->multicurrency_subprice
2875 '@phan-var-force Facture $this';
2876 '@phan-var-force FactureLigne $line';
2879 ($line->description ? $line->description : $line->desc),
2882 $line->remise_percent,
2886 $line->localtax1_tx,
2887 $line->localtax2_tx,
2890 $line->product_type,
2891 $line->fk_parent_line,
2892 $line->skip_update_total,
2893 $line->fk_fournprice,
2896 $line->special_code,
2897 $line->array_options,
2898 $line->situation_percent,
2900 $line->multicurrency_subprice
2906 '@phan-var-force FactureRec $this';
2907 '@phan-var-force FactureLigneRec $line';
2910 ($line->description ? $line->description : $line->desc),
2914 $line->localtax1_tx,
2915 $line->localtax2_tx,
2917 $line->remise_percent,
2922 $line->product_type,
2924 $line->special_code,
2927 $line->multicurrency_subprice,
2931 $line->fk_fournprice,
2933 $line->fk_parent_line
2936 case 'supplier_proposal':
2939 '@phan-var-force SupplierProposal $this';
2940 '@phan-var-force SupplierProposalLine $line';
2945 $line->remise_percent,
2947 $line->localtax1_tx,
2948 $line->localtax2_tx,
2949 ($line->description ? $line->description : $line->desc),
2952 $line->special_code,
2953 $line->fk_parent_line,
2954 $line->skip_update_total,
2955 $line->fk_fournprice,
2958 $line->product_type,
2959 $line->array_options,
2961 (int) $line->fk_unit,
2962 $line->multicurrency_subprice
2965 case 'order_supplier':
2968 '@phan-var-force CommandeFournisseur $this';
2969 '@phan-var-force CommandeFournisseurLigne $line';
2972 ($line->description ? $line->description : $line->desc),
2975 $line->remise_percent,
2977 $line->localtax1_tx,
2978 $line->localtax2_tx,
2981 $line->product_type,
2985 $line->array_options,
2987 $line->multicurrency_subprice,
2991 case 'invoice_supplier':
2994 '@phan-var-force FactureFournisseur $this';
2995 '@phan-var-force SupplierInvoiceLIne $line';
2998 ($line->description ? $line->description : $line->desc),
3001 $line->localtax1_tx,
3002 $line->localtax2_tx,
3007 $line->product_type,
3008 $line->remise_percent,
3012 $line->array_options,
3014 $line->multicurrency_subprice,
3019 dol_syslog(get_class($this).
'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
3027 dol_syslog(get_class($this).
'::setMulticurrencyRate Error '.$sql.
' - '.$this->db->error());
3028 $this->error = $this->db->error();
3032 dol_syslog(get_class($this).
'::setMulticurrencyRate, status of the object is incompatible');
3033 $this->error =
'Status of the object is incompatible '.$this->status;
3047 dol_syslog(get_class($this).
'::setPaymentTerms('.$id.
', '.var_export($deposit_percent,
true).
')');
3048 if ($this->
status >= 0 || $this->element ==
'societe') {
3050 $fieldname =
'fk_cond_reglement';
3051 if ($this->element ==
'societe') {
3052 $fieldname =
'cond_reglement';
3054 if (get_class($this) ==
'Fournisseur') {
3055 $fieldname =
'cond_reglement_supplier';
3058 if (empty($deposit_percent) || $deposit_percent < 0) {
3059 $deposit_percent = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent', $id);
3062 if ($deposit_percent > 100) {
3063 $deposit_percent = 100;
3066 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
3067 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
3068 if (in_array($this->table_element, array(
'propal',
'commande',
'societe'))) {
3069 $sql .=
" , deposit_percent = " . (empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape((
string) $deposit_percent).
"'");
3071 $sql .=
' WHERE rowid='.((int) $this->
id);
3073 if ($this->db->query($sql)) {
3074 $this->cond_reglement_id = $id;
3076 if (get_class($this) ==
'Fournisseur') {
3077 $this->cond_reglement_supplier_id = $id;
3079 $this->deposit_percent = $deposit_percent;
3082 dol_syslog(get_class($this).
'::setPaymentTerms Error '.$sql.
' - '.$this->db->error());
3083 $this->error = $this->db->error();
3087 dol_syslog(get_class($this).
'::setPaymentTerms, status of the object is incompatible');
3088 $this->error =
'Status of the object is incompatible '.$this->status;
3101 dol_syslog(get_class($this).
'::setTransportMode('.$id.
')');
3102 if ($this->
status >= 0 || $this->element ==
'societe') {
3103 $fieldname =
'fk_transport_mode';
3104 if ($this->element ==
'societe') {
3105 $fieldname =
'transport_mode';
3107 if (get_class($this) ==
'Fournisseur') {
3108 $fieldname =
'transport_mode_supplier';
3111 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
3112 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
3113 $sql .=
' WHERE rowid='.((int) $this->
id);
3115 if ($this->db->query($sql)) {
3116 $this->transport_mode_id = $id;
3118 if (get_class($this) ==
'Fournisseur') {
3119 $this->transport_mode_supplier_id = $id;
3123 dol_syslog(get_class($this).
'::setTransportMode Error '.$sql.
' - '.$this->db->error());
3124 $this->error = $this->db->error();
3128 dol_syslog(get_class($this).
'::setTransportMode, status of the object is incompatible');
3129 $this->error =
'Status of the object is incompatible '.$this->status;
3142 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms('.$id.
')');
3143 if ($this->
status >= 0 || $this->element ==
'societe') {
3144 $fieldname =
'retained_warranty_fk_cond_reglement';
3146 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
3147 $sql .=
" SET ".$fieldname.
" = ".((int) $id);
3148 $sql .=
' WHERE rowid='.((int) $this->
id);
3150 if ($this->db->query($sql)) {
3151 $this->retained_warranty_fk_cond_reglement = $id;
3154 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms Error '.$sql.
' - '.$this->db->error());
3155 $this->error = $this->db->error();
3159 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
3160 $this->error =
'Status of the object is incompatible '.$this->status;
3174 $fieldname =
'fk_delivery_address';
3175 if ($this->element ==
'delivery' || $this->element ==
'shipping') {
3176 $fieldname =
'fk_address';
3179 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ".$fieldname.
" = ".((int) $id);
3180 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
3182 if ($this->db->query($sql)) {
3183 $this->fk_delivery_address = $id;
3186 $this->error = $this->db->error();
3187 dol_syslog(get_class($this).
'::setDeliveryAddress Error '.$this->error);
3205 if (empty($userused)) {
3211 if (!$this->table_element) {
3212 dol_syslog(get_class($this).
"::setShippingMethod was called on object with property table_element not defined", LOG_ERR);
3218 if ($shipping_method_id < 0) {
3219 $shipping_method_id =
'NULL';
3221 dol_syslog(get_class($this).
'::setShippingMethod('.$shipping_method_id.
')');
3223 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3224 $sql .=
" SET fk_shipping_method = ".((int) $shipping_method_id);
3225 $sql .=
" WHERE rowid=".((int) $this->
id);
3226 $resql = $this->db->query($sql);
3228 dol_syslog(get_class($this).
'::setShippingMethod Error ', LOG_DEBUG);
3229 $this->error = $this->db->lasterror();
3234 $this->context = array(
'shippingmethodupdate' => 1);
3235 $result = $this->
call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
3243 $this->db->rollback();
3246 $this->shipping_method_id = ($shipping_method_id ==
'NULL') ?
null : $shipping_method_id;
3247 $this->db->commit();
3261 if (!$this->table_element) {
3262 dol_syslog(get_class($this).
"::setWarehouse was called on object with property table_element not defined", LOG_ERR);
3265 if ($warehouse_id < 0) {
3266 $warehouse_id =
'NULL';
3268 dol_syslog(get_class($this).
'::setWarehouse('.$warehouse_id.
')');
3270 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3271 $sql .=
" SET fk_warehouse = ".((int) $warehouse_id);
3272 $sql .=
" WHERE rowid=".((int) $this->
id);
3274 if ($this->db->query($sql)) {
3275 $this->warehouse_id = ($warehouse_id ==
'NULL') ?
null : $warehouse_id;
3278 dol_syslog(get_class($this).
'::setWarehouse Error ', LOG_DEBUG);
3279 $this->error = $this->db->error();
3294 if (!$this->table_element) {
3295 dol_syslog(get_class($this).
"::setDocModel was called on object with property table_element not defined", LOG_ERR);
3299 $newmodelpdf =
dol_trunc($modelpdf, 255);
3301 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3302 $sql .=
" SET model_pdf = '".$this->db->escape($newmodelpdf).
"'";
3303 $sql .=
" WHERE rowid = ".((int) $this->
id);
3305 dol_syslog(get_class($this).
"::setDocModel", LOG_DEBUG);
3306 $resql = $this->db->query($sql);
3308 $this->model_pdf = $modelpdf;
3329 if (empty($userused)) {
3335 if (!$this->table_element) {
3336 dol_syslog(get_class($this).
"::setBankAccount was called on object with property table_element not defined", LOG_ERR);
3341 if ($fk_account < 0) {
3342 $fk_account =
'NULL';
3344 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
3346 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3347 $sql .=
" SET fk_account = ".((int) $fk_account);
3348 $sql .=
" WHERE rowid=".((int) $this->
id);
3350 $resql = $this->db->query($sql);
3352 dol_syslog(get_class($this).
'::setBankAccount Error '.$sql.
' - '.$this->db->error());
3353 $this->error = $this->db->lasterror();
3358 $this->context[
'bankaccountupdate'] = 1;
3359 $triggerName = strtoupper(get_class($this)).
'_MODIFY';
3361 if ($triggerName ==
'FACTUREREC_MODIFY') {
3362 $triggerName =
'BILLREC_MODIFY';
3364 $result = $this->
call_trigger($triggerName, $userused);
3372 $this->db->rollback();
3375 $this->fk_account = ($fk_account ==
'NULL') ?
null : $fk_account;
3376 $this->db->commit();
3394 public function line_order($renum =
false, $rowidorder =
'ASC', $fk_parent_line =
true)
3397 if (!$this->table_element_line) {
3398 dol_syslog(get_class($this).
"::line_order was called on object with property table_element_line not defined", LOG_ERR);
3401 if (!$this->fk_element) {
3402 dol_syslog(get_class($this).
"::line_order was called on object with property fk_element not defined", LOG_ERR);
3406 $fieldposition =
'rang';
3407 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3408 $fieldposition =
'position';
3413 $sql =
"SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
3414 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3416 $sql .=
" AND " . $fieldposition .
" = 0";
3419 $sql .=
" AND " . $fieldposition .
" <> 0";
3422 dol_syslog(get_class($this).
"::line_order", LOG_DEBUG);
3423 $resql = $this->db->query($sql);
3425 $row = $this->db->fetch_row($resql);
3435 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3436 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3437 if ($fk_parent_line) {
3438 $sql .=
' AND fk_parent_line IS NULL';
3440 $sql .=
" ORDER BY " . $fieldposition .
" ASC, rowid " . $rowidorder;
3442 dol_syslog(get_class($this).
"::line_order search all parent lines", LOG_DEBUG);
3443 $resql = $this->db->query($sql);
3446 $num = $this->db->num_rows($resql);
3449 $row = $this->db->fetch_row($resql);
3451 if ($fk_parent_line) {
3454 if (!empty($children)) {
3455 foreach ($children as $child) {
3456 array_push($rows, $child);
3463 if (!empty($rows)) {
3464 foreach ($rows as $key => $row) {
3484 $fieldposition =
'rang';
3485 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3486 $fieldposition =
'position';
3491 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3492 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3493 $sql .=
' AND fk_parent_line = '.((int) $id);
3494 $sql .=
" ORDER BY " . $fieldposition .
" ASC";
3496 dol_syslog(get_class($this).
"::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
3498 $resql = $this->db->query($sql);
3499 if (!$resql || $this->db->num_rows($resql) <= 0) {
3503 while ($row = $this->db->fetch_row($resql)) {
3505 if (!empty($includealltree) && $includealltree <= 1000) {
3506 $rows = array_merge($rows, $this->
getChildrenOfLine($row[0], $includealltree + 1));
3520 public function line_up($rowid, $fk_parent_line =
true)
3523 $this->
line_order(
false,
'ASC', $fk_parent_line);
3543 $this->
line_order(
false,
'ASC', $fk_parent_line);
3564 global $hookmanager;
3565 $fieldposition =
'rang';
3566 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3567 $fieldposition =
'position';
3570 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3571 $sql .=
' WHERE rowid = '.((int) $rowid);
3573 dol_syslog(get_class($this).
"::updateRangOfLine", LOG_DEBUG);
3574 if (!$this->db->query($sql)) {
3579 $parameters = array(
'rowid' => $rowid,
'rang' => $rang,
'fieldposition' => $fieldposition);
3581 $reshook = $hookmanager->executeHooks(
'afterRankOfLineUpdate', $parameters, $this, $action);
3595 $num = count($rows);
3596 for ($i = 0; $i < $num; $i++) {
3614 $fieldposition =
'rang';
3615 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3616 $fieldposition =
'position';
3619 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3620 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3621 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang - 1));
3622 if (!$this->db->query($sql)) {
3623 $this->error = $this->db->lasterror();
3627 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang - 1));
3628 $sql .=
' WHERE rowid = '.((int) $rowid);
3629 if (!$this->db->query($sql)) {
3630 $this->error = $this->db->lasterror();
3647 if ($rang >= $max) {
3651 $fieldposition =
'rang';
3652 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3653 $fieldposition =
'position';
3656 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3657 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3658 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang + 1));
3659 if (!$this->db->query($sql)) {
3660 $this->error = $this->db->lasterror();
3664 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang + 1));
3665 $sql .=
' WHERE rowid = '.((int) $rowid);
3666 if (!$this->db->query($sql)) {
3667 $this->error = $this->db->lasterror();
3682 $fieldposition =
'rang';
3683 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3684 $fieldposition =
'position';
3687 $sql =
"SELECT " . $fieldposition .
" FROM ".$this->db->prefix().$this->table_element_line;
3688 $sql .=
" WHERE rowid = ".((int) $rowid);
3690 dol_syslog(get_class($this).
"::getRangOfLine", LOG_DEBUG);
3691 $resql = $this->db->query($sql);
3696 $row = $this->db->fetch_row($resql);
3708 $fieldposition =
'rang';
3709 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3710 $fieldposition =
'position';
3713 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3714 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3715 $sql .=
" AND " . $fieldposition .
" = ".((int) $rang);
3716 $resql = $this->db->query($sql);
3721 $row = $this->db->fetch_row($resql);
3735 $positionfield =
'rang';
3736 if (in_array($this->table_element, array(
'bom_bom',
'product_attribute'))) {
3737 $positionfield =
'position';
3740 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3741 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3744 if ($fk_parent_line) {
3745 $sql .=
" AND fk_parent_line = ".((int) $fk_parent_line);
3748 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3749 $resql = $this->db->query($sql);
3751 $row = $this->db->fetch_row($resql);
3753 if ($fk_parent_line) {
3754 if (!empty($row[0])) {
3777 if (!$this->table_element) {
3778 dol_syslog(get_class($this).
"::update_ref_ext was called on object with property table_element not defined", LOG_ERR);
3782 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3783 $sql .=
" SET ref_ext = '".$this->db->escape($ref_ext).
"'";
3785 $sql .=
" WHERE ".(isset($this->table_rowid) ? $this->table_rowid :
'rowid').
" = ".((
int) $this->id);
3787 dol_syslog(get_class($this).
"::update_ref_ext", LOG_DEBUG);
3788 if ($this->db->query($sql)) {
3789 $this->ref_ext = $ref_ext;
3792 $this->error = $this->db->error();
3811 if (!$this->table_element) {
3812 $this->error =
'update_note was called on object with property table_element not defined';
3813 dol_syslog(get_class($this).
"::update_note was called on object with property table_element not defined", LOG_ERR);
3816 if (!in_array($suffix, array(
'',
'_public',
'_private'))) {
3817 $this->error =
'update_note Parameter suffix must be empty, \'_private\' or \'_public\'';
3818 dol_syslog(get_class($this).
"::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
3822 $newsuffix = $suffix;
3825 if ($this->table_element ==
'product' && $newsuffix ==
'_private') {
3828 if (in_array($this->table_element, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
3829 $fieldusermod =
"fk_user_mod";
3830 } elseif ($this->table_element ==
'ecm_files') {
3831 $fieldusermod =
"fk_user_m";
3833 $fieldusermod =
"fk_user_modif";
3835 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3836 $sql .=
" SET note".$this->db->sanitize($newsuffix).
" = ".(!empty($note) ? (
"'".$this->db->escape($note).
"'") :
"NULL");
3837 $sql .=
", ".$this->db->sanitize($fieldusermod).
" = ".((int) $user->id);
3838 $sql .=
" WHERE rowid = ".((int) $this->
id);
3840 dol_syslog(get_class($this).
"::update_note", LOG_DEBUG);
3841 if ($this->db->query($sql)) {
3842 if ($suffix ==
'_public') {
3843 $this->note_public = $note;
3844 } elseif ($suffix ==
'_private') {
3845 $this->note_private = $note;
3847 $this->note = $note;
3848 $this->note_private = $note;
3850 if (empty($notrigger)) {
3851 switch ($this->element) {
3853 $trigger_name =
'COMPANY_MODIFY';
3856 $trigger_name =
'ORDER_MODIFY';
3859 $trigger_name =
'BILL_MODIFY';
3861 case 'invoice_supplier':
3862 $trigger_name =
'BILL_SUPPLIER_MODIFY';
3865 $trigger_name =
'BILLREC_MODIFIY';
3867 case 'expensereport':
3868 $trigger_name =
'EXPENSE_REPORT_MODIFY';
3871 $trigger_name = strtoupper($this->element) .
'_MODIFY';
3880 $this->error = $this->db->lasterror();
3911 public function update_price($exclspec = 0, $roundingadjust =
'auto', $nodatabaseupdate = 0, $seller =
null)
3914 global
$conf, $hookmanager, $action;
3916 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3917 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3920 } elseif ($reshook < 0) {
3925 $isElementForSupplier =
false;
3926 $roundTotalConstName =
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND';
3928 if ($this->element ==
'propal') {
3929 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3930 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3931 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3932 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3933 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3934 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3935 $isElementForSupplier =
true;
3936 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3937 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3938 $isElementForSupplier =
true;
3939 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3940 } elseif ($this->element ==
'supplier_proposal') {
3941 $isElementForSupplier =
true;
3942 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3944 if ($isElementForSupplier) {
3945 $roundTotalConstName =
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER';
3948 if (!empty($MODULE)) {
3951 foreach ($modsactivated as $mod) {
3952 if (isModEnabled($mod)) {
3959 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3961 $forcedroundingmode = $roundingadjust;
3962 if ($forcedroundingmode ==
'auto' && isset(
$conf->global->{$roundTotalConstName})) {
3964 } elseif ($forcedroundingmode ==
'auto') {
3965 $forcedroundingmode =
'0';
3970 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3973 $fieldtva =
'total_tva';
3974 $fieldlocaltax1 =
'total_localtax1';
3975 $fieldlocaltax2 =
'total_localtax2';
3976 $fieldup =
'subprice';
3977 $base_price_type =
'HT';
3978 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3982 if ($this->element ==
'invoice_supplier_rec') {
3985 if ($this->element ==
'expensereport') {
3989 $forcedroundingmode =
'0';
3990 $fieldup =
'value_unit';
3991 $base_price_type =
'TTC';
3994 $sql =
"SELECT rowid, qty, ".$this->db->sanitize($fieldup).
" as up, remise_percent, total_ht, ".$this->db->sanitize($fieldtva).
" as total_tva, total_ttc, ".$this->db->sanitize($fieldlocaltax1).
" as total_localtax1, ".$this->db->sanitize($fieldlocaltax2).
" as total_localtax2,";
3995 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3996 if ($this->table_element_line ==
'facturedet') {
3997 $sql .=
', situation_percent';
3999 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
4000 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
4001 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
4003 $product_field =
'product_type';
4004 if ($this->table_element_line ==
'contratdet') {
4005 $product_field =
'';
4007 if ($product_field) {
4008 $sql .=
" AND ".$product_field.
" <> 9";
4011 $sql .=
' ORDER by rowid';
4013 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
4015 $resql = $this->db->query($sql);
4017 $this->total_ht = 0;
4018 $this->total_tva = 0;
4019 $this->total_localtax1 = 0;
4020 $this->total_localtax2 = 0;
4021 $this->total_ttc = 0;
4022 $total_ht_by_vats = array();
4023 $total_tva_by_vats = array();
4024 $total_ttc_by_vats = array();
4025 $this->multicurrency_total_ht = 0;
4026 $this->multicurrency_total_tva = 0;
4027 $this->multicurrency_total_ttc = 0;
4031 $num = $this->db->num_rows($resql);
4034 $obj = $this->db->fetch_object($resql);
4037 $parameters = array(
'fk_element' => $obj->rowid);
4038 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
4040 if (empty($reshook) && $forcedroundingmode ==
'0') {
4042 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
4043 $tmpcal =
calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, $base_price_type, $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx);
4045 $diff_when_using_price_ht =
price2num((
float) $tmpcal[1] - $obj->total_tva,
'MT', 1);
4046 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
4050 if ($diff_on_current_total) {
4052 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line;
4053 $sqlfix .=
" SET ".$this->db->sanitize($fieldtva).
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]);
4054 $sqlfix .=
", multicurrency_total_tva = ".price2num((
float) $tmpcal[17]).
", multicurrency_total_ttc = ".
price2num((
float) $tmpcal[18]);
4055 $sqlfix .=
" WHERE rowid = ".((int) $obj->rowid);
4056 dol_syslog(
'Warn1: We found inconsistent data into detailed line (diff_on_current_total = '.$diff_on_current_total.
') for line rowid = '.$obj->rowid.
" (ht=".$obj->total_ht.
" vat=".$obj->total_tva.
" tax1=".$obj->total_localtax1.
" tax2=".$obj->total_localtax2.
" ttc=".$obj->total_ttc.
"). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix, LOG_WARNING);
4057 $resqlfix = $this->db->query($sqlfix);
4061 $obj->total_tva = $tmpcal[1];
4062 $obj->total_ttc = $tmpcal[2];
4063 $obj->multicurrency_total_tva = $tmpcal[17];
4064 $obj->multicurrency_total_ttc = $tmpcal[18];
4065 } elseif ($diff_when_using_price_ht) {
4068 if ((
float) $tmpcal[0] == (
float) $obj->total_ht) {
4073 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line;
4074 $sqlfix .=
" SET ".$this->db->sanitize($fieldtva).
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]);
4075 $sqlfix .=
", multicurrency_total_tva = ".price2num((
float) $tmpcal[17]).
", multicurrency_total_ttc = ".
price2num((
float) $tmpcal[18]);
4076 $sqlfix .=
" WHERE rowid = ".((int) $obj->rowid);
4077 dol_syslog(
'Warn2: We found a line with different rounding data into detailed line (diff_when_using_price_ht = '.$diff_when_using_price_ht.
' and diff_on_current_total = '.$diff_on_current_total.
') for line rowid = '.$obj->rowid.
" (total vat of line calculated=".$tmpcal[1].
", database=".$obj->total_tva.
"). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
4078 $resqlfix = $this->db->query($sqlfix);
4082 $obj->total_tva = $tmpcal[1];
4083 $obj->total_ttc = $tmpcal[2];
4084 $obj->multicurrency_total_tva = $tmpcal[17];
4085 $obj->multicurrency_total_ttc = $tmpcal[18];
4090 $this->total_ht += $obj->total_ht;
4091 $this->total_tva += $obj->total_tva;
4092 $this->total_localtax1 += $obj->total_localtax1;
4093 $this->total_localtax2 += $obj->total_localtax2;
4094 $this->total_ttc += $obj->total_ttc;
4095 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
4096 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
4097 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
4099 if (!isset($total_ht_by_vats[$obj->vatrate])) {
4100 $total_ht_by_vats[$obj->vatrate] = 0;
4102 if (!isset($total_tva_by_vats[$obj->vatrate])) {
4103 $total_tva_by_vats[$obj->vatrate] = 0;
4105 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
4106 $total_ttc_by_vats[$obj->vatrate] = 0;
4108 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
4109 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
4110 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
4112 if ($forcedroundingmode ==
'1') {
4113 if ($base_price_type ==
'TTC') {
4114 $tmpvat =
price2num($total_ttc_by_vats[$obj->vatrate] * $obj->vatrate / (100 + $obj->vatrate),
'MT', 1);
4116 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
4118 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - (
float) $tmpvat,
'MT', 1);
4121 $maxdiff = (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)));
4122 if (abs((
float) $diff) > $maxdiff) {
4124 $errmsg =
'We found a rounding difference after line '.($obj->rowid).
' between HT*VAT='.$tmpvat.
' and total in database='.$total_tva_by_vats[$obj->vatrate].
' (calculated with UP*qty) but diff='.$diff.
' is too high (> '.$maxdiff.
') to be corrected. Some data in your lines may be corrupted. Try to edit each line manually to fix this before restarting.';
4126 $this->error = $errmsg;
4131 if ($base_price_type ==
'TTC') {
4132 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$this->db->sanitize($fieldtva).
" = ".
price2num($obj->total_tva - (
float) $diff).
", total_ht = ".
price2num($obj->total_ht + (
float) $diff).
" WHERE rowid = ".((int) $obj->rowid);
4133 dol_syslog(
'We found a difference of '.$diff.
' for line rowid = '.$obj->rowid.
' between TotalHT('.$total_ht_by_vats[$obj->vatrate].
')*VATrate('.$obj->vatrate.
')='.$tmpvat.
' and total in database='.$total_tva_by_vats[$obj->vatrate].
" (calculated with UP*qty). We fix the total_vat and total_ht of line by running sqlfix = ".$sqlfix);
4135 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$this->db->sanitize($fieldtva).
" = ".
price2num($obj->total_tva - (
float) $diff).
", total_ttc = ".
price2num($obj->total_ttc - (
float) $diff).
" WHERE rowid = ".((int) $obj->rowid);
4136 dol_syslog(
'We found a difference of '.$diff.
' for line rowid = '.$obj->rowid.
' between TotalHT('.$total_ht_by_vats[$obj->vatrate].
')*VATrate('.$obj->vatrate.
')='.$tmpvat.
' and total in database='.$total_tva_by_vats[$obj->vatrate].
" (calculated with UP*qty). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
4139 $resqlfix = $this->db->query($sqlfix);
4145 $this->total_tva = (float)
price2num($this->total_tva - (
float) $diff,
'', 1);
4146 $total_tva_by_vats[$obj->vatrate] = (float)
price2num($total_tva_by_vats[$obj->vatrate] - (
float) $diff,
'', 1);
4147 if ($base_price_type ==
'TTC') {
4148 $this->total_ht = (float)
price2num($this->total_ht + (
float) $diff,
'', 1);
4149 $total_ht_by_vats[$obj->vatrate] = (float)
price2num($total_ht_by_vats[$obj->vatrate] + (
float) $diff,
'', 1);
4151 $this->total_ttc = (float)
price2num($this->total_ttc - (
float) $diff,
'', 1);
4152 $total_ttc_by_vats[$obj->vatrate] = (float)
price2num($total_ttc_by_vats[$obj->vatrate] - (
float) $diff,
'', 1);
4162 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
4164 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
4167 if (!empty($this->situation_cycle_ref) && !empty($this->situation_counter) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits')) {
4168 '@phan-var-force Facture $this';
4169 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4172 $prev_sits = $this->get_prev_sits();
4174 foreach ($prev_sits as $sit) {
4175 $this->total_ht -= $sit->total_ht;
4176 $this->total_tva -= $sit->total_tva;
4177 $this->total_localtax1 -= $sit->total_localtax1;
4178 $this->total_localtax2 -= $sit->total_localtax2;
4179 $this->total_ttc -= $sit->total_ttc;
4180 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
4181 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
4182 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
4189 $this->total_ht = (float)
price2num($this->total_ht);
4190 $this->total_tva = (float)
price2num($this->total_tva);
4191 $this->total_localtax1 = (float)
price2num($this->total_localtax1);
4192 $this->total_localtax2 = (float)
price2num($this->total_localtax2);
4193 $this->total_ttc = (float)
price2num($this->total_ttc);
4195 $this->db->free($resql);
4198 $fieldht =
'total_ht';
4200 $fieldlocaltax1 =
'localtax1';
4201 $fieldlocaltax2 =
'localtax2';
4202 $fieldttc =
'total_ttc';
4204 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
4205 $fieldtva =
'total_tva';
4208 if (!$error && empty($nodatabaseupdate)) {
4209 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
4210 $sql .=
" ".$this->db->sanitize($fieldht).
" = ".((float)
price2num($this->total_ht,
'MT', 1)).
",";
4211 $sql .=
" ".$this->db->sanitize($fieldtva).
" = ".((float)
price2num($this->total_tva,
'MT', 1)).
",";
4212 $sql .=
" ".$this->db->sanitize($fieldlocaltax1).
" = ".((float)
price2num($this->total_localtax1,
'MT', 1)).
",";
4213 $sql .=
" ".$this->db->sanitize($fieldlocaltax2).
" = ".((float)
price2num($this->total_localtax2,
'MT', 1)).
",";
4214 $sql .=
" ".$this->db->sanitize($fieldttc).
" = ".((float)
price2num($this->total_ttc,
'MT', 1));
4215 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
4216 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
4217 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
4218 $sql .=
" WHERE rowid = ".((int) $this->
id);
4220 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
4221 $resql = $this->db->query($sql);
4225 $this->error = $this->db->lasterror();
4226 $this->errors[] = $this->db->lasterror();
4231 $this->db->commit();
4234 $this->db->rollback();
4254 public function add_object_linked($origin =
null, $origin_id =
null, $f_user =
null, $notrigger = 0)
4257 global $user, $hookmanager, $action;
4259 if (empty($this->origin_type) && !empty($this->origin)) {
4260 $this->origin_type = $this->origin;
4262 $origin = (!empty($origin) ? $origin : $this->origin_type);
4263 $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
4264 $f_user = isset($f_user) ? $f_user : $user;
4267 if ($origin ==
'order') {
4268 $origin =
'commande';
4270 if ($origin ==
'invoice') {
4271 $origin =
'facture';
4273 if ($origin ==
'invoice_template') {
4274 $origin =
'facturerec';
4276 if ($origin ==
'supplierorder') {
4277 $origin =
'order_supplier';
4281 $targettype = $this->getElementType();
4283 $parameters = array(
'targettype' => $targettype);
4285 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
4287 if (!empty($hookmanager->resArray[
'targettype'])) {
4288 $targettype = $hookmanager->resArray[
'targettype'];
4295 $sql =
"INSERT INTO " . $this->db->prefix() .
"element_element (";
4296 $sql .=
"fk_source";
4297 $sql .=
", sourcetype";
4298 $sql .=
", fk_target";
4299 $sql .=
", targettype";
4300 $sql .=
") VALUES (";
4301 $sql .= ((int) $origin_id);
4302 $sql .=
", '" . $this->db->escape($origin) .
"'";
4303 $sql .=
", " . ((int) $this->
id);
4304 $sql .=
", '" . $this->db->escape($targettype) .
"'";
4307 dol_syslog(get_class($this) .
"::add_object_linked", LOG_DEBUG);
4308 if ($this->db->query($sql)) {
4311 $this->context[
'link_origin'] = $origin;
4312 $this->context[
'link_origin_id'] = $origin_id;
4313 $result = $this->call_trigger(
'OBJECT_LINK_INSERT', $f_user);
4320 $this->error = $this->db->lasterror();
4325 $this->db->commit();
4328 $this->db->rollback();
4342 $coreModule = array(
'knowledgemanagement',
'partnership',
'workstation',
'ticket',
'recruitment',
'eventorganization',
'asset');
4344 return ((!empty($this->module) && !in_array($this->module, $coreModule)) ? $this->module.
'_' :
'').$this->element;
4370 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
4372 global $hookmanager, $action;
4377 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4381 $this->linkedObjectsIds = array();
4382 $this->linkedObjects = array();
4384 $justsource =
false;
4385 $justtarget =
false;
4386 $withtargettype =
false;
4387 $withsourcetype =
false;
4390 if (is_object($hookmanager)) {
4391 $parameters = array(
'sourcetype' => $sourcetype,
'sourceid' => $sourceid,
'targettype' => $targettype,
'targetid' => $targetid);
4392 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
4394 if (!empty($hookmanager->resArray[
'sourcetype'])) {
4395 $sourcetype = $hookmanager->resArray[
'sourcetype'];
4397 if (!empty($hookmanager->resArray[
'sourceid'])) {
4398 $sourceid = $hookmanager->resArray[
'sourceid'];
4400 if (!empty($hookmanager->resArray[
'targettype'])) {
4401 $targettype = $hookmanager->resArray[
'targettype'];
4403 if (!empty($hookmanager->resArray[
'targetid'])) {
4404 $targetid = $hookmanager->resArray[
'targetid'];
4409 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
4411 if (!empty($targettype)) {
4412 $withtargettype =
true;
4415 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
4417 if (!empty($sourcetype)) {
4418 $withsourcetype =
true;
4422 $sourceid = (!empty($sourceid) ? $sourceid :
$this->id);
4423 $targetid = (!empty($targetid) ? $targetid :
$this->id);
4424 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->getElementType());
4425 $targettype = (!empty($targettype) ? $targettype : $this->getElementType());
4434 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
4435 $sql .=
" FROM ".$this->db->prefix().
"element_element";
4437 if ($justsource || $justtarget) {
4439 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4440 if ($withtargettype) {
4441 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
4443 } elseif ($justtarget) {
4444 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
4445 if ($withsourcetype) {
4446 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4450 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
4451 $sql .=
" ".$this->db->sanitize($clause).
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
4452 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
4453 $this->linkedObjectsFullLoaded[
$this->id] =
true;
4456 $sql .=
" ORDER BY ".$orderby;
4458 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
4459 $resql = $this->db->query($sql);
4461 $num = $this->db->num_rows($resql);
4464 $obj = $this->db->fetch_object($resql);
4465 if ($justsource || $justtarget) {
4467 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4468 } elseif ($justtarget) {
4469 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4472 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
4473 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4475 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
4476 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4482 if (!empty($this->linkedObjectsIds)) {
4483 $tmparray = $this->linkedObjectsIds;
4484 foreach ($tmparray as $objecttype => $objectids) {
4486 $element = $element_properties[
'element'];
4487 $classPath = $element_properties[
'classpath'];
4488 $classFile = $element_properties[
'classfile'];
4489 $className = $element_properties[
'classname'];
4490 $module = $element_properties[
'module'];
4493 if (isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4494 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4496 if (class_exists($className)) {
4497 foreach ($objectids as $i => $objectid) {
4498 $object =
new $className($this->db);
4499 '@phan-var-force CommonObject $object';
4500 $ret =
$object->fetch($objectid);
4502 $this->linkedObjects[$objecttype][$i] =
$object;
4508 unset($this->linkedObjectsIds[$objecttype]);
4527 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4528 unset($this->linkedObjectsFullLoaded[$this->
id]);
4546 public function updateObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $f_user =
null, $notrigger = 0)
4549 $updatesource =
false;
4550 $updatetarget =
false;
4551 $f_user = isset($f_user) ? $f_user : $user;
4553 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4554 $updatesource =
true;
4555 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4556 $updatetarget =
true;
4562 $sql =
"UPDATE " . $this->db->prefix() .
"element_element SET ";
4563 if ($updatesource) {
4564 $sql .=
"fk_source = " . ((int) $sourceid);
4565 $sql .=
", sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4566 $sql .=
" WHERE fk_target = " . ((int) $this->
id);
4567 $sql .=
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4568 } elseif ($updatetarget) {
4569 $sql .=
"fk_target = " . ((int) $targetid);
4570 $sql .=
", targettype = '" . $this->db->escape($targettype) .
"'";
4571 $sql .=
" WHERE fk_source = " . ((int) $this->
id);
4572 $sql .=
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4575 dol_syslog(get_class($this) .
"::updateObjectLinked", LOG_DEBUG);
4576 if ($this->db->query($sql)) {
4579 $this->context[
'link_source_id'] = $sourceid;
4580 $this->context[
'link_source_type'] = $sourcetype;
4581 $this->context[
'link_target_id'] = $targetid;
4582 $this->context[
'link_target_type'] = $targettype;
4583 $result = $this->call_trigger(
'OBJECT_LINK_MODIFY', $f_user);
4590 $this->error = $this->db->lasterror();
4595 $this->db->commit();
4598 $this->db->rollback();
4616 public function deleteObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $rowid = 0, $f_user =
null, $notrigger = 0)
4619 $deletesource =
false;
4620 $deletetarget =
false;
4621 $f_user = isset($f_user) ? $f_user : $user;
4623 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4624 $deletesource =
true;
4625 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4626 $deletetarget =
true;
4629 $element = $this->getElementType();
4630 $sourceid = (!empty($sourceid) ? $sourceid :
$this->id);
4631 $sourcetype = (!empty($sourcetype) ? $sourcetype : $element);
4632 $targetid = (!empty($targetid) ? $targetid :
$this->id);
4633 $targettype = (!empty($targettype) ? $targettype : $element);
4639 $this->context[
'link_id'] = $rowid;
4640 $this->context[
'link_source_id'] = $sourceid;
4641 $this->context[
'link_source_type'] = $sourcetype;
4642 $this->context[
'link_target_id'] = $targetid;
4643 $this->context[
'link_target_type'] = $targettype;
4644 $result = $this->call_trigger(
'OBJECT_LINK_DELETE', $f_user);
4652 $sql =
"DELETE FROM " . $this->db->prefix() .
"element_element";
4655 $sql .=
" rowid = " . ((int) $rowid);
4657 if ($deletesource) {
4658 $sql .=
" fk_source = " . ((int) $sourceid) .
" AND sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4659 $sql .=
" AND fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($element) .
"'";
4660 } elseif ($deletetarget) {
4661 $sql .=
" fk_target = " . ((int) $targetid) .
" AND targettype = '" . $this->db->escape($targettype) .
"'";
4662 $sql .=
" AND fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($element) .
"'";
4664 $sql .=
" (fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($element) .
"')";
4666 $sql .=
" (fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($element) .
"')";
4670 dol_syslog(get_class($this) .
"::deleteObjectLinked", LOG_DEBUG);
4671 if (!$this->db->query($sql)) {
4672 $this->error = $this->db->lasterror();
4673 $this->errors[] = $this->error;
4679 $this->db->commit();
4682 $this->db->rollback();
4698 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4701 if (!preg_match(
'/^[_a-zA-Z0-9]+$/', $field_select)) {
4702 dol_syslog(
'Invalid value $field_select for parameter '.$field_select.
' in call to getAllItemsLinkedByObjectID(). Must be a single field name.', LOG_ERR);
4707 $sql =
"SELECT ".$field_select.
" FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4708 $resql = $db->query($sql);
4711 if (!empty($resql)) {
4712 while ($res = $db->fetch_object($resql)) {
4713 $TRes[] = $res->{$field_select};
4730 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4736 $sql =
"SELECT COUNT(*) as nb FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4737 $resql = $db->query($sql);
4740 $res = $db->fetch_object($resql);
4759 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4765 $sql =
"DELETE FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4766 $resql = $db->query($sql);
4768 if (empty($resql)) {
4785 public function setStatut($status, $elementId =
null, $elementType =
'', $trigkey =
'', $fieldstatus =
'fk_statut')
4789 $savElementId = $elementId;
4791 $elementId = (!empty($elementId) ? $elementId :
$this->id);
4792 $elementTable = (!empty($elementType) ? $elementType : $this->table_element);
4796 if ($elementTable ==
'facture_rec') {
4797 $fieldstatus =
"suspended";
4799 if ($elementTable ==
'mailing') {
4800 $fieldstatus =
"statut";
4802 if ($elementTable ==
'cronjob') {
4803 $fieldstatus =
"status";
4805 if ($elementTable ==
'user') {
4806 $fieldstatus =
"statut";
4808 if ($elementTable ==
'expensereport') {
4809 $fieldstatus =
"fk_statut";
4811 if ($elementTable ==
'receptiondet_batch') {
4812 $fieldstatus =
"status";
4814 if ($elementTable ==
'prelevement_bons') {
4815 $fieldstatus =
"statut";
4817 if (isset($this->fields) && is_array($this->fields) && array_key_exists(
'status', $this->fields)) {
4818 $fieldstatus =
'status';
4821 $sql =
"UPDATE ".$this->db->prefix().$this->db->sanitize($elementTable);
4822 $sql .=
" SET ".$this->db->sanitize($fieldstatus).
" = ".((int) $status);
4825 if ($status == 1 && in_array($elementTable, array(
'expensereport',
'inventory'))) {
4826 $sql .=
", fk_user_valid = ".((int) $user->id);
4828 if ($status == 1 && in_array($elementTable, array(
'expensereport'))) {
4829 $sql .=
", date_valid = '".$this->db->idate(
dol_now()).
"'";
4831 if ($status == 1 && in_array($elementTable, array(
'inventory'))) {
4832 $sql .=
", date_validation = '".$this->db->idate(
dol_now()).
"'";
4834 $sql .=
" WHERE rowid = ".((int) $elementId);
4835 $sql .=
" AND ".$fieldstatus.
" <> ".((int) $status);
4837 dol_syslog(get_class($this).
"::setStatut", LOG_DEBUG);
4838 $resql = $this->db->query($sql);
4842 $nb_rows_affected = $this->db->affected_rows($resql);
4844 if ($nb_rows_affected > 0) {
4845 if (empty($trigkey)) {
4847 if ($this->element ==
'supplier_proposal' && $status == 2) {
4848 $trigkey =
'SUPPLIER_PROPOSAL_SIGN';
4850 if ($this->element ==
'supplier_proposal' && $status == 3) {
4851 $trigkey =
'SUPPLIER_PROPOSAL_REFUSE';
4853 if ($this->element ==
'supplier_proposal' && $status == 4) {
4854 $trigkey =
'SUPPLIER_PROPOSAL_CLOSE';
4856 if ($this->element ==
'fichinter' && $status == 3) {
4857 $trigkey =
'FICHINTER_CLASSIFY_DONE';
4859 if ($this->element ==
'fichinter' && $status == 2) {
4860 $trigkey =
'FICHINTER_CLASSIFY_BILLED';
4862 if ($this->element ==
'fichinter' && $status == 1) {
4863 $trigkey =
'FICHINTER_CLASSIFY_UNBILLED';
4867 $this->context = array_merge($this->context, array(
'newstatus' => $status));
4873 $result = $this->call_trigger($trigkey, $user);
4884 $this->db->commit();
4886 if (empty($savElementId)) {
4888 if ($fieldstatus ==
'tosell') {
4890 } elseif ($fieldstatus ==
'tobuy') {
4891 $this->status_buy = $status;
4892 } elseif ($fieldstatus ==
'tobatch') {
4893 $this->status_batch = $status;
4901 $this->db->rollback();
4902 dol_syslog(get_class($this).
"::setStatut ".$this->error, LOG_ERR);
4906 $this->error = $this->db->lasterror();
4907 $this->db->rollback();
4922 if (empty(
$id) && empty($ref)) {
4932 $sql =
"SELECT rowid, canvas";
4933 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
4934 $sql .=
" WHERE entity IN (".getEntity($this->element).
")";
4936 $sql .=
" AND rowid = ".((int)
$id);
4939 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
4942 $resql = $this->db->query($sql);
4944 $obj = $this->db->fetch_object($resql);
4946 $this->canvas = $obj->canvas;
4966 $sql =
"SELECT special_code FROM ".$this->db->prefix().$this->table_element_line;
4967 $sql .=
" WHERE rowid = ".((int) $lineid);
4968 $resql = $this->db->query($sql);
4970 $row = $this->db->fetch_row($resql);
4971 return (!empty($row[0]) ? $row[0] : 0);
4994 if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
4995 dol_print_error(
null,
'Called isObjectUsed on a class with property this->childtables not defined');
4999 $arraytoscan = $this->childtables;
5001 $tmparray = array_keys($this->childtables);
5002 if (is_numeric($tmparray[0])) {
5003 $arraytoscan = array_flip($this->childtables);
5008 foreach ($arraytoscan as $table => $element) {
5012 if (isset($element[
'enabled']) && !empty($element[
'enabled'])) {
5013 $enabled = (int)
dol_eval((
string) $element[
'enabled'], 1);
5014 if (empty($enabled)) {
5020 $sql =
"SELECT COUNT(*) as nb";
5021 $sql .=
" FROM ".$this->db->prefix().$table.
" as c";
5022 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
5023 $sql .=
", ".$this->db->prefix().$element[
'parent'].
" as p";
5025 if (!empty($element[
'fk_element'])) {
5026 $sql .=
" WHERE c.".$element[
'fk_element'].
" = ".((int)
$id);
5028 $sql .=
" WHERE c.".$this->fk_element.
" = ".((int)
$id);
5030 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
5031 $sql .=
" AND c.".$element[
'parentkey'].
" = p.rowid";
5033 if (!empty($element[
'parent']) && !empty($element[
'parenttypefield']) && !empty($element[
'parenttypevalue'])) {
5034 $sql .=
" AND c.".$element[
'parenttypefield'].
" = '".$this->db->escape($element[
'parenttypevalue']).
"'";
5036 if (!empty($entity)) {
5037 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
5038 $sql .=
" AND p.entity = ".((int) $entity);
5040 $sql .=
" AND c.entity = ".((int) $entity);
5044 $resql = $this->db->query($sql);
5046 $obj = $this->db->fetch_object($resql);
5048 $langs->load(
"errors");
5050 $haschild += $obj->nb;
5051 if (is_numeric($element)) {
5052 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
5053 } elseif (is_string($element)) {
5054 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element));
5056 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element[
'name']));
5061 $this->errors[] = $this->db->lasterror();
5065 if ($haschild > 0) {
5066 $this->errors[] =
"ErrorRecordHasChildren";
5083 foreach ($this->lines as $key => $val) {
5085 if ($predefined == -1) {
5088 if ($predefined == 1 && $val->fk_product > 0) {
5091 if ($predefined == 0 && $val->fk_product <= 0) {
5094 if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
5097 if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
5104 dol_syslog(get_class($this).
'::hasProductsOrServices we found '.$nb.
' qualified lines of products/servcies');
5115 if (!empty($this->table_element_line) && ($this->table_element_line !=
'expeditiondet')) {
5116 $total_discount = 0.00;
5118 $sql =
"SELECT subprice as pu_ht, qty, remise_percent, total_ht";
5119 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
5120 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
5122 dol_syslog(get_class($this).
'::getTotalDiscount', LOG_DEBUG);
5123 $resql = $this->db->query($sql);
5125 $num = $this->db->num_rows($resql);
5128 $obj = $this->db->fetch_object($resql);
5130 $pu_ht = $obj->pu_ht;
5132 $total_ht = $obj->total_ht;
5134 $total_discount_line = (float)
price2num(($pu_ht * $qty) - $total_ht,
'MT');
5135 $total_discount += $total_discount_line;
5142 return (
float)
price2num($total_discount);
5164 if (empty($this->lines)) {
5165 return array(
'weight' => $totalWeight,
'volume' => $totalVolume,
'ordered' => $totalOrdered,
'toship' => $totalToShip);
5168 foreach ($this->lines as $line) {
5169 if (isset($line->qty_asked)) {
5170 $totalOrdered += $line->qty_asked;
5172 if (isset($line->qty_shipped)) {
5173 $totalToShip += $line->qty_shipped;
5174 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
5175 if (empty($totalToShip)) {
5178 $totalToShip += $line->qty;
5182 if ($this->element ==
'shipping') {
5184 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
5186 $qty = $line->qty ? $line->qty : 0;
5189 $weight = !empty($line->weight) ? $line->weight : 0;
5190 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
5191 $volume = !empty($line->volume) ? $line->volume : 0;
5192 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
5194 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
5195 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
5196 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
5197 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
5201 if (!empty($weight_units)) {
5202 $weightUnit = $weight_units;
5204 if (!empty($volume_units)) {
5205 $volumeUnit = $volume_units;
5208 if (empty($totalWeight)) {
5211 if (empty($totalVolume)) {
5216 if ($weight_units < 50) {
5217 $trueWeightUnit = pow(10, $weightUnit);
5218 $totalWeight += $weight * $qty * $trueWeightUnit;
5220 if ($weight_units == 99) {
5222 $trueWeightUnit = 0.45359237;
5223 $totalWeight += $weight * $qty * $trueWeightUnit;
5224 } elseif ($weight_units == 98) {
5226 $trueWeightUnit = 0.0283495;
5227 $totalWeight += $weight * $qty * $trueWeightUnit;
5229 $totalWeight += $weight * $qty;
5232 if ($volume_units < 50) {
5234 $trueVolumeUnit = pow(10, $volumeUnit);
5236 $totalVolume += $volume * $qty * $trueVolumeUnit;
5238 $totalVolume += $volume * $qty;
5242 return array(
'weight' => $totalWeight,
'volume' => $totalVolume,
'ordered' => $totalOrdered,
'toship' => $totalToShip);
5255 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
5256 $extraparams =
dol_trunc($extraparams, 250);
5258 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
5259 $sql .=
" SET extraparams = ".(!empty($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null");
5260 $sql .=
" WHERE rowid = ".((int) $this->
id);
5262 dol_syslog(get_class($this).
"::setExtraParameters", LOG_DEBUG);
5263 $resql = $this->db->query($sql);
5265 $this->error = $this->db->lasterror();
5266 $this->db->rollback();
5269 $this->db->commit();
5292 global
$conf, $user, $langs,
$object, $hookmanager, $extrafields, $form;
5295 if (!is_object($extrafields)) {
5296 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5299 $extrafields->fetch_name_optionals_label($this->table_element_line);
5304 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5305 foreach ($dirtpls as $module => $reldir) {
5306 if (!empty($module)) {
5309 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_create.tpl.php';
5312 if (empty(
$conf->file->strict_mode)) {
5313 $res = @include $tpl;
5315 $res = include $tpl;
5342 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
5344 global
$conf, $hookmanager, $langs, $user, $form, $extrafields,
$object;
5346 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
5350 if (isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
5354 $num = count($this->lines);
5357 if (!is_object($extrafields)) {
5358 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5361 $extrafields->fetch_name_optionals_label($this->table_element_line);
5363 if (method_exists($this,
'loadExpeditions')) {
5365 $this->loadExpeditions();
5368 $parameters = array();
5369 $reshook = $hookmanager->executeHooks(
'printObjectLinesBlock', $parameters, $this, $action);
5370 if (empty($reshook)) {
5371 $parameters = array(
'num' => $num,
'dateSelector' => $dateSelector,
'seller' => $seller,
'buyer' => $buyer,
'selected' => $selected,
'table_element_line' => $this->table_element_line);
5372 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
5373 if (empty($reshook)) {
5377 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5378 foreach ($dirtpls as $module => $reldir) {
5380 if (!empty($module)) {
5383 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
5385 if (file_exists($tpl)) {
5386 if (empty(
$conf->file->strict_mode)) {
5387 $res = @include $tpl;
5389 $res = include $tpl;
5400 print
"<!-- begin printObjectLines() -->\n";
5401 foreach ($this->lines as $line) {
5405 if (is_object($hookmanager)) {
5406 if (empty($line->fk_parent_line)) {
5407 $parameters = array(
'line' => $line,
'num' => $num,
'i' => $i,
'dateSelector' => $dateSelector,
'seller' => $seller,
'buyer' => $buyer,
'selected' => $selected,
'table_element_line' => $line->table_element,
'defaulttpldir' => $defaulttpldir);
5408 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
5410 $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,
'defaulttpldir' => $defaulttpldir);
5411 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
5414 if (empty($reshook)) {
5415 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
5420 print
"<!-- end printObjectLines() -->\n";
5441 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
5445 global $disableedit, $disablemove, $disableremove;
5452 if ($action !=
'editline' || $selected != $line->id) {
5454 if (!empty($line->fk_product) && $line->fk_product > 0) {
5455 $product_static =
new Product($this->db);
5456 $product_static->fetch($line->fk_product);
5458 $product_static->ref = $line->ref;
5459 $product_static->label = !empty($line->label) ? $line->label :
"";
5461 $text = $product_static->getNomUrl(1);
5466 if (property_exists($this,
'socid') && !empty($this->socid) && !is_object($this->thirdparty)) {
5467 dol_print_error(
null,
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
5471 $prod =
new Product($this->db);
5472 $prod->fetch($line->fk_product);
5474 $outputlangs = $langs;
5476 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
5477 $newlang =
GETPOST(
'lang_id',
'aZ09');
5479 if (
getDolGlobalString(
'PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE') && empty($newlang) && is_object($this->thirdparty)) {
5480 $newlang = $this->thirdparty->default_lang;
5482 if (!empty($newlang)) {
5484 $outputlangs->setDefaultLang($newlang);
5487 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5489 $label = $line->product_label;
5492 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5493 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5496 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5503 if (isset($this->expeditions[$line->id])) {
5504 $qty_shipped = $this->expeditions[$line->id];
5506 $disableedit = ($qty_shipped > 0) && ($qty_shipped >= $line->qty);
5508 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5509 foreach ($dirtpls as $module => $reldir) {
5511 if (!empty($module)) {
5514 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5517 if (file_exists($tpl)) {
5518 if (empty(
$conf->file->strict_mode)) {
5519 $res = @include $tpl;
5521 $res = include $tpl;
5531 if ($this->
status == 0 && $action ==
'editline' && $selected == $line->id) {
5532 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5534 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5539 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5540 foreach ($dirtpls as $module => $reldir) {
5541 if (!empty($module)) {
5544 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5547 if (empty(
$conf->file->strict_mode)) {
5548 $res = @include $tpl;
5550 $res = include $tpl;
5575 global $langs, $hookmanager, $form, $action;
5577 print
'<!-- printOriginLinesList '.get_class($this).
' -->'.
"\n";
5578 print
'<tr class="liste_titre">';
5579 print
'<td class="linecolref">'.$langs->trans(
'Ref').
'</td>';
5580 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
5581 print
'<td class="linecolvat right">'.$langs->trans(
'VATRate').
'</td>';
5582 print
'<td class="linecoluht right">'.$langs->trans(
'PriceUHT').
'</td>';
5583 if (isModEnabled(
"multicurrency")) {
5584 print
'<td class="linecoluht_currency right">'.$langs->trans(
'PriceUHTCurrency').
'</td>';
5586 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
5588 print
'<td class="linecoluseunit left">'.$langs->trans(
'Unit').
'</td>';
5590 print
'<td class="linecoldiscount right">'.$langs->trans(
'ReductionShort').
'</td>';
5591 print
'<td class="linecolht right">'.$langs->trans(
'TotalHT').
'</td>';
5592 print
'<td class="center">';
5593 print $form->showCheckAddButtons(
'checkforselect', 1);
5598 if (!empty($this->lines)) {
5599 foreach ($this->lines as $line) {
5602 if (is_object($hookmanager)) {
5603 $parameters = array(
'line' => $line,
'i' => $i,
'restrictlist' => $restrictlist,
'selectedLines' => $selectedLines);
5604 if (!empty($line->fk_parent_line)) {
5605 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
5607 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
5609 if (empty($reshook)) {
5610 $this->printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
5631 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5633 global $langs,
$conf;
5636 if (!empty($line->date_start)) {
5638 $date_start = $line->date_start;
5640 $date_start = $line->date_debut_prevue;
5641 if ($line->date_debut_reel) {
5642 $date_start = $line->date_debut_reel;
5645 if (!empty($line->date_end)) {
5647 $date_end = $line->date_end;
5649 $date_end = $line->date_fin_prevue;
5650 if ($line->date_fin_reel) {
5651 $date_end = $line->date_fin_reel;
5656 $this->tpl[
'id'] = $line->id;
5658 $this->tpl[
'label'] =
'';
5659 if (!empty($line->fk_parent_line)) {
5660 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5663 if (($line->info_bits & 2) == 2) {
5665 if (property_exists($this,
'socid')) {
5666 $discount->fk_soc = $this->socid;
5667 $discount->socid = $this->socid;
5669 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5670 } elseif (!empty($line->fk_product)) {
5671 $productstatic =
new Product($this->db);
5672 $productstatic->id = $line->fk_product;
5673 $productstatic->ref = $line->ref;
5674 $productstatic->type = $line->fk_product_type;
5675 if (empty($productstatic->ref)) {
5676 $line->fetch_product();
5677 $productstatic = $line->product;
5680 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
5681 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5683 if ($line->product_type == 1 && ($date_start || $date_end)) {
5687 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
'Service'),
'service',
'class="pictofixedwidth"') :
img_object($langs->trans(
'Product'),
'product',
'class="pictofixedwidth"')));
5688 if (!empty($line->desc)) {
5689 $this->tpl[
'label'] .= $line->desc;
5691 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5695 if ($line->product_type == 1 && ($date_start || $date_end)) {
5700 if (!empty($line->desc)) {
5701 '@phan-var-force OrderLine|FactureLigne|ContratLigne|FactureFournisseurLigneRec|SupplierInvoiceLine|SupplierProposalLine $line';
5702 if ($line->desc ==
'(CREDIT_NOTE)') {
5704 $discount->fetch($line->fk_remise_except);
5705 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5706 } elseif ($line->desc ==
'(DEPOSIT)') {
5708 $discount->fetch($line->fk_remise_except);
5709 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5710 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5712 $discount->fetch($line->fk_remise_except);
5713 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5714 } elseif ($line->desc ==
'(EXCESS PAID)') {
5716 $discount->fetch($line->fk_remise_except);
5717 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5719 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5722 $this->tpl[
'description'] =
' ';
5726 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5727 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5728 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5729 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5732 $this->tpl[
'price'] =
price($line->subprice);
5733 $this->tpl[
'total_ht'] =
price($line->total_ht);
5734 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5735 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5737 $this->tpl[
'unit'] = $line->getLabelOfUnit(
'long', $langs);
5738 $this->tpl[
'unit_short'] = $line->getLabelOfUnit(
'short', $langs);
5741 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate((
string) $line->remise_percent,
true) :
' ';
5744 $this->tpl[
'strike'] = 0;
5746 $this->tpl[
'strike'] = 1;
5747 } elseif ($line->special_code == SUBTOTALS_SPECIAL_CODE) {
5748 $this->tpl[
'strike'] = 1;
5753 $dirtpls = array_merge(
$conf->modules_parts[
'tpl'], array($defaulttpldir));
5754 foreach ($dirtpls as $module => $reldir) {
5755 if (!empty($module)) {
5758 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5761 if (empty(
$conf->file->strict_mode)) {
5762 $res = @include $tpl;
5764 $res = include $tpl;
5789 $sql =
"INSERT INTO ".$this->db->prefix().
"element_resources (";
5790 $sql .=
"resource_id";
5791 $sql .=
", resource_type";
5792 $sql .=
", element_id";
5793 $sql .=
", element_type";
5795 $sql .=
", mandatory";
5796 $sql .=
") VALUES (";
5797 $sql .= ((int) $resource_id);
5798 $sql .=
", '".$this->db->escape($resource_type).
"'";
5799 $sql .=
", '".$this->db->escape((
string) $this->
id).
"'";
5800 $sql .=
", '".$this->db->escape($this->element).
"'";
5801 $sql .=
", '".$this->db->escape((
string) $busy).
"'";
5802 $sql .=
", '".$this->db->escape((
string) $mandatory).
"'";
5805 dol_syslog(get_class($this).
"::add_element_resource", LOG_DEBUG);
5806 if ($this->db->query($sql)) {
5807 $this->db->commit();
5810 $this->error = $this->db->lasterror();
5811 $this->db->rollback();
5832 $sql =
"DELETE FROM ".$this->db->prefix().
"element_resources";
5833 $sql .=
" WHERE rowid = ".((int) $rowid);
5835 dol_syslog(get_class($this).
"::delete_resource", LOG_DEBUG);
5837 $resql = $this->db->query($sql);
5839 $this->error = $this->db->lasterror();
5840 $this->db->rollback();
5844 $result = $this->call_trigger(strtoupper($element).
'_DELETE_RESOURCE', $user);
5846 $this->db->rollback();
5850 $this->db->commit();
5864 if (isset($this->lines) && is_array($this->lines)) {
5865 $nboflines = count($this->lines);
5866 for ($i = 0; $i < $nboflines; $i++) {
5867 if (is_object($this->lines[$i])) {
5868 $this->lines[$i] = clone $this->lines[$i];
5887 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5889 global
$conf, $langs, $hookmanager, $action;
5891 $srctemplatepath =
'';
5893 $parameters = array(
'modelspath' => $modelspath,
'modele' => $modele,
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails,
'hidedesc' => $hidedesc,
'hideref' => $hideref,
'moreparams' => $moreparams);
5894 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5896 if (!empty($reshook)) {
5900 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5902 if (empty($modele)) {
5903 $this->error =
'BadValueForParameterModele';
5908 $err = error_reporting();
5910 @set_time_limit(120);
5911 error_reporting($err);
5914 $tmp = explode(
':', $modele, 2);
5915 $saved_model = $modele;
5916 if (!empty($tmp[1])) {
5918 $srctemplatepath = $tmp[1];
5925 $dirmodels = array(
'/');
5926 if (is_array(
$conf->modules_parts[
'models'])) {
5927 $dirmodels = array_merge($dirmodels,
$conf->modules_parts[
'models']);
5929 foreach ($dirmodels as $reldir) {
5930 foreach (array(
'doc',
'pdf') as $prefix) {
5931 if (in_array(get_class($this), array(
'Adherent'))) {
5933 $file = $prefix.
"_".$modele.
".class.php";
5936 $file = $prefix.
"_".$modele.
".modules.php";
5943 if (file_exists($file)) {
5945 $classname = $prefix.
'_'.$modele;
5954 if ($filefound ===
'' || $classname ===
'') {
5955 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5956 $this->errors[] = $this->error;
5967 require_once $filefound;
5969 $obj =
new $classname($this->db);
5981 '@phan-var-force ModelePDFMember $obj';
5985 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5986 $varfortemplatedir = $obj->scandir;
5990 $listoffiles = array();
5993 $listofdir = explode(
',', $dirtoscan);
5994 foreach ($listofdir as $key => $tmpdir) {
5995 $tmpdir = trim($tmpdir);
5996 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5998 unset($listofdir[$key]);
6001 if (is_dir($tmpdir)) {
6002 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
6003 if (count($tmpfiles)) {
6004 $listoffiles = array_merge($listoffiles, $tmpfiles);
6009 if (count($listoffiles)) {
6010 foreach ($listoffiles as $record) {
6011 $srctemplatepath = $record[
'fullname'];
6017 if (empty($srctemplatepath)) {
6018 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
6023 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
6025 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
6026 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
6033 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
6036 $this->model_pdf = $saved_model;
6040 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards');
6042 $resultwritefile = -1;
6043 dol_syslog(
"Error generating document - Provided ".get_class($this).
" to ".get_class($obj).
"::write_file()", LOG_ERR);
6047 if ($this instanceof
Don) {
6048 $resultwritefile = $obj->write_file($this, $outputlangs );
6050 $resultwritefile = -1;
6051 dol_syslog(
"Error generating document - Provided ".get_class($this).
" to Don::write_file()", LOG_ERR);
6055 '@phan-var-force ModeleBarCode|ModeleExports|ModeleImports|ModelePDFAsset|ModelePDFContract|ModelePDFDeliveryOrder|ModelePDFEvaluation|ModelePDFFactures|ModelePDFFicheinter|ModelePDFMo|ModelePDFMovement|ModelePDFProduct|ModelePDFProjects|ModelePDFPropales|ModelePDFRecruitmentJobPosition|ModelePDFStock|ModelePDFStockTransfer|ModelePDFSupplierProposal|ModelePDFSuppliersInvoices|ModelePDFSuppliersOrders|ModelePDFSuppliersPayments|ModelePDFTask|ModelePDFTicket|ModelePDFUser|ModelePDFUserGroup|ModelePdfExpedition|ModelePdfReception|ModeleThirdPartyDoc $obj';
6056 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
6060 if ($resultwritefile > 0) {
6061 $outputlangs->charset_output = $sav_charset_output;
6064 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
6068 if (!empty($obj->result[
'fullpath'])) {
6069 $destfull = $obj->result[
'fullpath'];
6072 $update_main_doc_field = 0;
6073 if (!empty($obj->update_main_doc_field)) {
6074 $update_main_doc_field = 1;
6080 $this->indexFile($destfull, $update_main_doc_field);
6083 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);
6091 $outputlangs->charset_output = $sav_charset_output;
6092 $this->error = $obj->error;
6093 $this->errors = $obj->errors;
6094 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
6108 public function indexFile($destfull, $update_main_doc_field)
6110 global
$conf, $user;
6112 $upload_dir = dirname($destfull);
6113 $destfile = basename($destfull);
6114 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
6116 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
6117 $filename = basename($destfile);
6118 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
6119 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
6121 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
6122 $ecmfile =
new EcmFiles($this->db);
6123 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
6126 $setsharekey =
false;
6127 if ($this->element ==
'propal' || $this->element ==
'proposal') {
6129 $setsharekey =
true;
6132 $setsharekey =
true;
6135 if ($this->element ==
'commande' &&
getDolGlobalInt(
"ORDER_ALLOW_EXTERNAL_DOWNLOAD")) {
6136 $setsharekey =
true;
6138 if ($this->element ==
'facture' &&
getDolGlobalInt(
"INVOICE_ALLOW_EXTERNAL_DOWNLOAD")) {
6139 $setsharekey =
true;
6141 if ($this->element ==
'bank_account' &&
getDolGlobalInt(
"BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD")) {
6142 $setsharekey =
true;
6144 if ($this->element ==
'product' &&
getDolGlobalInt(
"PRODUCT_ALLOW_EXTERNAL_DOWNLOAD")) {
6145 $setsharekey =
true;
6147 if ($this->element ==
'contrat' &&
getDolGlobalInt(
"CONTRACT_ALLOW_EXTERNAL_DOWNLOAD")) {
6148 $setsharekey =
true;
6150 if ($this->element ==
'fichinter' &&
getDolGlobalInt(
"FICHINTER_ALLOW_EXTERNAL_DOWNLOAD")) {
6151 $setsharekey =
true;
6153 if ($this->element ==
'supplier_proposal' &&
getDolGlobalInt(
"SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD")) {
6154 $setsharekey =
true;
6156 if ($this->element ==
'societe_rib' &&
getDolGlobalInt(
"SOCIETE_RIB_ALLOW_ONLINESIGN")) {
6157 $setsharekey =
true;
6161 if (empty($ecmfile->share)) {
6162 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
6169 $ecmfile->fullpath_orig =
'';
6170 $ecmfile->gen_or_uploaded =
'generated';
6171 $ecmfile->description =
'';
6172 $ecmfile->keywords =
'';
6173 $ecmfile->src_object_type = $this->table_element;
6175 $result = $ecmfile->update($user);
6181 $ecmfile->entity =
$conf->entity;
6182 $ecmfile->filepath = $rel_dir;
6183 $ecmfile->filename = $filename;
6185 $ecmfile->fullpath_orig =
'';
6186 $ecmfile->gen_or_uploaded =
'generated';
6187 $ecmfile->description =
'';
6188 $ecmfile->keywords =
'';
6189 $ecmfile->src_object_type = $this->table_element;
6192 $result = $ecmfile->create($user);
6204 if ($update_main_doc_field && !empty($this->table_element)) {
6205 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
6206 $sql .=
" WHERE rowid = ".((int) $this->
id);
6208 $resql = $this->db->query($sql);
6213 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
6233 if (file_exists($file_osencoded)) {
6234 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
6237 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
6238 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
6239 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
6240 $maxheightmini = $tmparraysize[
'maxheightmini'];
6245 vignette($file_osencoded, $maxwidthsmall, $maxheightsmall,
'_small', $quality);
6249 vignette($file_osencoded, $maxwidthmini, $maxheightmini,
'_mini', $quality);
6289 if (GETPOSTISSET($fieldname)) {
6290 return GETPOST($fieldname, $type, 3);
6293 if (isset($alternatevalue)) {
6294 return $alternatevalue;
6297 $newelement = $this->element;
6298 if ($newelement ==
'facture') {
6299 $newelement =
'invoice';
6301 if ($newelement ==
'commande') {
6302 $newelement =
'order';
6304 if (empty($newelement)) {
6305 dol_syslog(
"Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
6309 $keyforfieldname = strtoupper($newelement.
'_DEFAULT_'.$fieldname);
6339 global $langs,
$conf;
6341 if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX .
'_') !== 0) {
6342 dol_print_error(
null,
'The trigger "' . $triggerName .
'" does not start with "' . self::TRIGGER_PREFIX .
'_" as required.');
6345 if (!is_object($langs)) {
6347 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
6349 $langs->load(
"main");
6352 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
6354 $result = $interface->run_triggers($triggerName, $this, $user, $langs,
$conf);
6357 if (!empty($this->errors)) {
6358 $this->errors = array_unique(array_merge($this->errors, $interface->errors));
6360 $this->errors = $interface->errors;
6381 if (!$this->element) {
6384 if (!($this->
id > 0)) {
6387 if (is_array($this->array_languages)) {
6391 $this->array_languages = array();
6393 $element = $this->element;
6394 if ($element ==
'categorie') {
6395 $element =
'categories';
6399 $sql =
"SELECT rowid, property, lang , value";
6400 $sql .=
" FROM ".$this->db->prefix().
"object_lang";
6401 $sql .=
" WHERE type_object = '".$this->db->escape($element).
"'";
6402 $sql .=
" AND fk_object = ".((int) $this->
id);
6404 $resql = $this->db->query($sql);
6406 $numrows = $this->db->num_rows($resql);
6409 while ($i < $numrows) {
6410 $obj = $this->db->fetch_object($resql);
6411 $key = $obj->property;
6412 $value = $obj->value;
6413 $codelang = $obj->lang;
6414 $type = $this->fields[$key][
'type'];
6417 if (preg_match(
'/date/', $type)) {
6418 $this->array_languages[$key][$codelang] = $this->db->jdate($value);
6420 $this->array_languages[$key][$codelang] = $value;
6427 $this->db->free($resql);
6450 foreach ($_POST as $postfieldkey => $postfieldvalue) {
6451 $tmparray = explode(
'-', $postfieldkey);
6452 if ($tmparray[0] !=
'field') {
6456 $element = $tmparray[1];
6457 $key = $tmparray[2];
6458 $codelang = $tmparray[3];
6461 if (!empty($onlykey) && $key != $onlykey) {
6464 if ($element != $this->element) {
6468 $key_type = $this->fields[$key][
'type'];
6471 if (isset($this->fields[$key][
'enabled'])) {
6472 $enabled = (int)
dol_eval((
string) $this->fields[$key][
'enabled'], 1, 1,
'1');
6479 if (empty($enabled)) {
6484 if (in_array($key_type, array(
'date'))) {
6488 } elseif (in_array($key_type, array(
'datetime'))) {
6492 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
6493 $value_arr =
GETPOST($postfieldkey,
'array');
6494 if (!empty($value_arr)) {
6495 $value_key = implode(
',', $value_arr);
6499 } elseif (in_array($key_type, array(
'price',
'double'))) {
6500 $value_arr =
GETPOST($postfieldkey,
'alpha');
6503 $value_key =
GETPOST($postfieldkey);
6504 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
6509 $this->array_languages[$key][$codelang] = $value_key;
6534 $savDisableCompute =
$conf->disable_compute;
6535 $conf->disable_compute = 1;
6537 $ret = $this->fetch(
$id);
6539 $conf->disable_compute = $savDisableCompute;
6557 global
$conf, $extrafields;
6559 if (empty($rowid)) {
6562 if (empty($rowid) && isset($this->rowid)) {
6563 $rowid = $this->rowid;
6567 if (!$this->table_element) {
6571 $this->array_options = array();
6573 if (!is_array($optionsArray)) {
6575 if (!isset($extrafields) || !is_object($extrafields)) {
6576 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6581 if (empty($extrafields->attributes[$this->table_element][
'loaded'])) {
6582 $extrafields->fetch_name_optionals_label($this->table_element);
6584 $optionsArray = (!empty($extrafields->attributes[$this->table_element][
'label']) ? $extrafields->attributes[$this->table_element][
'label'] :
null);
6586 global $extrafields;
6587 dol_syslog(
"Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
6590 $table_element = $this->table_element;
6591 if ($table_element ==
'categorie') {
6592 $table_element =
'categories';
6596 if (is_array($optionsArray) && count($optionsArray) > 0) {
6597 $sql =
"SELECT rowid";
6598 foreach ($optionsArray as $name => $label) {
6599 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || (!in_array($extrafields->attributes[$this->table_element][
'type'][$name], [
'separate',
'point',
'multipts',
'linestrg',
'polygon']))) {
6600 $sql .=
", ".$this->db->sanitize($name);
6603 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || in_array($extrafields->attributes[$this->table_element][
'type'][$name], array(
'point',
'multipts',
'linestrg',
'polygon'))) {
6605 $sql .=
", ST_AsWKT(".$name.
") as ".$this->db->sanitize($name);
6608 $sql .=
" FROM ".$this->db->prefix().$table_element.
"_extrafields";
6609 $sql .=
" WHERE fk_object = ".((int) $rowid);
6612 $resql = $this->db->query($sql);
6614 $numrows = $this->db->num_rows($resql);
6616 $tab = $this->db->fetch_array($resql);
6618 foreach ($tab as $key => $value) {
6620 if ($key !=
'rowid' && $key !=
'tms' && $key !=
'fk_member' && !is_int($key)) {
6622 if (!empty($extrafields->attributes[$this->table_element]) && in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date',
'datetime'))) {
6624 $this->array_options[
"options_".$key] = $this->db->jdate($value);
6626 $this->array_options[
"options_".$key] = $value;
6631 if (!empty($extrafields->attributes[$this->table_element][
'type'][$key]) && $extrafields->attributes[$this->table_element][
'type'][$key] ==
'password') {
6632 if (!empty($value) && preg_match(
'/^dolcrypt:/', $value)) {
6633 $this->array_options[
"options_".$key] =
dolDecrypt($value);
6642 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6643 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6644 $this->array_options[
'options_' . $key] =
null;
6651 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6652 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6653 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'computed'][$key])) {
6655 if (empty(
$conf->disable_compute)) {
6656 global $objectoffield;
6657 $objectoffield = $this;
6658 $this->array_options[
'options_' . $key] =
dol_eval((
string) $extrafields->attributes[$this->table_element][
'computed'][$key], 1, 0,
'2');
6664 $this->db->free($resql);
6672 $this->errors[] = $this->db->lasterror;
6693 $table_element = $this->table_element;
6694 if ($table_element ==
'categorie') {
6695 $table_element =
'categories';
6698 dol_syslog(get_class($this).
"::deleteExtraFields delete", LOG_DEBUG);
6700 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6702 $resql = $this->db->query($sql_del);
6704 $this->error = $this->db->lasterror();
6705 $this->db->rollback();
6708 $this->db->commit();
6725 global $langs, $user;
6727 if (
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLED') || empty($this->array_options)) {
6731 if (empty($userused)) {
6738 $langs->load(
'admin');
6739 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6741 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6744 $new_array_options = array();
6745 foreach ($this->array_options as $key => $value) {
6746 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6747 $new_array_options[$key] = $value;
6748 } elseif (in_array($key, array_keys($target_extrafields))) {
6749 $new_array_options[
'options_'.$key] = $value;
6753 foreach ($new_array_options as $key => $value) {
6754 $attributeKey = substr($key, 8);
6755 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6756 $attributeLabel = $langs->transnoentities($extrafields->attributes[$this->table_element][
'label'][$attributeKey]);
6757 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6758 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6759 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6760 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6764 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6765 $new_array_options[$key] =
null;
6770 if (!empty($this->context[
'createproductcombination']) && $this->context[
'createproductcombination'] ==
'createproductcombination' && !empty($attributeUnique)) {
6771 $new_array_options[$key] =
null;
6775 if ($attributeRequired) {
6776 $v = $this->array_options[$key];
6778 $langs->load(
"errors");
6779 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6780 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6785 if (!empty($attrfieldcomputed)) {
6787 $value =
dol_eval((
string) $attrfieldcomputed, 1, 0,
'2');
6788 dol_syslog($langs->trans(
"Extrafieldcomputed").
" on ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6789 $new_array_options[$key] = $value;
6791 $new_array_options[$key] =
null;
6795 switch ($attributeType) {
6799 if (!is_numeric($value) && $value !=
'') {
6800 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6802 } elseif ($value ===
'') {
6803 $new_array_options[$key] =
null;
6807 if ($value ===
'' || $value ===
false || $value ===
null) {
6808 $new_array_options[$key] =
null;
6814 if (!is_numeric($value) && $value !=
'') {
6815 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6816 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6818 } elseif ($value ==
'') {
6822 $new_array_options[$key] = $value;
6832 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6834 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6835 $algo = reset($tmparrays);
6840 if (is_object($this->oldcopy)) {
6842 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6844 if ($algo ==
'dolcrypt') {
6845 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6846 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6848 $new_array_options[$key] = $this->array_options[$key];
6851 $new_array_options[$key] = $this->array_options[$key];
6855 if ($algo ==
'dolcrypt') {
6856 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6857 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6859 $new_array_options[$key] = $this->array_options[$key];
6862 $new_array_options[$key] =
dol_hash($this->array_options[$key], $algo);
6868 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6869 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6871 $new_array_options[$key] = $this->array_options[$key];
6876 $new_array_options[$key] = $this->array_options[$key];
6879 $new_array_options[$key] = $this->array_options[$key];
6885 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6886 $this->array_options[$key] = strtotime($this->array_options[$key]);
6888 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6892 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6893 $this->array_options[$key] = strtotime($this->array_options[$key]);
6895 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6898 $param_list = array_keys($attributeParam[
'options']);
6901 $InfoFieldList = explode(
":", $param_list[0]);
6903 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6904 if ($value ==
'-1') {
6905 $new_array_options[$key] =
'';
6907 $object =
new $InfoFieldList[0]($this->db);
6908 '@phan-var-force CommonObject $object';
6912 $sqlFetchObject =
"SELECT rowid FROM ".$this->db->prefix().$object->table_element;
6913 if (is_numeric($value)) {
6914 $sqlFetchObject .=
" WHERE rowid = " . (int) $value;
6916 $sqlFetchObject .=
" WHERE ref = '" . $this->db->escape($value) .
"'";
6919 $obj = $this->db->getRow($sqlFetchObject);
6921 if ($obj !==
false) {
6922 $objectId = $obj->rowid;
6929 $new_array_options[$key] = $objectId;
6931 $this->error =
"Id/Ref '".$value.
"' for object '".
$object->element.
"' not found";
6936 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6941 if (is_array($this->array_options[$key])) {
6942 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6944 $new_array_options[$key] = $this->array_options[$key];
6950 $sqlColumnValues = [
'fk_object' => (int) $this->
id];
6952 foreach ($new_array_options as $key => $newValue) {
6953 $attributeKey = substr($key, 8);
6954 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6955 if ($attributeType ===
'separate') {
6959 $geoDataType = ExtraFields::$geoDataTypes[$attributeType] ??
null;
6961 if (! $geoDataType) {
6963 if ($newValue !=
'') {
6964 $sqlColumnValues[$attributeKey] =
"'".$this->db->escape($newValue).
"'";
6966 $sqlColumnValues[$attributeKey] =
'null';
6970 if (empty($newValue)) {
6971 $sqlColumnValues[$attributeKey] =
'null';
6974 if (preg_match(
'/error/i', $newValue)) {
6976 'Bad syntax string for '.$geoDataType[
'shortname'].
' '.$newValue.
' to generate SQL request',
6979 $sqlColumnValues[$attributeKey] =
'null';
6988 $sqlColumnValues[$key] = $geoDataType[
'ST_Function'].
"('".$this->db->escape($newValue).
"')";
6993 $table_element = $this->table_element;
6994 if ($table_element ==
'categorie') {
6995 $table_element =
'categories';
6997 $extrafieldsTable = $this->db->prefix() . $table_element .
'_extrafields';
6999 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
7002 if ($this->db->getRow(
"SELECT 1 FROM {$extrafieldsTable} WHERE fk_object = ".((int) $this->id))) {
7003 array_shift($sqlColumnValues);
7004 $sqlColumnValueString = implode(
7010 array_map(
function ($key) use ($sqlColumnValues) {
7011 return "{$key} = {$sqlColumnValues[$key]}";
7012 }, array_keys($sqlColumnValues))
7014 $sql =
"UPDATE {$extrafieldsTable} SET {$sqlColumnValueString} WHERE fk_object = ".((int) $this->
id);
7017 $extrafieldsRequiredOnOtherEntities = $extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] ?? array();
7018 foreach ($extrafieldsRequiredOnOtherEntities as $key => $extrafieldType) {
7019 if (isset($sqlColumnValues[$key])) {
7024 $sqlColumnValues[$key] =
"''";
7025 if (in_array($extrafieldType, array(
'int',
'double',
'price'))) {
7026 $sqlColumnValues[$key] = 0;
7029 $sqlColumns = implode(
',', array_keys($sqlColumnValues));
7030 $sqlValues = implode(
',', array_values($sqlColumnValues));
7031 $sql =
"INSERT INTO {$extrafieldsTable} ({$sqlColumns}) VALUES ({$sqlValues})";
7034 $resql = $this->db->query($sql);
7036 $this->error = $this->db->lasterror();
7040 if (!$error && $trigger) {
7042 $this->context = array(
'extrafieldaddupdate' => 1);
7043 $result = $this->call_trigger($trigger, $userused);
7051 $this->db->rollback();
7054 $this->db->commit();
7072 global $langs, $user;
7074 if (empty($userused)) {
7084 if (is_array($this->array_languages)) {
7085 $new_array_languages = $this->array_languages;
7087 foreach ($new_array_languages as $key => $value) {
7088 $attributeKey = $key;
7089 $attributeType = $this->fields[$attributeKey][
'type'];
7090 $attributeLabel = $this->fields[$attributeKey][
'label'];
7095 switch ($attributeType) {
7097 if (is_array($value) || (!is_numeric($value) && $value !=
'')) {
7098 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
7100 } elseif ($value ==
'') {
7101 $new_array_languages[$key] =
null;
7106 if (!is_numeric($value) && $value !=
'') {
7107 dol_syslog($langs->trans(
"ExtraLanguageHasWrongValue").
" on ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
7108 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
7110 } elseif ($value ==
'') {
7111 $new_array_languages[$key] =
null;
7113 $new_array_languages[$key] = $value;
7127 $table_element = $this->table_element;
7128 if ($table_element ==
'categorie') {
7129 $table_element =
'categories';
7132 dol_syslog(get_class($this).
"::insertExtraLanguages delete then insert", LOG_DEBUG);
7134 foreach ($new_array_languages as $key => $langcodearray) {
7135 foreach ($langcodearray as $langcode => $value) {
7136 $sql_del =
"DELETE FROM ".$this->db->prefix().
"object_lang";
7137 $sql_del .=
" WHERE fk_object = ".((int) $this->
id).
" AND property = '".$this->db->escape($key).
"' AND type_object = '".$this->db->escape($table_element).
"'";
7138 $sql_del .=
" AND lang = '".$this->db->escape($langcode).
"'";
7139 $this->db->query($sql_del);
7141 if ($value !==
'') {
7142 $sql =
"INSERT INTO ".$this->db->prefix().
"object_lang (fk_object, property, type_object, lang, value";
7143 $sql .=
") VALUES (".$this->id.
", '".$this->db->escape($key).
"', '".$this->db->escape($table_element).
"', '".$this->db->escape($langcode).
"', '".$this->db->escape($value).
"'";
7146 $resql = $this->db->query($sql);
7148 $this->error = $this->db->lasterror();
7156 if (!$error && $trigger) {
7158 $this->context = array(
'extralanguagesaddupdate' => 1);
7159 $result = $this->call_trigger($trigger, $userused);
7167 $this->db->rollback();
7170 $this->db->commit();
7190 global $langs, $user, $hookmanager;
7196 if (empty($userused)) {
7202 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
7204 $langs->load(
'admin');
7205 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
7207 $extrafields->fetch_name_optionals_label($this->table_element);
7209 $value = $this->array_options[
"options_".$key];
7211 $attributeKey = $key;
7212 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
7213 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
7214 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
7215 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
7216 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
7217 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
7220 if ($attributeRequired) {
7221 $mandatorypb =
false;
7222 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
7223 $mandatorypb =
true;
7225 if ($this->array_options[
"options_".$key] ===
'') {
7226 $mandatorypb =
true;
7229 $langs->load(
"errors");
7230 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
7231 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
7237 $new_array_options = $this->array_options;
7241 if (!empty($attrfieldcomputed)) {
7243 $value =
dol_eval((
string) $attrfieldcomputed, 1, 0,
'2');
7244 dol_syslog($langs->trans(
"Extrafieldcomputed").
" on ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
7246 $new_array_options[
"options_".$key] = $value;
7248 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7250 $new_array_options[
"options_".$key] =
null;
7252 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7256 switch ($attributeType) {
7258 if (!is_numeric($value) && $value !=
'') {
7259 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
7261 } elseif ($value ===
'') {
7262 $new_array_options[
"options_".$key] =
null;
7264 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7270 if (!is_numeric($value) && $value !=
'') {
7271 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" on ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
7272 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
7274 } elseif ($value ===
'') {
7278 $new_array_options[
"options_".$key] = $value;
7280 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7292 if ($this->array_options[
"options_".$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
7294 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
7295 $algo = reset($tmparrays);
7301 if (is_object($this->oldcopy)) {
7303 if (isset($this->oldcopy->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] == $this->oldcopy->array_options[
"options_".$key]) {
7304 if ($algo ==
'dolcrypt') {
7305 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7306 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7308 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7311 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7314 if ($algo ==
'dolcrypt') {
7315 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7316 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7318 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7321 $new_array_options[
"options_".$key] =
dol_hash($this->array_options[
"options_".$key], $algo);
7325 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7326 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7328 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7333 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7336 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7339 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7343 if (empty($this->array_options[
"options_".$key])) {
7344 $new_array_options[
"options_".$key] =
null;
7346 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7348 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
7352 if (empty($this->array_options[
"options_".$key])) {
7353 $new_array_options[
"options_".$key] =
null;
7355 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7357 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
7361 if (empty($this->array_options[
"options_".$key])) {
7362 $new_array_options[
"options_".$key] =
null;
7364 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7368 if ($this->array_options[
"options_".$key] ===
'') {
7369 $new_array_options[
"options_".$key] =
null;
7371 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7405 $new_array_options = array();
7406 if (is_array($this->array_options[
"options_".$key])) {
7407 $new_array_options[
"options_".$key] = implode(
',', $this->array_options[
"options_".$key]);
7409 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7412 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7418 $linealreadyfound = 0;
7421 $table_element = $this->table_element;
7422 if ($table_element ==
'categorie') {
7423 $table_element =
'categories';
7426 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
7427 $resql = $this->db->query($sql);
7429 $tmpobj = $this->db->fetch_object($resql);
7431 $linealreadyfound = $tmpobj->nb;
7436 if ($linealreadyfound) {
7437 if ($this->array_options[
"options_".$key] ===
null) {
7438 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = null";
7440 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($new_array_options[
"options_".$key]).
"'";
7442 $sql .=
" WHERE fk_object = ".((int) $this->
id);
7444 $resql = $this->db->query($sql);
7447 $this->error = $this->db->lasterror();
7450 $result = $this->insertExtraFields(
'', $user);
7457 $parameters = array(
'key' => $key);
7459 $reshook = $hookmanager->executeHooks(
'updateExtraFieldBeforeCommit', $parameters, $this, $action);
7465 if (!$error && $trigger) {
7467 $this->context = array(
'extrafieldupdate' => 1);
7468 $result = $this->call_trigger($trigger, $userused);
7476 dol_syslog(__METHOD__.$this->error, LOG_ERR);
7477 $this->db->rollback();
7480 $this->db->commit();
7496 return $this->array_options[
'options_'.$key] ??
null;
7508 $this->array_options[
'options_'.$key] = $value;
7525 if (empty($userused)) {
7553 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
7555 global
$conf, $langs, $form;
7560 if (!is_object($form)) {
7561 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
7562 $form =
new Form($this->db);
7565 if (!empty($this->fields)) {
7566 $val = $this->fields[$key];
7570 $fieldValidationErrorMsg =
'';
7571 $validationClass =
'';
7572 $fieldValidationErrorMsg = $this->getFieldError($key);
7573 if (!empty($fieldValidationErrorMsg)) {
7574 $validationClass =
' --error';
7576 $validationClass =
' --success';
7584 $param[
'options'] = array();
7587 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
7589 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7590 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7592 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7593 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7595 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
7596 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7598 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7599 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7601 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7602 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7604 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
7605 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7607 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
7608 $param[
'options'] = array($reg[1] =>
'N');
7610 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
7611 $param[
'options'] = array();
7614 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
7615 $param[
'options'] = array();
7617 } elseif (preg_match(
'/stars\((\d+)\)/', $val[
'type'], $reg)) {
7618 $param[
'options'] = array();
7622 $param[
'options'] = array();
7623 $type = $this->fields[$key][
'type'];
7628 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
7629 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
7631 if (empty($this->fields[$key][
'multiinput'])) {
7632 $type = (($this->fields[$key][
'type'] ==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
7636 $label = $this->fields[$key][
'label'];
7639 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
7641 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
7643 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
7645 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
7647 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
7649 $placeholder = (!empty($this->fields[$key][
'placeholder']) ? $this->fields[$key][
'placeholder'] : 0);
7652 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
7654 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
7655 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
7660 if (!preg_match(
'/^search_/', $keyprefix)) {
7661 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
7668 if (empty($morecss) && !empty($val[
'css'])) {
7669 $morecss = $val[
'css'];
7670 } elseif (empty($morecss)) {
7671 if ($type ==
'date') {
7672 $morecss =
'minwidth100imp';
7673 } elseif ($type ==
'datetime' || $type ==
'link') {
7674 $morecss =
'minwidth200imp';
7675 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', (
string) $type)) {
7676 $morecss =
'maxwidth75';
7677 } elseif ($type ==
'url') {
7678 $morecss =
'minwidth400';
7679 } elseif ($type ==
'boolean') {
7682 if (is_numeric($size) && round((
float) $size) < 12) {
7683 $morecss =
'minwidth100';
7684 } elseif (is_numeric($size) && round((
float) $size) <= 48) {
7685 $morecss =
'minwidth200';
7687 $morecss =
'minwidth400';
7693 if (!empty($validationClass)) {
7694 $morecss .= $validationClass;
7697 if (in_array($type, array(
'date'))) {
7698 $tmp = explode(
',', $size);
7703 if (!$required && $value ==
'') {
7708 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
7709 } elseif (in_array($type, array(
'datetime'))) {
7710 $tmp = explode(
',', $size);
7715 if (!$required && $value ==
'') {
7720 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
7721 } elseif (in_array($type, array(
'duration'))) {
7722 $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
7723 } elseif (in_array($type, array(
'int',
'integer'))) {
7724 $tmp = explode(
',', $size);
7726 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"'.($newsize > 0 ?
' maxlength="'.$newsize.
'"' :
'').
' value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7727 } elseif (in_array($type, array(
'real'))) {
7728 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7729 } elseif (preg_match(
'/varchar/', (
string) $type)) {
7730 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"'.($size > 0 ?
' maxlength="'.$size.
'"' :
'').
' value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($placeholder ?
' placeholder="'.
dolPrintHTMLForAttribute($placeholder).
'"' :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7731 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
7732 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7733 } elseif (preg_match(
'/^text/', (
string) $type)) {
7734 if (!preg_match(
'/search_/', $keyprefix)) {
7735 if (!empty($param[
'options'])) {
7738 $out .= $form->selectarray($keyprefix.$key.$keysuffix.
"_multiinput", $param[
'options'],
'', 1, 0, 0,
"flat maxwidthonphone".$morecss);
7739 $out .=
'<input id="'.$keyprefix.$key.$keysuffix.
'_multiinputadd" type="button" class="button" value="'.$langs->trans(
"Add").
'">';
7742 function handlemultiinputdisabling(htmlname){
7743 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
7744 multiinput = $("#"+htmlname+"_multiinput");
7745 multiinput.find("option").each(function(){
7746 tmpval = $("#"+htmlname).val();
7747 tmpvalarray = tmpval.split("\n");
7748 valtotest = $(this).val();
7749 if(tmpvalarray.includes(valtotest)){
7750 $(this).prop("disabled",true);
7752 if($(this).prop("disabled") == true){
7753 console.log(valtotest)
7754 $(this).prop("disabled", false);
7760 $(document).ready(function () {
7761 $("#'.$keyprefix.$key.$keysuffix.
'_multiinputadd").on("click",function() {
7762 tmpval = $("#'.$keyprefix.$key.$keysuffix.
'").val();
7763 tmpvalarray = tmpval.split(",");
7764 valtotest = $("#'.$keyprefix.$key.$keysuffix.
'_multiinput").val();
7765 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
7766 console.log("We add the selected value to the text area '.$keyprefix.$key.$keysuffix.
'");
7770 tmpval = tmpval + "\n" + valtotest;
7772 $("#'.$keyprefix.$key.$keysuffix.
'").val(tmpval);
7773 handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.
'");
7774 $("#'.$keyprefix.$key.$keysuffix.
'_multiinput").val(-1);
7776 console.log("We add nothing the text area '.$keyprefix.$key.$keysuffix.
'");
7779 $("#'.$keyprefix.$key.$keysuffix.
'").on("change",function(){
7780 handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.
'");
7782 handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.
'");
7784 $out .=
"</script>";
7785 $value = str_replace(
',',
"\n", $value);
7787 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7788 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
7789 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'',
'', $morecss);
7791 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7793 } elseif (preg_match(
'/^html/', (
string) $type)) {
7794 if (!preg_match(
'/search_/', $keyprefix)) {
7795 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7796 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
7797 $out = (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
7799 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7801 } elseif ($type ==
'boolean') {
7803 if (!empty($value)) {
7804 $checked =
' checked value="1" ';
7806 $checked =
' value="1" ';
7808 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
7809 } elseif ($type ==
'price') {
7810 if (!empty($value)) {
7811 $value =
price($value);
7813 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol(
$conf->currency);
7814 } elseif ($type ==
'stars') {
7815 $out =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7816 $out .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.
'_selection">';
7818 while ($i <= $size) {
7819 $out .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
7824 jQuery(function($) { /* commonobject.class.php 1 */
7825 let container = $("#'.$keyprefix.$key.$keysuffix.
'_selection");
7826 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.
'").val()) || 0;
7827 container.find(".star").each(function() {
7828 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
7830 container.find(".star").on("mouseover", function() {
7831 let selectedStar = $(this).data("value");
7832 container.find(".star").each(function() {
7833 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
7836 container.on("mouseout", function() {
7837 container.find(".star").each(function() {
7838 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
7841 container.find(".star").off("click").on("click", function() {
7842 selectedStars = $(this).data("value");
7843 if (selectedStars === 1 && $("#'.$keyprefix.$key.$keysuffix.
'").val() == 1) {
7846 $("#'.$keyprefix.$key.$keysuffix.
'").val(selectedStars);
7847 container.find(".star").each(function() {
7848 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
7853 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', (
string) $type)) {
7854 if (!empty($value)) {
7855 $value =
price($value);
7857 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
7858 } elseif ($type ==
'select') {
7861 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7862 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7868 foreach ($param[
'options'] as $keyb => $valb) {
7869 if ((
string) $keyb ==
'') {
7872 if (strpos($valb,
"|") !==
false) {
7873 list($valb, $parent) = explode(
'|', $valb);
7876 $tmpselect .=
'<option value="'.$keyb.
'"';
7877 $tmpselect .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
7878 if (!empty($parent)) {
7881 $tmpselect .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7882 $tmpselect .=
'>'.$langs->trans($valb).
'</option>';
7885 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7886 if ((!isset($this->fields[$key][
'default'])) || empty($this->fields[$key][
'notnull']) || ($this->fields[$key][
'notnull'] != 1) || $nbchoice >= 2) {
7887 $out .=
'<option value="0"> </option>';
7890 $out .=
'</select>';
7891 } elseif ($type ==
'sellist') {
7894 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7895 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7898 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7899 if (is_array($param[
'options'])) {
7900 $tmpparamoptions = array_keys($param[
'options']);
7901 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
7903 $InfoFieldList = explode(
":", $paramoptions[0], 5);
7915 if (! empty($InfoFieldList[4])) {
7917 $parenthesisopen = 0;
7918 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
7919 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
7922 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
7927 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
7928 $tmpafter = substr($InfoFieldList[4], $pos + 1);
7930 $InfoFieldList[4] = $tmpbefore;
7931 if ($tmpafter !==
'') {
7932 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
7938 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
7939 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
7950 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7952 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7953 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7954 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7956 $keyList = $InfoFieldList[2].
' as rowid';
7959 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7960 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7961 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
7962 $keyList .=
', main.'.$parentField;
7964 $keyList .=
', '.$parentField;
7968 $filter_categorie =
false;
7969 if (count($InfoFieldList) > 5) {
7970 if ($InfoFieldList[0] ==
'categorie') {
7971 $filter_categorie =
true;
7975 if (!$filter_categorie) {
7976 $fields_label = explode(
'|', $InfoFieldList[1]);
7977 if (is_array($fields_label)) {
7979 $keyList .= implode(
', ', $fields_label);
7983 $sql =
"SELECT " . $keyList;
7984 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7986 if (!empty($InfoFieldList[4])) {
7988 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7989 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7993 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7994 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
7996 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
8001 if (strpos($InfoFieldList[4],
'extra') !==
false) {
8002 $sql .=
" as main, " . $this->db->sanitize($this->db->prefix() . $InfoFieldList[0]) .
"_extrafields as extra";
8003 $sqlwhere .=
" WHERE extra.fk_object = main." . $this->db->sanitize($InfoFieldList[2]);
8009 $sqlwhere .=
' WHERE 1=1';
8026 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
8027 $sqlwhere .=
" AND entity = " . ((int)
$conf->entity);
8032 if (isset($InfoFieldList[7]) && preg_match(
'/^[a-z0-9_\-,]+$/i', $InfoFieldList[7])) {
8033 $sql .=
" ORDER BY ".$this->db->escape($InfoFieldList[7]);
8035 $sql .=
" ORDER BY ".$this->db->sanitize(implode(
', ', $fields_label));
8037 $sql .=
' LIMIT ' .
getDolGlobalInt(
'MAIN_EXTRAFIELDS_LIMIT_SELLIST_SQL', 1000);
8040 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
8041 $resql = $this->db->query($sql);
8043 $out .=
'<option value="0"> </option>';
8044 $num = $this->db->num_rows($resql);
8048 $obj = $this->db->fetch_object($resql);
8052 $fields_label = explode(
'|', $InfoFieldList[1]);
8053 if (count($fields_label) > 1) {
8055 foreach ($fields_label as $field_toshow) {
8056 $labeltoshow .= $obj->$field_toshow .
' ';
8059 $labeltoshow = $obj->{$InfoFieldList[1]};
8061 $labeltoshow =
dol_trunc($labeltoshow, 45);
8063 if ($value == $obj->rowid) {
8064 foreach ($fields_label as $field_toshow) {
8065 $translabel = $langs->trans($obj->$field_toshow);
8066 if ($translabel != $obj->$field_toshow) {
8067 $labeltoshow =
dol_trunc($translabel) .
' ';
8069 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
8072 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
8075 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8076 if ($translabel != $obj->{$InfoFieldList[1]}) {
8077 $labeltoshow =
dol_trunc($translabel, 18);
8079 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
8082 if (empty($labeltoshow)) {
8083 $labeltoshow =
'(not defined)';
8085 if ($value == $obj->rowid) {
8086 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
8089 if (!empty($InfoFieldList[3]) && $parentField) {
8090 $parent = $parentName .
':' . $obj->{$parentField};
8094 $out .=
'<option value="' . $obj->rowid .
'"';
8095 $out .= ($value == $obj->rowid ?
' selected' :
'');
8096 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
8097 $out .=
'>' . $labeltoshow .
'</option>';
8102 $this->db->free($resql);
8104 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
8107 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
8108 $categcode = $InfoFieldList[5];
8109 if (is_numeric($categcode)) {
8110 $categcode = Categorie::$MAP_ID_TO_CODE[(int) $InfoFieldList[5]];
8112 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
8113 $out .=
'<option value="0"> </option>';
8114 foreach ($data as $data_key => $data_value) {
8115 $out .=
'<option value="' . $data_key .
'"';
8116 $out .= ($value == $data_key ?
' selected' :
'');
8117 $out .=
'>' . $data_value .
'</option>';
8121 $out .=
'</select>';
8122 } elseif ($type ==
'checkbox') {
8123 $value_arr = explode(
',', $value);
8124 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0, $morecss, 0,
'100%');
8125 } elseif ($type ==
'radio') {
8127 foreach ($param[
'options'] as $keyopt => $valopt) {
8128 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
8129 $out .=
' value="'.$keyopt.
'"';
8130 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
8131 $out .= ($value == $keyopt ?
'checked' :
'');
8132 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
8134 } elseif ($type ==
'chkbxlst') {
8135 if (is_array($value)) {
8136 $value_arr = $value;
8138 $value_arr = explode(
',', $value);
8141 if (is_array($param[
'options'])) {
8142 $tmpparamoptions = array_keys($param[
'options']);
8143 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
8145 $InfoFieldList = explode(
":", $paramoptions[0], 5);
8157 if (! empty($InfoFieldList[4])) {
8159 $parenthesisopen = 0;
8160 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
8161 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
8164 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
8169 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
8170 $tmpafter = substr($InfoFieldList[4], $pos + 1);
8172 $InfoFieldList[4] = $tmpbefore;
8173 if ($tmpafter !==
'') {
8174 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
8179 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
8180 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
8188 '@phan-var-force array{0:string,1:string,2:string,3:string,3:string,5:string,6:string} $InfoFieldList';
8193 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
8195 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
8196 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
8197 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
8199 $keyList = $InfoFieldList[2].
' as rowid';
8202 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
8203 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
8204 if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra.') !==
false) {
8205 $keyList .=
', main.'.$parentField;
8207 $keyList .=
', '.$parentField;
8211 $filter_categorie =
false;
8212 if (count($InfoFieldList) > 5) {
8213 if ($InfoFieldList[0] ==
'categorie') {
8214 $filter_categorie =
true;
8219 if (!$filter_categorie) {
8220 $fields_label = explode(
'|', $InfoFieldList[1]);
8221 if (is_array($fields_label)) {
8223 $keyList .= implode(
', ', $fields_label);
8227 $sql =
"SELECT " . $keyList;
8228 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
8230 if (!empty($InfoFieldList[4])) {
8232 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
8233 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
8237 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
8238 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
8240 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
8245 if (strpos($InfoFieldList[4],
'extra') !==
false) {
8246 $sql .=
' as main, ' . $this->db->sanitize($this->db->prefix() . $InfoFieldList[0]) .
'_extrafields as extra';
8247 $sqlwhere .=
" WHERE extra.fk_object = main." . $this->db->sanitize($InfoFieldList[2]);
8253 $sqlwhere .=
' WHERE 1=1';
8270 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
8271 $sqlwhere .=
" AND entity = " . ((int)
$conf->entity);
8278 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
8280 $resql = $this->db->query($sql);
8282 $num = $this->db->num_rows($resql);
8289 $obj = $this->db->fetch_object($resql);
8293 $fields_label = explode(
'|', $InfoFieldList[1]);
8294 if (count($fields_label) > 1) {
8296 foreach ($fields_label as $field_toshow) {
8297 $labeltoshow .= $obj->$field_toshow .
' ';
8300 $labeltoshow = $obj->{$InfoFieldList[1]};
8302 $labeltoshow =
dol_trunc($labeltoshow, 45);
8304 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8305 foreach ($fields_label as $field_toshow) {
8306 $translabel = $langs->trans($obj->$field_toshow);
8307 if ($translabel != $obj->$field_toshow) {
8308 $labeltoshow =
dol_trunc($translabel, 18) .
' ';
8310 $labeltoshow =
dol_trunc($obj->$field_toshow, 18) .
' ';
8314 $data[$obj->rowid] = $labeltoshow;
8317 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8318 if ($translabel != $obj->{$InfoFieldList[1]}) {
8319 $labeltoshow =
dol_trunc($translabel, 18);
8321 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
8324 if (empty($labeltoshow)) {
8325 $labeltoshow =
'(not defined)';
8328 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8329 $data[$obj->rowid] = $labeltoshow;
8332 if (!empty($InfoFieldList[3]) && $parentField) {
8333 $parent = $parentName .
':' . $obj->{$parentField};
8337 $data[$obj->rowid] = $labeltoshow;
8342 $this->db->free($resql);
8344 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0,
'100%');
8346 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
8349 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
8350 $categcode = $InfoFieldList[5];
8351 if (is_numeric($categcode)) {
8352 $categcode = Categorie::$MAP_ID_TO_CODE[(int) $InfoFieldList[5]];
8354 $data = $form->select_all_categories($categcode,
'',
'parent', 64, $InfoFieldList[6], 1, 1);
8355 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0,
'100%');
8358 } elseif ($type ==
'link') {
8361 $param_list = array_keys($param[
'options']);
8362 $param_list_array = explode(
':', $param_list[0], 4);
8364 $showempty = (($required && $default !=
'') ? 0 : 1);
8366 if (!preg_match(
'/search_/', $keyprefix)) {
8367 if (!empty($param_list_array[2])) {
8369 if (!empty($this->fields[$key][
'picto'])) {
8370 $morecss .=
' widthcentpercentminusxx';
8372 $morecss .=
' widthcentpercentminusx';
8376 if (!empty($this->fields[$key][
'picto'])) {
8377 $morecss .=
' widthcentpercentminusx';
8390 $objectfield = $val;
8393 $out = $form->selectForForms($param_list_array[0], $keyprefix.$key.$keysuffix, (
int) $value, $showempty,
'',
'', $morecss, $moreparam, 0, (empty($val[
'disabled']) ? 0 : 1),
'', $objectfield);
8395 if (!empty($param_list_array[2])) {
8396 if ((!GETPOSTISSET(
'backtopage') || strpos(
GETPOST(
'backtopage'), $_SERVER[
'PHP_SELF']) === 0)
8397 && empty($val[
'disabled']) && empty($nonewbutton)) {
8398 list($class, $classfile) = explode(
':', $param_list[0]);
8399 if (file_exists(
dol_buildpath(dirname(dirname($classfile)).
'/card.php'))) {
8400 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/card.php', 1);
8402 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/'.strtolower($class).
'_card.php', 1);
8404 $paramforthenewlink =
'';
8405 $paramforthenewlink .= (GETPOSTISSET(
'action') ?
'&action='.GETPOST(
'action',
'aZ09') :
'');
8406 $paramforthenewlink .= (GETPOSTISSET(
'id') ?
'&id='.GETPOSTINT(
'id') :
'');
8407 $paramforthenewlink .= (GETPOSTISSET(
'origin') ?
'&origin='.GETPOST(
'origin',
'aZ09') :
'');
8408 $paramforthenewlink .= (GETPOSTISSET(
'originid') ?
'&originid='.GETPOSTINT(
'originid') :
'');
8409 $paramforthenewlink .=
'&fk_'.strtolower($class).
'=--IDFORBACKTOPAGE--';
8411 $out .=
'<a class="butActionNew" title="'.$langs->trans(
"New").
'" href="'.$url_path.
'?action=create&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($paramforthenewlink ?
'?'.$paramforthenewlink :
'')).
'"><span class="fa fa-plus-circle valignmiddle"></span></a>';
8414 } elseif ($type ==
'password') {
8416 if ($keyprefix.$key.$keysuffix ==
'pass_crypted') {
8417 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="pass" id="pass" value="" '.($moreparam ? $moreparam :
'').
'>';
8418 $out .=
'<input type="hidden" name="pass_crypted" id="pass_crypted" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
8420 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
8422 } elseif ($type ==
'array') {
8424 $newval[
'type'] =
'varchar(256)';
8427 if (!empty($value)) {
8428 foreach ($value as $option) {
8429 $out .=
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
8430 $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]', $option, $moreparam,
'',
'', $morecss).
'<br></span>';
8433 $out .=
'<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>';
8435 $newInput =
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
8436 $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]',
'', $moreparam,
'',
'', $morecss).
'<br></span>';
8438 if (!empty(
$conf->use_javascript_ajax)) {
8440 <script nonce="'.getNonce().
'">
8441 $(document).ready(function() {
8442 $("a#'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_add").click(function() {
8446 $(document).on("click", "a.'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_del", function() {
8447 $(this).parent().remove();
8453 if (!empty($hidden)) {
8454 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
8457 if ($isDependList == 1) {
8458 $out .= $this->getJSListDependancies(
'_common');
8466 if (!empty($fieldValidationErrorMsg) && function_exists(
'getFieldErrorIcon')) {
8467 $out .=
' '.getFieldErrorIcon($fieldValidationErrorMsg);
8486 public function showOutputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
8488 global
$conf, $langs, $form;
8492 if (!is_object($form)) {
8493 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
8494 $form =
new Form($this->db);
8498 $type = empty($val[
'type']) ?
'' : $val[
'type'];
8499 $size = empty($val[
'css']) ?
'' : $val[
'css'];
8503 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
8506 } elseif (preg_match(
'/varchar/', $type)) {
8509 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8511 if (empty($this->fields[$key][
'multiinput'])) {
8512 $type = (($this->fields[$key][
'type'] ==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
8515 if (isset($val[
'type']) && preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8519 $default = empty($val[
'default']) ?
'' : $val[
'default'];
8520 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
8521 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
8522 $required = empty($val[
'required']) ?
'' : $val[
'required'];
8524 $param[
'options'] = array();
8526 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8527 $param[
'options'] = $val[
'arrayofkeyval'];
8529 if (isset($val[
'type']) && preg_match(
'/^integer:([^:]*):([^:]*)/i', $val[
'type'], $reg)) {
8531 $stringforoptions = $reg[1].
':'.$reg[2];
8533 if ($reg[1] ==
'User') {
8534 $stringforoptions .=
':#getnomurlparam1=-1';
8536 $param[
'options'] = array($stringforoptions => $stringforoptions);
8537 } elseif (isset($val[
'type']) && preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8538 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
8540 } elseif (isset($val[
'type']) && preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8541 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
8543 } elseif (isset($val[
'type']) && preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
8544 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
8546 } elseif (isset($val[
'type']) && preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
8547 $param[
'options'] = array($reg[1] =>
'N');
8549 } elseif (isset($val[
'type']) && preg_match(
'/stars\((\d+)\)/', $val[
'type'], $reg)) {
8550 $param[
'options'] = array();
8555 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
8556 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
8557 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
8558 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
8568 $value =
dol_eval((
string) $computed, 1, 0,
'2');
8571 if (empty($morecss)) {
8572 if ($type ==
'date') {
8573 $morecss =
'minwidth100imp';
8574 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
8575 $morecss =
'minwidth200imp';
8576 } elseif (in_array($type, array(
'int',
'double',
'price'))) {
8577 $morecss =
'maxwidth75';
8578 } elseif ($type ==
'url') {
8579 $morecss =
'minwidth400';
8580 } elseif ($type ==
'boolean') {
8583 if (is_numeric($size) && round((
float) $size) < 12) {
8584 $morecss =
'minwidth100';
8585 } elseif (is_numeric($size) && round((
float) $size) <= 48) {
8586 $morecss =
'minwidth200';
8588 $morecss =
'minwidth400';
8594 if (in_array($key, array(
'rowid',
'ref')) && method_exists($this,
'getNomUrl')) {
8596 if ($key !=
'rowid' || empty($this->fields[
'ref'])) {
8597 $value = $this->getNomUrl(1,
'', 0,
'', 1);
8599 } elseif ($key ==
'status' && method_exists($this,
'getLibStatut')) {
8600 $value = $this->getLibStatut(3);
8601 } elseif ($type ==
'date') {
8602 if (!empty($value)) {
8607 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
8608 if (!empty($value)) {
8613 } elseif ($type ==
'duration') {
8614 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
8615 if (!is_null($value) && $value !==
'') {
8618 } elseif ($type ==
'double' || $type ==
'real') {
8619 if (!is_null($value) && $value !==
'') {
8620 $value =
price($value);
8622 } elseif ($type ==
'boolean') {
8624 if (!empty($value)) {
8625 $checked =
' checked ';
8628 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
8630 $value =
yn($value ? 1 : 0);
8632 } elseif ($type ==
'mail' || $type ==
'email') {
8634 } elseif ($type ==
'url') {
8636 } elseif ($type ==
'phone') {
8637 $value =
dol_print_phone((
string) $value,
'', 0, 0,
'',
' ',
'phone');
8638 } elseif ($type ==
'ip') {
8640 } elseif ($type ==
'stars') {
8641 $value =
'<input type="hidden" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.$this->id.
'" value="'.
dol_escape_htmltag((
string) $value).
'"'.($moreparam ? $moreparam :
'').
'>';
8642 $value .=
'<div class="star-selection" id="'.$keyprefix.$key.$keysuffix.$this->id.
'_selection">';
8644 while ($i <= $size) {
8645 $value .=
'<span class="star" data-value="'.$i.
'">'.
img_picto(
'',
'fontawesome_star_fas').
'</span>';
8650 $(document).ready(function() { /* commonobject.class.php 2 */
8651 let container = $("#'.$keyprefix.$key.$keysuffix.$this->id.
'_selection");
8652 let selectedStars = parseInt($("#'.$keyprefix.$key.$keysuffix.$this->id.
'").val()) || 0;
8653 container.find(".star").each(function() {
8654 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
8656 container.find(".star").on("mouseover", function() {
8657 let selectedStar = $(this).data("value");
8658 container.find(".star").each(function() {
8659 $(this).toggleClass("active", $(this).data("value") <= selectedStar);
8662 container.on("mouseout", function() {
8663 container.find(".star").each(function() {
8664 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
8667 container.find(".star").off("click").on("click", function() {
8668 selectedStars = $(this).data("value");
8669 if (selectedStars == 1 && $("#'.$keyprefix.$key.$keysuffix.$this->id.
'").val() == 1) {
8672 container.find("#'.$keyprefix.$key.$keysuffix.$this->id.
'").val(selectedStars);
8673 container.find(".star").each(function() {
8674 $(this).toggleClass("active", $(this).data("value") <= selectedStars);
8677 url: "ajax/'.$this->element.
'.php",
8680 objectId: "'.$this->
id.
'",
8681 field: "'.$keyprefix.$key.$keysuffix.
'",
8682 value: selectedStars,
8685 success: function(response) {
8686 var res = JSON.parse(response);
8687 console[res.status === "success" ? "log" : "error"](res.message);
8689 error: function(xhr, status, error) {
8690 console.log("Ajax request failed while updating '.$keyprefix.$key.$keysuffix.
':", error);
8696 } elseif ($type ==
'price') {
8697 if (!is_null($value) && $value !==
'') {
8698 $value =
price($value, 0, $langs, 0, 0, -1,
$conf->currency);
8700 } elseif ($type ==
'select') {
8701 $value = isset($param[
'options'][(
string) $value]) ? $param[
'options'][(string) $value] :
'';
8702 if (strpos($value,
"|") !==
false) {
8703 $value = $langs->trans(explode(
'|', $value)[0]);
8704 } elseif (! is_numeric($value)) {
8705 $value = $langs->trans($value);
8707 } elseif ($type ==
'sellist') {
8708 $param_list = array_keys($param[
'options']);
8709 $InfoFieldList = explode(
":", $param_list[0]);
8711 $selectkey =
"rowid";
8714 if (count($InfoFieldList) > 2 && !empty($InfoFieldList[2])) {
8715 $selectkey = $InfoFieldList[2];
8716 $keyList = $InfoFieldList[2].
' as rowid';
8719 $fields_label = explode(
'|', $InfoFieldList[1]);
8720 if (is_array($fields_label)) {
8722 $keyList .= implode(
', ', $fields_label);
8725 $filter_categorie =
false;
8726 if (count($InfoFieldList) > 5) {
8727 if ($InfoFieldList[0] ==
'categorie') {
8728 $filter_categorie =
true;
8732 $sql =
"SELECT ".$keyList;
8733 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8734 if (isset($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra') !==
false) {
8737 if ($selectkey ==
'rowid' && empty($value)) {
8738 $sql .=
" WHERE ".$selectkey.
" = 0";
8739 } elseif ($selectkey ==
'rowid') {
8740 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
8742 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape((
string) $value).
"'";
8747 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
8748 $resql = $this->db->query($sql);
8750 if (!$filter_categorie) {
8752 $numrows = $this->db->num_rows($resql);
8754 $obj = $this->db->fetch_object($resql);
8757 $fields_label = explode(
'|', $InfoFieldList[1]);
8759 if (is_array($fields_label) && count($fields_label) > 1) {
8760 foreach ($fields_label as $field_toshow) {
8762 if (!empty($obj->$field_toshow)) {
8763 $translabel = $langs->trans($obj->$field_toshow);
8765 if ($translabel != $field_toshow) {
8766 $value .=
dol_trunc($translabel, 18) .
' ';
8768 $value .= $obj->$field_toshow .
' ';
8773 if (!empty($obj->{$InfoFieldList[1]})) {
8774 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8776 if ($translabel != $obj->{$InfoFieldList[1]}) {
8779 $value = $obj->{$InfoFieldList[1]};
8784 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8787 $obj = $this->db->fetch_object($resql);
8789 $c->fetch($obj->rowid);
8790 $ways =
$c->print_all_ways();
8791 foreach ($ways as $way) {
8792 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8794 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8797 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8799 } elseif ($type ==
'radio') {
8800 $value = $param[
'options'][(string) $value];
8801 } elseif ($type ==
'checkbox') {
8802 $value_arr = explode(
',', (
string) $value);
8804 if (is_array($value_arr) && count($value_arr) > 0) {
8806 foreach ($value_arr as $keyval => $valueval) {
8807 if (!empty($valueval)) {
8808 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $param[
'options'][$valueval] .
'</li>';
8811 if (!empty($toprint)) {
8812 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
8815 } elseif ($type ==
'chkbxlst') {
8816 $value_arr = (isset($value) ? explode(
',', $value) : array());
8818 $param_list = array_keys($param[
'options']);
8819 $InfoFieldList = explode(
":", $param_list[0]);
8821 $selectkey =
"rowid";
8824 if (count($InfoFieldList) >= 3) {
8825 $selectkey = $InfoFieldList[2];
8826 $keyList = $InfoFieldList[2].
' as rowid';
8829 $fields_label = explode(
'|', $InfoFieldList[1]);
8830 if (is_array($fields_label)) {
8832 $keyList .= implode(
', ', $fields_label);
8835 $filter_categorie =
false;
8836 if (count($InfoFieldList) > 5) {
8837 if ($InfoFieldList[0] ==
'categorie') {
8838 $filter_categorie =
true;
8842 $sql =
"SELECT ".$keyList;
8843 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8844 if (isset($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra') !==
false) {
8850 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
8851 $resql = $this->db->query($sql);
8853 if (!$filter_categorie) {
8856 while ($obj = $this->db->fetch_object($resql)) {
8858 $fields_label = explode(
'|', $InfoFieldList[1]);
8859 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8860 if (is_array($fields_label) && count($fields_label) > 1) {
8861 foreach ($fields_label as $field_toshow) {
8863 if (!empty($obj->$field_toshow)) {
8864 $translabel = $langs->trans($obj->$field_toshow);
8866 if ($translabel != $field_toshow) {
8867 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8869 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->$field_toshow .
'</li>';
8874 if (!empty($obj->{$InfoFieldList[1]})) {
8875 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8877 if ($translabel != $obj->{$InfoFieldList[1]}) {
8878 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8880 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->{$InfoFieldList[1]} .
'</li>';
8886 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8889 while ($obj = $this->db->fetch_object($resql)) {
8890 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8892 $c->fetch($obj->rowid);
8893 $ways =
$c->print_all_ways();
8894 foreach ($ways as $way) {
8895 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . (
$c->color ?
' style="background: #' .
$c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8900 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8902 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8904 } elseif ($type ==
'link') {
8909 $param_list = array_keys($param[
'options']);
8913 $InfoFieldList = explode(
":", $param_list[0]);
8915 $classname = $InfoFieldList[0];
8916 $classpath = $InfoFieldList[1];
8919 $getnomurlparam = 3;
8920 $getnomurlparam2 =
'';
8922 if (preg_match(
'/#getnomurlparam1=([^#]*)/', $param_list[0], $regtmp)) {
8923 $getnomurlparam = $regtmp[1];
8925 if (preg_match(
'/#getnomurlparam2=([^#]*)/', $param_list[0], $regtmp)) {
8926 $getnomurlparam2 = $regtmp[1];
8929 if (!empty($classpath)) {
8932 if ($classname && !class_exists($classname)) {
8936 if ($element_prop) {
8937 $classname = $element_prop[
'classname'];
8942 if ($classname && class_exists($classname)) {
8943 $object =
new $classname($this->db);
8944 '@phan-var-force CommonObject $object';
8945 if (
$object->element ===
'product') {
8946 '@phan-var-force Product $object';
8947 $result =
$object->fetch((
int) $value,
'',
'',
'', 0, 1, 1);
8949 $result =
$object->fetch($value);
8952 if (
$object->element ===
'product') {
8953 '@phan-var-force Product $object';
8954 $get_name_url_param_arr = array($getnomurlparam, $getnomurlparam2, 0, -1, 0,
'', 0);
8955 if (isset($val[
'get_name_url_params'])) {
8956 $get_name_url_params = explode(
':', $val[
'get_name_url_params']);
8957 if (!empty($get_name_url_params)) {
8958 $param_num_max = count($get_name_url_param_arr) - 1;
8959 foreach ($get_name_url_params as $param_num => $param_value) {
8960 if ($param_num > $param_num_max) {
8963 $get_name_url_param_arr[$param_num] = $param_value;
8971 $value =
$object->getNomUrl($get_name_url_param_arr[0], $get_name_url_param_arr[1], $get_name_url_param_arr[2], $get_name_url_param_arr[3], $get_name_url_param_arr[4], $get_name_url_param_arr[5], $get_name_url_param_arr[6]);
8973 $value =
$object->getNomUrl($getnomurlparam, $getnomurlparam2);
8980 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
8981 return 'Error bad setup of extrafield';
8986 } elseif ($type ==
'password') {
8987 $value =
'<span class="opacitymedium">'.$langs->trans(
"Encrypted").
'</span>';
8989 } elseif ($type ==
'array') {
8990 if (is_array($value)) {
8991 $value = implode(
'<br>', $value);
8993 dol_syslog(__METHOD__.
' Expected array from dol_eval, but got '.gettype($value), LOG_ERR);
8994 return 'Error unexpected result from code evaluation';
8997 if (!empty($value) && preg_match(
'/^text/', (
string) $type) && !preg_match(
'/search_/', $keyprefix) && !empty($param[
'options'])) {
8998 $value = str_replace(
',',
"\n", $value);
9006 return is_null($out) ?
'' : $out;
9018 unset($this->validateFieldsErrors[$fieldKey]);
9032 $msg = $langs->trans(
"UnknownError");
9035 $this->error = $this->validateFieldsErrors[$fieldKey] = $msg;
9046 if (!empty($this->validateFieldsErrors[$fieldKey])) {
9047 return $this->validateFieldsErrors[$fieldKey];
9064 if (!class_exists(
'Validate')) {
9065 require_once DOL_DOCUMENT_ROOT .
'/core/class/validate.class.php';
9068 $this->clearFieldError($fieldKey);
9070 if (!array_key_exists($fieldKey, $fields) || !is_array($fields[$fieldKey])) {
9071 $this->setFieldError($fieldKey, $langs->trans(
'FieldNotFoundInObject'));
9075 $val = $fields[$fieldKey];
9078 $param[
'options'] = array();
9079 $type = $val[
'type'];
9082 if (isset($val[
'notnull']) && $val[
'notnull'] === 1) {
9096 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
9098 $maxSize = (int) $reg[1];
9099 } elseif (preg_match(
'/varchar/', $type)) {
9103 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
9107 if (!empty($val[
'type']) && preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
9111 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
9112 $param[
'options'] = $val[
'arrayofkeyval'];
9115 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
9117 $param[
'options'] = array($reg[1].
':'.$reg[2] => $reg[1].
':'.$reg[2]);
9118 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
9119 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
9121 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
9122 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
9124 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
9125 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
9134 $validate =
new Validate($this->db, $langs);
9144 if ($required && !$validate->isNotEmptyString($fieldValue)) {
9145 $this->setFieldError($fieldKey, $validate->error);
9147 } elseif (!$required && !$validate->isNotEmptyString($fieldValue)) {
9153 if (!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)) {
9154 $this->setFieldError($fieldKey, $validate->error);
9159 if (!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)) {
9160 $this->setFieldError($fieldKey, $validate->error);
9168 if (in_array($type, array(
'date',
'datetime',
'timestamp'))) {
9169 if (!$validate->isTimestamp($fieldValue)) {
9170 $this->setFieldError($fieldKey, $validate->error);
9175 } elseif ($type ==
'duration') {
9176 if (!$validate->isDuration($fieldValue)) {
9177 $this->setFieldError($fieldKey, $validate->error);
9182 } elseif (in_array($type, array(
'double',
'real',
'price'))) {
9184 if (!$validate->isNumeric($fieldValue)) {
9185 $this->setFieldError($fieldKey, $validate->error);
9190 } elseif ($type ==
'boolean') {
9191 if (!$validate->isBool($fieldValue)) {
9192 $this->setFieldError($fieldKey, $validate->error);
9197 } elseif ($type ==
'mail' || $type ==
'email') {
9198 if (!$validate->isEmail($fieldValue)) {
9199 $this->setFieldError($fieldKey, $validate->error);
9202 } elseif ($type ==
'url') {
9203 if (!$validate->isUrl($fieldValue)) {
9204 $this->setFieldError($fieldKey, $validate->error);
9209 } elseif ($type ==
'phone') {
9210 if (!$validate->isPhone($fieldValue)) {
9211 $this->setFieldError($fieldKey, $validate->error);
9216 } elseif ($type ==
'select' || $type ==
'radio') {
9217 if (!isset($param[
'options'][$fieldValue])) {
9218 $this->error = $langs->trans(
'RequireValidValue');
9223 } elseif ($type ==
'sellist' || $type ==
'chkbxlst') {
9224 $param_list = array_keys($param[
'options']);
9225 $InfoFieldList = explode(
":", $param_list[0]);
9226 $value_arr = explode(
',', $fieldValue);
9227 $value_arr = array_map(array($this->db,
'escape'), $value_arr);
9229 $selectkey =
"rowid";
9230 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
9231 $selectkey = $InfoFieldList[2];
9234 if (!$validate->isInDb($value_arr, $InfoFieldList[0], $selectkey)) {
9235 $this->setFieldError($fieldKey, $validate->error);
9240 } elseif ($type ==
'link') {
9241 $param_list = array_keys($param[
'options']);
9242 $InfoFieldList = explode(
":", $param_list[0]);
9243 $classname = $InfoFieldList[0];
9244 $classpath = $InfoFieldList[1];
9245 if (!$validate->isFetchable((
int) $fieldValue, $classname, $classpath)) {
9246 $lastIsFetchableError = $validate->error;
9249 if ($validate->isFetchableElement((
int) $fieldValue, $classname)) {
9253 $this->setFieldError($fieldKey, $lastIsFetchableError);
9277 public function showOptionals($extrafields, $mode =
'view', $params =
null, $keysuffix =
'', $keyprefix =
'', $onetrtd =
'', $display_type =
'card')
9279 global $db,
$conf, $langs, $action, $form, $hookmanager;
9281 if (!is_object($form)) {
9282 $form =
new Form($db);
9284 if (!is_object($extrafields)) {
9285 dol_syslog(
'Bad parameter extrafields for showOptionals', LOG_ERR);
9286 return 'Bad parameter extrafields for showOptionals';
9288 if (!is_array($extrafields->attributes[$this->table_element])) {
9289 dol_syslog(
"extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
9294 $parameters = array(
'mode' => $mode,
'params' => $params,
'keysuffix' => $keysuffix,
'keyprefix' => $keyprefix,
'display_type' => $display_type);
9295 $reshook = $hookmanager->executeHooks(
'showOptionals', $parameters, $this, $action);
9297 if (empty($reshook)) {
9298 if (is_array($extrafields->attributes[$this->table_element]) && array_key_exists(
'label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label']) > 0) {
9300 $out .=
'<!-- commonobject:showOptionals --> ';
9303 $nbofextrafieldsshown = 0;
9306 $lastseparatorkeyfound =
'';
9307 $extrafields_collapse_num =
'';
9308 $extrafields_collapse_num_old =
'';
9311 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $label) {
9315 if (is_array($params) && array_key_exists(
'onlykey', $params) && $key != $params[
'onlykey']) {
9321 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
9322 $enabled = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
9324 if (empty($enabled)) {
9329 if (isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
9330 $visibility = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
9334 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
9335 $perms = (int)
dol_eval((
string) $extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
9338 if (($mode ==
'create') && !in_array(abs($visibility), array(1, 3))) {
9340 } elseif (($mode ==
'edit') && !in_array(abs($visibility), array(1, 3, 4))) {
9342 $ef_name =
'options_' . $key;
9343 $ef_value = $this->array_options[$ef_name];
9344 $out .=
'<input type="hidden" name="' . $ef_name .
'" id="' . $ef_name .
'" value="' . $ef_value .
'" />' .
"\n";
9346 } elseif ($mode ==
'view' && empty($visibility)) {
9349 if (empty($perms)) {
9354 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
9355 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
9360 if (is_array($params) && count($params) > 0 && $display_type ==
'card') {
9361 if (array_key_exists(
'cols', $params)) {
9362 $colspan = $params[
'cols'];
9363 } elseif (array_key_exists(
'colspan', $params)) {
9365 if (preg_match(
'/colspan="(\d+)"/', $params[
'colspan'], $reg)) {
9368 $colspan = $params[
'colspan'];
9372 $colspan = intval($colspan);
9376 $value = ((!empty($this->array_options) && array_key_exists(
"options_".$key.$keysuffix, $this->array_options)) ? $this->array_options[
"options_".$key.$keysuffix] :
null);
9382 $check =
'alphanohtml';
9383 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text'))) {
9384 $check =
'restricthtml';
9386 $getposttemp =
GETPOST($keyprefix.
'options_'.$key.$keysuffix, $check, 3);
9388 if (is_array($getposttemp) || $getposttemp !=
'' || GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix)) {
9389 if (is_array($getposttemp)) {
9391 $value = implode(
",", $getposttemp);
9393 $value = $getposttemp;
9395 } elseif (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'int'))) {
9396 $value = (!empty($this->array_options[
"options_".$key]) || (isset($this->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] ===
'0')) ? $this->array_options[
"options_".$key] :
'';
9398 $value = (!empty($this->array_options[
"options_".$key]) ? $this->array_options[
"options_".$key] :
'');
9404 $nbofextrafieldsshown++;
9407 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
9408 $extrafields_collapse_num = $key;
9426 $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
9428 $lastseparatorkeyfound = $key;
9430 $collapse_group = $extrafields_collapse_num.(!empty($this->
id) ?
'_'.$this->id :
'');
9432 $class = (!empty($extrafields->attributes[$this->table_element][
'hidden'][$key]) ?
'hideobject ' :
'');
9434 if (is_array($params) && count($params) > 0) {
9435 if (array_key_exists(
'class', $params)) {
9436 $class .= $params[
'class'].
' ';
9438 if (array_key_exists(
'style', $params)) {
9439 $csstyle = $params[
'style'];
9444 $domData =
' data-element="extrafield"';
9445 $domData .=
' data-targetelement="'.$this->element.
'"';
9446 $domData .=
' data-targetid="'.$this->id.
'"';
9448 $html_id = (empty($this->
id) ?
'' :
'extrarow-'.$this->element.
'_'.$key.
'_'.
$this->id);
9449 if ($display_type ==
'card') {
9454 if ($action ==
'selectlines') {
9461 $force_values_on_change_company = (
9462 ($this->element ==
'facture' &&
getDolGlobalInt(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_INVOICE'))
9463 || ($this->element ==
'commande' &&
getDolGlobalInt(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_ORDER'))
9464 || ($this->element ==
'order_supplier' &&
getDolGlobalInt(
'THIRDPARTY_PROPAGATE_EXTRAFIELDS_TO_SUPPLIER_ORDER'))
9466 if ($force_values_on_change_company &&
GETPOSTINT(
'changecompany')) {
9467 $value = $this->array_options[
'options_'.$key] ?? $value;
9471 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date'))) {
9472 $datenotinstring =
null;
9473 if (array_key_exists(
'options_'.$key, $this->array_options)) {
9474 $datenotinstring = $this->array_options[
'options_'.$key];
9475 if (!is_numeric($this->array_options[
'options_'.$key])) {
9476 $datenotinstring = $this->db->jdate($datenotinstring);
9479 $datekey = $keyprefix.
'options_'.$key.$keysuffix;
9482 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'datetime'))) {
9483 $datenotinstring =
null;
9484 if (array_key_exists(
'options_'.$key, $this->array_options)) {
9485 $datenotinstring = $this->array_options[
'options_'.$key];
9486 if (!is_numeric($this->array_options[
'options_'.$key])) {
9487 $datenotinstring = $this->db->jdate($datenotinstring);
9490 $timekey = $keyprefix.
'options_'.$key.$keysuffix;
9491 $value = (GETPOSTISSET($timekey)) ?
dol_mktime(
GETPOSTINT($timekey.
'hour', 3),
GETPOSTINT($timekey.
'min', 3),
GETPOSTINT($timekey.
'sec', 3),
GETPOSTINT($timekey.
'month', 3),
GETPOSTINT($timekey.
'day', 3),
GETPOSTINT($timekey.
'year', 3),
'tzuserrel') : $datenotinstring;
9494 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'price',
'double'))) {
9495 if (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) {
9497 } elseif (isset($this->array_options[
'options_'.$key])) {
9498 $value = $this->array_options[
'options_'.$key];
9503 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text',
'varchar',
'select',
'radio',
'int',
'boolean'))) {
9504 if ($action ==
'create' || $mode ==
'create') {
9505 $value = (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element][
'default'][$key];
9509 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'checkbox'))) {
9510 if ($action ==
'create') {
9511 $value = (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) ? $value : explode(
',', $extrafields->attributes[$this->table_element][
'default'][$key]);
9516 $labeltoshow = $langs->trans($label);
9517 $helptoshow = $langs->trans($extrafields->attributes[$this->table_element][
'help'][$key]);
9518 if ($display_type ==
'card') {
9519 $out .=
'<tr '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="field_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
9520 if (
getDolGlobalString(
'MAIN_VIEW_LINE_NUMBER') && ($action ==
'view' || $action ==
'valid' || $action ==
'editline' || $action ==
'confirm_valid' || $action ==
'confirm_cancel')) {
9521 $out .=
'<td></td>';
9523 $out .=
'<td class="'.(empty($params[
'tdclass']) ?
'titlefieldmax45' : $params[
'tdclass']).
' wordbreak';
9524 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text') {
9527 } elseif ($display_type ==
'line') {
9528 $out .=
'<div '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="fieldline_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
9529 $out .=
'<div style="display: inline-block; padding-right:4px" class="wordbreak';
9534 $tpl_context = isset($params[
"tpl_context"]) ? $params[
"tpl_context"] :
"none";
9535 if ($tpl_context !=
"public") {
9536 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
9537 $out .=
' fieldrequired';
9541 if ($tpl_context ==
"public") {
9542 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
9543 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
9545 $out .= $labeltoshow;
9547 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
9548 $out .=
' <span style="color: red">*</span>';
9551 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
9552 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
9554 $out .= $labeltoshow;
9558 $out .= ($display_type ==
'card' ?
'</td>' :
'</div>');
9561 $html_id = !empty($this->
id) ? $this->element.
'_extras_'.$key.
'_'.$this->id :
'';
9562 if ($display_type ==
'card') {
9564 $out .=
'<td '.($html_id ?
'id="'.$html_id.
'" ' :
'').
' class="valuefieldcreate '.$this->element.
'_extras_'.$key;
9565 $out .=
'" '.($colspan ?
' colspan="'.$colspan.
'"' :
'');
9567 } elseif ($display_type ==
'line') {
9568 $out .=
'<div '.($html_id ?
'id="'.$html_id.
'" ' :
'').
' style="display: inline-block" class="valuefieldcreate '.$this->element.
'_extras_'.$key.
' extra_inline_'.$extrafields->attributes[$this->table_element][
'type'][$key].
'">';
9573 $out .= $extrafields->showOutputField($key, $value,
'', $this->table_element);
9576 $listoftypestoshowpicto = explode(
',',
getDolGlobalString(
'MAIN_TYPES_TO_SHOW_PICTO',
'email,phone,ip,password'));
9577 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], $listoftypestoshowpicto)) {
9578 $out .=
getPictoForType($extrafields->attributes[$this->table_element][
'type'][$key], ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text' ?
'tdtop' :
''));
9581 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'',
'', $this, $this->table_element);
9584 $listoftypestoshowpicto = explode(
',',
getDolGlobalString(
'MAIN_TYPES_TO_SHOW_PICTO',
'email,phone,ip,password'));
9585 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], $listoftypestoshowpicto)) {
9586 $out .=
getPictoForType($extrafields->attributes[$this->table_element][
'type'][$key], ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text' ?
'tdtop' :
''));
9588 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'',
'', $this, $this->table_element);
9592 $out .= ($display_type ==
'card' ?
'</td>' :
'</div>');
9593 $out .= ($display_type ==
'card' ?
'</tr>'.
"\n" :
'</div>');
9599 if (!empty(
$conf->use_javascript_ajax)) {
9600 $out .= $this->getJSListDependancies();
9603 $out .=
'<!-- commonobject:showOptionals end --> '.
"\n";
9605 if (empty($nbofextrafieldsshown)) {
9611 $out .= $hookmanager->resPrint;
9623 <script nonce="'.getNonce().
'">
9624 jQuery(document).ready(function() {
9625 function showOptions'.$type.
'(child_list, parent_list, orig_select)
9627 var val = $("select[name=\""+parent_list+"\"]").val();
9628 var parentVal = parent_list + ":" + val;
9629 if(typeof val == "string"){
9631 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
9632 $("select[name=\""+child_list+"\"] option[parent]").remove();
9633 $("select[name=\""+child_list+"\"]").append(options);
9635 var options = orig_select.find("option[parent]").clone();
9636 $("select[name=\""+child_list+"\"] option[parent]").remove();
9637 $("select[name=\""+child_list+"\"]").append(options);
9639 } else if(val > 0) {
9640 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
9641 $("select[name=\""+child_list+"\"] option[parent]").remove();
9642 $("select[name=\""+child_list+"\"]").append(options);
9644 var options = orig_select.find("option[parent]").clone();
9645 $("select[name=\""+child_list+"\"] option[parent]").remove();
9646 $("select[name=\""+child_list+"\"]").append(options);
9649 function setListDependencies'.$type.
'() {
9650 jQuery("select option[parent]").parent().each(function() {
9651 var orig_select = {};
9652 var child_list = $(this).attr("name");
9653 orig_select[child_list] = $(this).clone();
9654 var parent = $(this).find("option[parent]:first").attr("parent");
9655 var infos = parent.split(":");
9656 var parent_list = infos[0];
9658 //Hide daughters lists
9659 if ($("#"+child_list).val() == 0 && $("#"+parent_list).val() == 0){
9660 $("#"+child_list).hide();
9662 } else if ($("#"+parent_list).val() != 0){
9663 $("#"+parent_list).show();
9665 //Show the child list if the parent list value is selected
9666 $("select[name=\""+parent_list+"\"]").click(function() {
9667 if ($(this).val() != 0){
9668 $("#"+child_list).show()
9672 //When we change parent list
9673 $("select[name=\""+parent_list+"\"]").change(function() {
9674 showOptions'.$type.
'(child_list, parent_list, orig_select[child_list]);
9675 //Select the value 0 on child list after a change on the parent list
9676 $("#"+child_list).val(0).trigger("change");
9677 //Hide child lists if the parent value is set to 0
9678 if ($(this).val() == 0){
9679 $("#"+child_list).hide();
9685 setListDependencies'.$type.
'();
9700 $module = empty($this->module) ?
'' : $this->module;
9701 $element = $this->element;
9703 if ($element ==
'facturerec') {
9704 $element =
'facture';
9705 } elseif ($element ==
'invoice_supplier_rec') {
9706 return !$user->hasRight(
'fournisseur',
'facture') ? null : $user->hasRight(
'fournisseur',
'facture');
9707 } elseif ($module && $user->hasRight($module, $element)) {
9709 return $user->hasRight($module, $element);
9712 return $user->rights->$element;
9729 global $hookmanager;
9731 $parameters = array(
9732 'origin_id' => $origin_id,
9733 'dest_id' => $dest_id,
9734 'tables' => $tables,
9736 $reshook = $hookmanager->executeHooks(
'commonReplaceThirdparty', $parameters);
9739 } elseif ($reshook < 0) {
9740 return $ignoreerrors === 1;
9743 foreach ($tables as $table) {
9744 $sql =
'UPDATE '.$dbs->prefix().$table.
' SET fk_soc = '.((int) $dest_id).
' WHERE fk_soc = '.((int) $origin_id);
9746 if (!$dbs->
query($sql)) {
9747 if ($ignoreerrors) {
9772 foreach ($tables as $table) {
9773 $sql =
'UPDATE '.MAIN_DB_PREFIX.$table.
' SET fk_product = '.((int) $dest_id).
' WHERE fk_product = '.((int) $origin_id);
9775 if (!$dbs->
query($sql)) {
9776 if ($ignoreerrors) {
9799 public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0)
9805 if (($unitPrice > 0) && (isset(
$conf->global->ForceBuyingPriceIfNull) &&
getDolGlobalInt(
'ForceBuyingPriceIfNull') > 0)) {
9807 $buyPrice = $unitPrice * (1 - $discountPercent / 100);
9810 if (!empty($fk_product) && $fk_product > 0) {
9813 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9814 $product =
new Product($this->db);
9815 $result = $product->fetch($fk_product);
9817 $this->errors[] =
'ErrorProductIdDoesNotExists';
9820 if ($product->cost_price > 0) {
9821 $buyPrice = $product->cost_price;
9822 } elseif ($product->pmp > 0) {
9823 $buyPrice = $product->pmp;
9826 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9827 $product =
new Product($this->db);
9828 $result = $product->fetch($fk_product);
9830 $this->errors[] =
'ErrorProductIdDoesNotExists';
9833 if ($product->pmp > 0) {
9834 $buyPrice = $product->pmp;
9838 if (empty($buyPrice) && isset(
$conf->global->MARGIN_TYPE) && in_array(
$conf->global->MARGIN_TYPE, array(
'1',
'pmp',
'costprice'))) {
9839 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
9841 if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) {
9842 $buyPrice = $productFournisseur->fourn_unitprice;
9843 } elseif ($result < 0) {
9844 $this->errors[] = $productFournisseur->error;
9851 return (
float) $buyPrice;
9864 return array(
'dir' =>
'',
'file' =>
'',
'originalfile' =>
'',
'altfile' =>
'',
'email' =>
'',
'capture' =>
'');
9888 public function show_photos($modulepart, $sdir, $size = 0, $nbmax = 0, $nbbyrow = 5, $showfilename = 0, $showaction = 0, $maxHeight = 120, $maxWidth = 160, $nolink = 0, $overwritetitle = 0, $usesharelink = 0, $cache =
'', $addphotorefcss =
'photoref')
9891 global $user, $langs;
9893 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
9894 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
9896 $sortfield =
'position_name';
9902 $dir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9903 $pdir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9906 if ($modulepart ==
'product') {
9908 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9909 $pdir =
'/'.get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9912 if ($modulepart ==
'category') {
9913 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9914 $pdir =
'/'.get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9920 $relativedir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
9921 $relativedir = preg_replace(
'/^[\\/]/',
'', $relativedir);
9922 $relativedir = preg_replace(
'/[\\/]$/',
'', $relativedir);
9925 $dirthumb = $dir.
'thumbs/';
9926 $pdirthumb = $pdir.
'thumbs/';
9928 $return =
'<!-- Photo -->'.
"\n";
9931 $filearray =
dol_dir_list($dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
9940 '@phan-var-force array<array{name:string,path:string,level1name:string,relativename:string,fullname:string,date:string,size:int,perm:int,type:string,position_name:string,cover:string,keywords:string,acl:string,rowid:int,label:string,share:string}> $filearray';
9942 if (count($filearray)) {
9943 if ($sortfield && $sortorder) {
9947 foreach ($filearray as $key => $val) {
9949 $file = $val[
'name'];
9955 $viewfilename = $file;
9957 if ($size == 1 || $size ==
'small') {
9964 $photo_vignette = basename($file);
9971 if ($nbphoto == 1) {
9972 $return .=
'<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';
9975 if ($nbphoto % $nbbyrow == 1) {
9976 $return .=
'<tr class="center valignmiddle" style="border: 1px">';
9978 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%" class="photo">'.
"\n";
9979 } elseif ($nbbyrow < 0) {
9980 $return .=
'<div class="inline-block">'.
"\n";
9983 $relativefile = preg_replace(
'/^\//',
'', $pdir.$photo);
9984 if (empty($nolink)) {
9987 $return .=
'<a href="'.$urladvanced.
'">';
9989 $return .=
'<a href="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
9995 $alt = $langs->transnoentitiesnoconv(
'File').
': '.$relativefile;
9996 $alt .=
' - '.$langs->transnoentitiesnoconv(
'Size').
': '.$imgarray[
'width'].
'x'.$imgarray[
'height'];
9997 if ($overwritetitle) {
9998 if (is_numeric($overwritetitle)) {
10001 $alt = $overwritetitle;
10004 if (empty($cache) && !empty($val[
'label'])) {
10007 $cache = $val[
'label'];
10009 if ($usesharelink) {
10010 if (array_key_exists(
'share', $val) && $val[
'share']) {
10011 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
10012 $return .=
'<!-- Show original file (thumb not yet available with shared links) -->';
10013 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'"'.($maxHeight ?
' height="'.$maxHeight.
'"' :
'').
' src="'.DOL_URL_ROOT.
'/viewimage.php?hashp='.urlencode($val[
'share']).($cache ?
'&cache='.urlencode($cache) :
'').
'" title="'.
dol_escape_htmltag($alt).
'">';
10015 $return .=
'<!-- Show original file -->';
10016 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'" height="'.$maxHeight.
'" src="'.DOL_URL_ROOT.
'/viewimage.php?hashp='.urlencode($val[
'share']).($cache ?
'&cache='.urlencode($cache) :
'').
'" title="'.
dol_escape_htmltag($alt).
'">';
10019 $return .=
'<!-- Show nophoto file (because file is not shared) -->';
10020 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'" height="'.$maxHeight.
'" src="'.DOL_URL_ROOT.
'/public/theme/common/nophoto.png" title="'.
dol_escape_htmltag($alt).
'">';
10023 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
10024 $return .=
'<!-- Show thumb -->';
10025 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
' maxwidth150onsmartphone maxwidth200"'.($maxHeight ?
' height="'.$maxHeight.
'"' :
'').
' src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.($cache ?
'&cache='.urlencode($cache) :
'').
'&file='.urlencode($pdirthumb.$photo_vignette).
'" title="'.
dol_escape_htmltag($alt).
'">';
10027 $return .=
'<!-- Show original file -->';
10028 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'" height="'.$maxHeight.
'" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.($cache ?
'&cache='.urlencode($cache) :
'').
'&file='.urlencode($pdir.$photo).
'" title="'.
dol_escape_htmltag($alt).
'">';
10032 if (empty($nolink)) {
10036 if ($showfilename) {
10037 $return .=
'<br>'.$viewfilename;
10042 if ($photo_vignette && (
image_format_supported($photo) > 0) && ((isset($imgarray[
'width']) && $imgarray[
'width'] > $maxWidth) || (isset($imgarray[
'width']) && $imgarray[
'width'] > $maxHeight))) {
10043 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=addthumb&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">'.
img_picto($langs->trans(
'GenerateThumb'),
'refresh').
' </a>';
10046 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
10048 $return .=
'<a href="'.DOL_URL_ROOT.
'/core/photos_resize.php?modulepart='.urlencode(
'produit|service').
'&id='.$this->
id.
'&file='.urlencode($pdir.$viewfilename).
'" title="'.
dol_escape_htmltag($langs->trans(
"Resize")).
'">'.
img_picto($langs->trans(
"Resize"),
'resize',
'').
'</a> ';
10051 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
10057 if ($nbbyrow > 0) {
10058 $return .=
'</td>';
10059 if (($nbphoto % $nbbyrow) == 0) {
10060 $return .=
'</tr>';
10062 } elseif ($nbbyrow < 0) {
10063 $return .=
'</div>'.
"\n";
10067 if (empty($size)) {
10068 $return .=
'<img class="photo photowithmargin" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'">';
10070 if ($showfilename) {
10071 $return .=
'<br>'.$viewfilename;
10075 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
10077 $return .=
'<a href="'.DOL_URL_ROOT.
'/core/photos_resize.php?modulepart='.urlencode(
'produit|service').
'&id='.$this->
id.
'&file='.urlencode($pdir.$viewfilename).
'" title="'.
dol_escape_htmltag($langs->trans(
"Resize")).
'">'.
img_picto($langs->trans(
"Resize"),
'resize',
'').
'</a> ';
10080 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
10087 if ($nbmax && $nbphoto >= $nbmax) {
10093 if ($size == 1 || $size ==
'small') {
10094 if ($nbbyrow > 0) {
10096 while ($nbphoto % $nbbyrow) {
10097 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%"> </td>';
10102 $return .=
'</table>';
10108 $this->nbphoto = $nbphoto;
10122 if (is_array($info)) {
10123 if (isset($info[
'type']) && $info[
'type'] ==
'array') {
10140 if (isset($info[
'type']) && ($info[
'type'] ==
'date' || $info[
'type'] ==
'datetime' || $info[
'type'] ==
'timestamp')) {
10154 if (is_array($info)) {
10155 if (isset($info[
'type']) && ($info[
'type'] ==
'duration')) {
10173 if (is_array($info)) {
10174 if (isset($info[
'type']) && (preg_match(
'/(^int|int$)/i', $info[
'type']))) {
10192 if (is_array($info)) {
10193 if (isset($info[
'type']) && (preg_match(
'/^(double|real|price)/i', $info[
'type']))) {
10210 if (is_array($info)) {
10211 if (isset($info[
'type']) && $info[
'type'] ==
'text') {
10228 if (is_array($info)) {
10229 if (array_key_exists(
'notnull', $info) && $info[
'notnull'] !=
'1') {
10246 if (is_array($info)) {
10247 if (array_key_exists(
'notnull', $info) && $info[
'notnull'] ==
'-1') {
10264 if (is_array($info)) {
10265 if (array_key_exists(
'index', $info) && $info[
'index'] ==
true) {
10287 $queryarray = array();
10288 foreach ($this->fields as $field => $info) {
10290 if ($this->isDate($info)) {
10291 if (empty($this->{$field})) {
10292 $queryarray[$field] =
null;
10294 $queryarray[$field] = $this->db->idate($this->{$field});
10296 } elseif ($this->isDuration($info)) {
10298 if ((isset($this->{$field}) && $this->{$field} !=
'') || !empty($info[
'notnull'])) {
10299 if (!isset($this->{$field})) {
10300 if (!empty($info[
'default'])) {
10301 $queryarray[$field] = $info[
'default'];
10303 $queryarray[$field] = 0;
10306 $queryarray[$field] = (int) $this->{$field};
10309 $queryarray[$field] =
null;
10311 } elseif ($this->isInt($info) || $this->isFloat($info)) {
10312 if ($field ==
'entity' && is_null($this->{$field})) {
10313 $queryarray[$field] = ((int)
$conf->entity);
10316 if ((isset($this->{$field}) && ((
string) $this->{$field}) !=
'') || !empty($info[
'notnull'])) {
10317 if (!isset($this->{$field})) {
10318 $queryarray[$field] = 0;
10319 } elseif ($this->isInt($info)) {
10320 $queryarray[$field] = (int) $this->{$field};
10321 } elseif ($this->isFloat($info)) {
10322 $queryarray[$field] = (float) $this->{$field};
10325 $queryarray[$field] =
null;
10331 $queryarray[$field] = $this->{$field};
10334 if (array_key_exists(
'type', $info) && $info[
'type'] ==
'timestamp' && empty($queryarray[$field])) {
10335 unset($queryarray[$field]);
10337 if (!empty($info[
'notnull']) && $info[
'notnull'] == -1 && empty($queryarray[$field])) {
10338 $queryarray[$field] =
null;
10342 return $queryarray;
10355 foreach ($this->fields as $field => $info) {
10356 if ($this->isDate($info)) {
10357 if (!isset($obj->$field) || is_null($obj->$field) || $obj->$field ===
'' || $obj->$field ===
'0000-00-00 00:00:00' || $obj->$field ===
'1000-01-01 00:00:00') {
10358 $this->$field =
'';
10360 $this->$field = $db->jdate($obj->$field);
10362 } elseif ($this->isInt($info)) {
10363 if ($field ==
'rowid') {
10364 $this->
id = (int) $obj->$field;
10366 if ($this->isForcedToNullIfZero($info)) {
10367 if (empty($obj->$field)) {
10368 $this->$field =
null;
10370 $this->$field = (int) $obj->$field;
10373 if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists(
'notnull', $info) && $info[
'notnull'] == 1))) {
10374 $this->$field = (int) $obj->$field;
10376 $this->$field =
null;
10380 } elseif ($this->isFloat($info)) {
10381 if ($this->isForcedToNullIfZero($info)) {
10382 if (empty($obj->$field)) {
10383 $this->$field =
null;
10385 $this->$field = (float) $obj->$field;
10388 if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists(
'notnull', $info) && $info[
'notnull'] == 1))) {
10389 $this->$field = (float) $obj->$field;
10391 $this->$field =
null;
10395 $this->$field = isset($obj->$field) ? $obj->$field :
null;
10400 if (!isset($this->fields[
'ref']) && isset($this->
id)) {
10401 $this->
ref = (string) $this->
id;
10411 foreach ($this->fields as $field => $arr) {
10412 $this->$field =
null;
10425 $keys = array_keys($this->fields);
10426 if (!empty($alias)) {
10427 $keys_with_alias = array();
10428 foreach ($keys as $fieldname) {
10429 if (!empty($excludefields)) {
10430 if (in_array($fieldname, $excludefields)) {
10434 $keys_with_alias[] = $alias .
'.' . $fieldname;
10436 return implode(
', ', $keys_with_alias);
10438 return implode(
', ', $keys);
10449 protected function quote($value, $fieldsentry)
10451 if (is_null($value)) {
10453 } elseif (preg_match(
'/^(int|double|real|price)/i', $fieldsentry[
'type'])) {
10455 } elseif (preg_match(
'/int$/i', $fieldsentry[
'type'])) {
10456 return (
int) $value;
10457 } elseif ($fieldsentry[
'type'] ==
'boolean') {
10464 return "'".$this->db->escape($value).
"'";
10480 dol_syslog(get_class($this).
"::createCommon create", LOG_DEBUG);
10486 $fieldvalues = $this->setSaveQuery();
10490 if (array_key_exists(
'date_creation', $fieldvalues) && empty($fieldvalues[
'date_creation'])) {
10491 $fieldvalues[
'date_creation'] = $this->db->idate($now);
10492 $this->date_creation = $this->db->idate($now);
10495 if (array_key_exists(
'fk_user_creat', $fieldvalues) && !($fieldvalues[
'fk_user_creat'] > 0)) {
10496 $fieldvalues[
'fk_user_creat'] = $user->id;
10497 $this->fk_user_creat = $user->id;
10499 if (array_key_exists(
'user_creation_id', $fieldvalues) && !($fieldvalues[
'user_creation_id'] > 0)) {
10500 $fieldvalues[
'user_creation_id'] = $user->id;
10501 $this->user_creation_id = $user->id;
10503 if (array_key_exists(
'pass_crypted', $fieldvalues) && property_exists($this,
'pass')) {
10505 $tmparray =
dol_hash($this->pass,
'0', 0, 1);
10506 $fieldvalues[
'pass_crypted'] = $tmparray[
'pass_encrypted'];
10507 if (array_key_exists(
'pass_encoding', $fieldvalues) && property_exists($this,
'pass_encoding')) {
10508 $fieldvalues[
'pass_encoding'] = $tmparray[
'pass_encoding'];
10511 if (array_key_exists(
'ref', $fieldvalues)) {
10515 unset($fieldvalues[
'rowid']);
10519 foreach ($fieldvalues as $k => $v) {
10521 $value = $this->fields[$k];
10523 $values[$k] = $this->quote($v, $value);
10527 foreach ($keys as $key) {
10528 if (!isset($this->fields[$key])) {
10531 $key_fields = $this->fields[$key];
10534 if (preg_match(
'/^integer:/i', $key_fields[
'type']) && $values[$key] ==
'-1') {
10535 $values[$key] =
'';
10537 if (!empty($key_fields[
'foreignkey']) && $values[$key] ==
'-1') {
10538 $values[$key] =
'';
10541 if (isset($key_fields[
'notnull']) && $key_fields[
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && (!isset($key_fields[
'default']) || is_null($key_fields[
'default']))) {
10543 $langs->load(
"errors");
10544 dol_syslog(
"Mandatory field '".$key.
"' is empty and required into ->fields definition of class");
10545 $this->errors[] = $langs->trans(
"ErrorFieldRequired", isset($key_fields[
'label']) ? $key_fields[
'label'] : $key);
10549 if (isset($key_fields[
'notnull']) && $key_fields[
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && !is_null($key_fields[
'default'])) {
10550 $values[$key] = $this->quote($key_fields[
'default'], $key_fields);
10554 if (isset($key_fields[
'type']) && preg_match(
'/^integer:/i', $key_fields[
'type']) && empty($values[$key])) {
10555 if (isset($key_fields[
'default'])) {
10556 $values[$key] = ((int) $key_fields[
'default']);
10558 $values[$key] =
'null';
10561 if (!empty($key_fields[
'foreignkey']) && empty($values[$key])) {
10562 $values[$key] =
'null';
10570 $this->db->begin();
10573 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element;
10574 $sql .=
" (".implode(
", ", $keys).
')';
10575 $sql .=
" VALUES (".implode(
", ", $values).
")";
10577 $res = $this->db->query($sql);
10580 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
10581 $this->errors[] =
"ErrorRefAlreadyExists";
10583 $this->errors[] = $this->db->lasterror();
10589 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
10595 if (array_key_exists(
'ref', $this->fields) && array_key_exists(
'notnull', $this->fields[
'ref']) && $this->fields[
'ref'][
'notnull'] > 0 && array_key_exists(
'default', $this->fields[
'ref']) && $this->fields[
'ref'][
'default'] ==
'(PROV)') {
10596 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ref = '(PROV".((int) $this->
id).
")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->
id);
10597 $resqlupdate = $this->db->query($sql);
10599 if ($resqlupdate ===
false) {
10601 $this->errors[] = $this->db->lasterror();
10603 $this->
ref =
'(PROV'.$this->id.
')';
10610 $result = $this->insertExtraFields();
10617 if (!empty($this->table_element_line) && !empty($this->fk_element) && !empty($this->lines)) {
10618 foreach ($this->lines as $line) {
10619 $keyforparent = $this->fk_element;
10624 if (!is_object($line)) {
10625 $line = (object) $line;
10629 if (method_exists($line,
'insert')) {
10630 $result = $line->insert($user, 1);
10631 } elseif (method_exists($line,
'create')) {
10632 $result = $line->create($user, 1);
10635 $this->error = $line->error;
10636 $this->db->rollback();
10643 if (!$error && !$notrigger) {
10645 $result = $this->call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
10654 $this->db->rollback();
10657 $this->db->commit();
10674 if (empty(
$id) && empty($ref) && empty($morewhere)) {
10678 $fieldlist = $this->getFieldList(
't');
10679 if (empty($fieldlist)) {
10683 $sql =
"SELECT ".$fieldlist;
10684 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
' as t';
10687 $sql .=
' WHERE t.rowid = '.((int)
$id);
10688 } elseif (!empty($ref)) {
10689 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
10691 $sql .=
' WHERE 1 = 1';
10693 if (empty(
$id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
10694 $sql .=
' AND t.entity IN ('.getEntity($this->element).
')';
10697 $sql .= $morewhere;
10699 $sql .=
' LIMIT 1';
10701 $res = $this->db->query($sql);
10703 $obj = $this->db->fetch_object($res);
10705 $this->setVarsFromFetchObj($obj);
10709 if (empty($noextrafields)) {
10710 $result = $this->fetch_optionals();
10712 $this->error = $this->db->lasterror();
10713 $this->errors[] = $this->error;
10723 $this->error = $this->db->lasterror();
10724 $this->errors[] = $this->error;
10738 $objectlineclassname = get_class($this).
'Line';
10739 if (!class_exists($objectlineclassname)) {
10740 $this->error =
'Error, class '.$objectlineclassname.
' not found during call of fetchLinesCommon';
10744 $objectline =
new $objectlineclassname($this->db);
10745 '@phan-var-force CommonObjectLine $objectline';
10747 $sql =
"SELECT ".$objectline->getFieldList(
'l');
10748 $sql .=
" FROM ".$this->db->prefix().$objectline->table_element.
" as l";
10749 $sql .=
" WHERE l.fk_".$this->db->escape($this->element).
" = ".((int) $this->
id);
10751 $sql .= $morewhere;
10753 if (isset($objectline->fields[
'position'])) {
10754 $sql .= $this->db->order(
'position',
'ASC');
10757 $resql = $this->db->query($sql);
10759 $num_rows = $this->db->num_rows($resql);
10761 $this->lines = array();
10762 while ($i < $num_rows) {
10763 $obj = $this->db->fetch_object($resql);
10765 $newline =
new $objectlineclassname($this->db);
10766 '@phan-var-force CommonObjectLine $newline';
10767 $newline->setVarsFromFetchObj($obj);
10770 if (empty($noextrafields)) {
10771 $newline->fetch_optionals();
10774 $this->lines[] = $newline;
10781 $this->error = $this->db->lasterror();
10782 $this->errors[] = $this->error;
10796 dol_syslog(get_class($this).
"::updateCommon update", LOG_DEBUG);
10808 $fieldvalues = $this->setSaveQuery();
10812 if (array_key_exists(
'date_modification', $fieldvalues) && empty($fieldvalues[
'date_modification'])) {
10813 $fieldvalues[
'date_modification'] = $this->db->idate($now);
10815 if (array_key_exists(
'fk_user_modif', $fieldvalues) && !($fieldvalues[
'fk_user_modif'] > 0)) {
10816 $fieldvalues[
'fk_user_modif'] = $user->id;
10818 if (array_key_exists(
'user_modification_id', $fieldvalues) && !($fieldvalues[
'user_modification_id'] > 0)) {
10819 $fieldvalues[
'user_modification_id'] = $user->id;
10822 if (array_key_exists(
'pass_crypted', $fieldvalues) && property_exists($this,
'pass') && !empty($this->pass)) {
10824 $tmparray =
dol_hash($this->pass,
'0', 0, 1);
10825 $fieldvalues[
'pass_crypted'] = $tmparray[
'pass_encrypted'];
10826 if (array_key_exists(
'pass_encoding', $fieldvalues) && property_exists($this,
'pass_encoding')) {
10827 $fieldvalues[
'pass_encoding'] = $tmparray[
'pass_encoding'];
10830 if (array_key_exists(
'ref', $fieldvalues)) {
10834 unset($fieldvalues[
'rowid']);
10840 foreach ($fieldvalues as $k => $v) {
10842 $value = $this->fields[$k];
10844 $values[$k] = $this->quote($v, $value);
10845 if (($value[
"type"] ==
"text") && !empty($value[
'arrayofkeyval']) && is_array($value[
'arrayofkeyval'])) {
10847 $v = preg_replace(
'/\s/',
',', $v);
10848 $v = preg_replace(
'/,+/',
',', $v);
10851 $tmp[] = $k.
'='.$this->quote($v, $this->fields[$k]);
10855 foreach ($keys as $key) {
10856 if (preg_match(
'/^integer:/i', $this->fields[$key][
'type']) && $values[$key] ==
'-1') {
10857 $values[$key] =
'';
10859 if (!empty($this->fields[$key][
'foreignkey']) && $values[$key] ==
'-1') {
10860 $values[$key] =
'';
10872 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET '.implode(
', ', $tmp).
' WHERE rowid='.((int) $this->
id);
10874 $this->db->begin();
10877 $res = $this->db->query($sql);
10880 $this->errors[] = $this->db->lasterror();
10886 $result = $this->insertExtraFields();
10893 if (!$error && !$notrigger) {
10895 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
10904 $this->db->rollback();
10907 $this->db->commit();
10922 dol_syslog(get_class($this).
"::deleteCommon delete", LOG_DEBUG);
10926 $this->db->begin();
10928 if ($forcechilddeletion) {
10929 foreach ($this->childtables as $table) {
10930 $sql =
"DELETE FROM ".$this->db->prefix().$table.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10931 $resql = $this->db->query($sql);
10933 $this->error = $this->db->lasterror();
10934 $this->errors[] = $this->error;
10935 $this->db->rollback();
10939 } elseif (!empty($this->childtables)) {
10940 $objectisused = $this->isObjectUsed($this->
id);
10941 if (!empty($objectisused)) {
10942 dol_syslog(get_class($this).
"::deleteCommon Can't delete record as it has some child", LOG_WARNING);
10943 $this->error =
'ErrorRecordHasChildren';
10944 $this->errors[] = $this->error;
10945 $this->db->rollback();
10951 if (is_array($this->childtablesoncascade) && !empty($this->childtablesoncascade)) {
10952 foreach ($this->childtablesoncascade as $tabletodelete) {
10953 $deleteFromObject = explode(
':', $tabletodelete, 4);
10954 if (count($deleteFromObject) >= 2) {
10955 $className = str_replace(
'@',
'', $deleteFromObject[0]);
10956 $filePath = $deleteFromObject[1];
10957 $columnName = $deleteFromObject[2];
10959 if (!empty($deleteFromObject[3])) {
10960 $filter = $deleteFromObject[3];
10964 $childObject =
new $className($this->db);
10965 if (method_exists($childObject,
'deleteByParentField')) {
10966 '@phan-var-force CommonObject $childObject';
10967 $result = $childObject->deleteByParentField($this->
id, $columnName, $filter);
10970 $this->errors[] = $childObject->error;
10975 $this->errors[] =
"You defined a cascade delete on an object $className/$this->id but there is no method deleteByParentField for it";
10980 $this->errors[] =
'Cannot include child class file '.$filePath;
10985 $sql =
"DELETE FROM ".$this->db->prefix().$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10987 $resql = $this->db->query($sql);
10990 $this->error = $this->db->lasterror();
10991 $this->errors[] = $this->error;
11001 $result = $this->call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
11011 $res = $this->deleteEcmFiles(1);
11018 $res = $this->deleteObjectLinked();
11023 if (!$error && !empty($this->isextrafieldmanaged)) {
11024 $result = $this->deleteExtraFields();
11031 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
' WHERE rowid='.((int) $this->
id);
11033 $resql = $this->db->query($sql);
11036 $this->errors[] = $this->db->lasterror();
11042 $this->db->rollback();
11045 $this->db->commit();
11070 if (!empty($parentId) && !empty($parentField)) {
11071 if (empty($this->table_element)) {
11072 $this->error =
'Property table_element for object is not defined';
11073 $this->errors[] = $this->error;
11077 if (!method_exists($this,
'fetch')) {
11078 $this->error =
'Method fetch for object is not defined';
11079 $this->errors[] = $this->error;
11083 if (!method_exists($this,
'delete')) {
11084 $this->error =
'Method delete for object is not defined';
11085 $this->errors[] = $this->error;
11090 $this->db->begin();
11092 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
11093 $sql .=
" WHERE ".$this->db->sanitize($parentField).
" = ".(int) $parentId;
11096 $errormessage =
'';
11098 if ($errormessage) {
11099 $this->errors[] = $errormessage;
11100 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
11104 $resql = $this->db->query($sql);
11106 $this->errors[] = $this->db->lasterror();
11109 while ($obj = $this->db->fetch_object($resql)) {
11110 $result = $this->fetch($obj->rowid);
11113 $this->errors[] = $this->error;
11115 $result = $this->
delete($user);
11118 $this->errors[] = $this->error;
11126 if (empty($error)) {
11127 $this->db->commit();
11130 $this->error = implode(
', ', $this->errors);
11131 $this->db->rollback();
11132 return $error * -1;
11151 $tmpforobjectclass = get_class($this);
11152 $tmpforobjectlineclass = ucfirst($tmpforobjectclass).
'Line';
11154 $this->db->begin();
11157 $result = $this->call_trigger(
'LINE'.strtoupper($tmpforobjectclass).
'_DELETE', $user);
11163 if (empty($error)) {
11164 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element_line;
11165 $sql .=
" WHERE rowid = ".((int) $idline);
11167 $resql = $this->db->query($sql);
11169 $this->error =
"Error ".$this->db->lasterror();
11174 if (empty($error)) {
11176 $tmpobjectline =
new $tmpforobjectlineclass($this->db);
11177 '@phan-var-force CommonObjectLine $tmpobjectline';
11178 if (!isset($tmpobjectline->isextrafieldmanaged) || !empty($tmpobjectline->isextrafieldmanaged)) {
11179 $tmpobjectline->id = $idline;
11180 $result = $tmpobjectline->deleteExtraFields();
11183 $this->error =
"Error ".get_class($this).
"::deleteLineCommon deleteExtraFields error -4 ".$tmpobjectline->error;
11188 if (empty($error)) {
11189 $this->db->commit();
11192 dol_syslog(get_class($this).
"::deleteLineCommon ERROR:".$this->error, LOG_ERR);
11193 $this->db->rollback();
11212 $this->db->begin();
11214 $statusfield =
'status';
11215 if (in_array($this->element, array(
'don',
'donation',
'shipping',
'project_task'))) {
11216 $statusfield =
'fk_statut';
11219 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
11220 $sql .=
" SET ".$statusfield.
" = ".((int) $status);
11221 $sql .=
" WHERE rowid = ".((int) $this->
id);
11223 if ($this->db->query($sql)) {
11225 $this->oldcopy = clone $this;
11228 if (!$error && !$notrigger) {
11230 $result = $this->call_trigger($triggercode, $user);
11237 $this->
status = $status;
11238 if (property_exists($this,
'statut')) {
11239 $this->statut = $status;
11241 $this->db->commit();
11244 $this->db->rollback();
11248 $this->error = $this->db->error();
11249 $this->db->rollback();
11265 $this->specimen = 1;
11267 'label' =>
'This is label',
11268 'ref' =>
'ABCD1234',
11269 'description' =>
'This is a description',
11271 'note_public' =>
'Public note',
11272 'note_private' =>
'Private note',
11273 'date_creation' => (
dol_now() - 3600 * 48),
11274 'date_modification' => (
dol_now() - 3600 * 24),
11275 'fk_user_creat' => $user->id,
11276 'fk_user_modif' => $user->id,
11279 foreach ($fields as $key => $value) {
11280 if (array_key_exists($key, $this->fields)) {
11281 $this->{$key} = $value;
11286 if (property_exists($this,
'fields')) {
11287 foreach ($this->fields as $key => $value) {
11289 if (array_key_exists($key, $fields)) {
11293 if (!empty($value[
'default'])) {
11294 $this->$key = $value[
'default'];
11312 require_once DOL_DOCUMENT_ROOT.
'/core/class/comment.class.php';
11314 $comment =
new Comment($this->db);
11315 $result = $comment->fetchAllFor($this->element, $this->
id);
11317 $this->errors = array_merge($this->errors, $comment->errors);
11320 $this->comments = $comment->comments;
11322 return count($this->comments);
11332 return count($this->comments);
11343 if (!is_array($parameters)) {
11346 foreach ($parameters as $parameter) {
11347 if (isset($this->$parameter)) {
11348 $this->$parameter = trim($this->$parameter);
11367 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
11371 $existing =
$c->containing($this->
id, $type_categ,
'id');
11391 if (!is_array($categories)) {
11392 $categories = array($categories);
11395 dol_syslog(get_class($this).
"::setCategoriesCommon Object Id:".$this->
id.
' type_categ:'.$type_categ.
' nb tag add:'.count($categories), LOG_DEBUG);
11397 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
11399 if (empty($type_categ)) {
11400 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown category type. Done nothing.', LOG_ERR);
11406 $existing =
$c->containing($this->
id, $type_categ,
'id');
11407 if ($remove_existing) {
11409 if (is_array($existing)) {
11410 $to_del = array_diff($existing, $categories);
11411 $to_add = array_diff($categories, $existing);
11414 $to_add = $categories;
11418 $to_add = array_diff($categories, $existing);
11425 foreach ($to_del as $del) {
11426 if (
$c->fetch($del) > 0) {
11427 $result =
$c->del_type($this, $type_categ);
11430 $this->error =
$c->error;
11431 $this->errors =
$c->errors;
11438 foreach ($to_add as $add) {
11439 if (
$c->fetch($add) > 0) {
11440 $result =
$c->add_type($this, $type_categ);
11443 $this->error =
$c->error;
11444 $this->errors =
$c->errors;
11452 return $error ? (-1 * $error) : $ok;
11465 $this->db->begin();
11467 if (empty($type)) {
11468 $type = $this->table_element;
11471 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
11472 $categorystatic =
new Categorie($this->db);
11474 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_product)";
11475 $sql .=
" SELECT fk_categorie, $toId FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
11476 $sql .=
" WHERE fk_product = ".((int) $fromId);
11478 if (!$this->db->query($sql)) {
11479 $this->error = $this->db->lasterror();
11480 $this->db->rollback();
11484 $this->db->commit();
11498 $this->db->begin();
11502 switch ($this->element) {
11504 $element =
'propale';
11507 $element =
'produit';
11509 case 'order_supplier':
11510 $element =
'fournisseur/commande';
11512 case 'invoice_supplier':
11515 $element =
'fournisseur/facture/'.get_exdir($this->
id, 2, 0, 1, $this,
'invoice_supplier');
11518 $element =
'expedition/sending';
11521 case 'project_task':
11522 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
11524 $project_result = $this->fetchProject();
11525 if ($project_result >= 0) {
11526 $element =
'projet/'.dol_sanitizeFileName($this->project->ref).
'/';
11530 $element =
'contract';
11533 $element = $this->element;
11535 '@phan-var-force string $element';
11538 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files_extrafields WHERE fk_object IN (";
11539 $sql .=
" SELECT rowid FROM ".$this->db->prefix().
"ecm_files WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
11540 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
11543 if (!$this->db->query($sql)) {
11544 $this->error = $this->db->lasterror();
11545 $this->db->rollback();
11550 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files";
11551 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
11552 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int)
$conf->entity);
11554 if (!$this->db->query($sql)) {
11555 $this->error = $this->db->lasterror();
11556 $this->db->rollback();
11563 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files_extrafields";
11564 $sql .=
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix().
"ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ?
"" :
"@".$this->module)).
"' AND src_object_id = ".((int) $this->
id).
")";
11565 $resql = $this->db->query($sql);
11567 $this->error = $this->db->lasterror();
11568 $this->db->rollback();
11572 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files";
11573 $sql .=
" WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ?
"" :
"@".$this->module)).
"' AND src_object_id = ".((int) $this->
id);
11574 $resql = $this->db->query($sql);
11576 $this->error = $this->db->lasterror();
11577 $this->db->rollback();
11582 $this->db->commit();
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
global $dolibarr_main_url_root
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Class to manage members of a foundation.
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
getCategoriesCommon($type_categ)
Sets object to given categories.
indexFile($destfull, $update_main_doc_field)
Index a file into the ECM database.
getFormatedSupplierRef($objref)
Return supplier ref for screen output.
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteLineCommon(User $user, $idline, $notrigger=0)
Delete a line of object in database.
isEmpty()
isEmpty We consider CommonObject isEmpty if this->id is empty
clearFieldError($fieldKey)
clear validation message result for a field
static getCountOfItemsLinkedByObjectID($fk_object_where, $field_where, $table_element)
Count items linked to an object id in association table.
deleteEcmFiles($mode=0)
Delete related files of object in database.
getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0)
Return the link of last main doc file for direct public download.
liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='')
Return array with list of possible values for type of contacts.
getTooltipContent($params)
getTooltipContent
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
swapContactStatus($rowid)
Update status of a contact linked to object.
getFieldError($fieldKey)
get field error message
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $f_user=null, $notrigger=0)
Update object linked of a current object.
defineBuyPrice($unitPrice=0.0, $discountPercent=0.0, $fk_product=0)
Get buy price to use for margin calculation.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
liste_contact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1, $arrayoftcids=array())
Get array of all contacts for an object.
fetchObjectFrom($table, $field, $key, $element=null)
Load object from specific field.
fetchProject()
Load the project with id $this->fk_project into this->project.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
static deleteAllItemsLinkedByObjectID($fk_object_where, $field_where, $table_element)
Function used to remove all items linked to an object id in association table.
setFieldError($fieldKey, $msg='')
set validation error message a field
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
getDataToShowPhoto($modulepart, $imagesize)
Function used to get the logos or photos of an object.
setMulticurrencyCode($code)
Change the multicurrency code.
add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0)
Add resources to the current object : add entry into llx_element_resources Need $this->element & $thi...
emtpyObjectVars()
Sets all object fields to null.
fetch_projet()
Load the project with id $this->fk_project into this->project.
getIdContact($source, $code, $status=0)
Return id of contacts for a source and a contact code.
setExtraField($key, $value)
Convenience method for setting the value of an extrafield without actually updating it in the databas...
setDocModel($user, $modelpdf)
Set last model used by doc generator.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
getExtraField($key)
Convenience method for retrieving the value of an extrafield without actually fetching it from the da...
updateExtraField($key, $trigger=null, $userused=null)
Update 1 extra field value for the current object.
setPaymentTerms($id, $deposit_percent=null)
Change the payments terms.
isFloat($info)
Function test if type is float.
setBankAccount($fk_account, $notrigger=0, $userused=null)
Change the bank account.
setExtraParameters()
Set extra parameters.
setErrorsFromObject($object)
setErrorsFromObject
setShippingMethod($shipping_method_id, $notrigger=0, $userused=null)
Change the shipping method.
update_note_public($note)
Update public note (kept for backward compatibility)
getSpecialCode($lineid)
Get special code of a line.
clearObjectLinkedCache()
Clear the cache saying that all linked object were already loaded.
update_ref_ext($ref_ext)
Update external ref of element.
fetchOneLike($ref)
Looks for an object with ref matching the wildcard provided It does only work when $this->table_ref_f...
hasProductsOrServices($predefined=-1)
Function to say how many lines object contains.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
updateRangOfLine($rowid, $rang)
Update position of line (rang)
getDefaultCreateValueFor($fieldname, $alternatevalue=null, $type='alphanohtml')
Return the default value to use for a field when showing the create form of object.
createCommon(User $user, $notrigger=0)
Create object in the database.
getTotalWeightVolume()
Return into unit=0, the calculated total of weight and volume of all lines * qty Calculate by adding ...
update_note($note, $suffix='', $notrigger=0)
Update note of element.
getFullAddress($withcountry=0, $sep="\n", $withregion=0, $extralangcode='')
Return full address of contact.
fetch_project()
Load the project with id $this->fk_project into this->project.
setStatut($status, $elementId=null, $elementType='', $trigkey='', $fieldstatus='fk_statut')
Set status of an object.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
getNbComments()
Return nb comments already posted.
setVarsFromFetchObj(&$obj)
Function to load data from a SQL pointer into properties of current object $this.
printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0, $defaulttpldir='/core/tpl')
Return HTML table for object lines TODO Move this into an output class file (htmlline....
getChildrenOfLine($id, $includealltree=0)
Get children of line.
updateCommon(User $user, $notrigger=0)
Update object into database.
updateExtraLanguages($key, $trigger=null, $userused=null)
Update an extra language value for the current object.
deleteExtraFields()
Delete all extra fields values for the current object.
setStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a status.
deprecatedProperties()
Provide list of deprecated properties and replacements.
setSaveQuery()
Function to return the array of data key-value from the ->fields and all the ->properties of an objec...
setValuesForExtraLanguages($onlykey='')
Fill array_options property of object by extrafields value (using for data sent by forms) Used for ex...
insertExtraLanguages($trigger='', $userused=null)
Add/Update all extra languages values for the current object.
setTransportMode($id)
Change the transport mode methods.
isArray($info)
Function test if type is array.
isInt($info)
Function test if type is integer.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
delete_contact($rowid, $notrigger=0)
Delete a link to contact line.
updateLineUp($rowid, $rang)
Update position of line up (rang)
fetch_user($userid)
Load the user with id $userid into this->user.
errorsToString()
Method to output saved errors.
getListContactId($source='external')
Return list of id of contacts of object.
setWarehouse($warehouse_id)
Change the warehouse.
setDeliveryAddress($id)
Define delivery address.
fetchBarCode()
Load data for barcode into properties ->barcode_type* Properties ->barcode_type that is id of barcode...
getTotalDiscount()
Function that returns the total amount HT of discounts applied for all lines.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected=0, $extrafields=null, $defaulttpldir='/core/tpl')
Return HTML content of a detail line TODO Move this into an output class file (htmlline....
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
getValueFrom($table, $id, $field)
Getter generic.
trimParameters($parameters)
Trim object parameters.
fetch_product()
Load the product with id $this->fk_product into this->product.
isIndex($info)
Function test if is indexed.
quote($value, $fieldsentry)
Add quote to field value if necessary.
formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir='/core/tpl')
Show add free and predefined products/services form.
fetchComments()
Load comments linked with current task.
line_down($rowid, $fk_parent_line=true)
Update a line to have a higher rank.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
fetch_contact($contactid=null)
Load object contact with id=$this->contact_id into $this->contact.
setRetainedWarrantyPaymentTerms($id)
Change the retained warranty payments terms.
delThumbs($file)
Delete thumbs.
show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $overwritetitle=0, $usesharelink=0, $cache='', $addphotorefcss='photoref')
Show photos of an object (nbmax maximum), into several columns.
fetchLinesCommon($morewhere='', $noextrafields=0)
Load object in memory from the database.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
getRangOfLine($rowid)
Get position of line (rang)
showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0, $nonewbutton=0)
Return HTML string to put an input field into a page Code very similar with showInputField of extra f...
delete_resource($rowid, $element, $notrigger=0)
Delete a link to resource line.
update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0)
Update a link to contact line.
getElementType()
Return an element type string formatted like element_element target_type and source_type.
load_previous_next_ref($filter, $fieldid, $nodbprefix=0)
Load properties id_previous and id_next by comparing $fieldid with $this->ref.
setCategoriesCommon($categories, $type_categ='', $remove_existing=true)
Sets object to given categories.
fetchValuesForExtraLanguages()
Function to get alternative languages of a data into $this->array_languages This method is NOT called...
fetchNoCompute($id)
Function to make a fetch but set environment to avoid to load computed values before.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
getJSListDependancies($type='_extra')
setProject($projectid, $notrigger=0)
Link element with a project.
isForcedToNullIfZero($info)
Function test if field is forced to null if zero or empty.
line_ajaxorder($rows)
Update position of line with ajax (rang)
printOriginLinesList($restrictlist='', $selectedLines=array())
Return HTML table table of source object lines TODO Move this and previous function into output html ...
fetch_origin()
Read linked origin object.
getIdOfLine($rang)
Get rowid of the line relative to its position.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
deleteByParentField($parentId=0, $parentField='', $filter='', $filtermode="AND")
Delete all child object from a parent ID.
static getAllItemsLinkedByObjectID($fk_object_where, $field_select, $field_where, $table_element)
Function used to get an array with all items linked to an object id in association table.
__clone()
Overwrite magic function to solve problem of cloning object that are kept as references.
setPaymentMethods($id)
Change the payments methods.
updateLineDown($rowid, $rang, $max)
Update position of line down (rang)
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
getFormatedCustomerRef($objref)
Return customer ref for screen output.
getTooltipContentArray($params)
Return array of data to show into a tooltip.
isText($info)
Function test if type is text.
isDate($info)
Function test if type is date.
printOriginLine($line, $var, $restrictlist='', $defaulttpldir='/core/tpl', $selectedLines=array())
Return HTML with a line of table array of source object lines TODO Move this and previous function in...
showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd='', $display_type='card')
Function to show lines of extrafields with output data.
getCanvas($id=0, $ref='')
Load type of canvas of an object if it exists.
line_up($rowid, $fk_parent_line=true)
Update a line to have a lower rank.
isDuration($info)
Function test if type is duration.
canBeNull($info)
Function test if field can be null.
listeTypeContacts($source='internal', $option=0, $activeonly=0, $code='', $element='', $excludeelement='')
Return array with list of possible values for type of contacts.
call_trigger($triggerName, $user)
Call trigger based on this instance.
getRights()
Returns the rights used for this class.
addThumbs($file, $quality=50)
Build thumb.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
cloneCategories($fromId, $toId, $type='')
Copy related categories to another object.
fetch_barcode()
Load data for barcode into properties ->barcode_type* Properties ->barcode_type that is id of barcode...
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage Dolibarr database access.
Class to manage donations.
Class to manage ECM files.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage triggers.
Parent class of subscription templates.
Parent class to manage intervention document templates.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_SERVICE
Service.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
Class toolbox to validate values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getState($id, $withcode='0', $dbtouse=null, $withregion=0, $outputlangs=null, $entconv=1)
Return state translated from an id.
convertSecondToTime($iSecond, $format='all', $lengthOfDay=86400, $lengthOfWeek=7)
Return, in clear text, value of a number of seconds in days, hours and minutes.
dol_meta_create($object)
Create a meta file with document file into same directory.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir, $object=null)
Complete $filearray with data from database.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
dol_print_ip($ip, $mode=0, $showname=0)
Return an IP formatted to be shown on screen.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs=null, $mode=0, $extralangcode='')
Return a formatted address (part address/zip/town/state) according to country rules.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
getCallerInfoString()
Get caller info as a string that can be appended to a log message.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_print_url($url, $target='_blank', $max=32, $withpicto=0, $morecss='')
Show Url link.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getPictoForType($key, $morecss='')
Return the picto for a data type.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolPrintHTMLForAttribute($s, $escapeonlyhtmltags=0, $allowothertags=array())
Return a string ready to be output into an HTML attribute (alt, title, data-html, ....
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
if(!defined( 'IMAGETYPE_WEBP')) getDefaultImageSizes()
Return default values for image sizes.
dol_getImageSize($file, $url=false)
Return size of image file on disk (Supported extensions are gif, jpg, png, bmp and webp)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
$conf db user
Active Directory does not allow anonymous connections.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.