42require_once DOL_DOCUMENT_ROOT.
'/core/class/doldeprecationhandler.class.php';
51 use DolDeprecationHandler;
53 const TRIGGER_PREFIX =
'';
89 public $errors = array();
94 private $validateFieldsErrors = array();
112 public $element_for_permission;
117 public $table_element;
122 public $table_element_line =
'';
128 public $ismultientitymanaged;
138 public $array_options = array();
144 public $fields = array();
150 public $array_languages =
null;
155 public $contacts_ids;
160 public $linked_objects;
165 public $linkedObjectsIds;
170 public $linkedObjects;
175 private $linkedObjectsFullLoaded = array();
190 protected $table_ref_field =
'';
195 public $restrictiononfksoc = 0;
204 public $context = array();
316 private $commandeFournisseur;
332 public $ref_previous;
378 public $country_code;
396 public $fk_departement;
427 public $barcode_type;
433 public $barcode_type_code;
439 public $barcode_type_label;
445 public $barcode_type_coder;
451 public $mode_reglement_id;
457 public $cond_reglement_id;
462 public $demand_reason_id;
468 public $transport_mode_id;
477 private $cond_reglement;
481 protected $depr_cond_reglement;
488 public $fk_delivery_address;
494 public $shipping_method_id;
500 public $shipping_method;
506 public $fk_multicurrency;
512 public $multicurrency_code;
518 public $multicurrency_tx;
523 public $multicurrency_total_ht;
528 public $multicurrency_total_tva;
533 public $multicurrency_total_ttc;
538 public $multicurrency_total_localtax1;
543 public $multicurrency_total_localtax2;
555 public $last_main_doc;
580 public $note_private;
605 public $total_localtax1;
611 public $total_localtax2;
628 public $actiontypecode;
634 public $comments = array();
660 public $date_creation;
665 public $date_validation;
670 public $date_modification;
684 private $date_update;
689 public $date_cloture;
701 public $user_creation;
706 public $user_creation_id;
718 public $user_validation;
723 public $user_validation_id;
728 public $user_closing_id;
734 public $user_modification;
739 public $user_modification_id;
745 public $fk_user_creat;
751 public $fk_user_modif;
757 public $next_prev_filter;
762 public $specimen = 0;
774 private $alreadypaid;
784 public $labelStatus = array();
789 public $labelStatusShort = array();
800 public $showphoto_on_popup;
805 public $nb = array();
820 public $extraparams = array();
825 protected $childtables = array();
832 protected $childtablesoncascade = array();
842 public $cond_reglement_supplier_id;
849 public $deposit_percent;
855 public $retained_warranty_fk_cond_reglement;
860 public $warehouse_id;
865 public $isextrafieldmanaged = 0;
878 'alreadypaid' =>
'totalpaid',
879 'cond_reglement' =>
'depr_cond_reglement',
881 'commandeFournisseur' =>
'origin_object',
882 'expedition' =>
'origin_object',
883 'fk_project' =>
'fk_project',
884 'livraison' =>
'origin_object',
885 'projet' =>
'project',
886 'statut' =>
'status',
905 $sql =
"SELECT rowid, ref, ref_ext";
906 $sql .=
" FROM ".$db->prefix().$element;
907 $sql .=
" WHERE entity IN (".getEntity($element).
")";
910 $sql .=
" AND rowid = ".((int) $id);
912 $sql .=
" AND ref = '".$db->escape($ref).
"'";
913 } elseif ($ref_ext) {
914 $sql .=
" AND ref_ext = '".$db->escape($ref_ext).
"'";
916 $error =
'ErrorWrongParameters';
917 dol_syslog(get_class().
"::isExistingObject ".$error, LOG_ERR);
920 if ($ref || $ref_ext) {
921 $sql .=
" AND entity = ".((int) $conf->entity);
924 dol_syslog(get_class().
"::isExistingObject", LOG_DEBUG);
925 $resql = $db->query($sql);
927 $num = $db->num_rows($resql);
944 return (empty($this->
id));
959 $this->errors = array_merge($this->errors,
$object->errors);
984 global $action, $extrafields, $langs, $hookmanager;
987 $MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP =
getDolGlobalInt(
'MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP', 3);
993 if (!empty($extrafields->attributes[$this->table_element][
'label'])) {
994 $data[
'opendivextra'] =
'<div class="centpercent wordbreak divtooltipextra">';
995 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
996 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
999 if ($count >= abs($MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP)) {
1000 $data[
'more_extrafields'] =
'<br>...';
1004 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
1005 $enabled = (int)
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
1007 if ($enabled && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
1008 $enabled = (int)
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
1011 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
1012 $perms = (int)
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
1014 if (empty($enabled)) {
1017 if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
1020 if (empty($perms)) {
1023 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
1024 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
1026 $labelextra = $langs->trans((
string) $extrafields->attributes[$this->table_element][
'label'][$key]);
1027 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
1028 $data[$key] =
'<br><b><u>'. $labelextra .
'</u></b>';
1030 $value = (empty($this->array_options[
'options_' . $key]) ?
'' : $this->array_options[
'options_' . $key]);
1031 $data[$key] =
'<br><b>'. $labelextra .
':</b> ' . $extrafields->showOutputField($key, $value,
'', $this->table_element);
1035 $data[
'closedivextra'] =
'</div>';
1038 $hookmanager->initHooks(array($this->element .
'dao'));
1039 $parameters = array(
1040 'tooltipcontentarray' => &$data,
1041 'params' => $params,
1044 $hookmanager->executeHooks(
'getTooltipContent', $parameters, $this, $action);
1047 $label = implode($data);
1060 return $this->error.(is_array($this->errors) ? (($this->error !=
'' ?
', ' :
'').implode(
', ', $this->errors)) :
'');
1072 global $hookmanager;
1074 $parameters = array(
'objref' => $objref);
1076 $reshook = $hookmanager->executeHooks(
'getFormatedCustomerRef', $parameters, $this, $action);
1078 return $hookmanager->resArray[
'objref'];
1080 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
1091 global $hookmanager;
1093 $parameters = array(
'objref' => $objref);
1095 $reshook = $hookmanager->executeHooks(
'getFormatedSupplierRef', $parameters, $this, $action);
1097 return $hookmanager->resArray[
'objref'];
1099 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
1111 public function getFullAddress($withcountry = 0, $sep =
"\n", $withregion = 0, $extralangcode =
'')
1113 if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
1114 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
1115 $tmparray =
getCountry($this->country_id,
'all');
1116 $this->country_code = $tmparray[
'code'];
1117 $this->country = $tmparray[
'label'];
1120 if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) {
1121 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
1122 $tmparray =
getState($this->state_id,
'all',
null, 1);
1123 $this->state_code = $tmparray[
'code'];
1124 $this->state = $tmparray[
'label'];
1125 $this->region_code = $tmparray[
'region_code'];
1126 $this->region = $tmparray[
'region'];
1143 global $user, $dolibarr_main_url_root;
1145 if (empty($this->last_main_doc)) {
1149 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1150 $ecmfile =
new EcmFiles($this->db);
1151 $result = $ecmfile->fetch(0,
'', $this->last_main_doc);
1153 $this->error = $ecmfile->error;
1154 $this->errors = $ecmfile->errors;
1158 if (empty($ecmfile->id)) {
1160 if ($initsharekey) {
1161 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1183 } elseif (empty($ecmfile->share)) {
1185 if ($initsharekey) {
1186 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1188 $ecmfile->update($user);
1194 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1198 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1207 if (!empty($ecmfile->share)) {
1208 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$ecmfile->share;
1210 if ($forcedownload) {
1211 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
1214 if ($relativelink) {
1215 $linktoreturn =
'document.php'.($paramlink ?
'?'.$paramlink :
'');
1217 $linktoreturn = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
1221 return $linktoreturn;
1235 public function add_contact($fk_socpeople, $type_contact, $source =
'external', $notrigger = 0)
1238 global $user, $langs;
1241 dol_syslog(get_class($this).
"::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
1244 if ($fk_socpeople <= 0) {
1245 $langs->load(
"errors");
1246 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"1");
1247 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1250 if (!$type_contact) {
1251 $langs->load(
"errors");
1252 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"2");
1253 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1257 $id_type_contact = 0;
1258 if (is_numeric($type_contact)) {
1259 $id_type_contact = $type_contact;
1262 $sql =
"SELECT tc.rowid";
1263 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1264 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1265 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1266 $sql .=
" AND tc.code='".$this->db->escape($type_contact).
"' AND tc.active=1";
1268 $resql = $this->db->query($sql);
1270 $obj = $this->db->fetch_object($resql);
1272 $id_type_contact = $obj->rowid;
1277 if ($id_type_contact == 0) {
1278 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");
1286 $already_added =
false;
1287 if (is_array($TListeContacts) && !empty($TListeContacts)) {
1288 foreach ($TListeContacts as $array_contact) {
1289 if ($array_contact[
'status'] == 4 && $array_contact[
'id'] == $fk_socpeople && $array_contact[
'fk_c_type_contact'] == $id_type_contact) {
1290 $already_added =
true;
1296 if (!$already_added) {
1300 $sql =
"INSERT INTO ".$this->db->prefix().
"element_contact";
1301 $sql .=
" (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1302 $sql .=
" VALUES (".$this->id.
", ".((int) $fk_socpeople).
" , ";
1303 $sql .=
"'".$this->db->idate($datecreate).
"'";
1304 $sql .=
", 4, ".((int) $id_type_contact);
1307 $resql = $this->db->query($sql);
1310 $result = $this->
call_trigger(strtoupper($this->element).
'_ADD_CONTACT', $user);
1312 $this->db->rollback();
1317 $this->db->commit();
1320 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1321 $this->error = $this->db->errno();
1322 $this->db->rollback();
1325 $this->error = $this->db->lasterror();
1326 $this->db->rollback();
1346 $contacts = $objFrom->liste_contact(-1, $source);
1347 foreach ($contacts as $contact) {
1348 if ($this->
add_contact($contact[
'id'], $contact[
'fk_c_type_contact'], $contact[
'source']) < 0) {
1365 public function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0)
1369 $sql =
"UPDATE ".$this->db->prefix().
"element_contact set";
1370 $sql .=
" statut = ".$statut;
1371 if ($type_contact_id) {
1372 $sql .=
", fk_c_type_contact = ".((int) $type_contact_id);
1374 if ($fk_socpeople) {
1375 $sql .=
", fk_socpeople = ".((int) $fk_socpeople);
1377 $sql .=
" where rowid = ".((int) $rowid);
1378 $resql = $this->db->query($sql);
1382 $this->error = $this->db->lasterror();
1404 if (!$error && empty($notrigger)) {
1406 $this->context[
'contact_id'] = ((int) $rowid);
1407 $result = $this->
call_trigger(strtoupper($this->element).
'_DELETE_CONTACT', $user);
1415 dol_syslog(get_class($this).
"::delete_contact", LOG_DEBUG);
1417 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1418 $sql .=
" WHERE rowid = ".((int) $rowid);
1420 $result = $this->db->query($sql);
1423 $this->errors[] = $this->db->lasterror();
1428 $this->db->commit();
1431 $this->error = $this->db->lasterror();
1432 $this->db->rollback();
1452 if (!empty($typeContact)) {
1453 foreach ($typeContact as $key => $value) {
1454 array_push($temp, $key);
1456 $listId = implode(
",", $temp);
1461 if (empty($listId)) {
1465 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1466 $sql .=
" WHERE element_id = ".((int) $this->
id);
1467 $sql .=
" AND fk_c_type_contact IN (".$this->db->sanitize($listId).
")";
1469 dol_syslog(get_class($this).
"::delete_linked_contact", LOG_DEBUG);
1470 if ($this->db->query($sql)) {
1473 $this->error = $this->db->lasterror();
1490 public function liste_contact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1, $arrayoftcids = array())
1497 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
1498 if ($source ==
'internal') {
1499 $sql .=
", '-1' as socid, t.statut as statuscontact, t.login, t.photo, t.gender";
1501 if ($source ==
'external' || $source ==
'thirdparty') {
1502 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
1504 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1505 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
1506 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc,";
1507 $sql .=
" ".$this->db->prefix().
"element_contact ec";
1508 if ($source ==
'internal') {
1509 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user t on ec.fk_socpeople = t.rowid";
1511 if ($source ==
'external' || $source ==
'thirdparty') {
1512 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on ec.fk_socpeople = t.rowid";
1514 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
1515 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1516 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1518 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1520 if ($source ==
'internal') {
1521 $sql .=
" AND tc.source = 'internal'";
1523 $sql .=
" AND t.statut = ".((int) $status);
1526 if ($source ==
'external' || $source ==
'thirdparty') {
1527 $sql .=
" AND tc.source = 'external'";
1529 $sql .=
" AND t.statut = ".((int) $status);
1532 $sql .=
" AND tc.active = 1";
1533 if ($statusoflink >= 0) {
1534 $sql .=
" AND ec.statut = ".((int) $statusoflink);
1536 $sql .=
" ORDER BY t.lastname ASC";
1538 dol_syslog(get_class($this).
"::liste_contact", LOG_DEBUG);
1539 $resql = $this->db->query($sql);
1541 $num = $this->db->num_rows($resql);
1544 $obj = $this->db->fetch_object($resql);
1547 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1548 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1550 'parentId' => $this->
id,
1551 'source' => $obj->source,
1552 'socid' => $obj->socid,
1554 'nom' => $obj->lastname,
1555 'civility' => $obj->civility,
1556 'lastname' => $obj->lastname,
1557 'firstname' => $obj->firstname,
1558 'email' => $obj->email,
1559 'login' => (empty($obj->login) ?
'' : $obj->login),
1560 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
1561 'gender' => (empty($obj->gender) ?
'' : $obj->gender),
1562 'statuscontact' => $obj->statuscontact,
1563 'rowid' => $obj->rowid,
1564 'code' => $obj->code,
1565 'libelle' => $libelle_type,
1566 'status' => $obj->statuslink,
1567 'fk_c_type_contact' => $obj->fk_c_type_contact
1570 $tab[$i] = $obj->id;
1578 $this->error = $this->db->lasterror();
1593 $sql =
"SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1594 $sql .=
" tc.code, tc.libelle as type_label";
1595 $sql .=
" FROM (".$this->db->prefix().
"element_contact as ec, ".$this->db->prefix().
"c_type_contact as tc)";
1596 $sql .=
" WHERE ec.rowid =".((int) $rowid);
1597 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1598 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1600 dol_syslog(get_class($this).
"::swapContactStatus", LOG_DEBUG);
1601 $resql = $this->db->query($sql);
1603 $obj = $this->db->fetch_object($resql);
1604 $newstatut = ($obj->statut == 4) ? 5 : 4;
1606 $this->db->free($resql);
1609 $this->error = $this->db->error();
1626 public function liste_type_contact($source =
'internal', $order =
'position', $option = 0, $activeonly = 0, $code =
'')
1631 if (empty($order)) {
1632 $order =
'position';
1634 if ($order ==
'position') {
1639 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position";
1640 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1641 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1642 if ($activeonly == 1) {
1643 $sql .=
" AND tc.active=1";
1645 if (!empty($source) && $source !=
'all') {
1646 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1648 if (!empty($code)) {
1649 $sql .=
" AND tc.code='".$this->db->escape($code).
"'";
1651 $sql .= $this->db->order($order,
'ASC');
1654 $resql = $this->db->query($sql);
1656 $num = $this->db->num_rows($resql);
1659 $obj = $this->db->fetch_object($resql);
1661 $transkey =
"TypeContact_".$this->element.
"_".$source.
"_".$obj->code;
1662 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1663 if (empty($option)) {
1664 $tab[$obj->rowid] = $libelle_type;
1666 $tab[$obj->code] = $libelle_type;
1672 $this->error = $this->db->lasterror();
1689 public function listeTypeContacts($source =
'internal', $option = 0, $activeonly = 0, $code =
'', $element =
'', $excludeelement =
'')
1691 global $langs, $conf;
1693 $langs->loadLangs(array(
'bills',
'contracts',
'interventions',
'orders',
'projects',
'propal',
'ticket',
'agenda'));
1697 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position, tc.element, tc.module";
1698 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1700 $sqlWhere = array();
1701 if (!empty($element)) {
1702 $sqlWhere[] =
" tc.element='".$this->db->escape($element).
"'";
1704 if (!empty($excludeelement)) {
1705 $sqlWhere[] =
" tc.element <> '".$this->db->escape($excludeelement).
"'";
1708 if ($activeonly == 1) {
1709 $sqlWhere[] =
" tc.active=1";
1712 if (!empty($source) && $source !=
'all') {
1713 $sqlWhere[] =
" tc.source='".$this->db->escape($source).
"'";
1716 if (!empty($code)) {
1717 $sqlWhere[] =
" tc.code='".$this->db->escape($code).
"'";
1720 if (count($sqlWhere) > 0) {
1721 $sql .=
" WHERE ".implode(
' AND ', $sqlWhere);
1724 $sql .= $this->db->order(
'tc.element, tc.position',
'ASC');
1727 $resql = $this->db->query($sql);
1729 $num = $this->db->num_rows($resql);
1731 $langs->loadLangs(array(
"propal",
"orders",
"bills",
"suppliers",
"contracts",
"supplier_proposal"));
1733 while ($obj = $this->db->fetch_object($resql)) {
1734 $modulename = $obj->module ?? $obj->element;
1735 if (strpos($obj->element,
'project') !==
false) {
1736 $modulename =
'projet';
1737 } elseif ($obj->element ==
'contrat') {
1738 $element =
'contract';
1739 } elseif ($obj->element ==
'action') {
1740 $modulename =
'agenda';
1741 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1742 $modulename =
'fournisseur';
1744 if (!empty($conf->{$modulename}->enabled)) {
1745 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1746 $tmpelement = $obj->element;
1747 $transkey =
"TypeContact_".$tmpelement.
"_".$source.
"_".$obj->code;
1748 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1749 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1755 $this->error = $this->db->lasterror();
1778 if ($this->element ==
'shipping' && $this->origin_id != 0) {
1779 $id = $this->origin_id;
1780 $element =
'commande';
1781 } elseif ($this->element ==
'reception' && $this->origin_id != 0) {
1782 $id = $this->origin_id;
1783 $element =
'order_supplier';
1786 $element = $this->element;
1789 $sql =
"SELECT ec.fk_socpeople";
1790 $sql .=
" FROM ".$this->db->prefix().
"element_contact as ec,";
1791 if ($source ==
'internal') {
1792 $sql .=
" ".$this->db->prefix().
"user as c,";
1794 if ($source ==
'external') {
1795 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
1797 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc";
1798 $sql .=
" WHERE ec.element_id = ".((int) $id);
1799 $sql .=
" AND ec.fk_socpeople = c.rowid";
1800 if ($source ==
'internal') {
1801 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
1803 if ($source ==
'external') {
1804 $sql .=
" AND c.entity IN (".getEntity(
'societe').
")";
1806 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1807 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1808 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1810 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1812 $sql .=
" AND tc.active = 1";
1814 $sql .=
" AND ec.statut = ".((int) $status);
1817 dol_syslog(get_class($this).
"::getIdContact", LOG_DEBUG);
1818 $resql = $this->db->query($sql);
1820 while ($obj = $this->db->fetch_object($resql)) {
1821 $result[$i] = $obj->fk_socpeople;
1825 $this->error = $this->db->error();
1842 if (empty($contactid)) {
1843 $contactid = $this->contact_id;
1846 if (empty($contactid)) {
1850 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1851 $contact =
new Contact($this->db);
1852 $result = $contact->fetch($contactid);
1853 $this->contact = $contact;
1868 if (empty($this->socid) && empty($this->fk_soc) && empty($force_thirdparty_id)) {
1872 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1874 $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : 0);
1875 if ($force_thirdparty_id) {
1876 $idtofetch = $force_thirdparty_id;
1880 $thirdparty =
new Societe($this->db);
1881 $result = $thirdparty->fetch($idtofetch);
1883 $this->errors = array_merge($this->errors, $thirdparty->errors);
1885 $this->thirdparty = $thirdparty;
1888 if (
getDolGlobalString(
'PRODUIT_MULTIPRICES') && empty($this->thirdparty->price_level)) {
1889 $this->thirdparty->price_level = 1;
1908 if (!$this->table_ref_field) {
1912 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
1913 $sql .=
" WHERE ".$this->table_ref_field.
" LIKE '".$this->db->escape($ref).
"'";
1916 $query = $this->db->query($sql);
1918 if (!$this->db->num_rows($query)) {
1922 $result = $this->db->fetch_object($query);
1924 if (method_exists($this,
'fetch')) {
1925 return $this->fetch($result->rowid);
1927 $this->error =
'Fetch method not implemented on '.get_class($this);
1928 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
1929 array_push($this->errors, $this->error);
1947 dol_syslog(get_class($this).
'::fetch_barcode this->element='.$this->element.
' this->barcode_type='.$this->barcode_type);
1949 $idtype = $this->barcode_type;
1950 if (empty($idtype) && $idtype !=
'0') {
1951 if ($this->element ==
'product' &&
getDolGlobalString(
'PRODUIT_DEFAULT_BARCODE_TYPE')) {
1953 } elseif ($this->element ==
'societe') {
1956 dol_syslog(
'Call fetch_barcode with barcode_type not defined and cannot be guessed', LOG_WARNING);
1961 if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1962 $sql =
"SELECT rowid, code, libelle as label, coder";
1963 $sql .=
" FROM ".$this->db->prefix().
"c_barcode_type";
1964 $sql .=
" WHERE rowid = ".((int) $idtype);
1965 dol_syslog(get_class($this).
'::fetch_barcode', LOG_DEBUG);
1966 $resql = $this->db->query($sql);
1968 $obj = $this->db->fetch_object($resql);
1969 $this->barcode_type = $obj->rowid;
1970 $this->barcode_type_code = $obj->code;
1971 $this->barcode_type_label = $obj->label;
1972 $this->barcode_type_coder = $obj->coder;
1992 return $this->fetch_projet();
2004 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
2006 if (empty($this->fk_project) && !empty($this->fk_projet)) {
2007 $this->fk_project = $this->fk_projet;
2009 if (empty($this->fk_project)) {
2013 $project =
new Project($this->db);
2014 $result = $project->fetch($this->fk_project);
2016 $this->projet = $project;
2017 $this->project = $project;
2030 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
2033 if (empty($this->fk_product)) {
2037 $product =
new Product($this->db);
2039 $result = $product->fetch($this->fk_product);
2041 $this->product = $product;
2055 $user =
new User($this->db);
2056 $result = $user->fetch($userid);
2057 $this->
user = $user;
2071 $origin = $this->origin ? $this->origin : $this->origin_type;
2074 if ($origin ==
'shipping') {
2075 $origin =
'expedition';
2077 if ($origin ==
'delivery') {
2078 $origin =
'livraison';
2080 if ($origin ==
'order_supplier' || $origin ==
'supplier_order') {
2081 $origin =
'commandeFournisseur';
2084 $classname = ucfirst($origin);
2085 $this->origin_object =
new $classname($this->db);
2087 $this->origin_object->fetch($this->origin_id);
2105 $sql =
"SELECT rowid FROM ".$this->db->prefix().$table;
2106 $sql .=
" WHERE ".$field.
" = '".$this->db->escape($key).
"'";
2107 if (!empty($element)) {
2108 $sql .=
" AND entity IN (".getEntity($element).
")";
2110 $sql .=
" AND entity = ".((int) $conf->entity);
2113 dol_syslog(get_class($this).
'::fetchObjectFrom', LOG_DEBUG);
2114 $resql = $this->db->query($sql);
2116 $obj = $this->db->fetch_object($resql);
2119 if (method_exists($this,
'fetch')) {
2120 $result = $this->fetch($obj->rowid);
2122 $this->error =
'fetch() method not implemented on '.get_class($this);
2123 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
2124 array_push($this->errors, $this->error);
2144 if (!empty($id) && !empty($field) && !empty($table)) {
2145 $sql =
"SELECT ".$field.
" FROM ".$this->db->prefix().$table;
2146 $sql .=
" WHERE rowid = ".((int) $id);
2148 dol_syslog(get_class($this).
'::getValueFrom', LOG_DEBUG);
2149 $resql = $this->db->query($sql);
2151 $row = $this->db->fetch_row($resql);
2174 public function setValueFrom($field, $value, $table =
'', $id =
null, $format =
'', $id_field =
'', $fuser =
null, $trigkey =
'', $fk_user_field =
'fk_user_modif')
2178 if (empty($table)) {
2179 $table = $this->table_element;
2184 if (empty($format)) {
2187 if (empty($id_field)) {
2188 $id_field =
'rowid';
2192 if ($table ==
'product' && $field ==
'note_private') {
2196 if (in_array($table, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
2197 $fk_user_field =
'fk_user_mod';
2199 if (in_array($table, array(
'prelevement_bons'))) {
2200 $fk_user_field =
'';
2205 $sql =
"SELECT " . $field;
2206 $sql .=
" FROM " . MAIN_DB_PREFIX . $table;
2207 $sql .=
" WHERE " . $id_field .
" = " . ((int) $id);
2209 $resql = $this->db->query($sql);
2211 if ($obj = $this->db->fetch_object($resql)) {
2212 if ($format ==
'date') {
2213 $oldvalue = $this->db->jdate($obj->$field);
2215 $oldvalue = $obj->$field;
2219 $this->error = $this->db->lasterror();
2230 $sql =
"UPDATE ".$this->db->prefix().$table.
" SET ";
2232 if ($format ==
'text') {
2233 $sql .= $field.
" = '".$this->db->escape($value).
"'";
2234 } elseif ($format ==
'int') {
2235 $sql .= $field.
" = ".((int) $value);
2236 } elseif ($format ==
'date') {
2237 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value).
"'" :
"null");
2238 } elseif ($format ==
'dategmt') {
2239 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value,
'gmt').
"'" :
"null");
2242 if ($fk_user_field) {
2243 if (!empty($fuser) && is_object($fuser)) {
2244 $sql .=
", ".$fk_user_field.
" = ".((int) $fuser->id);
2245 } elseif (empty($fuser) || $fuser !=
'none') {
2246 $sql .=
", ".$fk_user_field.
" = ".((int) $user->id);
2250 $sql .=
" WHERE ".$id_field.
" = ".((int) $id);
2252 $resql = $this->db->query($sql);
2256 if (method_exists($this,
'fetch')) {
2257 $result = $this->fetch($id);
2259 $result = $this->fetchCommon($id);
2261 $this->oldcopy = clone $this;
2262 if (property_exists($this->oldcopy, $field)) {
2263 $this->oldcopy->$field = $oldvalue;
2267 $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
2275 if (property_exists($this, $field)) {
2276 $this->$field = $value;
2278 $this->db->commit();
2281 $this->db->rollback();
2285 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2286 $this->error =
'DB_ERROR_RECORD_ALREADY_EXISTS';
2288 $this->error = $this->db->lasterror();
2290 $this->db->rollback();
2309 global $conf, $user;
2311 if (!$this->table_element) {
2312 dol_print_error(
null, get_class($this).
"::load_previous_next_ref was called on object with property table_element not defined");
2315 if ($fieldid ==
'none') {
2320 if (in_array($this->table_element, array(
'facture_rec',
'facture_fourn_rec')) && $fieldid ==
'title') {
2326 if ($user->socid > 0) {
2327 $socid = $user->socid;
2332 $aliastablesociete =
's';
2333 if ($this->element ==
'societe') {
2334 $aliastablesociete =
'te';
2336 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2337 $sql =
"SELECT MAX(te.".$fieldid.
")";
2338 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2339 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2340 $tmparray = explode(
'@', $this->ismultientitymanaged);
2341 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2342 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2343 $sql .=
", ".$this->db->prefix().
"societe as s";
2344 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2345 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2347 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2348 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2350 if ($fieldid ==
'rowid') {
2351 $sql .=
" WHERE te.".$fieldid.
" < ".((int) $this->
id);
2353 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($this->
ref).
"'";
2355 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2356 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2358 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2359 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2362 $filtermax = $filter;
2367 if ($errormessage) {
2368 if (!preg_match(
'/^\s*AND/i', $filtermax)) {
2376 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2377 $tmparray = explode(
'@', $this->ismultientitymanaged);
2378 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2379 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2380 $sql .=
' AND te.fk_soc = s.rowid';
2382 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2383 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2384 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2385 $sql .=
" AND te.entity IS NOT NULL";
2387 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2390 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2393 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2394 $tmparray = explode(
'@', $this->ismultientitymanaged);
2395 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2397 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2398 $sql .=
' AND te.fk_soc = '.((int) $socid);
2400 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2401 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2403 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2404 $sql .=
' AND te.rowid = '.((int) $socid);
2408 $result = $this->db->query($sql);
2410 $this->error = $this->db->lasterror();
2413 $row = $this->db->fetch_row($result);
2414 $this->ref_previous = $row[0];
2416 $sql =
"SELECT MIN(te.".$fieldid.
")";
2417 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2418 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2419 $tmparray = explode(
'@', $this->ismultientitymanaged);
2420 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2421 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2422 $sql .=
", ".$this->db->prefix().
"societe as s";
2423 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2424 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2426 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2427 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2429 if ($fieldid ==
'rowid') {
2430 $sql .=
" WHERE te.".$fieldid.
" > ".((int) $this->
id);
2432 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($this->
ref).
"'";
2434 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2435 $sql .=
" AND (sc.fk_user = ".((int) $user->id);
2437 $userschilds = $user->getAllChildIds();
2438 $sql .=
" OR sc.fk_user IN (".$this->db->sanitize(implode(
',', $userschilds)).
")";
2442 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2443 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2446 $filtermin = $filter;
2451 if ($errormessage) {
2452 if (!preg_match(
'/^\s*AND/i', $filtermin)) {
2462 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2463 $tmparray = explode(
'@', $this->ismultientitymanaged);
2464 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2465 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2466 $sql .=
' AND te.fk_soc = s.rowid';
2468 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2469 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2470 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2471 $sql .=
" AND te.entity IS NOT NULL";
2473 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2476 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2479 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2480 $tmparray = explode(
'@', $this->ismultientitymanaged);
2481 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2483 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2484 $sql .=
' AND te.fk_soc = '.((int) $socid);
2486 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2487 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2489 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2490 $sql .=
' AND te.rowid = '.((int) $socid);
2495 $result = $this->db->query($sql);
2497 $this->error = $this->db->lasterror();
2500 $row = $this->db->fetch_row($result);
2501 $this->ref_next = $row[0];
2516 $contactAlreadySelected = array();
2517 $tab = $this->liste_contact(-1, $source);
2521 if ($source ==
'thirdparty') {
2522 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
2524 $contactAlreadySelected[$i] = $tab[$i][
'id'];
2528 return $contactAlreadySelected;
2544 if (!$this->table_element) {
2545 dol_syslog(get_class($this).
"::setProject was called on object with property table_element not defined", LOG_ERR);
2549 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2550 if (!empty($this->fields[
'fk_project'])) {
2552 $sql .=
" SET fk_project = ".((int) $projectid);
2554 $sql .=
" SET fk_project = NULL";
2556 $sql .=
' WHERE rowid = '.((int) $this->
id);
2557 } elseif ($this->table_element ==
'actioncomm') {
2559 $sql .=
" SET fk_project = ".((int) $projectid);
2561 $sql .=
" SET fk_project = NULL";
2563 $sql .=
' WHERE id = '.((int) $this->
id);
2566 $sql .=
' SET fk_projet = '.((int) $projectid);
2568 $sql .=
' SET fk_projet = NULL';
2570 $sql .=
" WHERE rowid = ".((int) $this->
id);
2575 dol_syslog(get_class($this).
"::setProject", LOG_DEBUG);
2576 if ($this->db->query($sql)) {
2577 $this->fk_project = ((int) $projectid);
2584 if (!$error && !$notrigger) {
2586 $result = $this->call_trigger(strtoupper($this->element) .
'_MODIFY', $user);
2595 $this->db->rollback();
2598 $this->db->commit();
2616 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2618 if ($this->
status >= 0 || $this->element ==
'societe') {
2620 $fieldname =
'fk_mode_reglement';
2621 if ($this->element ==
'societe') {
2622 $fieldname =
'mode_reglement';
2624 if (get_class($this) ==
'Fournisseur') {
2625 $fieldname =
'mode_reglement_supplier';
2627 if (get_class($this) ==
'Tva') {
2628 $fieldname =
'fk_typepayment';
2630 if (get_class($this) ==
'Salary') {
2631 $fieldname =
'fk_typepayment';
2634 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2635 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2636 $sql .=
' WHERE rowid='.((int) $this->
id);
2638 if ($this->db->query($sql)) {
2639 $this->mode_reglement_id = $id;
2641 if (get_class($this) ==
'Fournisseur') {
2642 $this->mode_reglement_supplier_id = $id;
2645 if (!$error && !$notrigger) {
2647 if (get_class($this) ==
'Commande') {
2648 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2650 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
2659 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2660 $this->error = $this->db->error();
2664 dol_syslog(get_class($this).
'::setPaymentMethods, status of the object is incompatible');
2665 $this->error =
'Status of the object is incompatible '.$this->status;
2678 dol_syslog(get_class($this).
'::setMulticurrencyCode('.$code.
')');
2679 if ($this->
status >= 0 || $this->element ==
'societe') {
2680 $fieldname =
'multicurrency_code';
2682 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2683 $sql .=
" SET ".$fieldname.
" = '".$this->db->escape($code).
"'";
2684 $sql .=
' WHERE rowid='.((int) $this->
id);
2686 if ($this->db->query($sql)) {
2687 $this->multicurrency_code = $code;
2691 $this->setMulticurrencyRate($rate, 2);
2696 dol_syslog(get_class($this).
'::setMulticurrencyCode Error '.$sql.
' - '.$this->db->error());
2697 $this->error = $this->db->error();
2701 dol_syslog(get_class($this).
'::setMulticurrencyCode, status of the object is incompatible');
2702 $this->error =
'Status of the object is incompatible '.$this->status;
2714 public function setMulticurrencyRate($rate, $mode = 1)
2716 dol_syslog(get_class($this).
'::setMulticurrencyRate('.$rate.
', '.$mode.
')');
2717 if ($this->
status >= 0 || $this->element ==
'societe') {
2718 $fieldname =
'multicurrency_tx';
2720 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2721 $sql .=
" SET ".$fieldname.
" = ".((float) $rate);
2722 $sql .=
' WHERE rowid='.((int) $this->
id);
2724 if ($this->db->query($sql)) {
2725 $this->multicurrency_tx = $rate;
2728 if (!empty($this->lines)) {
2729 foreach ($this->lines as &$line) {
2732 $line->subprice = 0;
2737 $line->multicurrency_subprice = 0;
2740 switch ($this->element) {
2748 $line->remise_percent,
2750 $line->localtax1_tx,
2751 $line->localtax2_tx,
2752 ($line->description ? $line->description : $line->desc),
2755 $line->special_code,
2756 $line->fk_parent_line,
2757 $line->skip_update_total,
2758 $line->fk_fournprice,
2761 $line->product_type,
2764 $line->array_options,
2766 $line->multicurrency_subprice
2774 ($line->description ? $line->description : $line->desc),
2777 $line->remise_percent,
2779 $line->localtax1_tx,
2780 $line->localtax2_tx,
2785 $line->product_type,
2786 $line->fk_parent_line,
2787 $line->skip_update_total,
2788 $line->fk_fournprice,
2791 $line->special_code,
2792 $line->array_options,
2794 $line->multicurrency_subprice
2802 ($line->description ? $line->description : $line->desc),
2805 $line->remise_percent,
2809 $line->localtax1_tx,
2810 $line->localtax2_tx,
2813 $line->product_type,
2814 $line->fk_parent_line,
2815 $line->skip_update_total,
2816 $line->fk_fournprice,
2819 $line->special_code,
2820 $line->array_options,
2821 $line->situation_percent,
2823 $line->multicurrency_subprice
2826 case 'supplier_proposal':
2833 $line->remise_percent,
2835 $line->localtax1_tx,
2836 $line->localtax2_tx,
2837 ($line->description ? $line->description : $line->desc),
2840 $line->special_code,
2841 $line->fk_parent_line,
2842 $line->skip_update_total,
2843 $line->fk_fournprice,
2846 $line->product_type,
2847 $line->array_options,
2849 $line->multicurrency_subprice
2852 case 'order_supplier':
2857 ($line->description ? $line->description : $line->desc),
2860 $line->remise_percent,
2862 $line->localtax1_tx,
2863 $line->localtax2_tx,
2866 $line->product_type,
2870 $line->array_options,
2872 $line->multicurrency_subprice,
2876 case 'invoice_supplier':
2881 ($line->description ? $line->description : $line->desc),
2884 $line->localtax1_tx,
2885 $line->localtax2_tx,
2890 $line->product_type,
2891 $line->remise_percent,
2895 $line->array_options,
2897 $line->multicurrency_subprice,
2902 dol_syslog(get_class($this).
'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
2910 dol_syslog(get_class($this).
'::setMulticurrencyRate Error '.$sql.
' - '.$this->db->error());
2911 $this->error = $this->db->error();
2915 dol_syslog(get_class($this).
'::setMulticurrencyRate, status of the object is incompatible');
2916 $this->error =
'Status of the object is incompatible '.$this->status;
2930 dol_syslog(get_class($this).
'::setPaymentTerms('.$id.
', '.var_export($deposit_percent,
true).
')');
2931 if ($this->
status >= 0 || $this->element ==
'societe') {
2933 $fieldname =
'fk_cond_reglement';
2934 if ($this->element ==
'societe') {
2935 $fieldname =
'cond_reglement';
2937 if (get_class($this) ==
'Fournisseur') {
2938 $fieldname =
'cond_reglement_supplier';
2941 if (empty($deposit_percent) || $deposit_percent < 0) {
2942 $deposit_percent = (float)
getDictionaryValue(
'c_payment_term',
'deposit_percent', $id);
2945 if ($deposit_percent > 100) {
2946 $deposit_percent = 100;
2949 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2950 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2951 if (in_array($this->table_element, array(
'propal',
'commande',
'societe'))) {
2952 $sql .=
" , deposit_percent = " . (empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape($deposit_percent).
"'");
2954 $sql .=
' WHERE rowid='.((int) $this->
id);
2956 if ($this->db->query($sql)) {
2957 $this->cond_reglement_id = $id;
2959 if (get_class($this) ==
'Fournisseur') {
2960 $this->cond_reglement_supplier_id = $id;
2962 $this->cond_reglement = $id;
2963 $this->deposit_percent = $deposit_percent;
2966 dol_syslog(get_class($this).
'::setPaymentTerms Error '.$sql.
' - '.$this->db->error());
2967 $this->error = $this->db->error();
2971 dol_syslog(get_class($this).
'::setPaymentTerms, status of the object is incompatible');
2972 $this->error =
'Status of the object is incompatible '.$this->status;
2985 dol_syslog(get_class($this).
'::setTransportMode('.$id.
')');
2986 if ($this->
status >= 0 || $this->element ==
'societe') {
2987 $fieldname =
'fk_transport_mode';
2988 if ($this->element ==
'societe') {
2989 $fieldname =
'transport_mode';
2991 if (get_class($this) ==
'Fournisseur') {
2992 $fieldname =
'transport_mode_supplier';
2995 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2996 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2997 $sql .=
' WHERE rowid='.((int) $this->
id);
2999 if ($this->db->query($sql)) {
3000 $this->transport_mode_id = $id;
3002 if (get_class($this) ==
'Fournisseur') {
3003 $this->transport_mode_supplier_id = $id;
3007 dol_syslog(get_class($this).
'::setTransportMode Error '.$sql.
' - '.$this->db->error());
3008 $this->error = $this->db->error();
3012 dol_syslog(get_class($this).
'::setTransportMode, status of the object is incompatible');
3013 $this->error =
'Status of the object is incompatible '.$this->status;
3026 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms('.$id.
')');
3027 if ($this->
status >= 0 || $this->element ==
'societe') {
3028 $fieldname =
'retained_warranty_fk_cond_reglement';
3030 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
3031 $sql .=
" SET ".$fieldname.
" = ".((int) $id);
3032 $sql .=
' WHERE rowid='.((int) $this->
id);
3034 if ($this->db->query($sql)) {
3035 $this->retained_warranty_fk_cond_reglement = $id;
3038 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms Error '.$sql.
' - '.$this->db->error());
3039 $this->error = $this->db->error();
3043 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
3044 $this->error =
'Status of the object is incompatible '.$this->status;
3058 $fieldname =
'fk_delivery_address';
3059 if ($this->element ==
'delivery' || $this->element ==
'shipping') {
3060 $fieldname =
'fk_address';
3063 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ".$fieldname.
" = ".((int) $id);
3064 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
3066 if ($this->db->query($sql)) {
3067 $this->fk_delivery_address = $id;
3070 $this->error = $this->db->error();
3071 dol_syslog(get_class($this).
'::setDeliveryAddress Error '.$this->error);
3089 if (empty($userused)) {
3095 if (!$this->table_element) {
3096 dol_syslog(get_class($this).
"::setShippingMethod was called on object with property table_element not defined", LOG_ERR);
3102 if ($shipping_method_id < 0) {
3103 $shipping_method_id =
'NULL';
3105 dol_syslog(get_class($this).
'::setShippingMethod('.$shipping_method_id.
')');
3107 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3108 $sql .=
" SET fk_shipping_method = ".((int) $shipping_method_id);
3109 $sql .=
" WHERE rowid=".((int) $this->
id);
3110 $resql = $this->db->query($sql);
3112 dol_syslog(get_class($this).
'::setShippingMethod Error ', LOG_DEBUG);
3113 $this->error = $this->db->lasterror();
3118 $this->context = array(
'shippingmethodupdate' => 1);
3119 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
3127 $this->db->rollback();
3130 $this->shipping_method_id = ($shipping_method_id ==
'NULL') ?
null : $shipping_method_id;
3131 $this->db->commit();
3145 if (!$this->table_element) {
3146 dol_syslog(get_class($this).
"::setWarehouse was called on object with property table_element not defined", LOG_ERR);
3149 if ($warehouse_id < 0) {
3150 $warehouse_id =
'NULL';
3152 dol_syslog(get_class($this).
'::setWarehouse('.$warehouse_id.
')');
3154 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3155 $sql .=
" SET fk_warehouse = ".((int) $warehouse_id);
3156 $sql .=
" WHERE rowid=".((int) $this->
id);
3158 if ($this->db->query($sql)) {
3159 $this->warehouse_id = ($warehouse_id ==
'NULL') ?
null : $warehouse_id;
3162 dol_syslog(get_class($this).
'::setWarehouse Error ', LOG_DEBUG);
3163 $this->error = $this->db->error();
3178 if (!$this->table_element) {
3179 dol_syslog(get_class($this).
"::setDocModel was called on object with property table_element not defined", LOG_ERR);
3183 $newmodelpdf =
dol_trunc($modelpdf, 255);
3185 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3186 $sql .=
" SET model_pdf = '".$this->db->escape($newmodelpdf).
"'";
3187 $sql .=
" WHERE rowid = ".((int) $this->
id);
3189 dol_syslog(get_class($this).
"::setDocModel", LOG_DEBUG);
3190 $resql = $this->db->query($sql);
3192 $this->model_pdf = $modelpdf;
3213 if (empty($userused)) {
3219 if (!$this->table_element) {
3220 dol_syslog(get_class($this).
"::setBankAccount was called on object with property table_element not defined", LOG_ERR);
3225 if ($fk_account < 0) {
3226 $fk_account =
'NULL';
3228 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
3230 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3231 $sql .=
" SET fk_account = ".((int) $fk_account);
3232 $sql .=
" WHERE rowid=".((int) $this->
id);
3234 $resql = $this->db->query($sql);
3236 dol_syslog(get_class($this).
'::setBankAccount Error '.$sql.
' - '.$this->db->error());
3237 $this->error = $this->db->lasterror();
3242 $this->context[
'bankaccountupdate'] = 1;
3243 $triggerName = strtoupper(get_class($this)).
'_MODIFY';
3245 if ($triggerName ==
'FACTUREREC_MODIFY') {
3246 $triggerName =
'BILLREC_MODIFY';
3248 $result = $this->call_trigger($triggerName, $userused);
3256 $this->db->rollback();
3259 $this->fk_account = ($fk_account ==
'NULL') ?
null : $fk_account;
3260 $this->db->commit();
3278 public function line_order($renum =
false, $rowidorder =
'ASC', $fk_parent_line =
true)
3281 if (!$this->table_element_line) {
3282 dol_syslog(get_class($this).
"::line_order was called on object with property table_element_line not defined", LOG_ERR);
3285 if (!$this->fk_element) {
3286 dol_syslog(get_class($this).
"::line_order was called on object with property fk_element not defined", LOG_ERR);
3290 $fieldposition =
'rang';
3291 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3292 $fieldposition =
'position';
3297 $sql =
"SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
3298 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3300 $sql .=
" AND " . $fieldposition .
" = 0";
3303 $sql .=
" AND " . $fieldposition .
" <> 0";
3306 dol_syslog(get_class($this).
"::line_order", LOG_DEBUG);
3307 $resql = $this->db->query($sql);
3309 $row = $this->db->fetch_row($resql);
3319 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3320 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3321 if ($fk_parent_line) {
3322 $sql .=
' AND fk_parent_line IS NULL';
3324 $sql .=
" ORDER BY " . $fieldposition .
" ASC, rowid " . $rowidorder;
3326 dol_syslog(get_class($this).
"::line_order search all parent lines", LOG_DEBUG);
3327 $resql = $this->db->query($sql);
3330 $num = $this->db->num_rows($resql);
3332 $row = $this->db->fetch_row($resql);
3334 $children = $this->getChildrenOfLine($row[0]);
3335 if (!empty($children)) {
3336 foreach ($children as $child) {
3337 array_push($rows, $child);
3344 if (!empty($rows)) {
3345 foreach ($rows as $key => $row) {
3346 $this->updateRangOfLine($row, ($key + 1));
3365 $fieldposition =
'rang';
3366 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3367 $fieldposition =
'position';
3372 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3373 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3374 $sql .=
' AND fk_parent_line = '.((int) $id);
3375 $sql .=
" ORDER BY " . $fieldposition .
" ASC";
3377 dol_syslog(get_class($this).
"::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
3378 $resql = $this->db->query($sql);
3380 if ($this->db->num_rows($resql) > 0) {
3381 while ($row = $this->db->fetch_row($resql)) {
3383 if (!empty($includealltree)) {
3384 $rows = array_merge($rows, $this->getChildrenOfLine($row[0], $includealltree));
3400 public function line_up($rowid, $fk_parent_line =
true)
3403 $this->line_order(
false,
'ASC', $fk_parent_line);
3406 $rang = $this->getRangOfLine($rowid);
3409 $this->updateLineUp($rowid, $rang);
3423 $this->line_order(
false,
'ASC', $fk_parent_line);
3426 $rang = $this->getRangOfLine($rowid);
3429 $max = $this->line_max();
3432 $this->updateLineDown($rowid, $rang, $max);
3444 global $hookmanager;
3445 $fieldposition =
'rang';
3446 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3447 $fieldposition =
'position';
3450 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3451 $sql .=
' WHERE rowid = '.((int) $rowid);
3453 dol_syslog(get_class($this).
"::updateRangOfLine", LOG_DEBUG);
3454 if (!$this->db->query($sql)) {
3458 $parameters = array(
'rowid' => $rowid,
'rang' => $rang,
'fieldposition' => $fieldposition);
3460 $reshook = $hookmanager->executeHooks(
'afterRankOfLineUpdate', $parameters, $this, $action);
3475 $num = count($rows);
3476 for ($i = 0; $i < $num; $i++) {
3477 $this->updateRangOfLine($rows[$i], ($i + 1));
3491 $fieldposition =
'rang';
3492 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3493 $fieldposition =
'position';
3496 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3497 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3498 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang - 1));
3499 if ($this->db->query($sql)) {
3500 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang - 1));
3501 $sql .=
' WHERE rowid = '.((int) $rowid);
3502 if (!$this->db->query($sql)) {
3522 $fieldposition =
'rang';
3523 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3524 $fieldposition =
'position';
3527 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3528 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3529 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang + 1));
3530 if ($this->db->query($sql)) {
3531 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang + 1));
3532 $sql .=
' WHERE rowid = '.((int) $rowid);
3533 if (!$this->db->query($sql)) {
3550 $fieldposition =
'rang';
3551 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3552 $fieldposition =
'position';
3555 $sql =
"SELECT " . $fieldposition .
" FROM ".$this->db->prefix().$this->table_element_line;
3556 $sql .=
" WHERE rowid = ".((int) $rowid);
3558 dol_syslog(get_class($this).
"::getRangOfLine", LOG_DEBUG);
3559 $resql = $this->db->query($sql);
3561 $row = $this->db->fetch_row($resql);
3576 $fieldposition =
'rang';
3577 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3578 $fieldposition =
'position';
3581 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3582 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3583 $sql .=
" AND " . $fieldposition .
" = ".((int) $rang);
3584 $resql = $this->db->query($sql);
3586 $row = $this->db->fetch_row($resql);
3603 $positionfield =
'rang';
3604 if (in_array($this->table_element, array(
'bom_bom',
'product_attribute'))) {
3605 $positionfield =
'position';
3609 if ($fk_parent_line) {
3610 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3611 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3612 $sql .=
" AND fk_parent_line = ".((int) $fk_parent_line);
3614 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3615 $resql = $this->db->query($sql);
3617 $row = $this->db->fetch_row($resql);
3618 if (!empty($row[0])) {
3621 return $this->getRangOfLine($fk_parent_line);
3626 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3627 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3629 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3630 $resql = $this->db->query($sql);
3632 $row = $this->db->fetch_row($resql);
3650 if (!$this->table_element) {
3651 dol_syslog(get_class($this).
"::update_ref_ext was called on object with property table_element not defined", LOG_ERR);
3655 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3656 $sql .=
" SET ref_ext = '".$this->db->escape($ref_ext).
"'";
3657 $sql .=
" WHERE ".(isset($this->table_rowid) ? $this->table_rowid :
'rowid').
" = ".((
int) $this->id);
3659 dol_syslog(get_class($this).
"::update_ref_ext", LOG_DEBUG);
3660 if ($this->db->query($sql)) {
3661 $this->ref_ext = $ref_ext;
3664 $this->error = $this->db->error();
3683 if (!$this->table_element) {
3684 $this->error =
'update_note was called on object with property table_element not defined';
3685 dol_syslog(get_class($this).
"::update_note was called on object with property table_element not defined", LOG_ERR);
3688 if (!in_array($suffix, array(
'',
'_public',
'_private'))) {
3689 $this->error =
'update_note Parameter suffix must be empty, \'_private\' or \'_public\'';
3690 dol_syslog(get_class($this).
"::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
3694 $newsuffix = $suffix;
3697 if ($this->table_element ==
'product' && $newsuffix ==
'_private') {
3700 if (in_array($this->table_element, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
3701 $fieldusermod =
"fk_user_mod";
3702 } elseif ($this->table_element ==
'ecm_files') {
3703 $fieldusermod =
"fk_user_m";
3705 $fieldusermod =
"fk_user_modif";
3707 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3708 $sql .=
" SET note".$newsuffix.
" = ".(!empty($note) ? (
"'".$this->db->escape($note).
"'") :
"NULL");
3709 $sql .=
", ".$fieldusermod.
" = ".((int) $user->id);
3710 $sql .=
" WHERE rowid = ".((int) $this->
id);
3712 dol_syslog(get_class($this).
"::update_note", LOG_DEBUG);
3713 if ($this->db->query($sql)) {
3714 if ($suffix ==
'_public') {
3715 $this->note_public = $note;
3716 } elseif ($suffix ==
'_private') {
3717 $this->note_private = $note;
3719 $this->note = $note;
3720 $this->note_private = $note;
3722 if (empty($notrigger)) {
3723 switch ($this->element) {
3725 $trigger_name =
'COMPANY_MODIFY';
3728 $trigger_name =
'ORDER_MODIFY';
3731 $trigger_name =
'BILL_MODIFY';
3733 case 'invoice_supplier':
3734 $trigger_name =
'BILL_SUPPLIER_MODIFY';
3737 $trigger_name =
'BILLREC_MODIFIY';
3739 case 'expensereport':
3740 $trigger_name =
'EXPENSE_REPORT_MODIFY';
3743 $trigger_name = strtoupper($this->element) .
'_MODIFY';
3745 $ret = $this->call_trigger($trigger_name, $user);
3752 $this->error = $this->db->lasterror();
3769 return $this->update_note($note,
'_public');
3783 public function update_price($exclspec = 0, $roundingadjust =
'auto', $nodatabaseupdate = 0, $seller =
null)
3786 global $conf, $hookmanager, $action;
3788 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3789 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3792 } elseif ($reshook < 0) {
3797 $isElementForSupplier =
false;
3798 $roundTotalConstName =
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND';
3800 if ($this->element ==
'propal') {
3801 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3802 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3803 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3804 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3805 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3806 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3807 $isElementForSupplier =
true;
3808 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3809 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3810 $isElementForSupplier =
true;
3811 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3812 } elseif ($this->element ==
'supplier_proposal') {
3813 $isElementForSupplier =
true;
3814 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3816 if ($isElementForSupplier) {
3817 $roundTotalConstName =
'MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND_SUPPLIER';
3820 if (!empty($MODULE)) {
3823 foreach ($modsactivated as $mod) {
3824 if (isModEnabled($mod)) {
3831 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3833 $forcedroundingmode = $roundingadjust;
3834 if ($forcedroundingmode ==
'auto' && isset($conf->global->{$roundTotalConstName})) {
3836 } elseif ($forcedroundingmode ==
'auto') {
3837 $forcedroundingmode =
'0';
3842 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3845 $fieldtva =
'total_tva';
3846 $fieldlocaltax1 =
'total_localtax1';
3847 $fieldlocaltax2 =
'total_localtax2';
3848 $fieldup =
'subprice';
3849 $base_price_type =
'HT';
3850 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3854 if ($this->element ==
'invoice_supplier_rec') {
3857 if ($this->element ==
'expensereport') {
3858 $fieldup =
'value_unit';
3859 $base_price_type =
'TTC';
3862 $sql =
"SELECT rowid, qty, ".$fieldup.
" as up, remise_percent, total_ht, ".$fieldtva.
" as total_tva, total_ttc, ".$fieldlocaltax1.
" as total_localtax1, ".$fieldlocaltax2.
" as total_localtax2,";
3863 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3864 if ($this->table_element_line ==
'facturedet') {
3865 $sql .=
', situation_percent';
3867 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
3868 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
3869 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3871 $product_field =
'product_type';
3872 if ($this->table_element_line ==
'contratdet') {
3873 $product_field =
'';
3875 if ($product_field) {
3876 $sql .=
" AND ".$product_field.
" <> 9";
3879 $sql .=
' ORDER by rowid';
3881 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3883 $resql = $this->db->query($sql);
3885 $this->total_ht = 0;
3886 $this->total_tva = 0;
3887 $this->total_localtax1 = 0;
3888 $this->total_localtax2 = 0;
3889 $this->total_ttc = 0;
3890 $total_ht_by_vats = array();
3891 $total_tva_by_vats = array();
3892 $total_ttc_by_vats = array();
3893 $this->multicurrency_total_ht = 0;
3894 $this->multicurrency_total_tva = 0;
3895 $this->multicurrency_total_ttc = 0;
3899 $num = $this->db->num_rows($resql);
3902 $obj = $this->db->fetch_object($resql);
3905 $parameters = array(
'fk_element' => $obj->rowid);
3906 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
3908 if (empty($reshook) && $forcedroundingmode ==
'0') {
3910 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3911 $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);
3913 $diff_when_using_price_ht =
price2num($tmpcal[1] - $obj->total_tva,
'MT', 1);
3914 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
3918 if ($diff_on_current_total) {
3920 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line;
3921 $sqlfix .=
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]);
3922 $sqlfix .=
", multicurrency_total_tva = ".price2num((
float) $tmpcal[17]).
", multicurrency_total_ttc = ".
price2num((
float) $tmpcal[18]);
3923 $sqlfix .=
" WHERE rowid = ".((int) $obj->rowid);
3924 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);
3925 $resqlfix = $this->db->query($sqlfix);
3929 $obj->total_tva = $tmpcal[1];
3930 $obj->total_ttc = $tmpcal[2];
3931 $obj->multicurrency_total_tva = $tmpcal[17];
3932 $obj->multicurrency_total_ttc = $tmpcal[18];
3933 } elseif ($diff_when_using_price_ht) {
3936 if ((
float) $tmpcal[0] == (
float) $obj->total_ht) {
3941 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line;
3942 $sqlfix .=
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]);
3943 $sqlfix .=
", multicurrency_total_tva = ".price2num((
float) $tmpcal[17]).
", multicurrency_total_ttc = ".
price2num((
float) $tmpcal[18]);
3944 $sqlfix .=
" WHERE rowid = ".((int) $obj->rowid);
3945 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);
3946 $resqlfix = $this->db->query($sqlfix);
3950 $obj->total_tva = $tmpcal[1];
3951 $obj->total_ttc = $tmpcal[2];
3952 $obj->multicurrency_total_tva = $tmpcal[17];
3953 $obj->multicurrency_total_ttc = $tmpcal[18];
3958 $this->total_ht += $obj->total_ht;
3959 $this->total_tva += $obj->total_tva;
3960 $this->total_localtax1 += $obj->total_localtax1;
3961 $this->total_localtax2 += $obj->total_localtax2;
3962 $this->total_ttc += $obj->total_ttc;
3963 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
3964 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
3965 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
3967 if (!isset($total_ht_by_vats[$obj->vatrate])) {
3968 $total_ht_by_vats[$obj->vatrate] = 0;
3970 if (!isset($total_tva_by_vats[$obj->vatrate])) {
3971 $total_tva_by_vats[$obj->vatrate] = 0;
3973 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3974 $total_ttc_by_vats[$obj->vatrate] = 0;
3976 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
3977 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3978 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3980 if ($forcedroundingmode ==
'1') {
3981 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
3982 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - (
float) $tmpvat,
'MT', 1);
3985 $maxdiff = (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)));
3986 if (abs((
float) $diff) > $maxdiff) {
3988 $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.';
3990 $this->error = $errmsg;
3994 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num($obj->total_tva - (
float) $diff).
", total_ttc = ".
price2num($obj->total_ttc - (
float) $diff).
" WHERE rowid = ".((int) $obj->rowid);
3995 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);
3997 $resqlfix = $this->db->query($sqlfix);
4003 $this->total_tva = (float)
price2num($this->total_tva - (
float) $diff,
'', 1);
4004 $this->total_ttc = (float)
price2num($this->total_ttc - (
float) $diff,
'', 1);
4005 $total_tva_by_vats[$obj->vatrate] = (float)
price2num($total_tva_by_vats[$obj->vatrate] - (
float) $diff,
'', 1);
4006 $total_ttc_by_vats[$obj->vatrate] = (float)
price2num($total_ttc_by_vats[$obj->vatrate] - (
float) $diff,
'', 1);
4014 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
4015 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
4018 if (!empty($this->situation_cycle_ref) && !empty($this->situation_counter) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits')) {
4019 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
4022 $prev_sits = $this->get_prev_sits();
4024 foreach ($prev_sits as $sit) {
4025 $this->total_ht -= $sit->total_ht;
4026 $this->total_tva -= $sit->total_tva;
4027 $this->total_localtax1 -= $sit->total_localtax1;
4028 $this->total_localtax2 -= $sit->total_localtax2;
4029 $this->total_ttc -= $sit->total_ttc;
4030 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
4031 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
4032 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
4039 $this->total_ht = (float)
price2num($this->total_ht);
4040 $this->total_tva = (float)
price2num($this->total_tva);
4041 $this->total_localtax1 = (float)
price2num($this->total_localtax1);
4042 $this->total_localtax2 = (float)
price2num($this->total_localtax2);
4043 $this->total_ttc = (float)
price2num($this->total_ttc);
4045 $this->db->free($resql);
4048 $fieldht =
'total_ht';
4050 $fieldlocaltax1 =
'localtax1';
4051 $fieldlocaltax2 =
'localtax2';
4052 $fieldttc =
'total_ttc';
4054 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
4055 $fieldtva =
'total_tva';
4058 if (!$error && empty($nodatabaseupdate)) {
4059 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
4060 $sql .=
" ".$fieldht.
" = ".((float)
price2num($this->total_ht,
'MT', 1)).
",";
4061 $sql .=
" ".$fieldtva.
" = ".((float)
price2num($this->total_tva,
'MT', 1)).
",";
4062 $sql .=
" ".$fieldlocaltax1.
" = ".((float)
price2num($this->total_localtax1,
'MT', 1)).
",";
4063 $sql .=
" ".$fieldlocaltax2.
" = ".((float)
price2num($this->total_localtax2,
'MT', 1)).
",";
4064 $sql .=
" ".$fieldttc.
" = ".((float)
price2num($this->total_ttc,
'MT', 1));
4065 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
4066 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
4067 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
4068 $sql .=
" WHERE rowid = ".((int) $this->
id);
4070 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
4071 $resql = $this->db->query($sql);
4075 $this->error = $this->db->lasterror();
4076 $this->errors[] = $this->db->lasterror();
4081 $this->db->commit();
4084 $this->db->rollback();
4104 public function add_object_linked($origin =
null, $origin_id =
null, $f_user =
null, $notrigger = 0)
4107 global $user, $hookmanager, $action;
4108 $origin = (!empty($origin) ? $origin : $this->origin);
4109 $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
4110 $f_user = isset($f_user) ? $f_user : $user;
4113 if ($origin ==
'order') {
4114 $origin =
'commande';
4116 if ($origin ==
'invoice') {
4117 $origin =
'facture';
4119 if ($origin ==
'invoice_template') {
4120 $origin =
'facturerec';
4122 if ($origin ==
'supplierorder') {
4123 $origin =
'order_supplier';
4127 $targettype = $this->getElementType();
4129 $parameters = array(
'targettype' => $targettype);
4131 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
4133 if (!empty($hookmanager->resArray[
'targettype'])) {
4134 $targettype = $hookmanager->resArray[
'targettype'];
4141 $sql =
"INSERT INTO " . $this->db->prefix() .
"element_element (";
4142 $sql .=
"fk_source";
4143 $sql .=
", sourcetype";
4144 $sql .=
", fk_target";
4145 $sql .=
", targettype";
4146 $sql .=
") VALUES (";
4147 $sql .= ((int) $origin_id);
4148 $sql .=
", '" . $this->db->escape($origin) .
"'";
4149 $sql .=
", " . ((int) $this->
id);
4150 $sql .=
", '" . $this->db->escape($targettype) .
"'";
4153 dol_syslog(get_class($this) .
"::add_object_linked", LOG_DEBUG);
4154 if ($this->db->query($sql)) {
4157 $this->context[
'link_origin'] = $origin;
4158 $this->context[
'link_origin_id'] = $origin_id;
4159 $result = $this->call_trigger(
'OBJECT_LINK_INSERT', $f_user);
4166 $this->error = $this->db->lasterror();
4171 $this->db->commit();
4174 $this->db->rollback();
4188 $coreModule = array(
'knowledgemanagement',
'partnership',
'workstation',
'ticket',
'recruitment',
'eventorganization',
'asset');
4190 return ((!empty($this->module) && !in_array($this->module, $coreModule)) ? $this->module.
'_' :
'').$this->element;
4216 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
4218 global $conf, $hookmanager, $action;
4223 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4227 $this->linkedObjectsIds = array();
4228 $this->linkedObjects = array();
4230 $justsource =
false;
4231 $justtarget =
false;
4232 $withtargettype =
false;
4233 $withsourcetype =
false;
4235 $parameters = array(
'sourcetype' => $sourcetype,
'sourceid' => $sourceid,
'targettype' => $targettype,
'targetid' => $targetid);
4237 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
4239 if (!empty($hookmanager->resArray[
'sourcetype'])) {
4240 $sourcetype = $hookmanager->resArray[
'sourcetype'];
4242 if (!empty($hookmanager->resArray[
'sourceid'])) {
4243 $sourceid = $hookmanager->resArray[
'sourceid'];
4245 if (!empty($hookmanager->resArray[
'targettype'])) {
4246 $targettype = $hookmanager->resArray[
'targettype'];
4248 if (!empty($hookmanager->resArray[
'targetid'])) {
4249 $targetid = $hookmanager->resArray[
'targetid'];
4253 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
4255 if (!empty($targettype)) {
4256 $withtargettype =
true;
4259 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
4261 if (!empty($sourcetype)) {
4262 $withsourcetype =
true;
4266 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4267 $targetid = (!empty($targetid) ? $targetid : $this->id);
4268 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->getElementType());
4269 $targettype = (!empty($targettype) ? $targettype : $this->getElementType());
4278 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
4279 $sql .=
" FROM ".$this->db->prefix().
"element_element";
4281 if ($justsource || $justtarget) {
4283 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4284 if ($withtargettype) {
4285 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
4287 } elseif ($justtarget) {
4288 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
4289 if ($withsourcetype) {
4290 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4294 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
4295 $sql .=
" ".$clause.
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
4296 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
4297 $this->linkedObjectsFullLoaded[$this->id] =
true;
4300 $sql .=
" ORDER BY ".$orderby;
4302 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
4303 $resql = $this->db->query($sql);
4305 $num = $this->db->num_rows($resql);
4308 $obj = $this->db->fetch_object($resql);
4309 if ($justsource || $justtarget) {
4311 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4312 } elseif ($justtarget) {
4313 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4316 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
4317 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4319 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
4320 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4326 if (!empty($this->linkedObjectsIds)) {
4327 $tmparray = $this->linkedObjectsIds;
4328 foreach ($tmparray as $objecttype => $objectids) {
4330 $element = $element_properties[
'element'];
4331 $classPath = $element_properties[
'classpath'];
4332 $classFile = $element_properties[
'classfile'];
4333 $className = $element_properties[
'classname'];
4334 $module = $element_properties[
'module'];
4337 if (isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4338 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4340 if (class_exists($className)) {
4341 foreach ($objectids as $i => $objectid) {
4342 $object =
new $className($this->db);
4343 $ret =
$object->fetch($objectid);
4345 $this->linkedObjects[$objecttype][$i] =
$object;
4351 unset($this->linkedObjectsIds[$objecttype]);
4370 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4371 unset($this->linkedObjectsFullLoaded[$this->
id]);
4389 public function updateObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $f_user =
null, $notrigger = 0)
4392 $updatesource =
false;
4393 $updatetarget =
false;
4394 $f_user = isset($f_user) ? $f_user : $user;
4396 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4397 $updatesource =
true;
4398 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4399 $updatetarget =
true;
4405 $sql =
"UPDATE " . $this->db->prefix() .
"element_element SET ";
4406 if ($updatesource) {
4407 $sql .=
"fk_source = " . ((int) $sourceid);
4408 $sql .=
", sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4409 $sql .=
" WHERE fk_target = " . ((int) $this->
id);
4410 $sql .=
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4411 } elseif ($updatetarget) {
4412 $sql .=
"fk_target = " . ((int) $targetid);
4413 $sql .=
", targettype = '" . $this->db->escape($targettype) .
"'";
4414 $sql .=
" WHERE fk_source = " . ((int) $this->
id);
4415 $sql .=
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4418 dol_syslog(get_class($this) .
"::updateObjectLinked", LOG_DEBUG);
4419 if ($this->db->query($sql)) {
4422 $this->context[
'link_source_id'] = $sourceid;
4423 $this->context[
'link_source_type'] = $sourcetype;
4424 $this->context[
'link_target_id'] = $targetid;
4425 $this->context[
'link_target_type'] = $targettype;
4426 $result = $this->call_trigger(
'OBJECT_LINK_MODIFY', $f_user);
4433 $this->error = $this->db->lasterror();
4438 $this->db->commit();
4441 $this->db->rollback();
4459 public function deleteObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $rowid = 0, $f_user =
null, $notrigger = 0)
4462 $deletesource =
false;
4463 $deletetarget =
false;
4464 $f_user = isset($f_user) ? $f_user : $user;
4466 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4467 $deletesource =
true;
4468 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4469 $deletetarget =
true;
4472 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4473 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
4474 $targetid = (!empty($targetid) ? $targetid : $this->id);
4475 $targettype = (!empty($targettype) ? $targettype : $this->element);
4481 $this->context[
'link_id'] = $rowid;
4482 $this->context[
'link_source_id'] = $sourceid;
4483 $this->context[
'link_source_type'] = $sourcetype;
4484 $this->context[
'link_target_id'] = $targetid;
4485 $this->context[
'link_target_type'] = $targettype;
4486 $result = $this->call_trigger(
'OBJECT_LINK_DELETE', $f_user);
4494 $sql =
"DELETE FROM " . $this->db->prefix() .
"element_element";
4497 $sql .=
" rowid = " . ((int) $rowid);
4499 if ($deletesource) {
4500 $sql .=
" fk_source = " . ((int) $sourceid) .
" AND sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4501 $sql .=
" AND fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4502 } elseif ($deletetarget) {
4503 $sql .=
" fk_target = " . ((int) $targetid) .
" AND targettype = '" . $this->db->escape($targettype) .
"'";
4504 $sql .=
" AND fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4506 $sql .=
" (fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"')";
4508 $sql .=
" (fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"')";
4512 dol_syslog(get_class($this) .
"::deleteObjectLinked", LOG_DEBUG);
4513 if (!$this->db->query($sql)) {
4514 $this->error = $this->db->lasterror();
4515 $this->errors[] = $this->error;
4521 $this->db->commit();
4524 $this->db->rollback();
4540 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4543 if (!preg_match(
'/^[_a-zA-Z0-9]+$/', $field_select)) {
4544 dol_syslog(
'Invalid value $field_select for parameter '.$field_select.
' in call to getAllItemsLinkedByObjectID(). Must be a single field name.', LOG_ERR);
4549 $sql =
"SELECT ".$field_select.
" FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4550 $resql = $db->query($sql);
4553 if (!empty($resql)) {
4554 while ($res = $db->fetch_object($resql)) {
4555 $TRes[] = $res->{$field_select};
4572 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4578 $sql =
"SELECT COUNT(*) as nb FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4579 $resql = $db->query($sql);
4582 $res = $db->fetch_object($resql);
4601 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4607 $sql =
"DELETE FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4608 $resql = $db->query($sql);
4610 if (empty($resql)) {
4627 public function setStatut($status, $elementId =
null, $elementType =
'', $trigkey =
'', $fieldstatus =
'fk_statut')
4631 $savElementId = $elementId;
4633 $elementId = (!empty($elementId) ? $elementId : $this->id);
4634 $elementTable = (!empty($elementType) ? $elementType : $this->table_element);
4638 if ($elementTable ==
'facture_rec') {
4639 $fieldstatus =
"suspended";
4641 if ($elementTable ==
'mailing') {
4642 $fieldstatus =
"statut";
4644 if ($elementTable ==
'cronjob') {
4645 $fieldstatus =
"status";
4647 if ($elementTable ==
'user') {
4648 $fieldstatus =
"statut";
4650 if ($elementTable ==
'expensereport') {
4651 $fieldstatus =
"fk_statut";
4653 if ($elementTable ==
'receptiondet_batch') {
4654 $fieldstatus =
"status";
4656 if ($elementTable ==
'prelevement_bons') {
4657 $fieldstatus =
"statut";
4659 if (isset($this->fields) && is_array($this->fields) && array_key_exists(
'status', $this->fields)) {
4660 $fieldstatus =
'status';
4663 $sql =
"UPDATE ".$this->db->prefix().$this->db->sanitize($elementTable);
4664 $sql .=
" SET ".$this->db->sanitize($fieldstatus).
" = ".((int) $status);
4667 if ($status == 1 && in_array($elementTable, array(
'expensereport',
'inventory'))) {
4668 $sql .=
", fk_user_valid = ".((int) $user->id);
4670 if ($status == 1 && in_array($elementTable, array(
'expensereport'))) {
4671 $sql .=
", date_valid = '".$this->db->idate(
dol_now()).
"'";
4673 if ($status == 1 && in_array($elementTable, array(
'inventory'))) {
4674 $sql .=
", date_validation = '".$this->db->idate(
dol_now()).
"'";
4676 $sql .=
" WHERE rowid = ".((int) $elementId);
4677 $sql .=
" AND ".$fieldstatus.
" <> ".((int) $status);
4679 dol_syslog(get_class($this).
"::setStatut", LOG_DEBUG);
4680 $resql = $this->db->query($sql);
4684 $nb_rows_affected = $this->db->affected_rows($resql);
4686 if ($nb_rows_affected > 0) {
4687 if (empty($trigkey)) {
4689 if ($this->element ==
'supplier_proposal' && $status == 2) {
4690 $trigkey =
'SUPPLIER_PROPOSAL_SIGN';
4692 if ($this->element ==
'supplier_proposal' && $status == 3) {
4693 $trigkey =
'SUPPLIER_PROPOSAL_REFUSE';
4695 if ($this->element ==
'supplier_proposal' && $status == 4) {
4696 $trigkey =
'SUPPLIER_PROPOSAL_CLOSE';
4698 if ($this->element ==
'fichinter' && $status == 3) {
4699 $trigkey =
'FICHINTER_CLASSIFY_DONE';
4701 if ($this->element ==
'fichinter' && $status == 2) {
4702 $trigkey =
'FICHINTER_CLASSIFY_BILLED';
4704 if ($this->element ==
'fichinter' && $status == 1) {
4705 $trigkey =
'FICHINTER_CLASSIFY_UNBILLED';
4709 $this->context = array_merge($this->context, array(
'newstatus' => $status));
4713 $result = $this->call_trigger($trigkey, $user);
4724 $this->db->commit();
4726 if (empty($savElementId)) {
4728 if ($fieldstatus ==
'tosell') {
4730 } elseif ($fieldstatus ==
'tobuy') {
4731 $this->status_buy = $status;
4739 $this->db->rollback();
4740 dol_syslog(get_class($this).
"::setStatut ".$this->error, LOG_ERR);
4744 $this->error = $this->db->lasterror();
4745 $this->db->rollback();
4762 if (empty($id) && empty($ref)) {
4772 $sql =
"SELECT rowid, canvas";
4773 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
4774 $sql .=
" WHERE entity IN (".getEntity($this->element).
")";
4776 $sql .=
" AND rowid = ".((int) $id);
4779 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
4782 $resql = $this->db->query($sql);
4784 $obj = $this->db->fetch_object($resql);
4786 $this->canvas = $obj->canvas;
4806 $sql =
"SELECT special_code FROM ".$this->db->prefix().$this->table_element_line;
4807 $sql .=
" WHERE rowid = ".((int) $lineid);
4808 $resql = $this->db->query($sql);
4810 $row = $this->db->fetch_row($resql);
4811 return (!empty($row[0]) ? $row[0] : 0);
4834 if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
4835 dol_print_error(
null,
'Called isObjectUsed on a class with property this->childtables not defined');
4839 $arraytoscan = $this->childtables;
4841 $tmparray = array_keys($this->childtables);
4842 if (is_numeric($tmparray[0])) {
4843 $arraytoscan = array_flip($this->childtables);
4848 foreach ($arraytoscan as $table => $element) {
4852 if (isset($element[
'enabled']) && !empty($element[
'enabled'])) {
4853 $enabled = (int)
dol_eval($element[
'enabled'], 1);
4854 if (empty($enabled)) {
4860 $sql =
"SELECT COUNT(*) as nb";
4861 $sql .=
" FROM ".$this->db->prefix().$table.
" as c";
4862 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4863 $sql .=
", ".$this->db->prefix().$element[
'parent'].
" as p";
4865 if (!empty($element[
'fk_element'])) {
4866 $sql .=
" WHERE c.".$element[
'fk_element'].
" = ".((int) $id);
4868 $sql .=
" WHERE c.".$this->fk_element.
" = ".((int) $id);
4870 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4871 $sql .=
" AND c.".$element[
'parentkey'].
" = p.rowid";
4873 if (!empty($element[
'parent']) && !empty($element[
'parenttypefield']) && !empty($element[
'parenttypevalue'])) {
4874 $sql .=
" AND c.".$element[
'parenttypefield'].
" = '".$this->db->escape($element[
'parenttypevalue']).
"'";
4876 if (!empty($entity)) {
4877 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4878 $sql .=
" AND p.entity = ".((int) $entity);
4880 $sql .=
" AND c.entity = ".((int) $entity);
4884 $resql = $this->db->query($sql);
4886 $obj = $this->db->fetch_object($resql);
4888 $langs->load(
"errors");
4890 $haschild += $obj->nb;
4891 if (is_numeric($element)) {
4892 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
4893 } elseif (is_string($element)) {
4894 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element));
4896 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element[
'name']));
4901 $this->errors[] = $this->db->lasterror();
4905 if ($haschild > 0) {
4906 $this->errors[] =
"ErrorRecordHasChildren";
4923 foreach ($this->lines as $key => $val) {
4925 if ($predefined == -1) {
4928 if ($predefined == 1 && $val->fk_product > 0) {
4931 if ($predefined == 0 && $val->fk_product <= 0) {
4934 if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
4937 if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
4944 dol_syslog(get_class($this).
'::hasProductsOrServices we found '.$nb.
' qualified lines of products/servcies');
4955 if (!empty($this->table_element_line)) {
4956 $total_discount = 0.00;
4958 $sql =
"SELECT subprice as pu_ht, qty, remise_percent, total_ht";
4959 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
4960 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
4962 dol_syslog(get_class($this).
'::getTotalDiscount', LOG_DEBUG);
4963 $resql = $this->db->query($sql);
4965 $num = $this->db->num_rows($resql);
4968 $obj = $this->db->fetch_object($resql);
4970 $pu_ht = $obj->pu_ht;
4972 $total_ht = $obj->total_ht;
4974 $total_discount_line = (float)
price2num(($pu_ht * $qty) - $total_ht,
'MT');
4975 $total_discount += $total_discount_line;
4982 return (
float)
price2num($total_discount);
5004 if (empty($this->lines)) {
5005 return array(
'weight' => $totalWeight,
'volume' => $totalVolume,
'ordered' => $totalOrdered,
'toship' => $totalToShip);
5008 foreach ($this->lines as $line) {
5009 if (isset($line->qty_asked)) {
5010 $totalOrdered += $line->qty_asked;
5012 if (isset($line->qty_shipped)) {
5013 $totalToShip += $line->qty_shipped;
5014 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
5015 if (empty($totalToShip)) {
5018 $totalToShip += $line->qty;
5022 if ($this->element ==
'shipping') {
5024 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
5026 $qty = $line->qty ? $line->qty : 0;
5029 $weight = !empty($line->weight) ? $line->weight : 0;
5030 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
5031 $volume = !empty($line->volume) ? $line->volume : 0;
5032 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
5034 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
5035 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
5036 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
5037 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
5041 if (!empty($weight_units)) {
5042 $weightUnit = $weight_units;
5044 if (!empty($volume_units)) {
5045 $volumeUnit = $volume_units;
5048 if (empty($totalWeight)) {
5051 if (empty($totalVolume)) {
5056 if ($weight_units < 50) {
5057 $trueWeightUnit = pow(10, $weightUnit);
5058 $totalWeight += $weight * $qty * $trueWeightUnit;
5060 if ($weight_units == 99) {
5062 $trueWeightUnit = 0.45359237;
5063 $totalWeight += $weight * $qty * $trueWeightUnit;
5064 } elseif ($weight_units == 98) {
5066 $trueWeightUnit = 0.0283495;
5067 $totalWeight += $weight * $qty * $trueWeightUnit;
5069 $totalWeight += $weight * $qty;
5072 if ($volume_units < 50) {
5074 $trueVolumeUnit = pow(10, $volumeUnit);
5076 $totalVolume += $volume * $qty * $trueVolumeUnit;
5078 $totalVolume += $volume * $qty;
5082 return array(
'weight' => $totalWeight,
'volume' => $totalVolume,
'ordered' => $totalOrdered,
'toship' => $totalToShip);
5095 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
5097 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
5098 $sql .=
" SET extraparams = ".(!empty($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null");
5099 $sql .=
" WHERE rowid = ".((int) $this->
id);
5101 dol_syslog(get_class($this).
"::setExtraParameters", LOG_DEBUG);
5102 $resql = $this->db->query($sql);
5104 $this->error = $this->db->lasterror();
5105 $this->db->rollback();
5108 $this->db->commit();
5131 global $conf, $user, $langs,
$object, $hookmanager, $extrafields, $form;
5134 if (!is_object($extrafields)) {
5135 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5138 $extrafields->fetch_name_optionals_label($this->table_element_line);
5143 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5144 foreach ($dirtpls as $module => $reldir) {
5145 if (!empty($module)) {
5148 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_create.tpl.php';
5151 if (empty($conf->file->strict_mode)) {
5152 $res = @include $tpl;
5154 $res = include $tpl;
5181 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
5183 global $conf, $hookmanager, $langs, $user, $form, $extrafields,
$object;
5185 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
5189 if (isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
5193 $num = count($this->lines);
5196 if (!is_object($extrafields)) {
5197 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5200 $extrafields->fetch_name_optionals_label($this->table_element_line);
5202 $parameters = array(
'num' => $num,
'dateSelector' => $dateSelector,
'seller' => $seller,
'buyer' => $buyer,
'selected' => $selected,
'table_element_line' => $this->table_element_line);
5203 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
5204 if (empty($reshook)) {
5208 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5209 foreach ($dirtpls as $module => $reldir) {
5211 if (!empty($module)) {
5214 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
5216 if (file_exists($tpl)) {
5217 if (empty($conf->file->strict_mode)) {
5218 $res = @include $tpl;
5220 $res = include $tpl;
5231 print
"<!-- begin printObjectLines() --><tbody>\n";
5232 foreach ($this->lines as $line) {
5234 $line->fetch_optionals();
5237 if (is_object($hookmanager)) {
5238 if (empty($line->fk_parent_line)) {
5239 $parameters = array(
'line' => $line,
'num' => $num,
'i' => $i,
'dateSelector' => $dateSelector,
'seller' => $seller,
'buyer' => $buyer,
'selected' => $selected,
'table_element_line' => $line->table_element,
'defaulttpldir' => $defaulttpldir);
5240 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
5242 $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);
5243 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
5246 if (empty($reshook)) {
5247 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
5252 print
"</tbody><!-- end printObjectLines() -->\n";
5272 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
5274 global $conf, $langs, $user,
$object, $hookmanager;
5276 global $object_rights, $disableedit, $disablemove, $disableremove;
5278 $object_rights = $this->getRights();
5285 if ($action !=
'editline' || $selected != $line->id) {
5287 if (!empty($line->fk_product) && $line->fk_product > 0) {
5288 $product_static =
new Product($this->db);
5289 $product_static->fetch($line->fk_product);
5291 $product_static->ref = $line->ref;
5292 $product_static->label = !empty($line->label) ? $line->label :
"";
5294 $text = $product_static->getNomUrl(1);
5298 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
5299 dol_print_error(
null,
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
5303 $prod =
new Product($this->db);
5304 $prod->fetch($line->fk_product);
5306 $outputlangs = $langs;
5308 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
5309 $newlang =
GETPOST(
'lang_id',
'aZ09');
5311 if (
getDolGlobalString(
'PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE') && empty($newlang) && is_object($this->thirdparty)) {
5312 $newlang = $this->thirdparty->default_lang;
5314 if (!empty($newlang)) {
5315 $outputlangs =
new Translate(
"", $conf);
5316 $outputlangs->setDefaultLang($newlang);
5319 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5321 $label = $line->product_label;
5324 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5325 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5328 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5333 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5334 foreach ($dirtpls as $module => $reldir) {
5336 if (!empty($module)) {
5339 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5342 if (file_exists($tpl)) {
5343 if (empty($conf->file->strict_mode)) {
5344 $res = @include $tpl;
5346 $res = include $tpl;
5356 if ($this->
status == 0 && $action ==
'editline' && $selected == $line->id) {
5357 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5359 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5364 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5365 foreach ($dirtpls as $module => $reldir) {
5366 if (!empty($module)) {
5369 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5372 if (empty($conf->file->strict_mode)) {
5373 $res = @include $tpl;
5375 $res = include $tpl;
5400 global $langs, $hookmanager, $form, $action;
5402 print
'<tr class="liste_titre">';
5403 print
'<td class="linecolref">'.$langs->trans(
'Ref').
'</td>';
5404 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
5405 print
'<td class="linecolvat right">'.$langs->trans(
'VATRate').
'</td>';
5406 print
'<td class="linecoluht right">'.$langs->trans(
'PriceUHT').
'</td>';
5407 if (isModEnabled(
"multicurrency")) {
5408 print
'<td class="linecoluht_currency right">'.$langs->trans(
'PriceUHTCurrency').
'</td>';
5410 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
5412 print
'<td class="linecoluseunit left">'.$langs->trans(
'Unit').
'</td>';
5414 print
'<td class="linecoldiscount right">'.$langs->trans(
'ReductionShort').
'</td>';
5415 print
'<td class="linecolht right">'.$langs->trans(
'TotalHT').
'</td>';
5416 print
'<td class="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
5420 if (!empty($this->lines)) {
5421 foreach ($this->lines as $line) {
5424 if (is_object($hookmanager)) {
5425 $parameters = array(
'line' => $line,
'i' => $i,
'restrictlist' => $restrictlist,
'selectedLines' => $selectedLines);
5426 if (!empty($line->fk_parent_line)) {
5427 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
5429 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
5431 if (empty($reshook)) {
5432 $this->printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
5453 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5455 global $langs, $conf;
5458 if (!empty($line->date_start)) {
5459 $date_start = $line->date_start;
5461 $date_start = $line->date_debut_prevue;
5462 if ($line->date_debut_reel) {
5463 $date_start = $line->date_debut_reel;
5466 if (!empty($line->date_end)) {
5467 $date_end = $line->date_end;
5469 $date_end = $line->date_fin_prevue;
5470 if ($line->date_fin_reel) {
5471 $date_end = $line->date_fin_reel;
5475 $this->tpl[
'id'] = $line->id;
5477 $this->tpl[
'label'] =
'';
5478 if (!empty($line->fk_parent_line)) {
5479 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5482 if (($line->info_bits & 2) == 2) {
5484 if (property_exists($this,
'socid')) {
5485 $discount->fk_soc = $this->socid;
5486 $discount->socid = $this->socid;
5488 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5489 } elseif (!empty($line->fk_product)) {
5490 $productstatic =
new Product($this->db);
5491 $productstatic->id = $line->fk_product;
5492 $productstatic->ref = $line->ref;
5493 $productstatic->type = $line->fk_product_type;
5494 if (empty($productstatic->ref)) {
5495 $line->fetch_product();
5496 $productstatic = $line->product;
5499 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
5500 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5502 if ($line->product_type == 1 && ($date_start || $date_end)) {
5506 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
''),
'service') :
img_object($langs->trans(
''),
'product')));
5507 if (!empty($line->desc)) {
5508 $this->tpl[
'label'] .= $line->desc;
5510 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5514 if ($line->product_type == 1 && ($date_start || $date_end)) {
5519 if (!empty($line->desc)) {
5520 if ($line->desc ==
'(CREDIT_NOTE)') {
5522 $discount->fetch($line->fk_remise_except);
5523 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5524 } elseif ($line->desc ==
'(DEPOSIT)') {
5526 $discount->fetch($line->fk_remise_except);
5527 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5528 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5530 $discount->fetch($line->fk_remise_except);
5531 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5532 } elseif ($line->desc ==
'(EXCESS PAID)') {
5534 $discount->fetch($line->fk_remise_except);
5535 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5537 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5540 $this->tpl[
'description'] =
' ';
5544 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5545 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5546 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5547 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5550 $this->tpl[
'price'] =
price($line->subprice);
5551 $this->tpl[
'total_ht'] =
price($line->total_ht);
5552 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5553 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5555 $this->tpl[
'unit'] = $langs->transnoentities($line->getLabelOfUnit(
'long'));
5557 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate($line->remise_percent,
true) :
' ';
5560 $this->tpl[
'strike'] = 0;
5562 $this->tpl[
'strike'] = 1;
5567 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5568 foreach ($dirtpls as $module => $reldir) {
5569 if (!empty($module)) {
5572 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5575 if (empty($conf->file->strict_mode)) {
5576 $res = @include $tpl;
5578 $res = include $tpl;
5603 $sql =
"INSERT INTO ".$this->db->prefix().
"element_resources (";
5604 $sql .=
"resource_id";
5605 $sql .=
", resource_type";
5606 $sql .=
", element_id";
5607 $sql .=
", element_type";
5609 $sql .=
", mandatory";
5610 $sql .=
") VALUES (";
5611 $sql .= ((int) $resource_id);
5612 $sql .=
", '".$this->db->escape($resource_type).
"'";
5613 $sql .=
", '".$this->db->escape($this->
id).
"'";
5614 $sql .=
", '".$this->db->escape($this->element).
"'";
5615 $sql .=
", '".$this->db->escape($busy).
"'";
5616 $sql .=
", '".$this->db->escape($mandatory).
"'";
5619 dol_syslog(get_class($this).
"::add_element_resource", LOG_DEBUG);
5620 if ($this->db->query($sql)) {
5621 $this->db->commit();
5624 $this->error = $this->db->lasterror();
5625 $this->db->rollback();
5646 $sql =
"DELETE FROM ".$this->db->prefix().
"element_resources";
5647 $sql .=
" WHERE rowid = ".((int) $rowid);
5649 dol_syslog(get_class($this).
"::delete_resource", LOG_DEBUG);
5651 $resql = $this->db->query($sql);
5653 $this->error = $this->db->lasterror();
5654 $this->db->rollback();
5658 $result = $this->call_trigger(strtoupper($element).
'_DELETE_RESOURCE', $user);
5660 $this->db->rollback();
5664 $this->db->commit();
5678 if (isset($this->lines) && is_array($this->lines)) {
5679 $nboflines = count($this->lines);
5680 for ($i = 0; $i < $nboflines; $i++) {
5681 if (is_object($this->lines[$i])) {
5682 $this->lines[$i] = clone $this->lines[$i];
5701 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5703 global $conf, $langs, $user, $hookmanager, $action;
5705 $srctemplatepath =
'';
5707 $parameters = array(
'modelspath' => $modelspath,
'modele' => $modele,
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails,
'hidedesc' => $hidedesc,
'hideref' => $hideref,
'moreparams' => $moreparams);
5708 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5710 if (!empty($reshook)) {
5714 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5716 if (empty($modele)) {
5717 $this->error =
'BadValueForParameterModele';
5722 $err = error_reporting();
5724 @set_time_limit(120);
5725 error_reporting($err);
5728 $tmp = explode(
':', $modele, 2);
5729 $saved_model = $modele;
5730 if (!empty($tmp[1])) {
5732 $srctemplatepath = $tmp[1];
5739 $dirmodels = array(
'/');
5740 if (is_array($conf->modules_parts[
'models'])) {
5741 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
5743 foreach ($dirmodels as $reldir) {
5744 foreach (array(
'doc',
'pdf') as $prefix) {
5745 if (in_array(get_class($this), array(
'Adherent'))) {
5747 $file = $prefix.
"_".$modele.
".class.php";
5750 $file = $prefix.
"_".$modele.
".modules.php";
5757 if (file_exists($file)) {
5759 $classname = $prefix.
'_'.$modele;
5768 if ($filefound ===
'' || $classname ===
'') {
5769 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5770 $this->errors[] = $this->error;
5781 require_once $filefound;
5783 $obj =
new $classname($this->db);
5786 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5787 $varfortemplatedir = $obj->scandir;
5791 $listoffiles = array();
5794 $listofdir = explode(
',', $dirtoscan);
5795 foreach ($listofdir as $key => $tmpdir) {
5796 $tmpdir = trim($tmpdir);
5797 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5799 unset($listofdir[$key]);
5802 if (is_dir($tmpdir)) {
5803 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
5804 if (count($tmpfiles)) {
5805 $listoffiles = array_merge($listoffiles, $tmpfiles);
5810 if (count($listoffiles)) {
5811 foreach ($listoffiles as $record) {
5812 $srctemplatepath = $record[
'fullname'];
5818 if (empty($srctemplatepath)) {
5819 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
5824 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
5826 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
5827 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
5834 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
5837 $this->model_pdf = $saved_model;
5839 if (in_array(get_class($this), array(
'Adherent'))) {
5840 '@phan-var-force Adherent $this';
5841 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards', $moreparams);
5843 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
5847 if ($resultwritefile > 0) {
5848 $outputlangs->charset_output = $sav_charset_output;
5851 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5855 if (!empty($obj->result[
'fullpath'])) {
5856 $destfull = $obj->result[
'fullpath'];
5859 $update_main_doc_field = 0;
5860 if (!empty($obj->update_main_doc_field)) {
5861 $update_main_doc_field = 1;
5867 $this->indexFile($destfull, $update_main_doc_field);
5870 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);
5878 $outputlangs->charset_output = $sav_charset_output;
5879 $this->error = $obj->error;
5880 $this->errors = $obj->errors;
5881 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
5895 public function indexFile($destfull, $update_main_doc_field)
5897 global $conf, $user;
5899 $upload_dir = dirname($destfull);
5900 $destfile = basename($destfull);
5901 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
5903 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5904 $filename = basename($destfile);
5905 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
5906 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
5908 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
5909 $ecmfile =
new EcmFiles($this->db);
5910 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
5913 $setsharekey =
false;
5914 if ($this->element ==
'propal' || $this->element ==
'proposal') {
5916 $setsharekey =
true;
5919 $setsharekey =
true;
5922 if ($this->element ==
'commande' &&
getDolGlobalInt(
"ORDER_ALLOW_EXTERNAL_DOWNLOAD")) {
5923 $setsharekey =
true;
5925 if ($this->element ==
'facture' &&
getDolGlobalInt(
"INVOICE_ALLOW_EXTERNAL_DOWNLOAD")) {
5926 $setsharekey =
true;
5928 if ($this->element ==
'bank_account' &&
getDolGlobalInt(
"BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD")) {
5929 $setsharekey =
true;
5931 if ($this->element ==
'product' &&
getDolGlobalInt(
"PRODUCT_ALLOW_EXTERNAL_DOWNLOAD")) {
5932 $setsharekey =
true;
5934 if ($this->element ==
'contrat' &&
getDolGlobalInt(
"CONTRACT_ALLOW_EXTERNAL_DOWNLOAD")) {
5935 $setsharekey =
true;
5937 if ($this->element ==
'fichinter' &&
getDolGlobalInt(
"FICHINTER_ALLOW_EXTERNAL_DOWNLOAD")) {
5938 $setsharekey =
true;
5940 if ($this->element ==
'supplier_proposal' &&
getDolGlobalInt(
"SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD")) {
5941 $setsharekey =
true;
5943 if ($this->element ==
'societe_rib' &&
getDolGlobalInt(
"SOCIETE_RIB_ALLOW_ONLINESIGN")) {
5944 $setsharekey =
true;
5948 if (empty($ecmfile->share)) {
5949 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5956 $ecmfile->fullpath_orig =
'';
5957 $ecmfile->gen_or_uploaded =
'generated';
5958 $ecmfile->description =
'';
5959 $ecmfile->keywords =
'';
5960 $result = $ecmfile->update($user);
5966 $ecmfile->entity = $conf->entity;
5967 $ecmfile->filepath = $rel_dir;
5968 $ecmfile->filename = $filename;
5970 $ecmfile->fullpath_orig =
'';
5971 $ecmfile->gen_or_uploaded =
'generated';
5972 $ecmfile->description =
'';
5973 $ecmfile->keywords =
'';
5974 $ecmfile->src_object_type = $this->table_element;
5975 $ecmfile->src_object_id = $this->id;
5977 $result = $ecmfile->create($user);
5989 if ($update_main_doc_field && !empty($this->table_element)) {
5990 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
5991 $sql .=
" WHERE rowid = ".((int) $this->
id);
5993 $resql = $this->db->query($sql);
5998 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
6017 if (file_exists($file_osencoded)) {
6018 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
6021 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
6022 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
6023 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
6024 $maxheightmini = $tmparraysize[
'maxheightmini'];
6030 vignette($file_osencoded, $maxwidthsmall, $maxheightsmall,
'_small', $quality);
6034 vignette($file_osencoded, $maxwidthmini, $maxheightmini,
'_mini', $quality);
6074 if (GETPOSTISSET($fieldname)) {
6075 return GETPOST($fieldname, $type, 3);
6078 if (isset($alternatevalue)) {
6079 return $alternatevalue;
6082 $newelement = $this->element;
6083 if ($newelement ==
'facture') {
6084 $newelement =
'invoice';
6086 if ($newelement ==
'commande') {
6087 $newelement =
'order';
6089 if (empty($newelement)) {
6090 dol_syslog(
"Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
6094 $keyforfieldname = strtoupper($newelement.
'_DEFAULT_'.$fieldname);
6124 global $langs, $conf;
6126 if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX .
'_') !== 0) {
6127 dol_print_error(
null,
'The trigger "' . $triggerName .
'" does not start with "' . self::TRIGGER_PREFIX .
'_" as required.');
6130 if (!is_object($langs)) {
6131 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
6135 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
6137 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
6140 if (!empty($this->errors)) {
6141 $this->errors = array_unique(array_merge($this->errors, $interface->errors));
6143 $this->errors = $interface->errors;
6163 if (!$this->element) {
6166 if (!($this->
id > 0)) {
6169 if (is_array($this->array_languages)) {
6173 $this->array_languages = array();
6175 $element = $this->element;
6176 if ($element ==
'categorie') {
6177 $element =
'categories';
6181 $sql =
"SELECT rowid, property, lang , value";
6182 $sql .=
" FROM ".$this->db->prefix().
"object_lang";
6183 $sql .=
" WHERE type_object = '".$this->db->escape($element).
"'";
6184 $sql .=
" AND fk_object = ".((int) $this->
id);
6187 $resql = $this->db->query($sql);
6189 $numrows = $this->db->num_rows($resql);
6192 while ($i < $numrows) {
6193 $obj = $this->db->fetch_object($resql);
6194 $key = $obj->property;
6195 $value = $obj->value;
6196 $codelang = $obj->lang;
6197 $type = $this->fields[$key][
'type'];
6200 if (preg_match(
'/date/', $type)) {
6201 $this->array_languages[$key][$codelang] = $this->db->jdate($value);
6203 $this->array_languages[$key][$codelang] = $value;
6210 $this->db->free($resql);
6232 foreach ($_POST as $postfieldkey => $postfieldvalue) {
6233 $tmparray = explode(
'-', $postfieldkey);
6234 if ($tmparray[0] !=
'field') {
6238 $element = $tmparray[1];
6239 $key = $tmparray[2];
6240 $codelang = $tmparray[3];
6243 if (!empty($onlykey) && $key != $onlykey) {
6246 if ($element != $this->element) {
6250 $key_type = $this->fields[$key][
'type'];
6253 if (isset($this->fields[$key][
'enabled'])) {
6254 $enabled = (int)
dol_eval($this->fields[$key][
'enabled'], 1, 1,
'1');
6261 if (empty($enabled)) {
6266 if (in_array($key_type, array(
'date'))) {
6270 } elseif (in_array($key_type, array(
'datetime'))) {
6274 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
6275 $value_arr =
GETPOST($postfieldkey,
'array');
6276 if (!empty($value_arr)) {
6277 $value_key = implode(
',', $value_arr);
6281 } elseif (in_array($key_type, array(
'price',
'double'))) {
6282 $value_arr =
GETPOST($postfieldkey,
'alpha');
6285 $value_key =
GETPOST($postfieldkey);
6286 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
6291 $this->array_languages[$key][$codelang] = $value_key;
6316 $savDisableCompute = $conf->disable_compute;
6317 $conf->disable_compute = 1;
6319 $ret = $this->fetch($id);
6321 $conf->disable_compute = $savDisableCompute;
6339 global $conf, $extrafields;
6341 if (empty($rowid)) {
6344 if (empty($rowid) && isset($this->
rowid)) {
6345 $rowid = $this->rowid;
6349 if (!$this->table_element) {
6353 $this->array_options = array();
6355 if (!is_array($optionsArray)) {
6357 if (!isset($extrafields) || !is_object($extrafields)) {
6358 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6363 if (empty($extrafields->attributes[$this->table_element][
'loaded'])) {
6364 $extrafields->fetch_name_optionals_label($this->table_element);
6366 $optionsArray = (!empty($extrafields->attributes[$this->table_element][
'label']) ? $extrafields->attributes[$this->table_element][
'label'] :
null);
6368 global $extrafields;
6369 dol_syslog(
"Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
6372 $table_element = $this->table_element;
6373 if ($table_element ==
'categorie') {
6374 $table_element =
'categories';
6378 if (is_array($optionsArray) && count($optionsArray) > 0) {
6379 $sql =
"SELECT rowid";
6380 foreach ($optionsArray as $name => $label) {
6381 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || (!in_array($extrafields->attributes[$this->table_element][
'type'][$name], [
'separate',
'point',
'multipts',
'linestrg',
'polygon']))) {
6385 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] ==
'point') {
6386 $sql .=
", ST_AsWKT(".$name.
") as ".$name;
6388 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] ==
'multipts') {
6389 $sql .=
", ST_AsWKT(".$name.
") as ".$name;
6391 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] ==
'linestrg') {
6392 $sql .=
", ST_AsWKT(".$name.
") as ".$name;
6394 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] ==
'polygon') {
6395 $sql .=
", ST_AsWKT(".$name.
") as ".$name;
6398 $sql .=
" FROM ".$this->db->prefix().$table_element.
"_extrafields";
6399 $sql .=
" WHERE fk_object = ".((int) $rowid);
6402 $resql = $this->db->query($sql);
6404 $numrows = $this->db->num_rows($resql);
6406 $tab = $this->db->fetch_array($resql);
6408 foreach ($tab as $key => $value) {
6410 if ($key !=
'rowid' && $key !=
'tms' && $key !=
'fk_member' && !is_int($key)) {
6412 if (!empty($extrafields->attributes[$this->table_element]) && in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date',
'datetime'))) {
6414 $this->array_options[
"options_".$key] = $this->db->jdate($value);
6416 $this->array_options[
"options_".$key] = $value;
6421 if (!empty($extrafields->attributes[$this->table_element][
'type'][$key]) && $extrafields->attributes[$this->table_element][
'type'][$key] ==
'password') {
6422 if (!empty($value) && preg_match(
'/^dolcrypt:/', $value)) {
6423 $this->array_options[
"options_".$key] =
dolDecrypt($value);
6432 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6433 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6434 $this->array_options[
'options_' . $key] =
null;
6441 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6442 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6443 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'computed'][$key])) {
6445 if (empty($conf->disable_compute)) {
6446 global $objectoffield;
6447 $objectoffield = $this;
6448 $this->array_options[
'options_' . $key] =
dol_eval($extrafields->attributes[$this->table_element][
'computed'][$key], 1, 0,
'2');
6454 $this->db->free($resql);
6462 $this->errors[] = $this->db->lasterror;
6485 $table_element = $this->table_element;
6486 if ($table_element ==
'categorie') {
6487 $table_element =
'categories';
6490 dol_syslog(get_class($this).
"::deleteExtraFields delete", LOG_DEBUG);
6492 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6494 $resql = $this->db->query($sql_del);
6496 $this->error = $this->db->lasterror();
6497 $this->db->rollback();
6500 $this->db->commit();
6517 global $conf, $langs, $user;
6523 if (empty($userused)) {
6529 if (!empty($this->array_options)) {
6531 $langs->load(
'admin');
6532 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6534 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6537 $new_array_options = array();
6538 foreach ($this->array_options as $key => $value) {
6539 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6540 $new_array_options[$key] = $value;
6541 } elseif (in_array($key, array_keys($target_extrafields))) {
6542 $new_array_options[
'options_'.$key] = $value;
6546 foreach ($new_array_options as $key => $value) {
6547 $attributeKey = substr($key, 8);
6548 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6549 $attributeLabel = $langs->transnoentities($extrafields->attributes[$this->table_element][
'label'][$attributeKey]);
6550 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6551 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6552 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6553 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6557 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6558 $new_array_options[$key] =
null;
6562 if ($attributeRequired) {
6563 $v = $this->array_options[$key];
6565 $langs->load(
"errors");
6566 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6567 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6575 if (!empty($attrfieldcomputed)) {
6577 $value =
dol_eval($attrfieldcomputed, 1, 0,
'2');
6578 dol_syslog($langs->trans(
"Extrafieldcomputed").
" on ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6579 $new_array_options[$key] = $value;
6581 $new_array_options[$key] =
null;
6585 switch ($attributeType) {
6587 if (!is_numeric($value) && $value !=
'') {
6588 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6590 } elseif ($value ==
'') {
6591 $new_array_options[$key] =
null;
6597 if (!is_numeric($value) && $value !=
'') {
6598 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6599 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6601 } elseif ($value ==
'') {
6605 $new_array_options[$key] = $value;
6615 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6617 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6618 $algo = reset($tmparrays);
6623 if (is_object($this->oldcopy)) {
6625 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6627 if ($algo ==
'dolcrypt') {
6628 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6629 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6631 $new_array_options[$key] = $this->array_options[$key];
6634 $new_array_options[$key] = $this->array_options[$key];
6638 if ($algo ==
'dolcrypt') {
6639 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6640 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6642 $new_array_options[$key] = $this->array_options[$key];
6645 $new_array_options[$key] =
dol_hash($this->array_options[$key], $algo);
6651 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6652 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6654 $new_array_options[$key] = $this->array_options[$key];
6659 $new_array_options[$key] = $this->array_options[$key];
6662 $new_array_options[$key] = $this->array_options[$key];
6668 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6669 $this->array_options[$key] = strtotime($this->array_options[$key]);
6671 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6675 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6676 $this->array_options[$key] = strtotime($this->array_options[$key]);
6678 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6681 $param_list = array_keys($attributeParam[
'options']);
6684 $InfoFieldList = explode(
":", $param_list[0]);
6686 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6687 if ($value ==
'-1') {
6688 $new_array_options[$key] =
'';
6690 $object =
new $InfoFieldList[0]($this->db);
6691 if (is_numeric($value)) {
6692 $res =
$object->fetch($value);
6694 $res =
$object->fetch(
'', $value);
6698 $new_array_options[$key] =
$object->id;
6700 $this->error =
"Id/Ref '".$value.
"' for object '".
$object->element.
"' not found";
6705 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6710 if (is_array($this->array_options[$key])) {
6711 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6713 $new_array_options[$key] = $this->array_options[$key];
6721 $table_element = $this->table_element;
6722 if ($table_element ==
'categorie') {
6723 $table_element =
'categories';
6726 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
6728 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6729 $this->db->query($sql_del);
6731 $sql =
"INSERT INTO ".$this->db->prefix().$table_element.
"_extrafields (fk_object";
6732 foreach ($new_array_options as $key => $value) {
6733 $attributeKey = substr($key, 8);
6735 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6736 $sql .=
",".$attributeKey;
6740 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6741 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6742 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6743 $sql .=
",".$tmpkey;
6747 $sql .=
") VALUES (".$this->id;
6749 foreach ($new_array_options as $key => $value) {
6750 $attributeKey = substr($key, 8);
6752 if (!in_array($extrafields->attributes[$this->table_element][
'type'][$attributeKey], [
'separate',
'point',
'multipts',
'linestrg',
'polygon'])) {
6753 if ($new_array_options[$key] !=
'' || $new_array_options[$key] ==
'0') {
6754 $sql .=
",'".$this->db->escape($new_array_options[$key]).
"'";
6759 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] ==
'point') {
6760 if (!empty($new_array_options[$key])) {
6761 $sql .=
",ST_PointFromText('".$this->db->escape($new_array_options[$key]).
"')";
6766 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] ==
'multipts') {
6767 if (!empty($new_array_options[$key])) {
6768 $sql .=
",ST_MultiPointFromText('".$this->db->escape($new_array_options[$key]).
"')";
6773 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] ==
'linestrg') {
6774 if (!empty($new_array_options[$key])) {
6775 $sql .=
",ST_LineFromText('".$this->db->escape($new_array_options[$key]).
"')";
6780 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] ==
'polygon') {
6781 if (!empty($new_array_options[$key])) {
6782 $sql .=
",ST_PolyFromText('".$this->db->escape($new_array_options[$key]).
"')";
6789 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6790 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6791 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6792 if (in_array($tmpval, array(
'int',
'double',
'price'))) {
6803 $resql = $this->db->query($sql);
6805 $this->error = $this->db->lasterror();
6809 if (!$error && $trigger) {
6811 $this->context = array(
'extrafieldaddupdate' => 1);
6812 $result = $this->call_trigger($trigger, $userused);
6820 $this->db->rollback();
6823 $this->db->commit();
6843 global $conf, $langs, $user;
6845 if (empty($userused)) {
6855 if (is_array($this->array_languages)) {
6856 $new_array_languages = $this->array_languages;
6858 foreach ($new_array_languages as $key => $value) {
6859 $attributeKey = $key;
6860 $attributeType = $this->fields[$attributeKey][
'type'];
6861 $attributeLabel = $this->fields[$attributeKey][
'label'];
6866 switch ($attributeType) {
6868 if (is_array($value) || (!is_numeric($value) && $value !=
'')) {
6869 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6871 } elseif ($value ==
'') {
6872 $new_array_languages[$key] =
null;
6877 if (!is_numeric($value) && $value !=
'') {
6878 dol_syslog($langs->trans(
"ExtraLanguageHasWrongValue").
" on ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6879 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6881 } elseif ($value ==
'') {
6882 $new_array_languages[$key] =
null;
6884 $new_array_languages[$key] = $value;
6898 $table_element = $this->table_element;
6899 if ($table_element ==
'categorie') {
6900 $table_element =
'categories';
6903 dol_syslog(get_class($this).
"::insertExtraLanguages delete then insert", LOG_DEBUG);
6905 foreach ($new_array_languages as $key => $langcodearray) {
6906 foreach ($langcodearray as $langcode => $value) {
6907 $sql_del =
"DELETE FROM ".$this->db->prefix().
"object_lang";
6908 $sql_del .=
" WHERE fk_object = ".((int) $this->
id).
" AND property = '".$this->db->escape($key).
"' AND type_object = '".$this->db->escape($table_element).
"'";
6909 $sql_del .=
" AND lang = '".$this->db->escape($langcode).
"'";
6910 $this->db->query($sql_del);
6912 if ($value !==
'') {
6913 $sql =
"INSERT INTO ".$this->db->prefix().
"object_lang (fk_object, property, type_object, lang, value";
6914 $sql .=
") VALUES (".$this->id.
", '".$this->db->escape($key).
"', '".$this->db->escape($table_element).
"', '".$this->db->escape($langcode).
"', '".$this->db->escape($value).
"'";
6917 $resql = $this->db->query($sql);
6919 $this->error = $this->db->lasterror();
6927 if (!$error && $trigger) {
6929 $this->context = array(
'extralanguagesaddupdate' => 1);
6930 $result = $this->call_trigger($trigger, $userused);
6938 $this->db->rollback();
6941 $this->db->commit();
6961 global $conf, $langs, $user, $hookmanager;
6967 if (empty($userused)) {
6973 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
6975 $langs->load(
'admin');
6976 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6978 $extrafields->fetch_name_optionals_label($this->table_element);
6980 $value = $this->array_options[
"options_".$key];
6982 $attributeKey = $key;
6983 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
6984 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
6985 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
6986 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
6987 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6988 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
6991 if ($attributeRequired) {
6992 $mandatorypb =
false;
6993 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
6994 $mandatorypb =
true;
6996 if ($this->array_options[
"options_".$key] ===
'') {
6997 $mandatorypb =
true;
7000 $langs->load(
"errors");
7001 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
7002 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
7008 $new_array_options = $this->array_options;
7012 if (!empty($attrfieldcomputed)) {
7014 $value =
dol_eval($attrfieldcomputed, 1, 0,
'2');
7015 dol_syslog($langs->trans(
"Extrafieldcomputed").
" on ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
7017 $new_array_options[
"options_".$key] = $value;
7019 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7021 $new_array_options[
"options_".$key] =
null;
7023 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7027 switch ($attributeType) {
7029 if (!is_numeric($value) && $value !=
'') {
7030 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
7032 } elseif ($value ===
'') {
7033 $new_array_options[
"options_".$key] =
null;
7035 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7041 if (!is_numeric($value) && $value !=
'') {
7042 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" on ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
7043 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
7045 } elseif ($value ===
'') {
7049 $new_array_options[
"options_".$key] = $value;
7051 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7063 if ($this->array_options[
"options_".$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
7065 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
7066 $algo = reset($tmparrays);
7072 if (is_object($this->oldcopy)) {
7074 if (isset($this->oldcopy->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] == $this->oldcopy->array_options[
"options_".$key]) {
7075 if ($algo ==
'dolcrypt') {
7076 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7077 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7079 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7082 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7085 if ($algo ==
'dolcrypt') {
7086 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7087 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7089 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7092 $new_array_options[
"options_".$key] =
dol_hash($this->array_options[
"options_".$key], $algo);
7096 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
7097 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
7099 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7104 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7107 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7110 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7114 if (empty($this->array_options[
"options_".$key])) {
7115 $new_array_options[
"options_".$key] =
null;
7117 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7119 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
7123 if (empty($this->array_options[
"options_".$key])) {
7124 $new_array_options[
"options_".$key] =
null;
7126 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7128 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
7132 if (empty($this->array_options[
"options_".$key])) {
7133 $new_array_options[
"options_".$key] =
null;
7135 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7139 if ($this->array_options[
"options_".$key] ===
'') {
7140 $new_array_options[
"options_".$key] =
null;
7142 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7176 $new_array_options = array();
7177 if (is_array($this->array_options[
"options_".$key])) {
7178 $new_array_options[
"options_".$key] = implode(
',', $this->array_options[
"options_".$key]);
7180 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7183 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7189 $linealreadyfound = 0;
7192 $table_element = $this->table_element;
7193 if ($table_element ==
'categorie') {
7194 $table_element =
'categories';
7197 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
7198 $resql = $this->db->query($sql);
7200 $tmpobj = $this->db->fetch_object($resql);
7202 $linealreadyfound = $tmpobj->nb;
7207 if ($linealreadyfound) {
7208 if ($this->array_options[
"options_".$key] ===
null) {
7209 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = null";
7211 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($new_array_options[
"options_".$key]).
"'";
7213 $sql .=
" WHERE fk_object = ".((int) $this->
id);
7215 $resql = $this->db->query($sql);
7218 $this->error = $this->db->lasterror();
7221 $result = $this->insertExtraFields(
'', $user);
7228 $parameters = array(
'key' => $key);
7230 $reshook = $hookmanager->executeHooks(
'updateExtraFieldBeforeCommit', $parameters, $this, $action);
7236 if (!$error && $trigger) {
7238 $this->context = array(
'extrafieldupdate' => 1);
7239 $result = $this->call_trigger($trigger, $userused);
7247 dol_syslog(__METHOD__.$this->error, LOG_ERR);
7248 $this->db->rollback();
7251 $this->db->commit();
7267 return $this->array_options[
'options_'.$key] ??
null;
7279 $this->array_options[
'options_'.$key] = $value;
7294 global $conf, $langs, $user;
7296 if (empty($userused)) {
7325 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
7327 global $conf, $langs, $form;
7329 if (!is_object($form)) {
7330 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
7331 $form =
new Form($this->db);
7334 if (!empty($this->fields)) {
7335 $val = $this->fields[$key];
7339 $fieldValidationErrorMsg =
'';
7340 $validationClass =
'';
7341 $fieldValidationErrorMsg = $this->getFieldError($key);
7342 if (!empty($fieldValidationErrorMsg)) {
7343 $validationClass =
' --error';
7345 $validationClass =
' --success';
7348 $valuemultiselectinput = array();
7353 $param[
'options'] = array();
7356 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
7358 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7359 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7361 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7362 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7364 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
7365 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7367 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7368 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7370 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7371 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7373 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
7374 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7376 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
7377 $param[
'options'] = array($reg[1] =>
'N');
7379 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
7380 $param[
'options'] = array();
7383 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
7384 $param[
'options'] = array();
7387 $param[
'options'] = array();
7388 $type = $this->fields[$key][
'type'];
7393 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
7394 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
7396 if (empty($this->fields[$key][
'multiinput'])) {
7397 $type = (($this->fields[$key][
'type'] ==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
7401 $label = $this->fields[$key][
'label'];
7404 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
7406 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
7408 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
7410 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
7412 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
7415 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
7417 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
7418 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
7420 $objectid = $this->id;
7423 if (!preg_match(
'/^search_/', $keyprefix)) {
7424 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
7431 if (empty($morecss) && !empty($val[
'css'])) {
7432 $morecss = $val[
'css'];
7433 } elseif (empty($morecss)) {
7434 if ($type ==
'date') {
7435 $morecss =
'minwidth100imp';
7436 } elseif ($type ==
'datetime' || $type ==
'link') {
7437 $morecss =
'minwidth200imp';
7438 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', (
string) $type)) {
7439 $morecss =
'maxwidth75';
7440 } elseif ($type ==
'url') {
7441 $morecss =
'minwidth400';
7442 } elseif ($type ==
'boolean') {
7445 if (is_numeric($size) && round((
float) $size) < 12) {
7446 $morecss =
'minwidth100';
7447 } elseif (is_numeric($size) && round((
float) $size) <= 48) {
7448 $morecss =
'minwidth200';
7450 $morecss =
'minwidth400';
7456 if (!empty($validationClass)) {
7457 $morecss .= $validationClass;
7460 if (in_array($type, array(
'date'))) {
7461 $tmp = explode(
',', $size);
7466 if (!$required && $value ==
'') {
7471 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
7472 } elseif (in_array($type, array(
'datetime'))) {
7473 $tmp = explode(
',', $size);
7478 if (!$required && $value ==
'') {
7483 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
7484 } elseif (in_array($type, array(
'duration'))) {
7485 $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
7486 } elseif (in_array($type, array(
'int',
'integer'))) {
7487 $tmp = explode(
',', $size);
7489 $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' :
'').
'>';
7490 } elseif (in_array($type, array(
'real'))) {
7491 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7492 } elseif (preg_match(
'/varchar/', (
string) $type)) {
7493 $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 :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7494 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
7495 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7496 } elseif (preg_match(
'/^text/', (
string) $type)) {
7497 if (!preg_match(
'/search_/', $keyprefix)) {
7498 if (!empty($param[
'options'])) {
7501 $out .= $form->selectarray($keyprefix.$key.$keysuffix.
"_multiinput", $param[
'options'],
'', 1, 0, 0,
"flat maxwidthonphone".$morecss);
7504 function handlemultiinputdisabling(htmlname){
7505 console.log("We handle the disabling of used options for "+htmlname+"_multiinput");
7506 multiinput = $("#"+htmlname+"_multiinput");
7507 multiinput.find("option").each(function(){
7508 tmpval = $("#"+htmlname).val();
7509 tmpvalarray = tmpval.split(",");
7510 valtotest = $(this).val();
7511 if(tmpvalarray.includes(valtotest)){
7512 $(this).prop("disabled",true);
7514 if($(this).prop("disabled") == true){
7515 console.log(valtotest)
7516 $(this).prop("disabled", false);
7522 $(document).ready(function () {
7523 $("#'.$keyprefix.$key.$keysuffix.
'_multiinput").on("change",function() {
7524 console.log("We add the selected value to the text area '.$keyprefix.$key.$keysuffix.
'");
7525 tmpval = $("#'.$keyprefix.$key.$keysuffix.
'").val();
7526 tmpvalarray = tmpval.split(",");
7527 valtotest = $(this).val();
7528 if(valtotest != -1 && !tmpvalarray.includes(valtotest)){
7532 tmpval = tmpval + "," + valtotest;
7534 $("#'.$keyprefix.$key.$keysuffix.
'").val(tmpval);
7535 handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.
'");
7538 $("#'.$keyprefix.$key.$keysuffix.
'").on("change",function(){
7539 handlemultiinputdisabling($(this).attr("id"));
7541 handlemultiinputdisabling("'.$keyprefix.$key.$keysuffix.
'");
7543 $out .=
"</script>";
7545 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7546 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
7547 $out .= (string) $doleditor->Create(1,
'',
true,
'',
'',
'', $morecss);
7549 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7551 } elseif (preg_match(
'/^html/', (
string) $type)) {
7552 if (!preg_match(
'/search_/', $keyprefix)) {
7553 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7554 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') &&
getDolGlobalInt(
'FCKEDITOR_ENABLE_SOCIETE'), ROWS_5,
'90%');
7555 $out = (string) $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
7557 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7559 } elseif ($type ==
'boolean') {
7561 if (!empty($value)) {
7562 $checked =
' checked value="1" ';
7564 $checked =
' value="1" ';
7566 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
7567 } elseif ($type ==
'price') {
7568 if (!empty($value)) {
7569 $value =
price($value);
7571 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
7572 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', (
string) $type)) {
7573 if (!empty($value)) {
7574 $value =
price($value);
7576 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
7577 } elseif ($type ==
'select') {
7579 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
7580 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7581 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7586 foreach ($param[
'options'] as $keyb => $valb) {
7587 if ((
string) $keyb ==
'') {
7590 if (strpos($valb,
"|") !==
false) {
7591 list($valb, $parent) = explode(
'|', $valb);
7594 $tmpselect .=
'<option value="'.$keyb.
'"';
7595 $tmpselect .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
7596 if (!empty($parent)) {
7599 $tmpselect .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7600 $tmpselect .=
'>'.$langs->trans($valb).
'</option>';
7603 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7604 if ((!isset($this->fields[$key][
'default'])) || ($this->fields[$key][
'notnull'] != 1) || $nbchoice >= 2) {
7605 $out .=
'<option value="0"> </option>';
7608 $out .=
'</select>';
7609 } elseif ($type ==
'sellist') {
7611 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
7612 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7613 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7616 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7617 if (is_array($param[
'options'])) {
7618 $tmpparamoptions = array_keys($param[
'options']);
7619 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
7621 $InfoFieldList = explode(
":", $paramoptions[0], 5);
7633 if (! empty($InfoFieldList[4])) {
7635 $parenthesisopen = 0;
7636 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
7637 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
7640 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
7645 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
7646 $tmpafter = substr($InfoFieldList[4], $pos + 1);
7648 $InfoFieldList[4] = $tmpbefore;
7649 if ($tmpafter !==
'') {
7650 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
7656 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
7657 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
7668 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7670 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7671 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7672 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7674 $keyList = $InfoFieldList[2].
' as rowid';
7677 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7678 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7679 $keyList .=
', '.$parentField;
7682 $filter_categorie =
false;
7683 if (count($InfoFieldList) > 5) {
7684 if ($InfoFieldList[0] ==
'categorie') {
7685 $filter_categorie =
true;
7689 if (!$filter_categorie) {
7690 $fields_label = explode(
'|', $InfoFieldList[1]);
7691 if (is_array($fields_label)) {
7693 $keyList .= implode(
', ', $fields_label);
7697 $sql =
"SELECT " . $keyList;
7698 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7700 if (!empty($InfoFieldList[4])) {
7702 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7703 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7707 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7708 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
7710 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7715 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7716 $sql .=
" as main, " . $this->db->sanitize($this->db->prefix() . $InfoFieldList[0]) .
"_extrafields as extra";
7717 $sqlwhere .=
" WHERE extra.fk_object = main." . $this->db->sanitize($InfoFieldList[2]);
7723 $sqlwhere .=
' WHERE 1=1';
7740 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7741 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7747 if (isset($InfoFieldList[7]) && preg_match(
'/^[a-z0-9_\-,]+$/i', $InfoFieldList[7])) {
7748 $sql .=
" ORDER BY ".$this->db->escape($InfoFieldList[7]);
7750 $sql .=
" ORDER BY ".$this->db->sanitize(implode(
', ', $fields_label));
7753 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
7754 $resql = $this->db->query($sql);
7756 $out .=
'<option value="0"> </option>';
7757 $num = $this->db->num_rows($resql);
7761 $obj = $this->db->fetch_object($resql);
7765 $fields_label = explode(
'|', $InfoFieldList[1]);
7766 if (count($fields_label) > 1) {
7768 foreach ($fields_label as $field_toshow) {
7769 $labeltoshow .= $obj->$field_toshow .
' ';
7772 $labeltoshow = $obj->{$InfoFieldList[1]};
7774 $labeltoshow =
dol_trunc($labeltoshow, 45);
7776 if ($value == $obj->rowid) {
7777 foreach ($fields_label as $field_toshow) {
7778 $translabel = $langs->trans($obj->$field_toshow);
7779 if ($translabel != $obj->$field_toshow) {
7780 $labeltoshow =
dol_trunc($translabel) .
' ';
7782 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
7785 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7788 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7789 if ($translabel != $obj->{$InfoFieldList[1]}) {
7790 $labeltoshow =
dol_trunc($translabel, 18);
7792 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
7795 if (empty($labeltoshow)) {
7796 $labeltoshow =
'(not defined)';
7798 if ($value == $obj->rowid) {
7799 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7802 if (!empty($InfoFieldList[3]) && $parentField) {
7803 $parent = $parentName .
':' . $obj->{$parentField};
7807 $out .=
'<option value="' . $obj->rowid .
'"';
7808 $out .= ($value == $obj->rowid ?
' selected' :
'');
7809 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
7810 $out .=
'>' . $labeltoshow .
'</option>';
7815 $this->db->free($resql);
7817 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7820 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7821 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7822 $out .=
'<option value="0"> </option>';
7823 foreach ($data as $data_key => $data_value) {
7824 $out .=
'<option value="' . $data_key .
'"';
7825 $out .= ($value == $data_key ?
' selected' :
'');
7826 $out .=
'>' . $data_value .
'</option>';
7830 $out .=
'</select>';
7831 } elseif ($type ==
'checkbox') {
7832 $value_arr = explode(
',', $value);
7833 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr, 0, 0, $morecss, 0,
'100%');
7834 } elseif ($type ==
'radio') {
7836 foreach ($param[
'options'] as $keyopt => $valopt) {
7837 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
7838 $out .=
' value="'.$keyopt.
'"';
7839 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
7840 $out .= ($value == $keyopt ?
'checked' :
'');
7841 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
7843 } elseif ($type ==
'chkbxlst') {
7844 if (is_array($value)) {
7845 $value_arr = $value;
7847 $value_arr = explode(
',', $value);
7850 if (is_array($param[
'options'])) {
7851 $tmpparamoptions = array_keys($param[
'options']);
7852 $paramoptions = preg_split(
'/[\r\n]+/', $tmpparamoptions[0]);
7854 $InfoFieldList = explode(
":", $paramoptions[0], 5);
7866 if (! empty($InfoFieldList[4])) {
7868 $parenthesisopen = 0;
7869 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
7870 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
7873 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
7878 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
7879 $tmpafter = substr($InfoFieldList[4], $pos + 1);
7881 $InfoFieldList[4] = $tmpbefore;
7882 if ($tmpafter !==
'') {
7883 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
7888 if (preg_match(
'/^\(?([a-z0-9]+)([=<>]+)(\d+)\)?$/i', $InfoFieldList[4], $reg)) {
7889 $InfoFieldList[4] =
'('.$reg[1].
':'.$reg[2].
':'.$reg[3].
')';
7897 '@phan-var-force array{0:string,1:string,2:string,3:string,3:string,5:string,6:string} $InfoFieldList';
7902 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7904 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7905 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7906 $keyList .=
', '.$parentField;
7908 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7909 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7910 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7912 $keyList = $InfoFieldList[2].
' as rowid';
7916 $filter_categorie =
false;
7917 if (count($InfoFieldList) > 5) {
7918 if ($InfoFieldList[0] ==
'categorie') {
7919 $filter_categorie =
true;
7924 if (!$filter_categorie) {
7925 $fields_label = explode(
'|', $InfoFieldList[1]);
7926 if (is_array($fields_label)) {
7928 $keyList .= implode(
', ', $fields_label);
7932 $sql =
"SELECT " . $keyList;
7933 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
7935 if (!empty($InfoFieldList[4])) {
7937 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7938 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7942 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7943 $InfoFieldList[4] = str_replace(
'$ID$', (
string) $objectid, $InfoFieldList[4]);
7945 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7950 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7951 $sql .=
' as main, ' . $this->db->sanitize($this->db->prefix() . $InfoFieldList[0]) .
'_extrafields as extra';
7952 $sqlwhere .=
" WHERE extra.fk_object = main." . $this->db->sanitize($InfoFieldList[2]);
7953 $sqlwhere .=
" AND " . $InfoFieldList[4];
7955 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7958 $sqlwhere .=
' WHERE 1=1';
7975 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7976 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7983 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
7985 $resql = $this->db->query($sql);
7987 $num = $this->db->num_rows($resql);
7994 $obj = $this->db->fetch_object($resql);
7998 $fields_label = explode(
'|', $InfoFieldList[1]);
7999 if (count($fields_label) > 1) {
8001 foreach ($fields_label as $field_toshow) {
8002 $labeltoshow .= $obj->$field_toshow .
' ';
8005 $labeltoshow = $obj->{$InfoFieldList[1]};
8007 $labeltoshow =
dol_trunc($labeltoshow, 45);
8009 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8010 foreach ($fields_label as $field_toshow) {
8011 $translabel = $langs->trans($obj->$field_toshow);
8012 if ($translabel != $obj->$field_toshow) {
8013 $labeltoshow =
dol_trunc($translabel, 18) .
' ';
8015 $labeltoshow =
dol_trunc($obj->$field_toshow, 18) .
' ';
8019 $data[$obj->rowid] = $labeltoshow;
8022 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8023 if ($translabel != $obj->{$InfoFieldList[1]}) {
8024 $labeltoshow =
dol_trunc($translabel, 18);
8026 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
8029 if (empty($labeltoshow)) {
8030 $labeltoshow =
'(not defined)';
8033 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8034 $data[$obj->rowid] = $labeltoshow;
8037 if (!empty($InfoFieldList[3]) && $parentField) {
8038 $parent = $parentName .
':' . $obj->{$parentField};
8042 $data[$obj->rowid] = $labeltoshow;
8047 $this->db->free($resql);
8049 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0,
'100%');
8051 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
8054 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
8055 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
8056 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr, 0, 0, $morecss, 0,
'100%');
8059 } elseif ($type ==
'link') {
8062 $param_list = array_keys($param[
'options']);
8063 $param_list_array = explode(
':', $param_list[0], 4);
8065 $showempty = (($required && $default !=
'') ? 0 : 1);
8067 if (!preg_match(
'/search_/', $keyprefix)) {
8068 if (!empty($param_list_array[2])) {
8069 if (!empty($this->fields[$key][
'picto'])) {
8070 $morecss .=
' widthcentpercentminusxx';
8072 $morecss .=
' widthcentpercentminusx';
8075 if (!empty($this->fields[$key][
'picto'])) {
8076 $morecss .=
' widthcentpercentminusx';
8080 $objectfield = $this->element.($this->module ?
'@'.$this->module :
'').
':'.$key.$keysuffix;
8081 $out = $form->selectForForms($param_list_array[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss, $moreparam, 0, (empty($val[
'disabled']) ? 0 : 1),
'', $objectfield);
8083 if (!empty($param_list_array[2])) {
8084 if ((!GETPOSTISSET(
'backtopage') || strpos(
GETPOST(
'backtopage'), $_SERVER[
'PHP_SELF']) === 0)
8085 && empty($val[
'disabled']) && empty($nonewbutton)) {
8086 list($class, $classfile) = explode(
':', $param_list[0]);
8087 if (file_exists(
dol_buildpath(dirname(dirname($classfile)).
'/card.php'))) {
8088 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/card.php', 1);
8090 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/'.strtolower($class).
'_card.php', 1);
8092 $paramforthenewlink =
'';
8093 $paramforthenewlink .= (GETPOSTISSET(
'action') ?
'&action='.GETPOST(
'action',
'aZ09') :
'');
8094 $paramforthenewlink .= (GETPOSTISSET(
'id') ?
'&id='.GETPOSTINT(
'id') :
'');
8095 $paramforthenewlink .= (GETPOSTISSET(
'origin') ?
'&origin='.GETPOST(
'origin',
'aZ09') :
'');
8096 $paramforthenewlink .= (GETPOSTISSET(
'originid') ?
'&originid='.GETPOSTINT(
'originid') :
'');
8097 $paramforthenewlink .=
'&fk_'.strtolower($class).
'=--IDFORBACKTOPAGE--';
8099 $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>';
8102 } elseif ($type ==
'password') {
8104 if ($keyprefix.$key.$keysuffix ==
'pass_crypted') {
8105 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="pass" id="pass" value="" '.($moreparam ? $moreparam :
'').
'>';
8106 $out .=
'<input type="hidden" name="pass_crypted" id="pass_crypted" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
8108 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
8110 } elseif ($type ==
'array') {
8112 $newval[
'type'] =
'varchar(256)';
8115 if (!empty($value)) {
8116 foreach ($value as $option) {
8117 $out .=
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
8118 $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]', $option, $moreparam,
'',
'', $morecss).
'<br></span>';
8121 $out .=
'<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>';
8123 $newInput =
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
8124 $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]',
'', $moreparam,
'',
'', $morecss).
'<br></span>';
8126 if (!empty($conf->use_javascript_ajax)) {
8128 <script nonce="'.getNonce().
'">
8129 $(document).ready(function() {
8130 $("a#'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_add").click(function() {
8134 $(document).on("click", "a.'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_del", function() {
8135 $(this).parent().remove();
8141 if (!empty($hidden)) {
8142 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
8145 if ($isDependList == 1) {
8146 $out .= $this->getJSListDependancies(
'_common');
8154 if (!empty($fieldValidationErrorMsg) && function_exists(
'getFieldErrorIcon')) {
8155 $out .=
' '.getFieldErrorIcon($fieldValidationErrorMsg);
8174 public function showOutputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
8176 global $conf, $langs, $form;
8178 if (!is_object($form)) {
8179 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
8180 $form =
new Form($this->db);
8184 $type = empty($val[
'type']) ?
'' : $val[
'type'];
8185 $size = empty($val[
'css']) ?
'' : $val[
'css'];
8189 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
8192 } elseif (preg_match(
'/varchar/', $type)) {
8195 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8196 if (empty($this->fields[$key][
'multiinput'])) {
8197 $type = (($this->fields[$key][
'type'] ==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
8200 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8204 $default = empty($val[
'default']) ?
'' : $val[
'default'];
8205 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
8206 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
8207 $required = empty($val[
'required']) ?
'' : $val[
'required'];
8209 $param[
'options'] = array();
8211 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8212 $param[
'options'] = $val[
'arrayofkeyval'];
8214 if (preg_match(
'/^integer:([^:]*):([^:]*)/i', $val[
'type'], $reg)) {
8216 $stringforoptions = $reg[1].
':'.$reg[2];
8218 if ($reg[1] ==
'User') {
8219 $stringforoptions .=
':#getnomurlparam1=-1';
8221 $param[
'options'] = array($stringforoptions => $stringforoptions);
8222 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8223 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
8225 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8226 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
8228 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
8229 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
8231 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
8232 $param[
'options'] = array($reg[1] =>
'N');
8236 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
8237 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
8238 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
8239 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
8249 $value =
dol_eval($computed, 1, 0,
'2');
8252 if (empty($morecss)) {
8253 if ($type ==
'date') {
8254 $morecss =
'minwidth100imp';
8255 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
8256 $morecss =
'minwidth200imp';
8257 } elseif (in_array($type, array(
'int',
'double',
'price'))) {
8258 $morecss =
'maxwidth75';
8259 } elseif ($type ==
'url') {
8260 $morecss =
'minwidth400';
8261 } elseif ($type ==
'boolean') {
8264 if (is_numeric($size) && round((
float) $size) < 12) {
8265 $morecss =
'minwidth100';
8266 } elseif (is_numeric($size) && round((
float) $size) <= 48) {
8267 $morecss =
'minwidth200';
8269 $morecss =
'minwidth400';
8275 if (in_array($key, array(
'rowid',
'ref')) && method_exists($this,
'getNomUrl')) {
8276 if ($key !=
'rowid' || empty($this->fields[
'ref'])) {
8277 $value = $this->getNomUrl(1,
'', 0,
'', 1);
8279 } elseif ($key ==
'status' && method_exists($this,
'getLibStatut')) {
8280 $value = $this->getLibStatut(3);
8281 } elseif ($type ==
'date') {
8282 if (!empty($value)) {
8287 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
8288 if (!empty($value)) {
8293 } elseif ($type ==
'duration') {
8294 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
8295 if (!is_null($value) && $value !==
'') {
8298 } elseif ($type ==
'double' || $type ==
'real') {
8299 if (!is_null($value) && $value !==
'') {
8300 $value =
price($value);
8302 } elseif ($type ==
'boolean') {
8304 if (!empty($value)) {
8305 $checked =
' checked ';
8308 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
8310 $value =
yn($value ? 1 : 0);
8312 } elseif ($type ==
'mail' || $type ==
'email') {
8314 } elseif ($type ==
'url') {
8316 } elseif ($type ==
'phone') {
8318 } elseif ($type ==
'ip') {
8320 } elseif ($type ==
'price') {
8321 if (!is_null($value) && $value !==
'') {
8322 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
8324 } elseif ($type ==
'select') {
8325 $value = isset($param[
'options'][(
string) $value]) ? $param[
'options'][(string) $value] :
'';
8326 if (strpos($value,
"|") !==
false) {
8327 $value = $langs->trans(explode(
'|', $value)[0]);
8328 } elseif (! is_numeric($value)) {
8329 $value = $langs->trans($value);
8331 } elseif ($type ==
'sellist') {
8332 $param_list = array_keys($param[
'options']);
8333 $InfoFieldList = explode(
":", $param_list[0]);
8335 $selectkey =
"rowid";
8338 if (count($InfoFieldList) > 2 && !empty($InfoFieldList[2])) {
8339 $selectkey = $InfoFieldList[2];
8340 $keyList = $InfoFieldList[2].
' as rowid';
8343 $fields_label = explode(
'|', $InfoFieldList[1]);
8344 if (is_array($fields_label)) {
8346 $keyList .= implode(
', ', $fields_label);
8349 $filter_categorie =
false;
8350 if (count($InfoFieldList) > 5) {
8351 if ($InfoFieldList[0] ==
'categorie') {
8352 $filter_categorie =
true;
8356 $sql =
"SELECT ".$keyList;
8357 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8358 if (strpos($InfoFieldList[4],
'extra') !==
false) {
8361 if ($selectkey ==
'rowid' && empty($value)) {
8362 $sql .=
" WHERE ".$selectkey.
" = 0";
8363 } elseif ($selectkey ==
'rowid') {
8364 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
8366 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
8371 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
8372 $resql = $this->db->query($sql);
8374 if (!$filter_categorie) {
8376 $numrows = $this->db->num_rows($resql);
8378 $obj = $this->db->fetch_object($resql);
8381 $fields_label = explode(
'|', $InfoFieldList[1]);
8383 if (is_array($fields_label) && count($fields_label) > 1) {
8384 foreach ($fields_label as $field_toshow) {
8386 if (!empty($obj->$field_toshow)) {
8387 $translabel = $langs->trans($obj->$field_toshow);
8389 if ($translabel != $field_toshow) {
8390 $value .=
dol_trunc($translabel, 18) .
' ';
8392 $value .= $obj->$field_toshow .
' ';
8397 if (!empty($obj->{$InfoFieldList[1]})) {
8398 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8400 if ($translabel != $obj->{$InfoFieldList[1]}) {
8403 $value = $obj->{$InfoFieldList[1]};
8408 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8411 $obj = $this->db->fetch_object($resql);
8413 $c->fetch($obj->rowid);
8414 $ways = $c->print_all_ways();
8415 foreach ($ways as $way) {
8416 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8418 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8421 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8423 } elseif ($type ==
'radio') {
8424 $value = $param[
'options'][(string) $value];
8425 } elseif ($type ==
'checkbox') {
8426 $value_arr = explode(
',', (
string) $value);
8428 if (is_array($value_arr) && count($value_arr) > 0) {
8430 foreach ($value_arr as $keyval => $valueval) {
8431 if (!empty($valueval)) {
8432 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $param[
'options'][$valueval] .
'</li>';
8435 if (!empty($toprint)) {
8436 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
8439 } elseif ($type ==
'chkbxlst') {
8440 $value_arr = (isset($value) ? explode(
',', $value) : array());
8442 $param_list = array_keys($param[
'options']);
8443 $InfoFieldList = explode(
":", $param_list[0]);
8445 $selectkey =
"rowid";
8448 if (count($InfoFieldList) >= 3) {
8449 $selectkey = $InfoFieldList[2];
8450 $keyList = $InfoFieldList[2].
' as rowid';
8453 $fields_label = explode(
'|', $InfoFieldList[1]);
8454 if (is_array($fields_label)) {
8456 $keyList .= implode(
', ', $fields_label);
8459 $filter_categorie =
false;
8460 if (count($InfoFieldList) > 5) {
8461 if ($InfoFieldList[0] ==
'categorie') {
8462 $filter_categorie =
true;
8466 $sql =
"SELECT ".$keyList;
8467 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8468 if (isset($InfoFieldList[4]) && strpos($InfoFieldList[4],
'extra') !==
false) {
8474 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
8475 $resql = $this->db->query($sql);
8477 if (!$filter_categorie) {
8480 while ($obj = $this->db->fetch_object($resql)) {
8482 $fields_label = explode(
'|', $InfoFieldList[1]);
8483 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8484 if (is_array($fields_label) && count($fields_label) > 1) {
8485 foreach ($fields_label as $field_toshow) {
8487 if (!empty($obj->$field_toshow)) {
8488 $translabel = $langs->trans($obj->$field_toshow);
8490 if ($translabel != $field_toshow) {
8491 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8493 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->$field_toshow .
'</li>';
8498 if (!empty($obj->{$InfoFieldList[1]})) {
8499 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8501 if ($translabel != $obj->{$InfoFieldList[1]}) {
8502 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8504 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->{$InfoFieldList[1]} .
'</li>';
8510 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8513 while ($obj = $this->db->fetch_object($resql)) {
8514 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8516 $c->fetch($obj->rowid);
8517 $ways = $c->print_all_ways();
8518 foreach ($ways as $way) {
8519 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8524 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8526 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8528 } elseif ($type ==
'link') {
8533 $param_list = array_keys($param[
'options']);
8537 $InfoFieldList = explode(
":", $param_list[0]);
8539 $classname = $InfoFieldList[0];
8540 $classpath = $InfoFieldList[1];
8543 $getnomurlparam = 3;
8544 $getnomurlparam2 =
'';
8546 if (preg_match(
'/#getnomurlparam1=([^#]*)/', $param_list[0], $regtmp)) {
8547 $getnomurlparam = $regtmp[1];
8549 if (preg_match(
'/#getnomurlparam2=([^#]*)/', $param_list[0], $regtmp)) {
8550 $getnomurlparam2 = $regtmp[1];
8553 if (!empty($classpath)) {
8556 if ($classname && !class_exists($classname)) {
8560 if ($element_prop) {
8561 $classname = $element_prop[
'classname'];
8566 if ($classname && class_exists($classname)) {
8567 $object =
new $classname($this->db);
8568 if (
$object->element ===
'product') {
8569 $result =
$object->fetch($value,
'',
'',
'', 0, 1, 1);
8571 $result =
$object->fetch($value);
8574 if (
$object->element ===
'product') {
8575 $get_name_url_param_arr = array($getnomurlparam, $getnomurlparam2, 0, -1, 0,
'', 0);
8576 if (isset($val[
'get_name_url_params'])) {
8577 $get_name_url_params = explode(
':', $val[
'get_name_url_params']);
8578 if (!empty($get_name_url_params)) {
8579 $param_num_max = count($get_name_url_param_arr) - 1;
8580 foreach ($get_name_url_params as $param_num => $param_value) {
8581 if ($param_num > $param_num_max) {
8584 $get_name_url_param_arr[$param_num] = $param_value;
8592 $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]);
8594 $value =
$object->getNomUrl($getnomurlparam, $getnomurlparam2);
8601 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
8602 return 'Error bad setup of extrafield';
8607 } elseif ($type ==
'password') {
8608 $value =
'<span class="opacitymedium">'.$langs->trans(
"Encrypted").
'</span>';
8610 } elseif ($type ==
'array') {
8611 if (is_array($value)) {
8612 $value = implode(
'<br>', $value);
8614 dol_syslog(__METHOD__.
' Expected array from dol_eval, but got '.gettype($value), LOG_ERR);
8615 return 'Error unexpected result from code evaluation';
8624 return is_null($out) ?
'' : $out;
8636 unset($this->validateFieldsErrors[$fieldKey]);
8650 $msg = $langs->trans(
"UnknownError");
8653 $this->error = $this->validateFieldsErrors[$fieldKey] = $msg;
8664 if (!empty($this->validateFieldsErrors[$fieldKey])) {
8665 return $this->validateFieldsErrors[$fieldKey];
8682 if (!class_exists(
'Validate')) {
8683 require_once DOL_DOCUMENT_ROOT .
'/core/class/validate.class.php';
8686 $this->clearFieldError($fieldKey);
8688 if (!isset($fields[$fieldKey]) || $fields[$fieldKey] ===
null) {
8689 $this->setFieldError($fieldKey, $langs->trans(
'FieldNotFoundInObject'));
8693 $val = $fields[$fieldKey];
8696 $param[
'options'] = array();
8697 $type = $val[
'type'];
8700 if (isset($val[
'notnull']) && $val[
'notnull'] === 1) {
8714 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
8717 } elseif (preg_match(
'/varchar/', $type)) {
8721 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8725 if (!empty($val[
'type']) && preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8729 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8730 $param[
'options'] = $val[
'arrayofkeyval'];
8733 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8735 $param[
'options'] = array($reg[1].
':'.$reg[2] => $reg[1].
':'.$reg[2]);
8736 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8737 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
8739 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8740 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
8742 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
8743 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
8752 $validate =
new Validate($this->db, $langs);
8762 if ($required && !$validate->isNotEmptyString($fieldValue)) {
8763 $this->setFieldError($fieldKey, $validate->error);
8765 } elseif (!$required && !$validate->isNotEmptyString($fieldValue)) {
8771 if (!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)) {
8772 $this->setFieldError($fieldKey, $validate->error);
8777 if (!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)) {
8778 $this->setFieldError($fieldKey, $validate->error);
8786 if (in_array($type, array(
'date',
'datetime',
'timestamp'))) {
8787 if (!$validate->isTimestamp($fieldValue)) {
8788 $this->setFieldError($fieldKey, $validate->error);
8793 } elseif ($type ==
'duration') {
8794 if (!$validate->isDuration($fieldValue)) {
8795 $this->setFieldError($fieldKey, $validate->error);
8800 } elseif (in_array($type, array(
'double',
'real',
'price'))) {
8802 if (!$validate->isNumeric($fieldValue)) {
8803 $this->setFieldError($fieldKey, $validate->error);
8808 } elseif ($type ==
'boolean') {
8809 if (!$validate->isBool($fieldValue)) {
8810 $this->setFieldError($fieldKey, $validate->error);
8815 } elseif ($type ==
'mail') {
8816 if (!$validate->isEmail($fieldValue)) {
8817 $this->setFieldError($fieldKey, $validate->error);
8820 } elseif ($type ==
'url') {
8821 if (!$validate->isUrl($fieldValue)) {
8822 $this->setFieldError($fieldKey, $validate->error);
8827 } elseif ($type ==
'phone') {
8828 if (!$validate->isPhone($fieldValue)) {
8829 $this->setFieldError($fieldKey, $validate->error);
8834 } elseif ($type ==
'select' || $type ==
'radio') {
8835 if (!isset($param[
'options'][$fieldValue])) {
8836 $this->error = $langs->trans(
'RequireValidValue');
8841 } elseif ($type ==
'sellist' || $type ==
'chkbxlst') {
8842 $param_list = array_keys($param[
'options']);
8843 $InfoFieldList = explode(
":", $param_list[0]);
8844 $value_arr = explode(
',', $fieldValue);
8845 $value_arr = array_map(array($this->db,
'escape'), $value_arr);
8847 $selectkey =
"rowid";
8848 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
8849 $selectkey = $InfoFieldList[2];
8852 if (!$validate->isInDb($value_arr, $InfoFieldList[0], $selectkey)) {
8853 $this->setFieldError($fieldKey, $validate->error);
8858 } elseif ($type ==
'link') {
8859 $param_list = array_keys($param[
'options']);
8860 $InfoFieldList = explode(
":", $param_list[0]);
8861 $classname = $InfoFieldList[0];
8862 $classpath = $InfoFieldList[1];
8863 if (!$validate->isFetchable($fieldValue, $classname, $classpath)) {
8864 $lastIsFetchableError = $validate->error;
8867 if ($validate->isFetchableElement($fieldValue, $classname)) {
8871 $this->setFieldError($fieldKey, $lastIsFetchableError);
8895 public function showOptionals($extrafields, $mode =
'view', $params =
null, $keysuffix =
'', $keyprefix =
'', $onetrtd =
'', $display_type =
'card')
8897 global $db, $conf, $langs, $action, $form, $hookmanager;
8899 if (!is_object($form)) {
8900 $form =
new Form($db);
8902 if (!is_object($extrafields)) {
8903 dol_syslog(
'Bad parameter extrafields for showOptionals', LOG_ERR);
8904 return 'Bad parameter extrafields for showOptionals';
8906 if (!is_array($extrafields->attributes[$this->table_element])) {
8907 dol_syslog(
"extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
8912 $parameters = array(
'mode' => $mode,
'params' => $params,
'keysuffix' => $keysuffix,
'keyprefix' => $keyprefix,
'display_type' => $display_type);
8913 $reshook = $hookmanager->executeHooks(
'showOptionals', $parameters, $this, $action);
8915 if (empty($reshook)) {
8916 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) {
8918 $out .=
'<!-- commonobject:showOptionals --> ';
8921 $nbofextrafieldsshown = 0;
8924 $lastseparatorkeyfound =
'';
8925 $extrafields_collapse_num =
'';
8926 $extrafields_collapse_num_old =
'';
8929 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $label) {
8933 if (is_array($params) && array_key_exists(
'onlykey', $params) && $key != $params[
'onlykey']) {
8939 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
8940 $enabled = (int)
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
8942 if (empty($enabled)) {
8947 if (isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
8948 $visibility = (int)
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
8952 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
8953 $perms = (int)
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
8956 if (($mode ==
'create') && !in_array(abs($visibility), array(1, 3))) {
8958 } elseif (($mode ==
'edit') && !in_array(abs($visibility), array(1, 3, 4))) {
8960 $ef_name =
'options_' . $key;
8961 $ef_value = $this->array_options[$ef_name];
8962 $out .=
'<input type="hidden" name="' . $ef_name .
'" id="' . $ef_name .
'" value="' . $ef_value .
'" />' .
"\n";
8964 } elseif ($mode ==
'view' && empty($visibility)) {
8967 if (empty($perms)) {
8972 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
8973 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
8978 if (is_array($params) && count($params) > 0 && $display_type ==
'card') {
8979 if (array_key_exists(
'cols', $params)) {
8980 $colspan = $params[
'cols'];
8981 } elseif (array_key_exists(
'colspan', $params)) {
8983 if (preg_match(
'/colspan="(\d+)"/', $params[
'colspan'], $reg)) {
8986 $colspan = $params[
'colspan'];
8990 $colspan = intval($colspan);
8994 $value = ((!empty($this->array_options) && array_key_exists(
"options_".$key.$keysuffix, $this->array_options)) ? $this->array_options[
"options_".$key.$keysuffix] :
null);
9000 $check =
'alphanohtml';
9001 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text'))) {
9002 $check =
'restricthtml';
9004 $getposttemp =
GETPOST($keyprefix.
'options_'.$key.$keysuffix, $check, 3);
9006 if (is_array($getposttemp) || $getposttemp !=
'' || GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix)) {
9007 if (is_array($getposttemp)) {
9009 $value = implode(
",", $getposttemp);
9011 $value = $getposttemp;
9013 } elseif (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'int'))) {
9014 $value =( !empty($this->array_options[
"options_".$key]) || (isset($this->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] ===
'0')) ? $this->array_options[
"options_".$key] :
'';
9016 $value = (!empty($this->array_options[
"options_".$key]) ? $this->array_options[
"options_".$key] :
'');
9022 $nbofextrafieldsshown++;
9025 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
9026 $extrafields_collapse_num = $key;
9044 $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
9046 $lastseparatorkeyfound = $key;
9048 $collapse_group = $extrafields_collapse_num.(!empty($this->
id) ?
'_'.$this->id :
'');
9050 $class = (!empty($extrafields->attributes[$this->table_element][
'hidden'][$key]) ?
'hideobject ' :
'');
9052 if (is_array($params) && count($params) > 0) {
9053 if (array_key_exists(
'class', $params)) {
9054 $class .= $params[
'class'].
' ';
9056 if (array_key_exists(
'style', $params)) {
9057 $csstyle = $params[
'style'];
9062 $domData =
' data-element="extrafield"';
9063 $domData .=
' data-targetelement="'.$this->element.
'"';
9064 $domData .=
' data-targetid="'.$this->id.
'"';
9066 $html_id = (empty($this->
id) ?
'' :
'extrarow-'.$this->element.
'_'.$key.
'_'.$this->id);
9067 if ($display_type ==
'card') {
9072 if ($action ==
'selectlines') {
9078 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date'))) {
9079 $datenotinstring =
null;
9080 if (array_key_exists(
'options_'.$key, $this->array_options)) {
9081 $datenotinstring = $this->array_options[
'options_'.$key];
9082 if (!is_numeric($this->array_options[
'options_'.$key])) {
9083 $datenotinstring = $this->db->jdate($datenotinstring);
9086 $datekey = $keyprefix.
'options_'.$key.$keysuffix;
9089 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'datetime'))) {
9090 $datenotinstring =
null;
9091 if (array_key_exists(
'options_'.$key, $this->array_options)) {
9092 $datenotinstring = $this->array_options[
'options_'.$key];
9093 if (!is_numeric($this->array_options[
'options_'.$key])) {
9094 $datenotinstring = $this->db->jdate($datenotinstring);
9097 $timekey = $keyprefix.
'options_'.$key.$keysuffix;
9098 $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;
9101 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'price',
'double'))) {
9102 if (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) {
9104 } elseif (isset($this->array_options[
'options_'.$key])) {
9105 $value = $this->array_options[
'options_'.$key];
9110 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text',
'varchar',
'select',
'radio',
'int',
'boolean'))) {
9111 if ($action ==
'create' || $mode ==
'create') {
9112 $value = (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element][
'default'][$key];
9116 $labeltoshow = $langs->trans($label);
9117 $helptoshow = $langs->trans($extrafields->attributes[$this->table_element][
'help'][$key]);
9118 if ($display_type ==
'card') {
9119 $out .=
'<tr '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="field_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
9120 if (
getDolGlobalString(
'MAIN_VIEW_LINE_NUMBER') && ($action ==
'view' || $action ==
'valid' || $action ==
'editline' || $action ==
'confirm_valid' || $action ==
'confirm_cancel')) {
9121 $out .=
'<td></td>';
9123 $out .=
'<td class="'.(empty($params[
'tdclass']) ?
'titlefieldmax45' : $params[
'tdclass']).
' wordbreak';
9124 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text') {
9127 } elseif ($display_type ==
'line') {
9128 $out .=
'<div '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="fieldline_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
9129 $out .=
'<div style="display: inline-block; padding-right:4px" class="wordbreak';
9134 $tpl_context = isset($params[
"tpl_context"]) ? $params[
"tpl_context"] :
"none";
9135 if ($tpl_context !=
"public") {
9136 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
9137 $out .=
' fieldrequired';
9141 if ($tpl_context ==
"public") {
9142 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
9143 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
9145 $out .= $labeltoshow;
9147 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
9148 $out .=
' <span style="color: red">*</span>';
9151 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
9152 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
9154 $out .= $labeltoshow;
9158 $out .= ($display_type ==
'card' ?
'</td>' :
'</div>');
9161 $html_id = !empty($this->
id) ? $this->element.
'_extras_'.$key.
'_'.$this->id :
'';
9162 if ($display_type ==
'card') {
9164 $out .=
'<td '.($html_id ?
'id="'.$html_id.
'" ' :
'').
' class="valuefieldcreate '.$this->element.
'_extras_'.$key;
9165 $out .=
'" '.($colspan ?
' colspan="'.$colspan.
'"' :
'');
9167 } elseif ($display_type ==
'line') {
9168 $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].
'">';
9173 $out .= $extrafields->showOutputField($key, $value,
'', $this->table_element);
9176 $listoftypestoshowpicto = explode(
',',
getDolGlobalString(
'MAIN_TYPES_TO_SHOW_PICTO',
'email,phone,ip,password'));
9177 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], $listoftypestoshowpicto)) {
9178 $out .=
getPictoForType($extrafields->attributes[$this->table_element][
'type'][$key], ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text' ?
'tdtop' :
''));
9181 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'', 0, $this->
id, $this->table_element);
9184 $listoftypestoshowpicto = explode(
',',
getDolGlobalString(
'MAIN_TYPES_TO_SHOW_PICTO',
'email,phone,ip,password'));
9185 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], $listoftypestoshowpicto)) {
9186 $out .=
getPictoForType($extrafields->attributes[$this->table_element][
'type'][$key], ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'text' ?
'tdtop' :
''));
9188 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'', 0, $this->
id, $this->table_element);
9192 $out .= ($display_type ==
'card' ?
'</td>' :
'</div>');
9193 $out .= ($display_type ==
'card' ?
'</tr>'.
"\n" :
'</div>');
9199 if (!empty($conf->use_javascript_ajax)) {
9200 $out .= $this->getJSListDependancies();
9203 $out .=
'<!-- commonobject:showOptionals end --> '.
"\n";
9205 if (empty($nbofextrafieldsshown)) {
9211 $out .= $hookmanager->resPrint;
9223 <script nonce="'.getNonce().
'">
9224 jQuery(document).ready(function() {
9225 function showOptions'.$type.
'(child_list, parent_list, orig_select)
9227 var val = $("select[name=\""+parent_list+"\"]").val();
9228 var parentVal = parent_list + ":" + val;
9229 if(typeof val == "string"){
9231 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
9232 $("select[name=\""+child_list+"\"] option[parent]").remove();
9233 $("select[name=\""+child_list+"\"]").append(options);
9235 var options = orig_select.find("option[parent]").clone();
9236 $("select[name=\""+child_list+"\"] option[parent]").remove();
9237 $("select[name=\""+child_list+"\"]").append(options);
9239 } else if(val > 0) {
9240 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
9241 $("select[name=\""+child_list+"\"] option[parent]").remove();
9242 $("select[name=\""+child_list+"\"]").append(options);
9244 var options = orig_select.find("option[parent]").clone();
9245 $("select[name=\""+child_list+"\"] option[parent]").remove();
9246 $("select[name=\""+child_list+"\"]").append(options);
9249 function setListDependencies'.$type.
'() {
9250 jQuery("select option[parent]").parent().each(function() {
9251 var orig_select = {};
9252 var child_list = $(this).attr("name");
9253 orig_select[child_list] = $(this).clone();
9254 var parent = $(this).find("option[parent]:first").attr("parent");
9255 var infos = parent.split(":");
9256 var parent_list = infos[0];
9258 //Hide daughters lists
9259 if ($("#"+child_list).val() == 0 && $("#"+parent_list).val() == 0){
9260 $("#"+child_list).hide();
9262 } else if ($("#"+parent_list).val() != 0){
9263 $("#"+parent_list).show();
9265 //Show the child list if the parent list value is selected
9266 $("select[name=\""+parent_list+"\"]").click(function() {
9267 if ($(this).val() != 0){
9268 $("#"+child_list).show()
9272 //When we change parent list
9273 $("select[name=\""+parent_list+"\"]").change(function() {
9274 showOptions'.$type.
'(child_list, parent_list, orig_select[child_list]);
9275 //Select the value 0 on child list after a change on the parent list
9276 $("#"+child_list).val(0).trigger("change");
9277 //Hide child lists if the parent value is set to 0
9278 if ($(this).val() == 0){
9279 $("#"+child_list).hide();
9285 setListDependencies'.$type.
'();
9300 $module = empty($this->module) ?
'' : $this->module;
9301 $element = $this->element;
9303 if ($element ==
'facturerec') {
9304 $element =
'facture';
9305 } elseif ($element ==
'invoice_supplier_rec') {
9306 return !$user->hasRight(
'fournisseur',
'facture') ? null : $user->hasRight(
'fournisseur',
'facture');
9307 } elseif ($module && $user->hasRight($module, $element)) {
9309 return $user->hasRight($module, $element);
9312 return $user->rights->$element;
9329 foreach ($tables as $table) {
9330 $sql =
'UPDATE '.$dbs->prefix().$table.
' SET fk_soc = '.((int) $dest_id).
' WHERE fk_soc = '.((int) $origin_id);
9332 if (!$dbs->
query($sql)) {
9333 if ($ignoreerrors) {
9358 foreach ($tables as $table) {
9359 $sql =
'UPDATE '.MAIN_DB_PREFIX.$table.
' SET fk_product = '.((int) $dest_id).
' WHERE fk_product = '.((int) $origin_id);
9361 if (!$dbs->
query($sql)) {
9362 if ($ignoreerrors) {
9385 public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0)
9391 if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) &&
getDolGlobalInt(
'ForceBuyingPriceIfNull') > 0)) {
9393 $buyPrice = $unitPrice * (1 - $discountPercent / 100);
9396 if (!empty($fk_product) && $fk_product > 0) {
9399 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9400 $product =
new Product($this->db);
9401 $result = $product->fetch($fk_product);
9403 $this->errors[] =
'ErrorProductIdDoesNotExists';
9406 if ($product->cost_price > 0) {
9407 $buyPrice = $product->cost_price;
9408 } elseif ($product->pmp > 0) {
9409 $buyPrice = $product->pmp;
9412 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9413 $product =
new Product($this->db);
9414 $result = $product->fetch($fk_product);
9416 $this->errors[] =
'ErrorProductIdDoesNotExists';
9419 if ($product->pmp > 0) {
9420 $buyPrice = $product->pmp;
9424 if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array(
'1',
'pmp',
'costprice'))) {
9425 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
9427 if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) {
9428 $buyPrice = $productFournisseur->fourn_unitprice;
9429 } elseif ($result < 0) {
9430 $this->errors[] = $productFournisseur->error;
9449 return array(
'dir' =>
'',
'file' =>
'',
'originalfile' =>
'',
'altfile' =>
'',
'email' =>
'',
'capture' =>
'');
9473 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')
9476 global $user, $langs;
9478 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
9479 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
9481 $sortfield =
'position_name';
9487 $dir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9488 $pdir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9491 if ($modulepart ==
'product') {
9493 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9494 $pdir =
'/'.get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9497 if ($modulepart ==
'category') {
9498 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9499 $pdir =
'/'.get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9505 $relativedir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
9506 $relativedir = preg_replace(
'/^[\\/]/',
'', $relativedir);
9507 $relativedir = preg_replace(
'/[\\/]$/',
'', $relativedir);
9510 $dirthumb = $dir.
'thumbs/';
9511 $pdirthumb = $pdir.
'thumbs/';
9513 $return =
'<!-- Photo -->'.
"\n";
9516 $filearray =
dol_dir_list($dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
9526 if (count($filearray)) {
9527 if ($sortfield && $sortorder) {
9531 foreach ($filearray as $key => $val) {
9533 $file = $val[
'name'];
9539 $viewfilename = $file;
9541 if ($size == 1 || $size ==
'small') {
9548 $photo_vignette = basename($file);
9555 if ($nbphoto == 1) {
9556 $return .=
'<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';
9559 if ($nbphoto % $nbbyrow == 1) {
9560 $return .=
'<tr class="center valignmiddle" style="border: 1px">';
9562 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%" class="photo">'.
"\n";
9563 } elseif ($nbbyrow < 0) {
9564 $return .=
'<div class="inline-block">'.
"\n";
9567 $relativefile = preg_replace(
'/^\//',
'', $pdir.$photo);
9568 if (empty($nolink)) {
9571 $return .=
'<a href="'.$urladvanced.
'">';
9573 $return .=
'<a href="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
9579 $alt = $langs->transnoentitiesnoconv(
'File').
': '.$relativefile;
9580 $alt .=
' - '.$langs->transnoentitiesnoconv(
'Size').
': '.$imgarray[
'width'].
'x'.$imgarray[
'height'];
9581 if ($overwritetitle) {
9582 if (is_numeric($overwritetitle)) {
9585 $alt = $overwritetitle;
9588 if (empty($cache) && !empty($val[
'label'])) {
9591 $cache = $val[
'label'];
9593 if ($usesharelink) {
9594 if (array_key_exists(
'share', $val) && $val[
'share']) {
9595 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
9596 $return .=
'<!-- Show original file (thumb not yet available with shared links) -->';
9597 $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).
'">';
9599 $return .=
'<!-- Show original file -->';
9600 $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).
'">';
9603 $return .=
'<!-- Show nophoto file (because file is not shared) -->';
9604 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'" height="'.$maxHeight.
'" src="'.DOL_URL_ROOT.
'/public/theme/common/nophoto.png" title="'.
dol_escape_htmltag($alt).
'">';
9607 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
9608 $return .=
'<!-- Show thumb -->';
9609 $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).
'">';
9611 $return .=
'<!-- Show original file -->';
9612 $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).
'">';
9616 if (empty($nolink)) {
9620 if ($showfilename) {
9621 $return .=
'<br>'.$viewfilename;
9626 if ($photo_vignette && (
image_format_supported($photo) > 0) && ((isset($imgarray[
'width']) && $imgarray[
'width'] > $maxWidth) || (isset($imgarray[
'width']) && $imgarray[
'width'] > $maxHeight))) {
9627 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=addthumb&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">'.
img_picto($langs->trans(
'GenerateThumb'),
'refresh').
' </a>';
9630 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
9632 $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> ';
9635 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
9643 if (($nbphoto % $nbbyrow) == 0) {
9646 } elseif ($nbbyrow < 0) {
9647 $return .=
'</div>'.
"\n";
9652 $return .=
'<img class="photo photowithmargin" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'">';
9654 if ($showfilename) {
9655 $return .=
'<br>'.$viewfilename;
9659 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
9661 $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> ';
9664 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.
newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
9671 if ($nbmax && $nbphoto >= $nbmax) {
9677 if ($size == 1 || $size ==
'small') {
9680 while ($nbphoto % $nbbyrow) {
9681 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%"> </td>';
9686 $return .=
'</table>';
9692 $this->nbphoto = $nbphoto;
9706 if (is_array($info)) {
9707 if (isset($info[
'type']) && $info[
'type'] ==
'array') {
9724 if (isset($info[
'type']) && ($info[
'type'] ==
'date' || $info[
'type'] ==
'datetime' || $info[
'type'] ==
'timestamp')) {
9738 if (is_array($info)) {
9739 if (isset($info[
'type']) && ($info[
'type'] ==
'duration')) {
9757 if (is_array($info)) {
9758 if (isset($info[
'type']) && (preg_match(
'/(^int|int$)/i', $info[
'type']))) {
9776 if (is_array($info)) {
9777 if (isset($info[
'type']) && (preg_match(
'/^(double|real|price)/i', $info[
'type']))) {
9794 if (is_array($info)) {
9795 if (isset($info[
'type']) && $info[
'type'] ==
'text') {
9812 if (is_array($info)) {
9813 if (array_key_exists(
'notnull', $info) && $info[
'notnull'] !=
'1') {
9830 if (is_array($info)) {
9831 if (array_key_exists(
'notnull', $info) && $info[
'notnull'] ==
'-1') {
9848 if (is_array($info)) {
9849 if (array_key_exists(
'index', $info) && $info[
'index'] ==
true) {
9871 $queryarray = array();
9872 foreach ($this->fields as $field => $info) {
9874 if ($this->isDate($info)) {
9875 if (empty($this->{$field})) {
9876 $queryarray[$field] =
null;
9878 $queryarray[$field] = $this->db->idate($this->{$field});
9880 } elseif ($this->isDuration($info)) {
9882 if ((isset($this->{$field}) && $this->{$field} !=
'') || !empty($info[
'notnull'])) {
9883 if (!isset($this->{$field})) {
9884 if (!empty($info[
'default'])) {
9885 $queryarray[$field] = $info[
'default'];
9887 $queryarray[$field] = 0;
9890 $queryarray[$field] = (int) $this->{$field};
9893 $queryarray[$field] =
null;
9895 } elseif ($this->isInt($info) || $this->isFloat($info)) {
9896 if ($field ==
'entity' && is_null($this->{$field})) {
9897 $queryarray[$field] = ((int) $conf->entity);
9900 if ((isset($this->{$field}) && ((
string) $this->{$field}) !=
'') || !empty($info[
'notnull'])) {
9901 if (!isset($this->{$field})) {
9902 $queryarray[$field] = 0;
9903 } elseif ($this->isInt($info)) {
9904 $queryarray[$field] = (int) $this->{$field};
9905 } elseif ($this->isFloat($info)) {
9906 $queryarray[$field] = (float) $this->{$field};
9909 $queryarray[$field] =
null;
9915 $queryarray[$field] = $this->{$field};
9918 if (array_key_exists(
'type', $info) && $info[
'type'] ==
'timestamp' && empty($queryarray[$field])) {
9919 unset($queryarray[$field]);
9921 if (!empty($info[
'notnull']) && $info[
'notnull'] == -1 && empty($queryarray[$field])) {
9922 $queryarray[$field] =
null;
9939 foreach ($this->fields as $field => $info) {
9940 if ($this->isDate($info)) {
9941 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') {
9944 $this->$field = $db->jdate($obj->$field);
9946 } elseif ($this->isInt($info)) {
9947 if ($field ==
'rowid') {
9948 $this->
id = (int) $obj->$field;
9950 if ($this->isForcedToNullIfZero($info)) {
9951 if (empty($obj->$field)) {
9952 $this->$field =
null;
9954 $this->$field = (int) $obj->$field;
9957 if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists(
'notnull', $info) && $info[
'notnull'] == 1))) {
9958 $this->$field = (int) $obj->$field;
9960 $this->$field =
null;
9964 } elseif ($this->isFloat($info)) {
9965 if ($this->isForcedToNullIfZero($info)) {
9966 if (empty($obj->$field)) {
9967 $this->$field =
null;
9969 $this->$field = (float) $obj->$field;
9972 if (isset($obj->$field) && (!is_null($obj->$field) || (array_key_exists(
'notnull', $info) && $info[
'notnull'] == 1))) {
9973 $this->$field = (float) $obj->$field;
9975 $this->$field =
null;
9979 $this->$field = isset($obj->$field) ? $obj->$field :
null;
9984 if (!isset($this->fields[
'ref']) && isset($this->
id)) {
9985 $this->
ref = (string) $this->
id;
9995 foreach ($this->fields as $field => $arr) {
9996 $this->$field =
null;
10009 $keys = array_keys($this->fields);
10010 if (!empty($alias)) {
10011 $keys_with_alias = array();
10012 foreach ($keys as $fieldname) {
10013 if (!empty($excludefields)) {
10014 if (in_array($fieldname, $excludefields)) {
10018 $keys_with_alias[] = $alias .
'.' . $fieldname;
10020 return implode(
',', $keys_with_alias);
10022 return implode(
',', $keys);
10033 protected function quote($value, $fieldsentry)
10035 if (is_null($value)) {
10037 } elseif (preg_match(
'/^(int|double|real|price)/i', $fieldsentry[
'type'])) {
10039 } elseif (preg_match(
'/int$/i', $fieldsentry[
'type'])) {
10040 return (
int) $value;
10041 } elseif ($fieldsentry[
'type'] ==
'boolean') {
10048 return "'".$this->db->escape($value).
"'";
10064 dol_syslog(get_class($this).
"::createCommon create", LOG_DEBUG);
10070 $fieldvalues = $this->setSaveQuery();
10074 if (array_key_exists(
'date_creation', $fieldvalues) && empty($fieldvalues[
'date_creation'])) {
10075 $fieldvalues[
'date_creation'] = $this->db->idate($now);
10077 if (array_key_exists(
'fk_user_creat', $fieldvalues) && !($fieldvalues[
'fk_user_creat'] > 0)) {
10078 $fieldvalues[
'fk_user_creat'] = $user->id;
10079 $this->fk_user_creat = $user->id;
10081 if (array_key_exists(
'user_creation_id', $fieldvalues) && !($fieldvalues[
'user_creation_id'] > 0)) {
10082 $fieldvalues[
'user_creation_id'] = $user->id;
10083 $this->user_creation_id = $user->id;
10085 if (array_key_exists(
'pass_crypted', $fieldvalues) && property_exists($this,
'pass')) {
10087 $fieldvalues[
'pass_crypted'] =
dol_hash($this->pass);
10089 if (array_key_exists(
'ref', $fieldvalues)) {
10093 unset($fieldvalues[
'rowid']);
10097 foreach ($fieldvalues as $k => $v) {
10099 $value = $this->fields[$k];
10101 $values[$k] = $this->quote($v, $value);
10105 foreach ($keys as $key) {
10106 if (!isset($this->fields[$key])) {
10109 $key_fields = $this->fields[$key];
10112 if (preg_match(
'/^integer:/i', $key_fields[
'type']) && $values[$key] ==
'-1') {
10113 $values[$key] =
'';
10115 if (!empty($key_fields[
'foreignkey']) && $values[$key] ==
'-1') {
10116 $values[$key] =
'';
10119 if (isset($key_fields[
'notnull']) && $key_fields[
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && (!isset($key_fields[
'default']) || is_null($key_fields[
'default']))) {
10121 $langs->load(
"errors");
10122 dol_syslog(
"Mandatory field '".$key.
"' is empty and required into ->fields definition of class");
10123 $this->errors[] = $langs->trans(
"ErrorFieldRequired", isset($key_fields[
'label']) ? $key_fields[
'label'] : $key);
10127 if (isset($key_fields[
'notnull']) && $key_fields[
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && !is_null($key_fields[
'default'])) {
10128 $values[$key] = $this->quote($key_fields[
'default'], $key_fields);
10132 if (isset($key_fields[
'type']) && preg_match(
'/^integer:/i', $key_fields[
'type']) && empty($values[$key])) {
10133 if (isset($key_fields[
'default'])) {
10134 $values[$key] = ((int) $key_fields[
'default']);
10136 $values[$key] =
'null';
10139 if (!empty($key_fields[
'foreignkey']) && empty($values[$key])) {
10140 $values[$key] =
'null';
10148 $this->db->begin();
10151 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element;
10152 $sql .=
" (".implode(
", ", $keys).
')';
10153 $sql .=
" VALUES (".implode(
", ", $values).
")";
10155 $res = $this->db->query($sql);
10158 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
10159 $this->errors[] =
"ErrorRefAlreadyExists";
10161 $this->errors[] = $this->db->lasterror();
10167 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
10173 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)') {
10174 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ref = '(PROV".((int) $this->
id).
")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->
id);
10175 $resqlupdate = $this->db->query($sql);
10177 if ($resqlupdate ===
false) {
10179 $this->errors[] = $this->db->lasterror();
10181 $this->
ref =
'(PROV'.$this->id.
')';
10188 $result = $this->insertExtraFields();
10195 if (!empty($this->table_element_line) && !empty($this->fk_element)) {
10196 foreach ($this->lines as $line) {
10197 $keyforparent = $this->fk_element;
10198 $line->$keyforparent = $this->id;
10202 if (!is_object($line)) {
10203 $line = (object) $line;
10207 if (method_exists($line,
'insert')) {
10208 $result = $line->insert($user, 1);
10209 } elseif (method_exists($line,
'create')) {
10210 $result = $line->create($user, 1);
10213 $this->error = $line->error;
10214 $this->db->rollback();
10221 if (!$error && !$notrigger) {
10223 $result = $this->call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
10232 $this->db->rollback();
10235 $this->db->commit();
10250 public function fetchCommon($id, $ref =
null, $morewhere =
'', $noextrafields = 0)
10252 if (empty($id) && empty($ref) && empty($morewhere)) {
10256 $fieldlist = $this->getFieldList(
't');
10257 if (empty($fieldlist)) {
10261 $sql =
"SELECT ".$fieldlist;
10262 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
' as t';
10265 $sql .=
' WHERE t.rowid = '.((int) $id);
10266 } elseif (!empty($ref)) {
10267 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
10269 $sql .=
' WHERE 1 = 1';
10271 if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
10272 $sql .=
' AND t.entity IN ('.getEntity($this->element).
')';
10275 $sql .= $morewhere;
10277 $sql .=
' LIMIT 1';
10279 $res = $this->db->query($sql);
10281 $obj = $this->db->fetch_object($res);
10283 $this->setVarsFromFetchObj($obj);
10287 if (empty($noextrafields)) {
10288 $result = $this->fetch_optionals();
10290 $this->error = $this->db->lasterror();
10291 $this->errors[] = $this->error;
10301 $this->error = $this->db->lasterror();
10302 $this->errors[] = $this->error;
10316 $objectlineclassname = get_class($this).
'Line';
10317 if (!class_exists($objectlineclassname)) {
10318 $this->error =
'Error, class '.$objectlineclassname.
' not found during call of fetchLinesCommon';
10322 $objectline =
new $objectlineclassname($this->db);
10323 '@phan-var-force CommonObjectLine $objectline';
10325 $sql =
"SELECT ".$objectline->getFieldList(
'l');
10326 $sql .=
" FROM ".$this->db->prefix().$objectline->table_element.
" as l";
10327 $sql .=
" WHERE l.fk_".$this->db->escape($this->element).
" = ".((int) $this->
id);
10329 $sql .= $morewhere;
10331 if (isset($objectline->fields[
'position'])) {
10332 $sql .= $this->db->order(
'position',
'ASC');
10335 $resql = $this->db->query($sql);
10337 $num_rows = $this->db->num_rows($resql);
10339 $this->lines = array();
10340 while ($i < $num_rows) {
10341 $obj = $this->db->fetch_object($resql);
10343 $newline =
new $objectlineclassname($this->db);
10344 '@phan-var-force CommonObjectLine $newline';
10345 $newline->setVarsFromFetchObj($obj);
10353 $this->lines[] = $newline;
10360 $this->error = $this->db->lasterror();
10361 $this->errors[] = $this->error;
10375 dol_syslog(get_class($this).
"::updateCommon update", LOG_DEBUG);
10387 $fieldvalues = $this->setSaveQuery();
10391 if (array_key_exists(
'date_modification', $fieldvalues) && empty($fieldvalues[
'date_modification'])) {
10392 $fieldvalues[
'date_modification'] = $this->db->idate($now);
10394 if (array_key_exists(
'fk_user_modif', $fieldvalues) && !($fieldvalues[
'fk_user_modif'] > 0)) {
10395 $fieldvalues[
'fk_user_modif'] = $user->id;
10397 if (array_key_exists(
'user_modification_id', $fieldvalues) && !($fieldvalues[
'user_modification_id'] > 0)) {
10398 $fieldvalues[
'user_modification_id'] = $user->id;
10400 if (array_key_exists(
'ref', $fieldvalues)) {
10404 unset($fieldvalues[
'rowid']);
10410 foreach ($fieldvalues as $k => $v) {
10412 $value = $this->fields[$k];
10414 $values[$k] = $this->quote($v, $value);
10416 $tmp[] = $k.
'='.$this->quote($v, $this->fields[$k]);
10420 foreach ($keys as $key) {
10421 if (preg_match(
'/^integer:/i', $this->fields[$key][
'type']) && $values[$key] ==
'-1') {
10422 $values[$key] =
'';
10424 if (!empty($this->fields[$key][
'foreignkey']) && $values[$key] ==
'-1') {
10425 $values[$key] =
'';
10437 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET '.implode(
', ', $tmp).
' WHERE rowid='.((int) $this->
id);
10439 $this->db->begin();
10442 $res = $this->db->query($sql);
10445 $this->errors[] = $this->db->lasterror();
10451 $result = $this->insertExtraFields();
10458 if (!$error && !$notrigger) {
10460 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
10469 $this->db->rollback();
10472 $this->db->commit();
10487 dol_syslog(get_class($this).
"::deleteCommon delete", LOG_DEBUG);
10491 $this->db->begin();
10493 if ($forcechilddeletion) {
10494 foreach ($this->childtables as $table) {
10495 $sql =
"DELETE FROM ".$this->db->prefix().$table.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10496 $resql = $this->db->query($sql);
10498 $this->error = $this->db->lasterror();
10499 $this->errors[] = $this->error;
10500 $this->db->rollback();
10504 } elseif (!empty($this->childtables)) {
10505 $objectisused = $this->isObjectUsed($this->
id);
10506 if (!empty($objectisused)) {
10507 dol_syslog(get_class($this).
"::deleteCommon Can't delete record as it has some child", LOG_WARNING);
10508 $this->error =
'ErrorRecordHasChildren';
10509 $this->errors[] = $this->error;
10510 $this->db->rollback();
10516 if (is_array($this->childtablesoncascade) && !empty($this->childtablesoncascade)) {
10517 foreach ($this->childtablesoncascade as $tabletodelete) {
10518 $deleteFromObject = explode(
':', $tabletodelete, 4);
10519 if (count($deleteFromObject) >= 2) {
10520 $className = str_replace(
'@',
'', $deleteFromObject[0]);
10521 $filePath = $deleteFromObject[1];
10522 $columnName = $deleteFromObject[2];
10524 if (!empty($deleteFromObject[3])) {
10525 $filter = $deleteFromObject[3];
10528 $childObject =
new $className($this->db);
10529 if (method_exists($childObject,
'deleteByParentField')) {
10530 '@phan-var-force CommonObject $childObject';
10531 $result = $childObject->deleteByParentField($this->
id, $columnName, $filter);
10534 $this->errors[] = $childObject->error;
10539 $this->errors[] =
"You defined a cascade delete on an object $className/$this->id but there is no method deleteByParentField for it";
10544 $this->errors[] =
'Cannot include child class file '.$filePath;
10549 $sql =
"DELETE FROM ".$this->db->prefix().$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10551 $resql = $this->db->query($sql);
10554 $this->error = $this->db->lasterror();
10555 $this->errors[] = $this->error;
10565 $result = $this->call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
10575 $res = $this->deleteEcmFiles(1);
10582 $res = $this->deleteObjectLinked();
10587 if (!$error && !empty($this->isextrafieldmanaged)) {
10588 $result = $this->deleteExtraFields();
10595 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
' WHERE rowid='.((int) $this->
id);
10597 $resql = $this->db->query($sql);
10600 $this->errors[] = $this->db->lasterror();
10606 $this->db->rollback();
10609 $this->db->commit();
10632 if (!empty($parentId) && !empty($parentField)) {
10633 $this->db->begin();
10635 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
10636 $sql .=
" WHERE ".$this->db->sanitize($parentField).
" = ".(int) $parentId;
10639 $errormessage =
'';
10641 if ($errormessage) {
10642 $this->errors[] = $errormessage;
10643 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
10647 $resql = $this->db->query($sql);
10649 $this->errors[] = $this->db->lasterror();
10652 while ($obj = $this->db->fetch_object($resql)) {
10653 $result = $this->fetch($obj->rowid);
10656 $this->errors[] = $this->error;
10658 $result = $this->
delete($user);
10661 $this->errors[] = $this->error;
10669 if (empty($error)) {
10670 $this->db->commit();
10673 $this->error = implode(
', ', $this->errors);
10674 $this->db->rollback();
10675 return $error * -1;
10694 $tmpforobjectclass = get_class($this);
10695 $tmpforobjectlineclass = ucfirst($tmpforobjectclass).
'Line';
10697 $this->db->begin();
10700 $result = $this->call_trigger(
'LINE'.strtoupper($tmpforobjectclass).
'_DELETE', $user);
10706 if (empty($error)) {
10707 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element_line;
10708 $sql .=
" WHERE rowid = ".((int) $idline);
10710 $resql = $this->db->query($sql);
10712 $this->error =
"Error ".$this->db->lasterror();
10717 if (empty($error)) {
10719 $tmpobjectline =
new $tmpforobjectlineclass($this->db);
10720 '@phan-var-force CommonObjectLine $tmpobjectline';
10721 if (!isset($tmpobjectline->isextrafieldmanaged) || !empty($tmpobjectline->isextrafieldmanaged)) {
10722 $tmpobjectline->id = $idline;
10723 $result = $tmpobjectline->deleteExtraFields();
10726 $this->error =
"Error ".get_class($this).
"::deleteLineCommon deleteExtraFields error -4 ".$tmpobjectline->error;
10731 if (empty($error)) {
10732 $this->db->commit();
10735 dol_syslog(get_class($this).
"::deleteLineCommon ERROR:".$this->error, LOG_ERR);
10736 $this->db->rollback();
10755 $this->db->begin();
10757 $statusfield =
'status';
10758 if (in_array($this->element, array(
'don',
'donation',
'shipping'))) {
10759 $statusfield =
'fk_statut';
10762 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
10763 $sql .=
" SET ".$statusfield.
" = ".((int) $status);
10764 $sql .=
" WHERE rowid = ".((int) $this->
id);
10766 if ($this->db->query($sql)) {
10768 $this->oldcopy = clone $this;
10771 if (!$error && !$notrigger) {
10773 $result = $this->call_trigger($triggercode, $user);
10780 $this->
status = $status;
10781 if (property_exists($this,
'statut')) {
10782 $this->
statut = $status;
10784 $this->db->commit();
10787 $this->db->rollback();
10791 $this->error = $this->db->error();
10792 $this->db->rollback();
10810 $this->db->begin();
10812 $statusfield =
'signed_status';
10814 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
10815 $sql .=
" SET ".$statusfield.
" = ".((int) $status);
10816 $sql .=
" WHERE rowid = ".((int) $this->
id);
10818 if ($this->db->query($sql)) {
10820 $this->oldcopy = clone $this;
10823 if (!$error && !$notrigger) {
10825 $result = $this->call_trigger($triggercode, $user);
10832 $this->
status = $status;
10833 $this->db->commit();
10836 $this->db->rollback();
10840 $this->error = $this->db->error();
10841 $this->db->rollback();
10858 $this->specimen = 1;
10860 'label' =>
'This is label',
10861 'ref' =>
'ABCD1234',
10862 'description' =>
'This is a description',
10864 'note_public' =>
'Public note',
10865 'note_private' =>
'Private note',
10866 'date_creation' => (
dol_now() - 3600 * 48),
10867 'date_modification' => (
dol_now() - 3600 * 24),
10868 'fk_user_creat' => $user->id,
10869 'fk_user_modif' => $user->id,
10872 foreach ($fields as $key => $value) {
10873 if (array_key_exists($key, $this->fields)) {
10874 $this->{$key} = $value;
10879 if (property_exists($this,
'fields')) {
10880 foreach ($this->fields as $key => $value) {
10882 if (array_key_exists($key, $fields)) {
10886 if (!empty($value[
'default'])) {
10887 $this->$key = $value[
'default'];
10905 require_once DOL_DOCUMENT_ROOT.
'/core/class/comment.class.php';
10907 $comment =
new Comment($this->db);
10908 $result = $comment->fetchAllFor($this->element, $this->
id);
10910 $this->errors = array_merge($this->errors, $comment->errors);
10913 $this->comments = $comment->comments;
10915 return count($this->comments);
10925 return count($this->comments);
10936 if (!is_array($parameters)) {
10939 foreach ($parameters as $parameter) {
10940 if (isset($this->$parameter)) {
10941 $this->$parameter = trim($this->$parameter);
10960 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
10964 $existing = $c->containing($this->
id, $type_categ,
'id');
10984 if (!is_array($categories)) {
10985 $categories = array($categories);
10988 dol_syslog(get_class($this).
"::setCategoriesCommon Object Id:".$this->
id.
' type_categ:'.$type_categ.
' nb tag add:'.count($categories), LOG_DEBUG);
10990 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
10992 if (empty($type_categ)) {
10993 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown category type. Done nothing.', LOG_ERR);
10999 $existing = $c->containing($this->
id, $type_categ,
'id');
11000 if ($remove_existing) {
11002 if (is_array($existing)) {
11003 $to_del = array_diff($existing, $categories);
11004 $to_add = array_diff($categories, $existing);
11007 $to_add = $categories;
11011 $to_add = array_diff($categories, $existing);
11018 foreach ($to_del as $del) {
11019 if ($c->fetch($del) > 0) {
11020 $result = $c->del_type($this, $type_categ);
11023 $this->error = $c->error;
11024 $this->errors = $c->errors;
11031 foreach ($to_add as $add) {
11032 if ($c->fetch($add) > 0) {
11033 $result = $c->add_type($this, $type_categ);
11036 $this->error = $c->error;
11037 $this->errors = $c->errors;
11045 return $error ? (-1 * $error) : $ok;
11058 $this->db->begin();
11060 if (empty($type)) {
11061 $type = $this->table_element;
11064 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
11065 $categorystatic =
new Categorie($this->db);
11067 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_product)";
11068 $sql .=
" SELECT fk_categorie, $toId FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
11069 $sql .=
" WHERE fk_product = ".((int) $fromId);
11071 if (!$this->db->query($sql)) {
11072 $this->error = $this->db->lasterror();
11073 $this->db->rollback();
11077 $this->db->commit();
11091 $this->db->begin();
11095 switch ($this->element) {
11097 $element =
'propale';
11100 $element =
'produit';
11102 case 'order_supplier':
11103 $element =
'fournisseur/commande';
11105 case 'invoice_supplier':
11108 $element =
'fournisseur/facture/'.get_exdir($this->
id, 2, 0, 1, $this,
'invoice_supplier');
11111 $element =
'expedition/sending';
11114 case 'project_task':
11115 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
11117 $project_result = $this->fetch_projet();
11118 if ($project_result >= 0) {
11119 $element =
'projet/'.dol_sanitizeFileName($this->project->ref).
'/';
11123 $element = $this->element;
11125 '@phan-var-force string $element';
11128 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files_extrafields WHERE fk_object IN (";
11129 $sql .=
" SELECT rowid FROM ".$this->db->prefix().
"ecm_files WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
11130 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
11133 if (!$this->db->query($sql)) {
11134 $this->error = $this->db->lasterror();
11135 $this->db->rollback();
11140 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files";
11141 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
11142 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
11144 if (!$this->db->query($sql)) {
11145 $this->error = $this->db->lasterror();
11146 $this->db->rollback();
11153 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files_extrafields";
11154 $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).
")";
11155 $resql = $this->db->query($sql);
11157 $this->error = $this->db->lasterror();
11158 $this->db->rollback();
11162 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files";
11163 $sql .=
" WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ?
"" :
"@".$this->module)).
"' AND src_object_id = ".((int) $this->
id);
11164 $resql = $this->db->query($sql);
11166 $this->error = $this->db->lasterror();
11167 $this->db->rollback();
11172 $this->db->commit();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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 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.
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.
addThumbs($file)
Build thumb.
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)
insertExtraLanguages($trigger='', $userused=null)
Add/Update all extra fields 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.
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.
setSignedStatusCommon($user, $status, $notrigger=0, $triggercode='')
Set to a signed status.
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.
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 ECM files.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage triggers.
static getIdAndTxFromCode($dbs, $code, $date_document='')
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.
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.
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.
completeFileArrayWithDatabaseInfo(&$filearray, $relativedir)
Complete $filearray with data from database.
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='')
Format phone numbers according to country.
dol_print_ip($ip, $mode=0)
Return an IP formatted to be shown on screen.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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 '.
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.
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_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
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'.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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...
getDolGlobalString($key, $default='')
Return 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.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $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:/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.
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a symmetric encryption.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid