47 const TRIGGER_PREFIX =
'';
83 public $errors = array();
88 private $validateFieldsErrors = array();
104 public $element_for_permission;
109 public $table_element;
114 public $table_element_line =
'';
119 public $ismultientitymanaged;
129 public $array_options = array();
134 public $fields = array();
139 public $array_languages =
null;
144 public $contacts_ids;
149 public $linked_objects;
154 public $linkedObjectsIds;
159 public $linkedObjects;
164 private $linkedObjectsFullLoaded = array();
179 protected $table_ref_field =
'';
184 public $restrictiononfksoc = 0;
192 public $context = array();
267 public $origin_object;
292 public $ref_previous;
334 public $country_code;
377 public $barcode_type;
383 public $barcode_type_code;
389 public $barcode_type_label;
395 public $barcode_type_coder;
401 public $mode_reglement_id;
407 public $cond_reglement_id;
412 public $demand_reason_id;
418 public $transport_mode_id;
425 public $cond_reglement;
432 public $fk_delivery_address;
438 public $shipping_method_id;
444 public $shipping_method;
450 public $fk_multicurrency;
455 public $multicurrency_code;
460 public $multicurrency_tx;
465 public $multicurrency_total_ht;
470 public $multicurrency_total_tva;
475 public $multicurrency_total_ttc;
480 public $multicurrency_total_localtax1;
485 public $multicurrency_total_localtax2;
504 public $last_main_doc;
529 public $note_private;
553 public $total_localtax1;
559 public $total_localtax2;
576 public $comments = array();
602 public $date_creation;
607 public $date_validation;
623 public $date_cloture;
635 public $user_creation;
640 public $user_creation_id;
652 public $user_validation;
657 public $user_validation_id;
662 public $user_closing_id;
668 public $user_modification;
673 public $user_modification_id;
676 public $next_prev_filter;
681 public $specimen = 0;
701 public $labelStatus = array();
706 public $labelStatusShort = array();
717 public $showphoto_on_popup;
722 public $nb = array();
737 public $extraparams = array();
742 protected $childtables = array();
749 protected $childtablesoncascade = array();
759 public $cond_reglement_supplier_id;
764 public $deposit_percent;
770 public $retained_warranty_fk_cond_reglement;
775 public $warehouse_id;
794 $sql =
"SELECT rowid, ref, ref_ext";
795 $sql .=
" FROM ".$db->prefix().$element;
796 $sql .=
" WHERE entity IN (".getEntity($element).
")";
799 $sql .=
" AND rowid = ".((int) $id);
801 $sql .=
" AND ref = '".$db->escape($ref).
"'";
802 } elseif ($ref_ext) {
803 $sql .=
" AND ref_ext = '".$db->escape($ref_ext).
"'";
805 $error =
'ErrorWrongParameters';
809 if ($ref || $ref_ext) {
810 $sql .=
" AND entity = ".((int) $conf->entity);
813 dol_syslog(get_class().
"::isExistingObject", LOG_DEBUG);
814 $resql = $db->query($sql);
816 $num = $db->num_rows($resql);
834 if (!empty($object->error)) {
835 $this->error = $object->error;
837 if (!empty($object->errors)) {
838 $this->errors = array_merge($this->errors, $object->errors);
863 global $action, $extrafields, $langs, $hookmanager;
866 $MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP =
getDolGlobalInt(
'MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP', 3);
872 if (!empty($extrafields->attributes[$this->table_element][
'label'])) {
873 $datas[
'opendivextra'] =
'<div class="centpercent wordbreak divtooltipextra">';
874 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
875 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
878 if ($count >= abs($MAX_EXTRAFIELDS_TO_SHOW_IN_TOOLTIP)) {
879 $datas[
'more_extrafields'] =
'<br>...';
883 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
884 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
886 if ($enabled && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
887 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
890 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
891 $perms =
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
893 if (empty($enabled)) {
896 if (abs($enabled) != 1 && abs($enabled) != 3 && abs($enabled) != 5 && abs($enabled) != 4) {
902 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
903 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
905 $labelextra = $langs->trans((
string) $extrafields->attributes[$this->table_element][
'label'][$key]);
906 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
907 $datas[$key]=
'<br><b><u>'. $labelextra .
'</u></b>';
909 $value = (empty($this->array_options[
'options_' . $key]) ?
'' : $this->array_options[
'options_' . $key]);
910 $datas[$key]=
'<br><b>'. $labelextra .
':</b> ' . $extrafields->showOutputField($key, $value,
'', $this->table_element);
914 $datas[
'closedivextra'] =
'</div>';
917 $hookmanager->initHooks(array($this->element .
'dao'));
919 'tooltipcontentarray' => &$datas,
923 $hookmanager->executeHooks(
'getTooltipContent', $parameters, $this, $action);
926 $label = implode($datas);
939 return $this->error.(is_array($this->errors) ? (($this->error !=
'' ?
', ' :
'').join(
', ', $this->errors)) :
'');
953 $parameters = array(
'objref'=>$objref);
955 $reshook = $hookmanager->executeHooks(
'getFormatedCustomerRef', $parameters, $this, $action);
957 return $hookmanager->resArray[
'objref'];
959 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
972 $parameters = array(
'objref'=>$objref);
974 $reshook = $hookmanager->executeHooks(
'getFormatedSupplierRef', $parameters, $this, $action);
976 return $hookmanager->resArray[
'objref'];
978 return $objref.(isset($hookmanager->resArray[
'objref']) ? $hookmanager->resArray[
'objref'] :
'');
990 public function getFullAddress($withcountry = 0, $sep =
"\n", $withregion = 0, $extralangcode =
'')
992 if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) {
993 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
994 $tmparray =
getCountry($this->country_id,
'all');
995 $this->country_code = $tmparray[
'code'];
996 $this->country = $tmparray[
'label'];
999 if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_code))) {
1000 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
1001 $tmparray =
getState($this->state_id,
'all', 0, 1);
1002 $this->state_code = $tmparray[
'code'];
1003 $this->state = $tmparray[
'label'];
1004 $this->region_code = $tmparray[
'region_code'];
1005 $this->region = $tmparray[
'region'];
1022 global $user, $dolibarr_main_url_root;
1024 if (empty($this->last_main_doc)) {
1028 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
1029 $ecmfile =
new EcmFiles($this->db);
1030 $result = $ecmfile->fetch(0,
'', $this->last_main_doc);
1032 $this->error = $ecmfile->error;
1033 $this->errors = $ecmfile->errors;
1037 if (empty($ecmfile->id)) {
1039 if ($initsharekey) {
1040 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1062 } elseif (empty($ecmfile->share)) {
1064 if ($initsharekey) {
1065 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1067 $ecmfile->update($user);
1073 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1077 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1086 if (!empty($ecmfile->share)) {
1087 $paramlink .= ($paramlink ?
'&' :
'').
'hashp='.$ecmfile->share;
1089 if ($forcedownload) {
1090 $paramlink .= ($paramlink ?
'&' :
'').
'attachment=1';
1093 if ($relativelink) {
1094 $linktoreturn =
'document.php'.($paramlink ?
'?'.$paramlink :
'');
1096 $linktoreturn = $urlwithroot.
'/document.php'.($paramlink ?
'?'.$paramlink :
'');
1100 return $linktoreturn;
1114 public function add_contact($fk_socpeople, $type_contact, $source =
'external', $notrigger = 0)
1117 global $user, $langs;
1120 dol_syslog(get_class($this).
"::add_contact $fk_socpeople, $type_contact, $source, $notrigger");
1123 if ($fk_socpeople <= 0) {
1124 $langs->load(
"errors");
1125 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"1");
1126 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1129 if (!$type_contact) {
1130 $langs->load(
"errors");
1131 $this->error = $langs->trans(
"ErrorWrongValueForParameterX",
"2");
1132 dol_syslog(get_class($this).
"::add_contact ".$this->error, LOG_ERR);
1136 $id_type_contact = 0;
1137 if (is_numeric($type_contact)) {
1138 $id_type_contact = $type_contact;
1141 $sql =
"SELECT tc.rowid";
1142 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1143 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1144 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1145 $sql .=
" AND tc.code='".$this->db->escape($type_contact).
"' AND tc.active=1";
1147 $resql = $this->db->query($sql);
1149 $obj = $this->db->fetch_object($resql);
1151 $id_type_contact = $obj->rowid;
1156 if ($id_type_contact == 0) {
1157 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");
1165 $already_added =
false;
1166 if (is_array($TListeContacts) && !empty($TListeContacts)) {
1167 foreach ($TListeContacts as $array_contact) {
1168 if ($array_contact[
'status'] == 4 && $array_contact[
'id'] == $fk_socpeople && $array_contact[
'fk_c_type_contact'] == $id_type_contact) {
1169 $already_added =
true;
1175 if (!$already_added) {
1179 $sql =
"INSERT INTO ".$this->db->prefix().
"element_contact";
1180 $sql .=
" (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) ";
1181 $sql .=
" VALUES (".$this->id.
", ".((int) $fk_socpeople).
" , ";
1182 $sql .=
"'".$this->db->idate($datecreate).
"'";
1183 $sql .=
", 4, ".((int) $id_type_contact);
1186 $resql = $this->db->query($sql);
1189 $result = $this->
call_trigger(strtoupper($this->element).
'_ADD_CONTACT', $user);
1191 $this->db->rollback();
1196 $this->db->commit();
1199 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1200 $this->error = $this->db->errno();
1201 $this->db->rollback();
1204 $this->error = $this->db->lasterror();
1205 $this->db->rollback();
1225 $contacts = $objFrom->liste_contact(-1, $source);
1226 foreach ($contacts as $contact) {
1227 if ($this->
add_contact($contact[
'id'], $contact[
'fk_c_type_contact'], $contact[
'source']) < 0) {
1244 public function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0)
1248 $sql =
"UPDATE ".$this->db->prefix().
"element_contact set";
1249 $sql .=
" statut = ".$statut;
1250 if ($type_contact_id) {
1251 $sql .=
", fk_c_type_contact = ".((int) $type_contact_id);
1253 if ($fk_socpeople) {
1254 $sql .=
", fk_socpeople = ".((int) $fk_socpeople);
1256 $sql .=
" where rowid = ".((int) $rowid);
1257 $resql = $this->db->query($sql);
1261 $this->error = $this->db->lasterror();
1283 if (!$error && empty($notrigger)) {
1285 $this->context[
'contact_id'] = ((int) $rowid);
1286 $result = $this->
call_trigger(strtoupper($this->element).
'_DELETE_CONTACT', $user);
1294 dol_syslog(get_class($this).
"::delete_contact", LOG_DEBUG);
1296 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"element_contact";
1297 $sql .=
" WHERE rowid = ".((int) $rowid);
1299 $result = $this->db->query($sql);
1302 $this->errors[] = $this->db->lasterror();
1307 $this->db->commit();
1310 $this->error = $this->db->lasterror();
1311 $this->db->rollback();
1331 if (!empty($typeContact)) {
1332 foreach ($typeContact as $key => $value) {
1333 array_push($temp, $key);
1335 $listId = implode(
",", $temp);
1340 if (empty($listId)) {
1344 $sql =
"DELETE FROM ".$this->db->prefix().
"element_contact";
1345 $sql .=
" WHERE element_id = ".((int) $this->
id);
1346 $sql .=
" AND fk_c_type_contact IN (".$this->db->sanitize($listId).
")";
1348 dol_syslog(get_class($this).
"::delete_linked_contact", LOG_DEBUG);
1349 if ($this->db->query($sql)) {
1352 $this->error = $this->db->lasterror();
1369 public function liste_contact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1, $arrayoftcids = array())
1376 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
1377 if ($source ==
'internal') {
1378 $sql .=
", '-1' as socid, t.statut as statuscontact, t.login, t.photo";
1380 if ($source ==
'external' || $source ==
'thirdparty') {
1381 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
1383 $sql .=
", t.civility as civility, t.lastname as lastname, t.firstname, t.email";
1384 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_label";
1385 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact tc,";
1386 $sql .=
" ".$this->db->prefix().
"element_contact ec";
1387 if ($source ==
'internal') {
1388 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user t on ec.fk_socpeople = t.rowid";
1390 if ($source ==
'external' || $source ==
'thirdparty') {
1391 $sql .=
" LEFT JOIN ".$this->db->prefix().
"socpeople t on ec.fk_socpeople = t.rowid";
1393 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
1394 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1395 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1397 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1399 if ($source ==
'internal') {
1400 $sql .=
" AND tc.source = 'internal'";
1402 $sql .=
" AND t.statut = ".((int) $status);
1405 if ($source ==
'external' || $source ==
'thirdparty') {
1406 $sql .=
" AND tc.source = 'external'";
1408 $sql .=
" AND t.statut = ".((int) $status);
1411 $sql .=
" AND tc.active = 1";
1412 if ($statusoflink >= 0) {
1413 $sql .=
" AND ec.statut = ".((int) $statusoflink);
1415 $sql .=
" ORDER BY t.lastname ASC";
1417 dol_syslog(get_class($this).
"::liste_contact", LOG_DEBUG);
1418 $resql = $this->db->query($sql);
1420 $num = $this->db->num_rows($resql);
1423 $obj = $this->db->fetch_object($resql);
1426 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
1427 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1429 'parentId' => $this->
id,
1430 'source' => $obj->source,
1431 'socid' => $obj->socid,
1433 'nom' => $obj->lastname,
1434 'civility' => $obj->civility,
1435 'lastname' => $obj->lastname,
1436 'firstname' => $obj->firstname,
1437 'email'=>$obj->email,
1438 'login'=> (empty($obj->login) ?
'' : $obj->login),
1439 'photo' => (empty($obj->photo) ?
'' : $obj->photo),
1440 'statuscontact' => $obj->statuscontact,
1441 'rowid' => $obj->rowid,
1442 'code' => $obj->code,
1443 'libelle' => $libelle_type,
1444 'status' => $obj->statuslink,
1445 'fk_c_type_contact' => $obj->fk_c_type_contact
1448 $tab[$i] = $obj->id;
1456 $this->error = $this->db->lasterror();
1471 $sql =
"SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,";
1472 $sql .=
" tc.code, tc.libelle as type_label";
1473 $sql .=
" FROM (".$this->db->prefix().
"element_contact as ec, ".$this->db->prefix().
"c_type_contact as tc)";
1474 $sql .=
" WHERE ec.rowid =".((int) $rowid);
1475 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
1476 $sql .=
" AND tc.element = '".$this->db->escape($this->element).
"'";
1478 dol_syslog(get_class($this).
"::swapContactStatus", LOG_DEBUG);
1479 $resql = $this->db->query($sql);
1481 $obj = $this->db->fetch_object($resql);
1482 $newstatut = ($obj->statut == 4) ? 5 : 4;
1484 $this->db->free($resql);
1487 $this->error = $this->db->error();
1504 public function liste_type_contact($source =
'internal', $order =
'position', $option = 0, $activeonly = 0, $code =
'')
1509 if (empty($order)) {
1510 $order =
'position';
1512 if ($order ==
'position') {
1517 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position";
1518 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1519 $sql .=
" WHERE tc.element='".$this->db->escape($this->element).
"'";
1520 if ($activeonly == 1) {
1521 $sql .=
" AND tc.active=1";
1523 if (!empty($source) && $source !=
'all') {
1524 $sql .=
" AND tc.source='".$this->db->escape($source).
"'";
1526 if (!empty($code)) {
1527 $sql .=
" AND tc.code='".$this->db->escape($code).
"'";
1529 $sql .= $this->db->order($order,
'ASC');
1532 $resql = $this->db->query($sql);
1534 $num = $this->db->num_rows($resql);
1537 $obj = $this->db->fetch_object($resql);
1539 $transkey =
"TypeContact_".$this->element.
"_".$source.
"_".$obj->code;
1540 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1541 if (empty($option)) {
1542 $tab[$obj->rowid] = $libelle_type;
1544 $tab[$obj->code] = $libelle_type;
1550 $this->error = $this->db->lasterror();
1567 public function listeTypeContacts($source =
'internal', $option = 0, $activeonly = 0, $code =
'', $element =
'', $excludeelement =
'')
1569 global $langs, $conf;
1571 $langs->loadLangs(array(
'bills',
'contracts',
'interventions',
'orders',
'projects',
'propal',
'ticket',
'agenda'));
1575 $sql =
"SELECT DISTINCT tc.rowid, tc.code, tc.libelle as type_label, tc.position, tc.element, tc.module";
1576 $sql .=
" FROM ".$this->db->prefix().
"c_type_contact as tc";
1578 $sqlWhere = array();
1579 if (!empty($element)) {
1580 $sqlWhere[] =
" tc.element='".$this->db->escape($element).
"'";
1582 if (!empty($excludeelement)) {
1583 $sqlWhere[] =
" tc.element <> '".$this->db->escape($excludeelement).
"'";
1586 if ($activeonly == 1) {
1587 $sqlWhere[] =
" tc.active=1";
1590 if (!empty($source) && $source !=
'all') {
1591 $sqlWhere[] =
" tc.source='".$this->db->escape($source).
"'";
1594 if (!empty($code)) {
1595 $sqlWhere[] =
" tc.code='".$this->db->escape($code).
"'";
1598 if (count($sqlWhere) > 0) {
1599 $sql .=
" WHERE ".implode(
' AND ', $sqlWhere);
1602 $sql .= $this->db->order(
'tc.element, tc.position',
'ASC');
1605 $resql = $this->db->query($sql);
1607 $num = $this->db->num_rows($resql);
1609 $langs->loadLangs(array(
"propal",
"orders",
"bills",
"suppliers",
"contracts",
"supplier_proposal"));
1611 while ($obj = $this->db->fetch_object($resql)) {
1612 $modulename = $obj->module ?? $obj->element;
1613 if (strpos($obj->element,
'project') !==
false) {
1614 $modulename =
'projet';
1615 } elseif ($obj->element ==
'contrat') {
1616 $element =
'contract';
1617 } elseif ($obj->element ==
'action') {
1618 $modulename =
'agenda';
1619 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1620 $modulename =
'fournisseur';
1621 } elseif (strpos($obj->element,
'supplier') !==
false && $obj->element !=
'supplier_proposal') {
1622 $modulename =
'fournisseur';
1624 if (!empty($conf->{$modulename}->enabled)) {
1625 $libelle_element = $langs->trans(
'ContactDefault_'.$obj->element);
1626 $tmpelement = $obj->element;
1627 $transkey =
"TypeContact_".$tmpelement.
"_".$source.
"_".$obj->code;
1628 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_label);
1629 if (empty($option)) {
1630 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1632 $tab[$obj->rowid] = $libelle_element.
' - '.$libelle_type;
1639 $this->error = $this->db->lasterror();
1662 if ($this->element ==
'shipping' && $this->origin_id != 0) {
1663 $id = $this->origin_id;
1664 $element =
'commande';
1665 } elseif ($this->element ==
'reception' && $this->origin_id != 0) {
1666 $id = $this->origin_id;
1667 $element =
'order_supplier';
1670 $element = $this->element;
1673 $sql =
"SELECT ec.fk_socpeople";
1674 $sql .=
" FROM ".$this->db->prefix().
"element_contact as ec,";
1675 if ($source ==
'internal') {
1676 $sql .=
" ".$this->db->prefix().
"user as c,";
1678 if ($source ==
'external') {
1679 $sql .=
" ".$this->db->prefix().
"socpeople as c,";
1681 $sql .=
" ".$this->db->prefix().
"c_type_contact as tc";
1682 $sql .=
" WHERE ec.element_id = ".((int) $id);
1683 $sql .=
" AND ec.fk_socpeople = c.rowid";
1684 if ($source ==
'internal') {
1685 $sql .=
" AND c.entity IN (".getEntity(
'user').
")";
1687 if ($source ==
'external') {
1688 $sql .=
" AND c.entity IN (".getEntity(
'societe').
")";
1690 $sql .=
" AND ec.fk_c_type_contact = tc.rowid";
1691 $sql .=
" AND tc.element = '".$this->db->escape($element).
"'";
1692 $sql .=
" AND tc.source = '".$this->db->escape($source).
"'";
1694 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
1696 $sql .=
" AND tc.active = 1";
1698 $sql .=
" AND ec.statut = ".((int) $status);
1701 dol_syslog(get_class($this).
"::getIdContact", LOG_DEBUG);
1702 $resql = $this->db->query($sql);
1704 while ($obj = $this->db->fetch_object($resql)) {
1705 $result[$i] = $obj->fk_socpeople;
1709 $this->error = $this->db->error();
1726 if (empty($contactid)) {
1727 $contactid = $this->contact_id;
1730 if (empty($contactid)) {
1734 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1735 $contact =
new Contact($this->db);
1736 $result = $contact->fetch($contactid);
1737 $this->contact = $contact;
1751 if (empty($this->socid) && empty($this->fk_soc) && empty($force_thirdparty_id)) {
1755 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1757 $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : 0);
1758 if ($force_thirdparty_id) {
1759 $idtofetch = $force_thirdparty_id;
1763 $thirdparty =
new Societe($this->db);
1764 $result = $thirdparty->fetch($idtofetch);
1766 $this->errors=array_merge($this->errors, $thirdparty->errors);
1768 $this->thirdparty = $thirdparty;
1771 if (
getDolGlobalString(
'PRODUIT_MULTIPRICES') && empty($this->thirdparty->price_level)) {
1772 $this->thirdparty->price_level = 1;
1791 if (!$this->table_ref_field) {
1795 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
1796 $sql .=
" WHERE ".$this->table_ref_field.
" LIKE '".$this->db->escape($ref).
"'";
1799 $query = $this->db->query($sql);
1801 if (!$this->db->num_rows($query)) {
1805 $result = $this->db->fetch_object($query);
1807 if (method_exists($this,
'fetch')) {
1808 return $this->fetch($result->rowid);
1810 $this->error =
'Fetch method not implemented on '.get_class($this);
1811 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
1812 array_push($this->errors, $this->error);
1830 dol_syslog(get_class($this).
'::fetch_barcode this->element='.$this->element.
' this->barcode_type='.$this->barcode_type);
1832 $idtype = $this->barcode_type;
1833 if (empty($idtype) && $idtype !=
'0') {
1834 if ($this->element ==
'product' &&
getDolGlobalString(
'PRODUIT_DEFAULT_BARCODE_TYPE')) {
1835 $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
1836 } elseif ($this->element ==
'societe') {
1837 $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
1839 dol_syslog(
'Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
1844 if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) {
1845 $sql =
"SELECT rowid, code, libelle as label, coder";
1846 $sql .=
" FROM ".$this->db->prefix().
"c_barcode_type";
1847 $sql .=
" WHERE rowid = ".((int) $idtype);
1848 dol_syslog(get_class($this).
'::fetch_barcode', LOG_DEBUG);
1849 $resql = $this->db->query($sql);
1851 $obj = $this->db->fetch_object($resql);
1852 $this->barcode_type = $obj->rowid;
1853 $this->barcode_type_code = $obj->code;
1854 $this->barcode_type_label = $obj->label;
1855 $this->barcode_type_coder = $obj->coder;
1875 return $this->fetch_projet();
1887 include_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
1889 if (empty($this->fk_project) && !empty($this->fk_projet)) {
1890 $this->fk_project = $this->fk_projet;
1892 if (empty($this->fk_project)) {
1896 $project =
new Project($this->db);
1897 $result = $project->fetch($this->fk_project);
1899 $this->projet = $project;
1900 $this->project = $project;
1913 include_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
1915 if (empty($this->fk_product)) {
1919 $product =
new Product($this->db);
1920 $result = $product->fetch($this->fk_product);
1922 $this->product = $product;
1936 $user =
new User($this->db);
1937 $result = $user->fetch($userid);
1938 $this->
user = $user;
1953 if ($this->origin ==
'shipping') {
1954 $this->origin =
'expedition';
1956 if ($this->origin ==
'delivery') {
1957 $this->origin =
'livraison';
1959 if ($this->origin ==
'order_supplier' || $this->origin ==
'supplier_order') {
1960 $this->origin =
'commandeFournisseur';
1963 $origin = $this->origin;
1965 $classname = ucfirst($origin);
1966 $this->origin_object =
new $classname($this->db);
1967 $this->origin_object->fetch($this->origin_id);
1970 $this->$origin = $this->origin_object;
1988 $sql =
"SELECT rowid FROM ".$this->db->prefix().$table;
1989 $sql .=
" WHERE ".$field.
" = '".$this->db->escape($key).
"'";
1990 if (!empty($element)) {
1991 $sql .=
" AND entity IN (".getEntity($element).
")";
1993 $sql .=
" AND entity = ".((int) $conf->entity);
1996 dol_syslog(get_class($this).
'::fetchObjectFrom', LOG_DEBUG);
1997 $resql = $this->db->query($sql);
1999 $obj = $this->db->fetch_object($resql);
2002 if (method_exists($this,
'fetch')) {
2003 return $this->fetch($obj->rowid);
2005 $this->error =
'fetch() method not implemented on '.get_class($this);
2006 dol_syslog(get_class($this).
'::fetchOneLike Error='.$this->error, LOG_ERR);
2007 array_push($this->errors, $this->error);
2027 if (!empty($id) && !empty($field) && !empty($table)) {
2028 $sql =
"SELECT ".$field.
" FROM ".$this->db->prefix().$table;
2029 $sql .=
" WHERE rowid = ".((int) $id);
2031 dol_syslog(get_class($this).
'::getValueFrom', LOG_DEBUG);
2032 $resql = $this->db->query($sql);
2034 $row = $this->db->fetch_row($resql);
2057 public function setValueFrom($field, $value, $table =
'', $id =
null, $format =
'', $id_field =
'', $fuser =
null, $trigkey =
'', $fk_user_field =
'fk_user_modif')
2061 if (empty($table)) {
2062 $table = $this->table_element;
2067 if (empty($format)) {
2070 if (empty($id_field)) {
2071 $id_field =
'rowid';
2075 if ($table ==
'product' && $field ==
'note_private') {
2079 if (in_array($table, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
2080 $fk_user_field =
'fk_user_mod';
2082 if (in_array($table, array(
'prelevement_bons'))) {
2083 $fk_user_field =
'';
2089 $sql =
"SELECT " . $field;
2090 $sql .=
" FROM " . MAIN_DB_PREFIX . $table;
2091 $sql .=
" WHERE " . $id_field .
" = " . ((int) $id);
2093 $resql = $this->db->query($sql);
2095 if ($obj = $this->db->fetch_object($resql)) {
2096 if ($format ==
'date') {
2097 $oldvalue = $this->db->jdate($obj->$field);
2099 $oldvalue = $obj->$field;
2103 $this->error = $this->db->lasterror();
2114 $sql =
"UPDATE ".$this->db->prefix().$table.
" SET ";
2116 if ($format ==
'text') {
2117 $sql .= $field.
" = '".$this->db->escape($value).
"'";
2118 } elseif ($format ==
'int') {
2119 $sql .= $field.
" = ".((int) $value);
2120 } elseif ($format ==
'date') {
2121 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value).
"'" :
"null");
2122 } elseif ($format ==
'dategmt') {
2123 $sql .= $field.
" = ".($value ?
"'".$this->db->idate($value,
'gmt').
"'" :
"null");
2126 if ($fk_user_field) {
2127 if (!empty($fuser) && is_object($fuser)) {
2128 $sql .=
", ".$fk_user_field.
" = ".((int) $fuser->id);
2129 } elseif (empty($fuser) || $fuser !=
'none') {
2130 $sql .=
", ".$fk_user_field.
" = ".((int) $user->id);
2134 $sql .=
" WHERE ".$id_field.
" = ".((int) $id);
2136 $resql = $this->db->query($sql);
2140 if (method_exists($this,
'fetch')) {
2141 $result = $this->fetch($id);
2143 $result = $this->fetchCommon($id);
2145 $this->oldcopy = clone $this;
2146 if (property_exists($this->oldcopy, $field)) {
2147 $this->oldcopy->$field = $oldvalue;
2151 $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user);
2159 if (property_exists($this, $field)) {
2160 $this->$field = $value;
2162 $this->db->commit();
2165 $this->db->rollback();
2169 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2170 $this->error =
'DB_ERROR_RECORD_ALREADY_EXISTS';
2172 $this->error = $this->db->lasterror();
2174 $this->db->rollback();
2192 global $conf, $user;
2194 if (!$this->table_element) {
2195 dol_print_error(
'', get_class($this).
"::load_previous_next_ref was called on objet with property table_element not defined");
2198 if ($fieldid ==
'none') {
2203 if (in_array($this->table_element, array(
'facture_rec',
'facture_fourn_rec')) && $fieldid ==
'title') {
2209 if ($user->socid > 0) {
2210 $socid = $user->socid;
2215 $aliastablesociete =
's';
2216 if ($this->element ==
'societe') {
2217 $aliastablesociete =
'te';
2219 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2220 $sql =
"SELECT MAX(te.".$fieldid.
")";
2221 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2222 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2223 $tmparray = explode(
'@', $this->ismultientitymanaged);
2224 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2225 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2226 $sql .=
", ".$this->db->prefix().
"societe as s";
2227 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2228 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2230 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2231 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2233 if ($fieldid ==
'rowid') {
2234 $sql .=
" WHERE te.".$fieldid.
" < ".((int) $this->
id);
2236 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($this->
ref).
"'";
2238 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2239 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2241 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2242 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2244 if (!empty($filter)) {
2245 if (!preg_match(
'/^\s*AND/i', $filter)) {
2250 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2251 $tmparray = explode(
'@', $this->ismultientitymanaged);
2252 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2253 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2254 $sql .=
' AND te.fk_soc = s.rowid';
2256 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2257 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2258 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2259 $sql .=
" AND te.entity IS NOT NULL";
2261 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2264 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2267 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2268 $tmparray = explode(
'@', $this->ismultientitymanaged);
2269 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2271 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2272 $sql .=
' AND te.fk_soc = '.((int) $socid);
2274 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2275 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2277 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2278 $sql .=
' AND te.rowid = '.((int) $socid);
2282 $result = $this->db->query($sql);
2284 $this->error = $this->db->lasterror();
2287 $row = $this->db->fetch_row($result);
2288 $this->ref_previous = $row[0];
2290 $sql =
"SELECT MIN(te.".$fieldid.
")";
2291 $sql .=
" FROM ".(empty($nodbprefix) ? $this->db->prefix() :
'').$this->table_element.
" as te";
2292 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2293 $tmparray = explode(
'@', $this->ismultientitymanaged);
2294 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2295 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2296 $sql .=
", ".$this->db->prefix().
"societe as s";
2297 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2298 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2300 if ($restrictiononfksoc && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2301 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2303 if ($fieldid ==
'rowid') {
2304 $sql .=
" WHERE te.".$fieldid.
" > ".((int) $this->
id);
2306 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($this->
ref).
"'";
2308 if ($restrictiononfksoc == 1 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2309 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2311 if ($restrictiononfksoc == 2 && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2312 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2314 if (!empty($filter)) {
2315 if (!preg_match(
'/^\s*AND/i', $filter)) {
2320 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2321 $tmparray = explode(
'@', $this->ismultientitymanaged);
2322 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2323 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && !$user->hasRight(
'societe',
'client',
'voir') && !$socid) {
2324 $sql .=
' AND te.fk_soc = s.rowid';
2326 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2327 if ($this->element ==
'user' &&
getDolGlobalInt(
'MULTICOMPANY_TRANSVERSE_MODE')) {
2328 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2329 $sql .=
" AND te.entity IS NOT NULL";
2331 $sql .=
" AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix().
"usergroup_user as ug WHERE ug.entity IN (".
getEntity(
'usergroup').
"))";
2334 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2337 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2338 $tmparray = explode(
'@', $this->ismultientitymanaged);
2339 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2341 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2342 $sql .=
' AND te.fk_soc = '.((int) $socid);
2344 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2345 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2347 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2348 $sql .=
' AND te.rowid = '.((int) $socid);
2353 $result = $this->db->query($sql);
2355 $this->error = $this->db->lasterror();
2358 $row = $this->db->fetch_row($result);
2359 $this->ref_next = $row[0];
2374 $contactAlreadySelected = array();
2375 $tab = $this->liste_contact(-1, $source);
2379 if ($source ==
'thirdparty') {
2380 $contactAlreadySelected[$i] = $tab[$i][
'socid'];
2382 $contactAlreadySelected[$i] = $tab[$i][
'id'];
2386 return $contactAlreadySelected;
2402 if (!$this->table_element) {
2403 dol_syslog(get_class($this).
"::setProject was called on objet with property table_element not defined", LOG_ERR);
2407 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2408 if (!empty($this->fields[
'fk_project'])) {
2410 $sql .=
" SET fk_project = ".((int) $projectid);
2412 $sql .=
" SET fk_project = NULL";
2414 $sql .=
' WHERE rowid = '.((int) $this->
id);
2415 } elseif ($this->table_element ==
'actioncomm') {
2417 $sql .=
" SET fk_project = ".((int) $projectid);
2419 $sql .=
" SET fk_project = NULL";
2421 $sql .=
' WHERE id = '.((int) $this->
id);
2424 $sql .=
' SET fk_projet = '.((int) $projectid);
2426 $sql .=
' SET fk_projet = NULL';
2428 $sql .=
" WHERE rowid = ".((int) $this->
id);
2433 dol_syslog(get_class($this).
"::setProject", LOG_DEBUG);
2434 if ($this->db->query($sql)) {
2435 $this->fk_project = ((int) $projectid);
2442 if (!$error && !$notrigger) {
2444 $result = $this->call_trigger(strtoupper($this->element) .
'_MODIFY', $user);
2453 $this->db->rollback();
2456 $this->db->commit();
2474 dol_syslog(get_class($this).
'::setPaymentMethods('.$id.
')');
2476 if ($this->
statut >= 0 || $this->element ==
'societe') {
2478 $fieldname =
'fk_mode_reglement';
2479 if ($this->element ==
'societe') {
2480 $fieldname =
'mode_reglement';
2482 if (get_class($this) ==
'Fournisseur') {
2483 $fieldname =
'mode_reglement_supplier';
2485 if (get_class($this) ==
'Tva') {
2486 $fieldname =
'fk_typepayment';
2488 if (get_class($this) ==
'Salary') {
2489 $fieldname =
'fk_typepayment';
2492 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2493 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2494 $sql .=
' WHERE rowid='.((int) $this->
id);
2496 if ($this->db->query($sql)) {
2497 $this->mode_reglement_id = $id;
2499 if (get_class($this) ==
'Fournisseur') {
2500 $this->mode_reglement_supplier_id = $id;
2503 if (!$error && !$notrigger) {
2505 if (get_class($this) ==
'Commande') {
2506 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2508 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
2517 dol_syslog(get_class($this).
'::setPaymentMethods Error '.$this->db->error());
2518 $this->error = $this->db->error();
2522 dol_syslog(get_class($this).
'::setPaymentMethods, status of the object is incompatible');
2523 $this->error =
'Status of the object is incompatible '.$this->statut;
2536 dol_syslog(get_class($this).
'::setMulticurrencyCode('.$code.
')');
2537 if ($this->
statut >= 0 || $this->element ==
'societe') {
2538 $fieldname =
'multicurrency_code';
2540 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2541 $sql .=
" SET ".$fieldname.
" = '".$this->db->escape($code).
"'";
2542 $sql .=
' WHERE rowid='.((int) $this->
id);
2544 if ($this->db->query($sql)) {
2545 $this->multicurrency_code = $code;
2549 $this->setMulticurrencyRate($rate, 2);
2554 dol_syslog(get_class($this).
'::setMulticurrencyCode Error '.$sql.
' - '.$this->db->error());
2555 $this->error = $this->db->error();
2559 dol_syslog(get_class($this).
'::setMulticurrencyCode, status of the object is incompatible');
2560 $this->error =
'Status of the object is incompatible '.$this->statut;
2572 public function setMulticurrencyRate($rate, $mode = 1)
2574 dol_syslog(get_class($this).
'::setMulticurrencyRate('.$rate.
','.$mode.
')');
2575 if ($this->
statut >= 0 || $this->element ==
'societe') {
2576 $fieldname =
'multicurrency_tx';
2578 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2579 $sql .=
" SET ".$fieldname.
" = ".((float) $rate);
2580 $sql .=
' WHERE rowid='.((int) $this->
id);
2582 if ($this->db->query($sql)) {
2583 $this->multicurrency_tx = $rate;
2586 if (!empty($this->lines)) {
2587 foreach ($this->lines as &$line) {
2590 $line->subprice = 0;
2595 $line->multicurrency_subprice = 0;
2598 switch ($this->element) {
2606 $line->remise_percent,
2608 $line->localtax1_tx,
2609 $line->localtax2_tx,
2610 ($line->description ? $line->description : $line->desc),
2613 $line->special_code,
2614 $line->fk_parent_line,
2615 $line->skip_update_total,
2616 $line->fk_fournprice,
2619 $line->product_type,
2622 $line->array_options,
2624 $line->multicurrency_subprice
2632 ($line->description ? $line->description : $line->desc),
2635 $line->remise_percent,
2637 $line->localtax1_tx,
2638 $line->localtax2_tx,
2643 $line->product_type,
2644 $line->fk_parent_line,
2645 $line->skip_update_total,
2646 $line->fk_fournprice,
2649 $line->special_code,
2650 $line->array_options,
2652 $line->multicurrency_subprice
2660 ($line->description ? $line->description : $line->desc),
2663 $line->remise_percent,
2667 $line->localtax1_tx,
2668 $line->localtax2_tx,
2671 $line->product_type,
2672 $line->fk_parent_line,
2673 $line->skip_update_total,
2674 $line->fk_fournprice,
2677 $line->special_code,
2678 $line->array_options,
2679 $line->situation_percent,
2681 $line->multicurrency_subprice
2684 case 'supplier_proposal':
2691 $line->remise_percent,
2693 $line->localtax1_tx,
2694 $line->localtax2_tx,
2695 ($line->description ? $line->description : $line->desc),
2698 $line->special_code,
2699 $line->fk_parent_line,
2700 $line->skip_update_total,
2701 $line->fk_fournprice,
2704 $line->product_type,
2705 $line->array_options,
2707 $line->multicurrency_subprice
2710 case 'order_supplier':
2715 ($line->description ? $line->description : $line->desc),
2718 $line->remise_percent,
2720 $line->localtax1_tx,
2721 $line->localtax2_tx,
2724 $line->product_type,
2728 $line->array_options,
2730 $line->multicurrency_subprice,
2734 case 'invoice_supplier':
2739 ($line->description ? $line->description : $line->desc),
2742 $line->localtax1_tx,
2743 $line->localtax2_tx,
2748 $line->product_type,
2749 $line->remise_percent,
2753 $line->array_options,
2755 $line->multicurrency_subprice,
2760 dol_syslog(get_class($this).
'::setMulticurrencyRate no updateline defined', LOG_DEBUG);
2768 dol_syslog(get_class($this).
'::setMulticurrencyRate Error '.$sql.
' - '.$this->db->error());
2769 $this->error = $this->db->error();
2773 dol_syslog(get_class($this).
'::setMulticurrencyRate, status of the object is incompatible');
2774 $this->error =
'Status of the object is incompatible '.$this->statut;
2788 dol_syslog(get_class($this).
'::setPaymentTerms('.$id.
', '.var_export($deposit_percent,
true).
')');
2789 if ($this->
statut >= 0 || $this->element ==
'societe') {
2791 $fieldname =
'fk_cond_reglement';
2792 if ($this->element ==
'societe') {
2793 $fieldname =
'cond_reglement';
2795 if (get_class($this) ==
'Fournisseur') {
2796 $fieldname =
'cond_reglement_supplier';
2799 if (empty($deposit_percent) || $deposit_percent < 0) {
2803 if ($deposit_percent > 100) {
2804 $deposit_percent = 100;
2807 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2808 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2809 if (in_array($this->table_element, array(
'propal',
'commande',
'societe'))) {
2810 $sql .=
" , deposit_percent = " . (empty($deposit_percent) ?
'NULL' :
"'".$this->db->escape($deposit_percent).
"'");
2812 $sql .=
' WHERE rowid='.((int) $this->
id);
2814 if ($this->db->query($sql)) {
2815 $this->cond_reglement_id = $id;
2817 if (get_class($this) ==
'Fournisseur') {
2818 $this->cond_reglement_supplier_id = $id;
2820 $this->cond_reglement = $id;
2821 $this->deposit_percent = $deposit_percent;
2824 dol_syslog(get_class($this).
'::setPaymentTerms Error '.$sql.
' - '.$this->db->error());
2825 $this->error = $this->db->error();
2829 dol_syslog(get_class($this).
'::setPaymentTerms, status of the object is incompatible');
2830 $this->error =
'Status of the object is incompatible '.$this->statut;
2843 dol_syslog(get_class($this).
'::setTransportMode('.$id.
')');
2844 if ($this->
statut >= 0 || $this->element ==
'societe') {
2845 $fieldname =
'fk_transport_mode';
2846 if ($this->element ==
'societe') {
2847 $fieldname =
'transport_mode';
2849 if (get_class($this) ==
'Fournisseur') {
2850 $fieldname =
'transport_mode_supplier';
2853 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2854 $sql .=
" SET ".$fieldname.
" = ".(($id > 0 || $id ==
'0') ? ((
int) $id) :
'NULL');
2855 $sql .=
' WHERE rowid='.((int) $this->
id);
2857 if ($this->db->query($sql)) {
2858 $this->transport_mode_id = $id;
2860 if (get_class($this) ==
'Fournisseur') {
2861 $this->transport_mode_supplier_id = $id;
2865 dol_syslog(get_class($this).
'::setTransportMode Error '.$sql.
' - '.$this->db->error());
2866 $this->error = $this->db->error();
2870 dol_syslog(get_class($this).
'::setTransportMode, status of the object is incompatible');
2871 $this->error =
'Status of the object is incompatible '.$this->statut;
2884 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms('.$id.
')');
2885 if ($this->
statut >= 0 || $this->element ==
'societe') {
2886 $fieldname =
'retained_warranty_fk_cond_reglement';
2888 $sql =
'UPDATE '.$this->db->prefix().$this->table_element;
2889 $sql .=
" SET ".$fieldname.
" = ".((int) $id);
2890 $sql .=
' WHERE rowid='.((int) $this->
id);
2892 if ($this->db->query($sql)) {
2893 $this->retained_warranty_fk_cond_reglement = $id;
2896 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms Error '.$sql.
' - '.$this->db->error());
2897 $this->error = $this->db->error();
2901 dol_syslog(get_class($this).
'::setRetainedWarrantyPaymentTerms, status of the object is incompatible');
2902 $this->error =
'Status of the object is incompatible '.$this->statut;
2916 $fieldname =
'fk_delivery_address';
2917 if ($this->element ==
'delivery' || $this->element ==
'shipping') {
2918 $fieldname =
'fk_address';
2921 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ".$fieldname.
" = ".((int) $id);
2922 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = 0";
2924 if ($this->db->query($sql)) {
2925 $this->fk_delivery_address = $id;
2928 $this->error = $this->db->error();
2929 dol_syslog(get_class($this).
'::setDeliveryAddress Error '.$this->error);
2948 if (empty($userused)) {
2954 if (!$this->table_element) {
2955 dol_syslog(get_class($this).
"::setShippingMethod was called on objet with property table_element not defined", LOG_ERR);
2961 if ($shipping_method_id < 0) {
2962 $shipping_method_id =
'NULL';
2964 dol_syslog(get_class($this).
'::setShippingMethod('.$shipping_method_id.
')');
2966 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
2967 $sql .=
" SET fk_shipping_method = ".((int) $shipping_method_id);
2968 $sql .=
" WHERE rowid=".((int) $this->
id);
2969 $resql = $this->db->query($sql);
2971 dol_syslog(get_class($this).
'::setShippingMethod Error ', LOG_DEBUG);
2972 $this->error = $this->db->lasterror();
2977 $this->context = array(
'shippingmethodupdate'=>1);
2978 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $userused);
2986 $this->db->rollback();
2989 $this->shipping_method_id = ($shipping_method_id ==
'NULL') ?
null : $shipping_method_id;
2990 $this->db->commit();
3004 if (!$this->table_element) {
3005 dol_syslog(get_class($this).
"::setWarehouse was called on objet with property table_element not defined", LOG_ERR);
3008 if ($warehouse_id < 0) {
3009 $warehouse_id =
'NULL';
3011 dol_syslog(get_class($this).
'::setWarehouse('.$warehouse_id.
')');
3013 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3014 $sql .=
" SET fk_warehouse = ".((int) $warehouse_id);
3015 $sql .=
" WHERE rowid=".((int) $this->
id);
3017 if ($this->db->query($sql)) {
3018 $this->warehouse_id = ($warehouse_id ==
'NULL') ?
null : $warehouse_id;
3021 dol_syslog(get_class($this).
'::setWarehouse Error ', LOG_DEBUG);
3022 $this->error = $this->db->error();
3037 if (!$this->table_element) {
3038 dol_syslog(get_class($this).
"::setDocModel was called on objet with property table_element not defined", LOG_ERR);
3042 $newmodelpdf =
dol_trunc($modelpdf, 255);
3044 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3045 $sql .=
" SET model_pdf = '".$this->db->escape($newmodelpdf).
"'";
3046 $sql .=
" WHERE rowid = ".((int) $this->
id);
3048 dol_syslog(get_class($this).
"::setDocModel", LOG_DEBUG);
3049 $resql = $this->db->query($sql);
3051 $this->model_pdf = $modelpdf;
3072 if (empty($userused)) {
3078 if (!$this->table_element) {
3079 dol_syslog(get_class($this).
"::setBankAccount was called on objet with property table_element not defined", LOG_ERR);
3084 if ($fk_account < 0) {
3085 $fk_account =
'NULL';
3087 dol_syslog(get_class($this).
'::setBankAccount('.$fk_account.
')');
3089 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3090 $sql .=
" SET fk_account = ".((int) $fk_account);
3091 $sql .=
" WHERE rowid=".((int) $this->
id);
3093 $resql = $this->db->query($sql);
3095 dol_syslog(get_class($this).
'::setBankAccount Error '.$sql.
' - '.$this->db->error());
3096 $this->error = $this->db->lasterror();
3101 $this->context[
'bankaccountupdate'] = 1;
3102 $triggerName = strtoupper(get_class($this)).
'_MODIFY';
3104 if ($triggerName ==
'FACTUREREC_MODIFY') {
3105 $triggerName =
'BILLREC_MODIFY';
3107 $result = $this->call_trigger($triggerName, $userused);
3115 $this->db->rollback();
3118 $this->fk_account = ($fk_account ==
'NULL') ?
null : $fk_account;
3119 $this->db->commit();
3137 public function line_order($renum =
false, $rowidorder =
'ASC', $fk_parent_line =
true)
3140 if (!$this->table_element_line) {
3141 dol_syslog(get_class($this).
"::line_order was called on objet with property table_element_line not defined", LOG_ERR);
3144 if (!$this->fk_element) {
3145 dol_syslog(get_class($this).
"::line_order was called on objet with property fk_element not defined", LOG_ERR);
3149 $fieldposition =
'rang';
3150 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3151 $fieldposition =
'position';
3156 $sql =
"SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line;
3157 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3159 $sql .=
" AND " . $fieldposition .
" = 0";
3162 $sql .=
" AND " . $fieldposition .
" <> 0";
3165 dol_syslog(get_class($this).
"::line_order", LOG_DEBUG);
3166 $resql = $this->db->query($sql);
3168 $row = $this->db->fetch_row($resql);
3178 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3179 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3180 if ($fk_parent_line) {
3181 $sql .=
' AND fk_parent_line IS NULL';
3183 $sql .=
" ORDER BY " . $fieldposition .
" ASC, rowid " . $rowidorder;
3185 dol_syslog(get_class($this).
"::line_order search all parent lines", LOG_DEBUG);
3186 $resql = $this->db->query($sql);
3189 $num = $this->db->num_rows($resql);
3191 $row = $this->db->fetch_row($resql);
3193 $childrens = $this->getChildrenOfLine($row[0]);
3194 if (!empty($childrens)) {
3195 foreach ($childrens as $child) {
3196 array_push($rows, $child);
3203 if (!empty($rows)) {
3204 foreach ($rows as $key => $row) {
3205 $this->updateRangOfLine($row, ($key + 1));
3224 $fieldposition =
'rang';
3225 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3226 $fieldposition =
'position';
3231 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3232 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3233 $sql .=
' AND fk_parent_line = '.((int) $id);
3234 $sql .=
" ORDER BY " . $fieldposition .
" ASC";
3236 dol_syslog(get_class($this).
"::getChildrenOfLine search children lines for line ".$id, LOG_DEBUG);
3237 $resql = $this->db->query($sql);
3239 if ($this->db->num_rows($resql) > 0) {
3240 while ($row = $this->db->fetch_row($resql)) {
3242 if (!empty($includealltree)) {
3243 $rows = array_merge($rows, $this->getChildrenOfLine($row[0], $includealltree));
3259 public function line_up($rowid, $fk_parent_line =
true)
3262 $this->line_order(
false,
'ASC', $fk_parent_line);
3265 $rang = $this->getRangOfLine($rowid);
3268 $this->updateLineUp($rowid, $rang);
3282 $this->line_order(
false,
'ASC', $fk_parent_line);
3285 $rang = $this->getRangOfLine($rowid);
3288 $max = $this->line_max();
3291 $this->updateLineDown($rowid, $rang, $max);
3303 global $hookmanager;
3304 $fieldposition =
'rang';
3305 if (in_array($this->table_element_line, array(
'bom_bomline',
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3306 $fieldposition =
'position';
3309 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3310 $sql .=
' WHERE rowid = '.((int) $rowid);
3312 dol_syslog(get_class($this).
"::updateRangOfLine", LOG_DEBUG);
3313 if (!$this->db->query($sql)) {
3317 $parameters=array(
'rowid'=>$rowid,
'rang'=>$rang,
'fieldposition' => $fieldposition);
3319 $reshook = $hookmanager->executeHooks(
'afterRankOfLineUpdate', $parameters, $this, $action);
3334 $num = count($rows);
3335 for ($i = 0; $i < $num; $i++) {
3336 $this->updateRangOfLine($rows[$i], ($i + 1));
3350 $fieldposition =
'rang';
3351 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3352 $fieldposition =
'position';
3355 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3356 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3357 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang - 1));
3358 if ($this->db->query($sql)) {
3359 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang - 1));
3360 $sql .=
' WHERE rowid = '.((int) $rowid);
3361 if (!$this->db->query($sql)) {
3381 $fieldposition =
'rang';
3382 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3383 $fieldposition =
'position';
3386 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) $rang);
3387 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3388 $sql .=
" AND " . $fieldposition .
" = " . ((int) ($rang + 1));
3389 if ($this->db->query($sql)) {
3390 $sql =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldposition.
" = ".((int) ($rang + 1));
3391 $sql .=
' WHERE rowid = '.((int) $rowid);
3392 if (!$this->db->query($sql)) {
3409 $fieldposition =
'rang';
3410 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3411 $fieldposition =
'position';
3414 $sql =
"SELECT " . $fieldposition .
" FROM ".$this->db->prefix().$this->table_element_line;
3415 $sql .=
" WHERE rowid = ".((int) $rowid);
3417 dol_syslog(get_class($this).
"::getRangOfLine", LOG_DEBUG);
3418 $resql = $this->db->query($sql);
3420 $row = $this->db->fetch_row($resql);
3435 $fieldposition =
'rang';
3436 if (in_array($this->table_element_line, array(
'ecm_files',
'emailcollector_emailcollectoraction',
'product_attribute_value'))) {
3437 $fieldposition =
'position';
3440 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element_line;
3441 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3442 $sql .=
" AND " . $fieldposition .
" = ".((int) $rang);
3443 $resql = $this->db->query($sql);
3445 $row = $this->db->fetch_row($resql);
3462 $positionfield =
'rang';
3463 if (in_array($this->table_element, array(
'bom_bom',
'product_attribute'))) {
3464 $positionfield =
'position';
3468 if ($fk_parent_line) {
3469 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3470 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3471 $sql .=
" AND fk_parent_line = ".((int) $fk_parent_line);
3473 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3474 $resql = $this->db->query($sql);
3476 $row = $this->db->fetch_row($resql);
3477 if (!empty($row[0])) {
3480 return $this->getRangOfLine($fk_parent_line);
3485 $sql =
"SELECT max(".$positionfield.
") FROM ".$this->db->prefix().$this->table_element_line;
3486 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3488 dol_syslog(get_class($this).
"::line_max", LOG_DEBUG);
3489 $resql = $this->db->query($sql);
3491 $row = $this->db->fetch_row($resql);
3509 if (!$this->table_element) {
3510 dol_syslog(get_class($this).
"::update_ref_ext was called on objet with property table_element not defined", LOG_ERR);
3514 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3515 $sql .=
" SET ref_ext = '".$this->db->escape($ref_ext).
"'";
3516 $sql .=
" WHERE ".(isset($this->table_rowid) ? $this->table_rowid :
'rowid').
" = ".((
int) $this->id);
3518 dol_syslog(get_class($this).
"::update_ref_ext", LOG_DEBUG);
3519 if ($this->db->query($sql)) {
3520 $this->ref_ext = $ref_ext;
3523 $this->error = $this->db->error();
3542 if (!$this->table_element) {
3543 $this->error =
'update_note was called on objet with property table_element not defined';
3544 dol_syslog(get_class($this).
"::update_note was called on objet with property table_element not defined", LOG_ERR);
3547 if (!in_array($suffix, array(
'',
'_public',
'_private'))) {
3548 $this->error =
'update_note Parameter suffix must be empty, \'_private\' or \'_public\'';
3549 dol_syslog(get_class($this).
"::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
3553 $newsuffix = $suffix;
3556 if ($this->table_element ==
'product' && $newsuffix ==
'_private') {
3559 if (in_array($this->table_element, array(
'actioncomm',
'adherent',
'advtargetemailing',
'cronjob',
'establishment'))) {
3560 $fieldusermod =
"fk_user_mod";
3561 } elseif ($this->table_element ==
'ecm_files') {
3562 $fieldusermod =
"fk_user_m";
3564 $fieldusermod =
"fk_user_modif";
3566 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
3567 $sql .=
" SET note".$newsuffix.
" = ".(!empty($note) ? (
"'".$this->db->escape($note).
"'") :
"NULL");
3568 $sql .=
", ".$fieldusermod.
" = ".((int) $user->id);
3569 $sql .=
" WHERE rowid = ".((int) $this->
id);
3571 dol_syslog(get_class($this).
"::update_note", LOG_DEBUG);
3572 if ($this->db->query($sql)) {
3573 if ($suffix ==
'_public') {
3574 $this->note_public = $note;
3575 } elseif ($suffix ==
'_private') {
3576 $this->note_private = $note;
3578 $this->note = $note;
3579 $this->note_private = $note;
3581 if (empty($notrigger)) {
3582 switch ($this->element) {
3584 $trigger_name =
'COMPANY_MODIFY';
3587 $trigger_name =
'ORDER_MODIFY';
3590 $trigger_name =
'BILL_MODIFY';
3592 case 'invoice_supplier':
3593 $trigger_name =
'BILL_SUPPLIER_MODIFY';
3596 $trigger_name =
'BILLREC_MODIFIY';
3598 case 'expensereport':
3599 $trigger_name =
'EXPENSE_REPORT_MODIFY';
3602 $trigger_name = strtoupper($this->element) .
'_MODIFY';
3604 $ret = $this->call_trigger($trigger_name, $user);
3611 $this->error = $this->db->lasterror();
3628 return $this->update_note($note,
'_public');
3642 public function update_price($exclspec = 0, $roundingadjust =
'none', $nodatabaseupdate = 0, $seller =
null)
3645 global $conf, $hookmanager, $action;
3647 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3648 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3651 } elseif ($reshook < 0) {
3657 if ($this->element ==
'propal') {
3658 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3659 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3660 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3661 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3662 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3663 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3664 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3665 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3666 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3667 } elseif ($this->element ==
'supplier_proposal') {
3668 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3671 if (!empty($MODULE)) {
3674 foreach ($modsactivated as $mod) {
3675 if (isModEnabled($mod)) {
3682 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3684 $forcedroundingmode = $roundingadjust;
3685 if ($forcedroundingmode ==
'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3687 } elseif ($forcedroundingmode ==
'auto') {
3688 $forcedroundingmode =
'0';
3693 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3696 $fieldtva =
'total_tva';
3697 $fieldlocaltax1 =
'total_localtax1';
3698 $fieldlocaltax2 =
'total_localtax2';
3699 $fieldup =
'subprice';
3700 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3704 if ($this->element ==
'invoice_supplier_rec') {
3707 if ($this->element ==
'expensereport') {
3708 $fieldup =
'value_unit';
3711 $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,";
3712 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3713 if ($this->table_element_line ==
'facturedet') {
3714 $sql .=
', situation_percent';
3716 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
3717 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
3718 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3720 $product_field =
'product_type';
3721 if ($this->table_element_line ==
'contratdet') {
3722 $product_field =
'';
3724 if ($product_field) {
3725 $sql .=
" AND ".$product_field.
" <> 9";
3728 $sql .=
' ORDER by rowid';
3730 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3732 $resql = $this->db->query($sql);
3734 $this->total_ht = 0;
3735 $this->total_tva = 0;
3736 $this->total_localtax1 = 0;
3737 $this->total_localtax2 = 0;
3738 $this->total_ttc = 0;
3739 $total_ht_by_vats = array();
3740 $total_tva_by_vats = array();
3741 $total_ttc_by_vats = array();
3742 $this->multicurrency_total_ht = 0;
3743 $this->multicurrency_total_tva = 0;
3744 $this->multicurrency_total_ttc = 0;
3748 $num = $this->db->num_rows($resql);
3751 $obj = $this->db->fetch_object($resql);
3754 $parameters = array(
'fk_element' => $obj->rowid);
3755 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
3757 if (empty($reshook) && $forcedroundingmode ==
'0') {
3759 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3760 $tmpcal =
calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0,
'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx);
3762 $diff_when_using_price_ht =
price2num($tmpcal[1] - $obj->total_tva,
'MT', 1);
3763 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
3767 if ($diff_on_current_total) {
3769 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]).
" WHERE rowid = ".((int) $obj->rowid);
3770 dol_syslog(
'We found unconsistent 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);
3771 $resqlfix = $this->db->query($sqlfix);
3775 $obj->total_tva = $tmpcal[1];
3776 $obj->total_ttc = $tmpcal[2];
3777 } elseif ($diff_when_using_price_ht && $roundingadjust ==
'0') {
3780 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num((
float) $tmpcal[1]).
", total_ttc = ".
price2num((
float) $tmpcal[2]).
" WHERE rowid = ".((int) $obj->rowid);
3781 dol_syslog(
'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);
3782 $resqlfix = $this->db->query($sqlfix);
3786 $obj->total_tva = $tmpcal[1];
3787 $obj->total_ttc = $tmpcal[2];
3791 $this->total_ht += $obj->total_ht;
3792 $this->total_tva += $obj->total_tva;
3793 $this->total_localtax1 += $obj->total_localtax1;
3794 $this->total_localtax2 += $obj->total_localtax2;
3795 $this->total_ttc += $obj->total_ttc;
3796 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
3797 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
3798 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
3800 if (!isset($total_ht_by_vats[$obj->vatrate])) {
3801 $total_ht_by_vats[$obj->vatrate] = 0;
3803 if (!isset($total_tva_by_vats[$obj->vatrate])) {
3804 $total_tva_by_vats[$obj->vatrate] = 0;
3806 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3807 $total_ttc_by_vats[$obj->vatrate] = 0;
3809 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
3810 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3811 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3813 if ($forcedroundingmode ==
'1') {
3814 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
3815 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat,
'MT', 1);
3818 if (abs($diff) > (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)))) {
3820 $errmsg =
'A rounding difference was detected into TOTAL but is too high to be corrected. Some data in your lines may be corrupted. Try to edit each line manually to fix this before restarting.';
3822 $this->error = $errmsg;
3826 $sqlfix =
"UPDATE ".$this->db->prefix().$this->table_element_line.
" SET ".$fieldtva.
" = ".
price2num($obj->total_tva - $diff).
", total_ttc = ".
price2num($obj->total_ttc - $diff).
" WHERE rowid = ".((int) $obj->rowid);
3827 dol_syslog(
'We found a difference of '.$diff.
' for line rowid = '.$obj->rowid.
". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix);
3829 $resqlfix = $this->db->query($sqlfix);
3835 $this->total_tva = (float)
price2num($this->total_tva - $diff,
'', 1);
3836 $this->total_ttc = (float)
price2num($this->total_ttc - $diff,
'', 1);
3837 $total_tva_by_vats[$obj->vatrate] = (float)
price2num($total_tva_by_vats[$obj->vatrate] - $diff,
'', 1);
3838 $total_ttc_by_vats[$obj->vatrate] = (float)
price2num($total_ttc_by_vats[$obj->vatrate] - $diff,
'', 1);
3846 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
3847 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
3850 if (!empty($this->situation_cycle_ref) && !empty($this->situation_counter) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits')) {
3851 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
3853 $prev_sits = $this->get_prev_sits();
3855 foreach ($prev_sits as $sit) {
3856 $this->total_ht -= $sit->total_ht;
3857 $this->total_tva -= $sit->total_tva;
3858 $this->total_localtax1 -= $sit->total_localtax1;
3859 $this->total_localtax2 -= $sit->total_localtax2;
3860 $this->total_ttc -= $sit->total_ttc;
3861 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
3862 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
3863 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
3869 $this->total_ht = (float)
price2num($this->total_ht);
3870 $this->total_tva = (float)
price2num($this->total_tva);
3871 $this->total_localtax1 = (float)
price2num($this->total_localtax1);
3872 $this->total_localtax2 = (float)
price2num($this->total_localtax2);
3873 $this->total_ttc = (float)
price2num($this->total_ttc);
3875 $this->db->free($resql);
3878 $fieldht =
'total_ht';
3880 $fieldlocaltax1 =
'localtax1';
3881 $fieldlocaltax2 =
'localtax2';
3882 $fieldttc =
'total_ttc';
3884 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
3885 $fieldtva =
'total_tva';
3888 if (!$error && empty($nodatabaseupdate)) {
3889 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
3890 $sql .=
" ".$fieldht.
" = ".((float)
price2num($this->total_ht,
'MT', 1)).
",";
3891 $sql .=
" ".$fieldtva.
" = ".((float)
price2num($this->total_tva,
'MT', 1)).
",";
3892 $sql .=
" ".$fieldlocaltax1.
" = ".((float)
price2num($this->total_localtax1,
'MT', 1)).
",";
3893 $sql .=
" ".$fieldlocaltax2.
" = ".((float)
price2num($this->total_localtax2,
'MT', 1)).
",";
3894 $sql .=
" ".$fieldttc.
" = ".((float)
price2num($this->total_ttc,
'MT', 1));
3895 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
3896 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
3897 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
3898 $sql .=
" WHERE rowid = ".((int) $this->
id);
3900 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3901 $resql = $this->db->query($sql);
3905 $this->error = $this->db->lasterror();
3906 $this->errors[] = $this->db->lasterror();
3911 $this->db->commit();
3914 $this->db->rollback();
3934 public function add_object_linked($origin =
null, $origin_id =
null, $f_user =
null, $notrigger = 0)
3937 global $user, $hookmanager, $action;
3938 $origin = (!empty($origin) ? $origin : $this->origin);
3939 $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id);
3940 $f_user = isset($f_user) ? $f_user : $user;
3943 if ($origin ==
'order') {
3944 $origin =
'commande';
3946 if ($origin ==
'invoice') {
3947 $origin =
'facture';
3949 if ($origin ==
'invoice_template') {
3950 $origin =
'facturerec';
3952 if ($origin ==
'supplierorder') {
3953 $origin =
'order_supplier';
3958 $coremodule = array(
'knowledgemanagement',
'partnership',
'workstation',
'ticket',
'recruitment',
'eventorganization',
'asset');
3960 $targettype = ((!empty($this->module) && ! in_array($this->module, $coremodule)) ? $this->module.
'_' :
'').$this->element;
3962 $parameters = array(
'targettype'=>$targettype);
3964 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3966 if (!empty($hookmanager->resArray[
'targettype'])) {
3967 $targettype = $hookmanager->resArray[
'targettype'];
3974 $sql =
"INSERT INTO " . $this->db->prefix() .
"element_element (";
3975 $sql .=
"fk_source";
3976 $sql .=
", sourcetype";
3977 $sql .=
", fk_target";
3978 $sql .=
", targettype";
3979 $sql .=
") VALUES (";
3980 $sql .= ((int) $origin_id);
3981 $sql .=
", '" . $this->db->escape($origin) .
"'";
3982 $sql .=
", " . ((int) $this->
id);
3983 $sql .=
", '" . $this->db->escape($targettype) .
"'";
3986 dol_syslog(get_class($this) .
"::add_object_linked", LOG_DEBUG);
3987 if ($this->db->query($sql)) {
3990 $this->context[
'link_origin'] = $origin;
3991 $this->context[
'link_origin_id'] = $origin_id;
3992 $result = $this->call_trigger(
'OBJECT_LINK_INSERT', $f_user);
3999 $this->error = $this->db->lasterror();
4004 $this->db->commit();
4007 $this->db->rollback();
4034 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
4036 global $conf, $hookmanager, $action;
4041 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4045 $this->linkedObjectsIds = array();
4046 $this->linkedObjects = array();
4048 $justsource =
false;
4049 $justtarget =
false;
4050 $withtargettype =
false;
4051 $withsourcetype =
false;
4053 $parameters = array(
'sourcetype'=>$sourcetype,
'sourceid'=>$sourceid,
'targettype'=>$targettype,
'targetid'=>$targetid);
4055 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
4057 if (!empty($hookmanager->resArray[
'sourcetype'])) {
4058 $sourcetype = $hookmanager->resArray[
'sourcetype'];
4060 if (!empty($hookmanager->resArray[
'sourceid'])) {
4061 $sourceid = $hookmanager->resArray[
'sourceid'];
4063 if (!empty($hookmanager->resArray[
'targettype'])) {
4064 $targettype = $hookmanager->resArray[
'targettype'];
4066 if (!empty($hookmanager->resArray[
'targetid'])) {
4067 $targetid = $hookmanager->resArray[
'targetid'];
4071 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
4073 if (!empty($targettype)) {
4074 $withtargettype =
true;
4077 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
4079 if (!empty($sourcetype)) {
4080 $withsourcetype =
true;
4084 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4085 $targetid = (!empty($targetid) ? $targetid : $this->id);
4086 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
4087 $targettype = (!empty($targettype) ? $targettype : $this->element);
4096 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
4097 $sql .=
" FROM ".$this->db->prefix().
"element_element";
4099 if ($justsource || $justtarget) {
4101 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4102 if ($withtargettype) {
4103 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
4105 } elseif ($justtarget) {
4106 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
4107 if ($withsourcetype) {
4108 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
4112 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
4113 $sql .=
" ".$clause.
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
4114 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
4115 $this->linkedObjectsFullLoaded[$this->id] =
true;
4118 $sql .=
" ORDER BY ".$orderby;
4120 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
4121 $resql = $this->db->query($sql);
4123 $num = $this->db->num_rows($resql);
4126 $obj = $this->db->fetch_object($resql);
4127 if ($justsource || $justtarget) {
4129 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4130 } elseif ($justtarget) {
4131 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4134 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
4135 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4137 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
4138 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4144 if (!empty($this->linkedObjectsIds)) {
4145 $tmparray = $this->linkedObjectsIds;
4146 foreach ($tmparray as $objecttype => $objectids) {
4148 $module = $element = $subelement = $objecttype;
4150 if ($objecttype !=
'supplier_proposal' && $objecttype !=
'order_supplier' && $objecttype !=
'invoice_supplier'
4151 && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
4152 $module = $element = $regs[1];
4153 $subelement = $regs[2];
4156 $classpath = $element.
'/class';
4158 if ($objecttype ==
'facture') {
4159 $classpath =
'compta/facture/class';
4160 } elseif ($objecttype ==
'facturerec') {
4161 $classpath =
'compta/facture/class';
4162 $module =
'facture';
4163 } elseif ($objecttype ==
'propal') {
4164 $classpath =
'comm/propal/class';
4165 } elseif ($objecttype ==
'supplier_proposal') {
4166 $classpath =
'supplier_proposal/class';
4167 } elseif ($objecttype ==
'shipping') {
4168 $classpath =
'expedition/class';
4169 $subelement =
'expedition';
4170 $module =
'expedition';
4171 } elseif ($objecttype ==
'delivery') {
4172 $classpath =
'delivery/class';
4173 $subelement =
'delivery';
4174 $module =
'delivery_note';
4175 } elseif ($objecttype ==
'invoice_supplier' || $objecttype ==
'order_supplier') {
4176 $classpath =
'fourn/class';
4177 $module =
'fournisseur';
4178 } elseif ($objecttype ==
'fichinter') {
4179 $classpath =
'fichinter/class';
4180 $subelement =
'fichinter';
4181 $module =
'ficheinter';
4182 } elseif ($objecttype ==
'subscription') {
4183 $classpath =
'adherents/class';
4184 $module =
'adherent';
4185 } elseif ($objecttype ==
'contact') {
4186 $module =
'societe';
4187 } elseif ($objecttype ==
'action') {
4189 $subelement =
'actionComm';
4193 $classfile = strtolower($subelement);
4194 $classname = ucfirst($subelement);
4196 if ($objecttype ==
'order') {
4197 $classfile =
'commande';
4198 $classname =
'Commande';
4199 } elseif ($objecttype ==
'invoice_supplier') {
4200 $classfile =
'fournisseur.facture';
4201 $classname =
'FactureFournisseur';
4202 } elseif ($objecttype ==
'order_supplier') {
4203 $classfile =
'fournisseur.commande';
4204 $classname =
'CommandeFournisseur';
4205 } elseif ($objecttype ==
'supplier_proposal') {
4206 $classfile =
'supplier_proposal';
4207 $classname =
'SupplierProposal';
4208 } elseif ($objecttype ==
'facturerec') {
4209 $classfile =
'facture-rec';
4210 $classname =
'FactureRec';
4211 } elseif ($objecttype ==
'subscription') {
4212 $classfile =
'subscription';
4213 $classname =
'Subscription';
4214 } elseif ($objecttype ==
'project' || $objecttype ==
'projet') {
4215 $classpath =
'projet/class';
4216 $classfile =
'project';
4217 $classname =
'Project';
4218 } elseif ($objecttype ==
'conferenceorboothattendee') {
4219 $classpath =
'eventorganization/class';
4220 $classfile =
'conferenceorboothattendee';
4221 $classname =
'ConferenceOrBoothAttendee';
4222 $module =
'eventorganization';
4223 } elseif ($objecttype ==
'conferenceorbooth') {
4224 $classpath =
'eventorganization/class';
4225 $classfile =
'conferenceorbooth';
4226 $classname =
'ConferenceOrBooth';
4227 $module =
'eventorganization';
4228 } elseif ($objecttype ==
'mo') {
4229 $classpath =
'mrp/class';
4236 if (isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4237 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4240 if (class_exists($classname)) {
4241 foreach ($objectids as $i => $objectid) {
4242 $object =
new $classname($this->db);
4243 $ret = $object->fetch($objectid);
4245 $this->linkedObjects[$objecttype][$i] = $object;
4251 unset($this->linkedObjectsIds[$objecttype]);
4270 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
4271 unset($this->linkedObjectsFullLoaded[$this->
id]);
4289 public function updateObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $f_user =
null, $notrigger = 0)
4292 $updatesource =
false;
4293 $updatetarget =
false;
4294 $f_user = isset($f_user) ? $f_user : $user;
4296 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4297 $updatesource =
true;
4298 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4299 $updatetarget =
true;
4305 $sql =
"UPDATE " . $this->db->prefix() .
"element_element SET ";
4306 if ($updatesource) {
4307 $sql .=
"fk_source = " . ((int) $sourceid);
4308 $sql .=
", sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4309 $sql .=
" WHERE fk_target = " . ((int) $this->
id);
4310 $sql .=
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4311 } elseif ($updatetarget) {
4312 $sql .=
"fk_target = " . ((int) $targetid);
4313 $sql .=
", targettype = '" . $this->db->escape($targettype) .
"'";
4314 $sql .=
" WHERE fk_source = " . ((int) $this->
id);
4315 $sql .=
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4318 dol_syslog(get_class($this) .
"::updateObjectLinked", LOG_DEBUG);
4319 if ($this->db->query($sql)) {
4322 $this->context[
'link_source_id'] = $sourceid;
4323 $this->context[
'link_source_type'] = $sourcetype;
4324 $this->context[
'link_target_id'] = $targetid;
4325 $this->context[
'link_target_type'] = $targettype;
4326 $result = $this->call_trigger(
'OBJECT_LINK_MODIFY', $f_user);
4333 $this->error = $this->db->lasterror();
4338 $this->db->commit();
4341 $this->db->rollback();
4359 public function deleteObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $rowid = 0, $f_user =
null, $notrigger = 0)
4362 $deletesource =
false;
4363 $deletetarget =
false;
4364 $f_user = isset($f_user) ? $f_user : $user;
4366 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) {
4367 $deletesource =
true;
4368 } elseif (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) {
4369 $deletetarget =
true;
4372 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
4373 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
4374 $targetid = (!empty($targetid) ? $targetid : $this->id);
4375 $targettype = (!empty($targettype) ? $targettype : $this->element);
4381 $this->context[
'link_id'] = $rowid;
4382 $this->context[
'link_source_id'] = $sourceid;
4383 $this->context[
'link_source_type'] = $sourcetype;
4384 $this->context[
'link_target_id'] = $targetid;
4385 $this->context[
'link_target_type'] = $targettype;
4386 $result = $this->call_trigger(
'OBJECT_LINK_DELETE', $f_user);
4394 $sql =
"DELETE FROM " . $this->db->prefix() .
"element_element";
4397 $sql .=
" rowid = " . ((int) $rowid);
4399 if ($deletesource) {
4400 $sql .=
" fk_source = " . ((int) $sourceid) .
" AND sourcetype = '" . $this->db->escape($sourcetype) .
"'";
4401 $sql .=
" AND fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"'";
4402 } elseif ($deletetarget) {
4403 $sql .=
" fk_target = " . ((int) $targetid) .
" AND targettype = '" . $this->db->escape($targettype) .
"'";
4404 $sql .=
" AND fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"'";
4406 $sql .=
" (fk_source = " . ((int) $this->
id) .
" AND sourcetype = '" . $this->db->escape($this->element) .
"')";
4408 $sql .=
" (fk_target = " . ((int) $this->
id) .
" AND targettype = '" . $this->db->escape($this->element) .
"')";
4412 dol_syslog(get_class($this) .
"::deleteObjectLinked", LOG_DEBUG);
4413 if (!$this->db->query($sql)) {
4414 $this->error = $this->db->lasterror();
4415 $this->errors[] = $this->error;
4421 $this->db->commit();
4424 $this->db->rollback();
4440 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4443 if (!preg_match(
'/^[_a-zA-Z0-9]+$/', $field_select)) {
4444 dol_syslog(
'Invalid value $field_select for parameter '.$field_select.
' in call to getAllItemsLinkedByObjectID(). Must be a single field name.', LOG_ERR);
4449 $sql =
"SELECT ".$field_select.
" FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4450 $resql = $db->query($sql);
4453 if (!empty($resql)) {
4454 while ($res = $db->fetch_object($resql)) {
4455 $TRes[] = $res->{$field_select};
4472 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4478 $sql =
"SELECT COUNT(*) as nb FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4479 $resql = $db->query($sql);
4482 $res = $db->fetch_object($resql);
4501 if (empty($fk_object_where) || empty($field_where) || empty($table_element)) {
4507 $sql =
"DELETE FROM ".$db->prefix().$table_element.
" WHERE ".$field_where.
" = ".((int) $fk_object_where);
4508 $resql = $db->query($sql);
4510 if (empty($resql)) {
4527 public function setStatut($status, $elementId =
null, $elementType =
'', $trigkey =
'', $fieldstatus =
'fk_statut')
4529 global $user, $langs, $conf;
4531 $savElementId = $elementId;
4533 $elementId = (!empty($elementId) ? $elementId : $this->id);
4534 $elementTable = (!empty($elementType) ? $elementType : $this->table_element);
4538 if ($elementTable ==
'facture_rec') {
4539 $fieldstatus =
"suspended";
4541 if ($elementTable ==
'mailing') {
4542 $fieldstatus =
"statut";
4544 if ($elementTable ==
'cronjob') {
4545 $fieldstatus =
"status";
4547 if ($elementTable ==
'user') {
4548 $fieldstatus =
"statut";
4550 if ($elementTable ==
'expensereport') {
4551 $fieldstatus =
"fk_statut";
4553 if ($elementTable ==
'commande_fournisseur_dispatch') {
4554 $fieldstatus =
"status";
4556 if ($elementTable ==
'prelevement_bons') {
4557 $fieldstatus =
"statut";
4559 if (isset($this->fields) && is_array($this->fields) && array_key_exists(
'status', $this->fields)) {
4560 $fieldstatus =
'status';
4563 $sql =
"UPDATE ".$this->db->prefix().$elementTable;
4564 $sql .=
" SET ".$fieldstatus.
" = ".((int) $status);
4567 if ($status == 1 && in_array($elementTable, array(
'expensereport',
'inventory'))) {
4568 $sql .=
", fk_user_valid = ".((int) $user->id);
4570 if ($status == 1 && in_array($elementTable, array(
'expensereport'))) {
4571 $sql .=
", date_valid = '".$this->db->idate(
dol_now()).
"'";
4573 if ($status == 1 && in_array($elementTable, array(
'inventory'))) {
4574 $sql .=
", date_validation = '".$this->db->idate(
dol_now()).
"'";
4576 $sql .=
" WHERE rowid = ".((int) $elementId);
4577 $sql .=
" AND ".$fieldstatus.
" <> ".((int) $status);
4579 dol_syslog(get_class($this).
"::setStatut", LOG_DEBUG);
4580 $resql = $this->db->query($sql);
4584 $nb_rows_affected = $this->db->affected_rows($resql);
4586 if ($nb_rows_affected > 0) {
4587 if (empty($trigkey)) {
4589 if ($this->element ==
'supplier_proposal' && $status == 2) {
4590 $trigkey =
'SUPPLIER_PROPOSAL_SIGN';
4592 if ($this->element ==
'supplier_proposal' && $status == 3) {
4593 $trigkey =
'SUPPLIER_PROPOSAL_REFUSE';
4595 if ($this->element ==
'supplier_proposal' && $status == 4) {
4596 $trigkey =
'SUPPLIER_PROPOSAL_CLOSE';
4598 if ($this->element ==
'fichinter' && $status == 3) {
4599 $trigkey =
'FICHINTER_CLASSIFY_DONE';
4601 if ($this->element ==
'fichinter' && $status == 2) {
4602 $trigkey =
'FICHINTER_CLASSIFY_BILLED';
4604 if ($this->element ==
'fichinter' && $status == 1) {
4605 $trigkey =
'FICHINTER_CLASSIFY_UNBILLED';
4611 $result = $this->call_trigger($trigkey, $user);
4622 $this->db->commit();
4624 if (empty($savElementId)) {
4626 if ($fieldstatus ==
'tosell') {
4628 } elseif ($fieldstatus ==
'tobuy') {
4629 $this->status_buy = $status;
4638 $this->db->rollback();
4639 dol_syslog(get_class($this).
"::setStatut ".$this->error, LOG_ERR);
4643 $this->error = $this->db->lasterror();
4644 $this->db->rollback();
4661 if (empty($id) && empty($ref)) {
4671 $sql =
"SELECT rowid, canvas";
4672 $sql .=
" FROM ".$this->db->prefix().$this->table_element;
4673 $sql .=
" WHERE entity IN (".getEntity($this->element).
")";
4675 $sql .=
" AND rowid = ".((int) $id);
4678 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
4681 $resql = $this->db->query($sql);
4683 $obj = $this->db->fetch_object($resql);
4685 $this->canvas = $obj->canvas;
4705 $sql =
"SELECT special_code FROM ".$this->db->prefix().$this->table_element_line;
4706 $sql .=
" WHERE rowid = ".((int) $lineid);
4707 $resql = $this->db->query($sql);
4709 $row = $this->db->fetch_row($resql);
4710 return (!empty($row[0]) ? $row[0] : 0);
4733 if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) {
4734 dol_print_error(
'Called isObjectUsed on a class with property this->childtables not defined');
4738 $arraytoscan = $this->childtables;
4740 $tmparray = array_keys($this->childtables);
4741 if (is_numeric($tmparray[0])) {
4742 $arraytoscan = array_flip($this->childtables);
4747 foreach ($arraytoscan as $table => $element) {
4750 $sql =
"SELECT COUNT(*) as nb";
4751 $sql.=
" FROM ".$this->db->prefix().$table.
" as c";
4752 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4753 $sql.=
", ".$this->db->prefix().$element[
'parent'].
" as p";
4755 if (!empty($element[
'fk_element'])) {
4756 $sql.=
" WHERE c.".$element[
'fk_element'].
" = ".((int) $id);
4758 $sql.=
" WHERE c.".$this->fk_element.
" = ".((int) $id);
4760 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4761 $sql.=
" AND c.".$element[
'parentkey'].
" = p.rowid";
4763 if (!empty($element[
'parent']) && !empty($element[
'parenttypefield']) && !empty($element[
'parenttypevalue'])) {
4764 $sql.=
" AND c.".$element[
'parenttypefield'].
" = '".$this->db->escape($element[
'parenttypevalue']).
"'";
4766 if (!empty($entity)) {
4767 if (!empty($element[
'parent']) && !empty($element[
'parentkey'])) {
4768 $sql.=
" AND p.entity = ".((int) $entity);
4770 $sql.=
" AND c.entity = ".((int) $entity);
4774 $resql = $this->db->query($sql);
4776 $obj = $this->db->fetch_object($resql);
4778 $langs->load(
"errors");
4780 $haschild += $obj->nb;
4781 if (is_numeric($element)) {
4782 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $table);
4783 } elseif (is_string($element)) {
4784 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element));
4786 $this->errors[] = $langs->transnoentitiesnoconv(
"ErrorRecordHasAtLeastOneChildOfType", method_exists($this,
'getNomUrl') ? $this->getNomUrl() : $this->ref, $langs->transnoentitiesnoconv($element[
'name']));
4791 $this->errors[] = $this->db->lasterror();
4795 if ($haschild > 0) {
4796 $this->errors[] =
"ErrorRecordHasChildren";
4813 foreach ($this->lines as $key => $val) {
4815 if ($predefined == -1) {
4818 if ($predefined == 1 && $val->fk_product > 0) {
4821 if ($predefined == 0 && $val->fk_product <= 0) {
4824 if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) {
4827 if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) {
4834 dol_syslog(get_class($this).
'::hasProductsOrServices we found '.$nb.
' qualified lines of products/servcies');
4845 if (!empty($this->table_element_line)) {
4846 $total_discount = 0.00;
4848 $sql =
"SELECT subprice as pu_ht, qty, remise_percent, total_ht";
4849 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
4850 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
4852 dol_syslog(get_class($this).
'::getTotalDiscount', LOG_DEBUG);
4853 $resql = $this->db->query($sql);
4855 $num = $this->db->num_rows($resql);
4858 $obj = $this->db->fetch_object($resql);
4860 $pu_ht = $obj->pu_ht;
4862 $total_ht = $obj->total_ht;
4864 $total_discount_line = (float)
price2num(($pu_ht * $qty) - $total_ht,
'MT');
4865 $total_discount += $total_discount_line;
4894 foreach ($this->lines as $line) {
4895 if (isset($line->qty_asked)) {
4896 if (empty($totalOrdered)) {
4899 $totalOrdered += $line->qty_asked;
4901 if (isset($line->qty_shipped)) {
4902 if (empty($totalToShip)) {
4905 $totalToShip += $line->qty_shipped;
4906 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
4907 if (empty($totalToShip)) {
4910 $totalToShip += $line->qty;
4914 if ($this->element ==
'shipping') {
4916 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
4918 $qty = $line->qty ? $line->qty : 0;
4921 $weight = !empty($line->weight) ? $line->weight : 0;
4922 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
4923 $volume = !empty($line->volume) ? $line->volume : 0;
4924 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
4926 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
4927 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
4928 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
4929 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
4933 if (!empty($weight_units)) {
4934 $weightUnit = $weight_units;
4936 if (!empty($volume_units)) {
4937 $volumeUnit = $volume_units;
4940 if (empty($totalWeight)) {
4943 if (empty($totalVolume)) {
4948 if ($weight_units < 50) {
4949 $trueWeightUnit = pow(10, $weightUnit);
4950 $totalWeight += $weight * $qty * $trueWeightUnit;
4952 if ($weight_units == 99) {
4954 $trueWeightUnit = 0.45359237;
4955 $totalWeight += $weight * $qty * $trueWeightUnit;
4956 } elseif ($weight_units == 98) {
4958 $trueWeightUnit = 0.0283495;
4959 $totalWeight += $weight * $qty * $trueWeightUnit;
4961 $totalWeight += $weight * $qty;
4964 if ($volume_units < 50) {
4966 $trueVolumeUnit = pow(10, $volumeUnit);
4968 $totalVolume += $volume * $qty * $trueVolumeUnit;
4970 $totalVolume += $volume * $qty;
4974 return array(
'weight'=>$totalWeight,
'volume'=>$totalVolume,
'ordered'=>$totalOrdered,
'toship'=>$totalToShip);
4987 $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) :
null);
4989 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
4990 $sql .=
" SET extraparams = ".(!empty($extraparams) ?
"'".$this->db->escape($extraparams).
"'" :
"null");
4991 $sql .=
" WHERE rowid = ".((int) $this->
id);
4993 dol_syslog(get_class($this).
"::setExtraParameters", LOG_DEBUG);
4994 $resql = $this->db->query($sql);
4996 $this->error = $this->db->lasterror();
4997 $this->db->rollback();
5000 $this->db->commit();
5023 global $conf, $user, $langs, $object, $hookmanager, $extrafields, $form;
5026 if (!is_object($extrafields)) {
5027 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5030 $extrafields->fetch_name_optionals_label($this->table_element_line);
5035 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5036 foreach ($dirtpls as $module => $reldir) {
5037 if (!empty($module)) {
5040 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_create.tpl.php';
5043 if (empty($conf->file->strict_mode)) {
5044 $res = @include $tpl;
5046 $res = include $tpl;
5073 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
5075 global $conf, $hookmanager, $langs, $user, $form, $extrafields, $object;
5077 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
5081 if (isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
5085 $num = count($this->lines);
5088 if (!is_object($extrafields)) {
5089 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5092 $extrafields->fetch_name_optionals_label($this->table_element_line);
5094 $parameters = array(
'num'=>$num,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$this->table_element_line);
5095 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
5096 if (empty($reshook)) {
5100 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5101 foreach ($dirtpls as $module => $reldir) {
5103 if (!empty($module)) {
5106 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
5108 if (file_exists($tpl)) {
5109 if (empty($conf->file->strict_mode)) {
5110 $res = @include $tpl;
5112 $res = include $tpl;
5123 print
"<!-- begin printObjectLines() --><tbody>\n";
5124 foreach ($this->lines as $line) {
5126 $line->fetch_optionals();
5129 if (is_object($hookmanager)) {
5130 if (empty($line->fk_parent_line)) {
5131 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element,
'defaulttpldir'=>$defaulttpldir);
5132 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
5134 $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);
5135 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
5138 if (empty($reshook)) {
5139 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
5144 print
"</tbody><!-- end printObjectLines() -->\n";
5164 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
5166 global $conf, $langs, $user, $object, $hookmanager;
5168 global $object_rights, $disableedit, $disablemove, $disableremove;
5170 $object_rights = $this->getRights();
5177 if ($action !=
'editline' || $selected != $line->id) {
5179 if (!empty($line->fk_product) && $line->fk_product > 0) {
5180 $product_static =
new Product($this->db);
5181 $product_static->fetch($line->fk_product);
5183 $product_static->ref = $line->ref;
5184 $product_static->label = !empty($line->label) ? $line->label :
"";
5186 $text = $product_static->getNomUrl(1);
5190 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
5191 dol_print_error(
'',
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
5195 $prod =
new Product($this->db);
5196 $prod->fetch($line->fk_product);
5198 $outputlangs = $langs;
5200 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
5201 $newlang =
GETPOST(
'lang_id',
'aZ09');
5203 if (
getDolGlobalString(
'PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE') && empty($newlang) && is_object($this->thirdparty)) {
5204 $newlang = $this->thirdparty->default_lang;
5206 if (!empty($newlang)) {
5207 $outputlangs =
new Translate(
"", $conf);
5208 $outputlangs->setDefaultLang($newlang);
5211 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5213 $label = $line->product_label;
5216 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5217 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5220 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5225 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5226 foreach ($dirtpls as $module => $reldir) {
5228 if (!empty($module)) {
5231 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5234 if (file_exists($tpl)) {
5235 if (empty($conf->file->strict_mode)) {
5236 $res = @include $tpl;
5238 $res = include $tpl;
5248 if ($this->
statut == 0 && $action ==
'editline' && $selected == $line->id) {
5249 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5251 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5256 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5257 foreach ($dirtpls as $module => $reldir) {
5258 if (!empty($module)) {
5261 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5264 if (empty($conf->file->strict_mode)) {
5265 $res = @include $tpl;
5267 $res = include $tpl;
5292 global $langs, $hookmanager, $conf, $form, $action;
5294 print
'<tr class="liste_titre">';
5295 print
'<td class="linecolref">'.$langs->trans(
'Ref').
'</td>';
5296 print
'<td class="linecoldescription">'.$langs->trans(
'Description').
'</td>';
5297 print
'<td class="linecolvat right">'.$langs->trans(
'VATRate').
'</td>';
5298 print
'<td class="linecoluht right">'.$langs->trans(
'PriceUHT').
'</td>';
5299 if (isModEnabled(
"multicurrency")) {
5300 print
'<td class="linecoluht_currency right">'.$langs->trans(
'PriceUHTCurrency').
'</td>';
5302 print
'<td class="linecolqty right">'.$langs->trans(
'Qty').
'</td>';
5304 print
'<td class="linecoluseunit left">'.$langs->trans(
'Unit').
'</td>';
5306 print
'<td class="linecoldiscount right">'.$langs->trans(
'ReductionShort').
'</td>';
5307 print
'<td class="linecolht right">'.$langs->trans(
'TotalHT').
'</td>';
5308 print
'<td class="center">'.$form->showCheckAddButtons(
'checkforselect', 1).
'</td>';
5312 if (!empty($this->lines)) {
5313 foreach ($this->lines as $line) {
5316 if (is_object($hookmanager)) {
5317 $parameters = array(
'line'=>$line,
'i'=>$i,
'restrictlist'=>$restrictlist,
'selectedLines'=> $selectedLines);
5318 if (!empty($line->fk_parent_line)) {
5319 $parameters[
'fk_parent_line'] = $line->fk_parent_line;
5321 $reshook = $hookmanager->executeHooks(
'printOriginObjectLine', $parameters, $this, $action);
5323 if (empty($reshook)) {
5324 $this->printOriginLine($line,
'', $restrictlist,
'/core/tpl', $selectedLines);
5345 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5347 global $langs, $conf;
5350 if (!empty($line->date_start)) {
5351 $date_start = $line->date_start;
5353 $date_start = $line->date_debut_prevue;
5354 if ($line->date_debut_reel) {
5355 $date_start = $line->date_debut_reel;
5358 if (!empty($line->date_end)) {
5359 $date_end = $line->date_end;
5361 $date_end = $line->date_fin_prevue;
5362 if ($line->date_fin_reel) {
5363 $date_end = $line->date_fin_reel;
5367 $this->tpl[
'id'] = $line->id;
5369 $this->tpl[
'label'] =
'';
5370 if (!empty($line->fk_parent_line)) {
5371 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5374 if (($line->info_bits & 2) == 2) {
5376 if (property_exists($this,
'socid')) {
5377 $discount->fk_soc = $this->socid;
5379 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5380 } elseif (!empty($line->fk_product)) {
5381 if (empty($line->product)) {
5382 $line->fetch_product();
5384 $productstatic = $line->product;
5386 $this->tpl[
'label'] .= (is_object($productstatic) ? $productstatic->getNomUrl(1) : $line->ref);
5387 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5389 if ($line->product_type == 1 && ($date_start || $date_end)) {
5393 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
''),
'service') :
img_object($langs->trans(
''),
'product')));
5394 if (!empty($line->desc)) {
5395 $this->tpl[
'label'] .= $line->desc;
5397 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5401 if ($line->product_type == 1 && ($date_start || $date_end)) {
5406 if (!empty($line->desc)) {
5407 if ($line->desc ==
'(CREDIT_NOTE)') {
5409 $discount->fetch($line->fk_remise_except);
5410 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5411 } elseif ($line->desc ==
'(DEPOSIT)') {
5413 $discount->fetch($line->fk_remise_except);
5414 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5415 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5417 $discount->fetch($line->fk_remise_except);
5418 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5419 } elseif ($line->desc ==
'(EXCESS PAID)') {
5421 $discount->fetch($line->fk_remise_except);
5422 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5424 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5427 $this->tpl[
'description'] =
' ';
5431 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5432 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5433 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5434 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5437 $this->tpl[
'price'] =
price($line->subprice);
5438 $this->tpl[
'total_ht'] =
price($line->total_ht);
5439 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5440 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5442 $this->tpl[
'unit'] = $langs->transnoentities($line->getLabelOfUnit(
'long'));
5444 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate($line->remise_percent,
true) :
' ';
5447 $this->tpl[
'strike'] = 0;
5449 $this->tpl[
'strike'] = 1;
5454 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5455 foreach ($dirtpls as $module => $reldir) {
5456 if (!empty($module)) {
5459 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5462 if (empty($conf->file->strict_mode)) {
5463 $res = @include $tpl;
5465 $res = include $tpl;
5490 $sql =
"INSERT INTO ".$this->db->prefix().
"element_resources (";
5491 $sql .=
"resource_id";
5492 $sql .=
", resource_type";
5493 $sql .=
", element_id";
5494 $sql .=
", element_type";
5496 $sql .=
", mandatory";
5497 $sql .=
") VALUES (";
5498 $sql .= ((int) $resource_id);
5499 $sql .=
", '".$this->db->escape($resource_type).
"'";
5500 $sql .=
", '".$this->db->escape($this->
id).
"'";
5501 $sql .=
", '".$this->db->escape($this->element).
"'";
5502 $sql .=
", '".$this->db->escape($busy).
"'";
5503 $sql .=
", '".$this->db->escape($mandatory).
"'";
5506 dol_syslog(get_class($this).
"::add_element_resource", LOG_DEBUG);
5507 if ($this->db->query($sql)) {
5508 $this->db->commit();
5511 $this->error = $this->db->lasterror();
5512 $this->db->rollback();
5533 $sql =
"DELETE FROM ".$this->db->prefix().
"element_resources";
5534 $sql .=
" WHERE rowid = ".((int) $rowid);
5536 dol_syslog(get_class($this).
"::delete_resource", LOG_DEBUG);
5538 $resql = $this->db->query($sql);
5540 $this->error = $this->db->lasterror();
5541 $this->db->rollback();
5545 $result = $this->call_trigger(strtoupper($element).
'_DELETE_RESOURCE', $user);
5547 $this->db->rollback();
5551 $this->db->commit();
5565 if (isset($this->lines) && is_array($this->lines)) {
5566 $nboflines = count($this->lines);
5567 for ($i = 0; $i < $nboflines; $i++) {
5568 if (is_object($this->lines[$i])) {
5569 $this->lines[$i] = clone $this->lines[$i];
5588 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5590 global $conf, $langs, $user, $hookmanager, $action;
5592 $srctemplatepath =
'';
5594 $parameters = array(
'modelspath'=>$modelspath,
'modele'=>$modele,
'outputlangs'=>$outputlangs,
'hidedetails'=>$hidedetails,
'hidedesc'=>$hidedesc,
'hideref'=>$hideref,
'moreparams'=>$moreparams);
5595 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5597 if (!empty($reshook)) {
5601 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5603 if (empty($modele)) {
5604 $this->error =
'BadValueForParameterModele';
5609 $err = error_reporting();
5611 @set_time_limit(120);
5612 error_reporting($err);
5615 $tmp = explode(
':', $modele, 2);
5616 $saved_model = $modele;
5617 if (!empty($tmp[1])) {
5619 $srctemplatepath = $tmp[1];
5626 $dirmodels = array(
'/');
5627 if (is_array($conf->modules_parts[
'models'])) {
5628 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
5630 foreach ($dirmodels as $reldir) {
5631 foreach (array(
'doc',
'pdf') as $prefix) {
5632 if (in_array(get_class($this), array(
'Adherent'))) {
5634 $file = $prefix.
"_".$modele.
".class.php";
5637 $file = $prefix.
"_".$modele.
".modules.php";
5644 if (file_exists($file)) {
5646 $classname = $prefix.
'_'.$modele;
5656 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5657 $this->errors[] = $this->error;
5668 require_once $filefound;
5670 $obj =
new $classname($this->db);
5673 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5674 $varfortemplatedir = $obj->scandir;
5678 $listoffiles = array();
5681 $listofdir = explode(
',', $dirtoscan);
5682 foreach ($listofdir as $key => $tmpdir) {
5683 $tmpdir = trim($tmpdir);
5684 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5686 unset($listofdir[$key]);
5689 if (is_dir($tmpdir)) {
5690 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
5691 if (count($tmpfiles)) {
5692 $listoffiles = array_merge($listoffiles, $tmpfiles);
5697 if (count($listoffiles)) {
5698 foreach ($listoffiles as $record) {
5699 $srctemplatepath = $record[
'fullname'];
5705 if (empty($srctemplatepath)) {
5706 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
5711 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
5713 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
5714 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
5721 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
5724 $this->model_pdf = $saved_model;
5726 if (in_array(get_class($this), array(
'Adherent'))) {
5727 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards', $moreparams);
5729 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
5733 if ($resultwritefile > 0) {
5734 $outputlangs->charset_output = $sav_charset_output;
5737 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5741 if (!empty($obj->result[
'fullpath'])) {
5742 $destfull = $obj->result[
'fullpath'];
5745 $update_main_doc_field = 0;
5746 if (!empty($obj->update_main_doc_field)) {
5747 $update_main_doc_field = 1;
5753 $this->indexFile($destfull, $update_main_doc_field);
5756 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);
5764 $outputlangs->charset_output = $sav_charset_output;
5765 $this->error = $obj->error;
5766 $this->errors = $obj->errors;
5767 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
5781 public function indexFile($destfull, $update_main_doc_field)
5783 global $conf, $user;
5785 $upload_dir = dirname($destfull);
5786 $destfile = basename($destfull);
5787 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
5789 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5790 $filename = basename($destfile);
5791 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
5792 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
5794 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
5795 $ecmfile =
new EcmFiles($this->db);
5796 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
5799 $setsharekey =
false;
5800 if ($this->element ==
'propal' || $this->element ==
'proposal') {
5802 $setsharekey =
true;
5805 $setsharekey =
true;
5808 if ($this->element ==
'commande' &&
getDolGlobalInt(
"ORDER_ALLOW_EXTERNAL_DOWNLOAD")) {
5809 $setsharekey =
true;
5811 if ($this->element ==
'facture' &&
getDolGlobalInt(
"INVOICE_ALLOW_EXTERNAL_DOWNLOAD")) {
5812 $setsharekey =
true;
5814 if ($this->element ==
'bank_account' &&
getDolGlobalInt(
"BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD")) {
5815 $setsharekey =
true;
5817 if ($this->element ==
'product' &&
getDolGlobalInt(
"PRODUCT_ALLOW_EXTERNAL_DOWNLOAD")) {
5818 $setsharekey =
true;
5820 if ($this->element ==
'contrat' &&
getDolGlobalInt(
"CONTRACT_ALLOW_EXTERNAL_DOWNLOAD")) {
5821 $setsharekey =
true;
5823 if ($this->element ==
'fichinter' &&
getDolGlobalInt(
"FICHINTER_ALLOW_EXTERNAL_DOWNLOAD")) {
5824 $setsharekey =
true;
5826 if ($this->element ==
'supplier_proposal' &&
getDolGlobalInt(
"SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD")) {
5827 $setsharekey =
true;
5829 if ($this->element ==
'societe_rib' &&
getDolGlobalInt(
"SOCIETE_RIB_ALLOW_ONLINESIGN")) {
5830 $setsharekey =
true;
5834 if (empty($ecmfile->share)) {
5835 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5842 $ecmfile->fullpath_orig =
'';
5843 $ecmfile->gen_or_uploaded =
'generated';
5844 $ecmfile->description =
'';
5845 $ecmfile->keywords =
'';
5846 $result = $ecmfile->update($user);
5852 $ecmfile->entity = $conf->entity;
5853 $ecmfile->filepath = $rel_dir;
5854 $ecmfile->filename = $filename;
5856 $ecmfile->fullpath_orig =
'';
5857 $ecmfile->gen_or_uploaded =
'generated';
5858 $ecmfile->description =
'';
5859 $ecmfile->keywords =
'';
5860 $ecmfile->src_object_type = $this->table_element;
5861 $ecmfile->src_object_id = $this->id;
5863 $result = $ecmfile->create($user);
5875 if ($update_main_doc_field && !empty($this->table_element)) {
5876 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
5877 $sql .=
" WHERE rowid = ".((int) $this->
id);
5879 $resql = $this->db->query($sql);
5884 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
5903 if (file_exists($file_osencoded)) {
5904 require_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
5907 $maxwidthsmall = $tmparraysize[
'maxwidthsmall'];
5908 $maxheightsmall = $tmparraysize[
'maxheightsmall'];
5909 $maxwidthmini = $tmparraysize[
'maxwidthmini'];
5910 $maxheightmini = $tmparraysize[
'maxheightmini'];
5916 vignette($file_osencoded, $maxwidthsmall, $maxheightsmall,
'_small', $quality);
5920 vignette($file_osencoded, $maxwidthmini, $maxheightmini,
'_mini', $quality);
5959 global $conf, $_POST;
5962 if (GETPOSTISSET($fieldname)) {
5963 return GETPOST($fieldname, $type, 3);
5966 if (isset($alternatevalue)) {
5967 return $alternatevalue;
5970 $newelement = $this->element;
5971 if ($newelement ==
'facture') {
5972 $newelement =
'invoice';
5974 if ($newelement ==
'commande') {
5975 $newelement =
'order';
5977 if (empty($newelement)) {
5978 dol_syslog(
"Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
5982 $keyforfieldname = strtoupper($newelement.
'_DEFAULT_'.$fieldname);
6012 global $langs, $conf;
6014 if (!empty(self::TRIGGER_PREFIX) && strpos($triggerName, self::TRIGGER_PREFIX .
'_') !== 0) {
6015 dol_print_error(
'',
'The trigger "' . $triggerName .
'" does not start with "' . self::TRIGGER_PREFIX .
'_" as required.');
6018 if (!is_object($langs)) {
6019 include_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
6023 include_once DOL_DOCUMENT_ROOT.
'/core/class/interfaces.class.php';
6025 $result = $interface->run_triggers($triggerName, $this, $user, $langs, $conf);
6028 if (!empty($this->errors)) {
6029 $this->errors = array_unique(array_merge($this->errors, $interface->errors));
6031 $this->errors = $interface->errors;
6051 if (!$this->element) {
6054 if (!($this->
id > 0)) {
6057 if (is_array($this->array_languages)) {
6061 $this->array_languages = array();
6063 $element = $this->element;
6064 if ($element ==
'categorie') {
6065 $element =
'categories';
6069 $sql =
"SELECT rowid, property, lang , value";
6070 $sql .=
" FROM ".$this->db->prefix().
"object_lang";
6071 $sql .=
" WHERE type_object = '".$this->db->escape($element).
"'";
6072 $sql .=
" AND fk_object = ".((int) $this->
id);
6075 $resql = $this->db->query($sql);
6077 $numrows = $this->db->num_rows($resql);
6080 while ($i < $numrows) {
6081 $obj = $this->db->fetch_object($resql);
6082 $key = $obj->property;
6083 $value = $obj->value;
6084 $codelang = $obj->lang;
6085 $type = $this->fields[$key][
'type'];
6088 if (preg_match(
'/date/', $type)) {
6089 $this->array_languages[$key][$codelang] = $this->db->jdate($value);
6091 $this->array_languages[$key][$codelang] = $value;
6098 $this->db->free($resql);
6119 global $_POST, $langs;
6122 foreach ($_POST as $postfieldkey => $postfieldvalue) {
6123 $tmparray = explode(
'-', $postfieldkey);
6124 if ($tmparray[0] !=
'field') {
6128 $element = $tmparray[1];
6129 $key = $tmparray[2];
6130 $codelang = $tmparray[3];
6133 if (!empty($onlykey) && $key != $onlykey) {
6136 if ($element != $this->element) {
6140 $key_type = $this->fields[$key][
'type'];
6143 if (isset($this->fields[$key][
'enabled'])) {
6144 $enabled =
dol_eval($this->fields[$key][
'enabled'], 1, 1,
'1');
6151 if (empty($enabled)) {
6156 if (in_array($key_type, array(
'date'))) {
6160 } elseif (in_array($key_type, array(
'datetime'))) {
6163 $value_key =
dol_mktime(
GETPOST($postfieldkey.
"hour",
'int'),
GETPOST($postfieldkey.
"min",
'int'), 0,
GETPOST($postfieldkey.
"month",
'int'),
GETPOST($postfieldkey.
"day",
'int'),
GETPOST($postfieldkey.
"year",
'int'));
6164 } elseif (in_array($key_type, array(
'checkbox',
'chkbxlst'))) {
6165 $value_arr =
GETPOST($postfieldkey,
'array');
6166 if (!empty($value_arr)) {
6167 $value_key = implode(
',', $value_arr);
6171 } elseif (in_array($key_type, array(
'price',
'double'))) {
6172 $value_arr =
GETPOST($postfieldkey,
'alpha');
6175 $value_key =
GETPOST($postfieldkey);
6176 if (in_array($key_type, array(
'link')) && $value_key ==
'-1') {
6181 $this->array_languages[$key][$codelang] = $value_key;
6206 $savDisableCompute = $conf->disable_compute;
6207 $conf->disable_compute = 1;
6209 $ret = $this->fetch($id);
6211 $conf->disable_compute = $savDisableCompute;
6229 global $conf, $extrafields;
6231 if (empty($rowid)) {
6234 if (empty($rowid) && isset($this->
rowid)) {
6235 $rowid = $this->rowid;
6239 if (!$this->table_element) {
6243 $this->array_options = array();
6245 if (!is_array($optionsArray)) {
6247 if (!isset($extrafields) || !is_object($extrafields)) {
6248 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6253 if (empty($extrafields->attributes[$this->table_element][
'loaded'])) {
6254 $extrafields->fetch_name_optionals_label($this->table_element);
6256 $optionsArray = (!empty($extrafields->attributes[$this->table_element][
'label']) ? $extrafields->attributes[$this->table_element][
'label'] :
null);
6258 global $extrafields;
6259 dol_syslog(
"Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
6262 $table_element = $this->table_element;
6263 if ($table_element ==
'categorie') {
6264 $table_element =
'categories';
6268 if (is_array($optionsArray) && count($optionsArray) > 0) {
6269 $sql =
"SELECT rowid";
6270 foreach ($optionsArray as $name => $label) {
6271 if (empty($extrafields->attributes[$this->table_element][
'type'][$name]) || $extrafields->attributes[$this->table_element][
'type'][$name] !=
'separate') {
6275 $sql .=
" FROM ".$this->db->prefix().$table_element.
"_extrafields";
6276 $sql .=
" WHERE fk_object = ".((int) $rowid);
6279 $resql = $this->db->query($sql);
6281 $numrows = $this->db->num_rows($resql);
6283 $tab = $this->db->fetch_array($resql);
6285 foreach ($tab as $key => $value) {
6287 if ($key !=
'rowid' && $key !=
'tms' && $key !=
'fk_member' && !is_int($key)) {
6289 if (!empty($extrafields->attributes[$this->table_element]) && in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date',
'datetime'))) {
6291 $this->array_options[
"options_".$key] = $this->db->jdate($value);
6293 $this->array_options[
"options_".$key] = $value;
6298 if (!empty($extrafields->attributes[$this->table_element][
'type'][$key]) && $extrafields->attributes[$this->table_element][
'type'][$key] ==
'password') {
6299 if (!empty($value) && preg_match(
'/^dolcrypt:/', $value)) {
6300 $this->array_options[
"options_".$key] =
dolDecrypt($value);
6308 if (is_array($extrafields->attributes[$this->table_element][
'label'])) {
6309 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
6310 if (!empty($extrafields->attributes[$this->table_element]) && !empty($extrafields->attributes[$this->table_element][
'computed'][$key])) {
6312 if (empty($conf->disable_compute)) {
6313 global $objectoffield;
6314 $objectoffield = $this;
6315 $this->array_options[
'options_' . $key] =
dol_eval($extrafields->attributes[$this->table_element][
'computed'][$key], 1, 0,
'2');
6321 $this->db->free($resql);
6329 $this->errors[]=$this->db->lasterror;
6352 $table_element = $this->table_element;
6353 if ($table_element ==
'categorie') {
6354 $table_element =
'categories';
6357 dol_syslog(get_class($this).
"::deleteExtraFields delete", LOG_DEBUG);
6359 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6361 $resql = $this->db->query($sql_del);
6363 $this->error = $this->db->lasterror();
6364 $this->db->rollback();
6367 $this->db->commit();
6384 global $conf, $langs, $user;
6390 if (empty($userused)) {
6396 if (!empty($this->array_options)) {
6398 $langs->load(
'admin');
6399 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6401 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6404 $new_array_options = array();
6405 foreach ($this->array_options as $key => $value) {
6406 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6407 $new_array_options[$key] = $value;
6408 } elseif (in_array($key, array_keys($target_extrafields))) {
6409 $new_array_options[
'options_'.$key] = $value;
6413 foreach ($new_array_options as $key => $value) {
6414 $attributeKey = substr($key, 8);
6415 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6416 $attributeLabel = $langs->transnoentities($extrafields->attributes[$this->table_element][
'label'][$attributeKey]);
6417 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6418 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6419 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6420 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6424 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6425 $new_array_options[$key] =
null;
6429 if ($attributeRequired) {
6430 $v = $this->array_options[$key];
6432 $langs->load(
"errors");
6433 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6434 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6442 if (!empty($attrfieldcomputed)) {
6444 $value =
dol_eval($attrfieldcomputed, 1, 0,
'2');
6445 dol_syslog($langs->trans(
"Extrafieldcomputed").
" on ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6446 $new_array_options[$key] = $value;
6448 $new_array_options[$key] =
null;
6452 switch ($attributeType) {
6454 if (!is_numeric($value) && $value !=
'') {
6455 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6457 } elseif ($value ==
'') {
6458 $new_array_options[$key] =
null;
6464 if (!is_numeric($value) && $value !=
'') {
6465 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6466 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6468 } elseif ($value ==
'') {
6472 $new_array_options[$key] = $value;
6482 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6484 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6485 $algo = reset($tmparrays);
6490 if (is_object($this->oldcopy)) {
6492 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6494 if ($algo ==
'dolcrypt') {
6495 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6496 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6498 $new_array_options[$key] = $this->array_options[$key];
6501 $new_array_options[$key] = $this->array_options[$key];
6505 if ($algo ==
'dolcrypt') {
6506 if (!preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6507 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6509 $new_array_options[$key] = $this->array_options[$key];
6512 $new_array_options[$key] =
dol_hash($this->array_options[$key], $algo);
6518 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[$key])) {
6519 $new_array_options[$key] =
dolEncrypt($this->array_options[$key]);
6521 $new_array_options[$key] = $this->array_options[$key];
6526 $new_array_options[$key] = $this->array_options[$key];
6529 $new_array_options[$key] = $this->array_options[$key];
6535 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6536 $this->array_options[$key] = strtotime($this->array_options[$key]);
6538 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6542 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6543 $this->array_options[$key] = strtotime($this->array_options[$key]);
6545 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6548 $param_list = array_keys($attributeParam[
'options']);
6551 $InfoFieldList = explode(
":", $param_list[0]);
6553 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6554 if ($value ==
'-1') {
6555 $new_array_options[$key] =
'';
6557 $object =
new $InfoFieldList[0]($this->db);
6558 if (is_numeric($value)) {
6559 $res = $object->fetch($value);
6561 $res = $object->fetch(
'', $value);
6565 $new_array_options[$key] = $object->id;
6567 $this->error =
"Id/Ref '".$value.
"' for object '".$object->element.
"' not found";
6572 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6577 if (is_array($this->array_options[$key])) {
6578 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6580 $new_array_options[$key] = $this->array_options[$key];
6588 $table_element = $this->table_element;
6589 if ($table_element ==
'categorie') {
6590 $table_element =
'categories';
6593 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
6595 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6596 $this->db->query($sql_del);
6598 $sql =
"INSERT INTO ".$this->db->prefix().$table_element.
"_extrafields (fk_object";
6599 foreach ($new_array_options as $key => $value) {
6600 $attributeKey = substr($key, 8);
6602 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6603 $sql .=
",".$attributeKey;
6607 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6608 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6609 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6610 $sql .=
",".$tmpkey;
6614 $sql .=
") VALUES (".$this->id;
6616 foreach ($new_array_options as $key => $value) {
6617 $attributeKey = substr($key, 8);
6619 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6620 if ($new_array_options[$key] !=
'' || $new_array_options[$key] ==
'0') {
6621 $sql .=
",'".$this->db->escape($new_array_options[$key]).
"'";
6628 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6629 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6630 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6631 if (in_array($tmpval, array(
'int',
'double',
'price'))) {
6642 $resql = $this->db->query($sql);
6644 $this->error = $this->db->lasterror();
6648 if (!$error && $trigger) {
6650 $this->context = array(
'extrafieldaddupdate'=>1);
6651 $result = $this->call_trigger($trigger, $userused);
6659 $this->db->rollback();
6662 $this->db->commit();
6682 global $conf, $langs, $user;
6684 if (empty($userused)) {
6694 if (is_array($this->array_languages)) {
6695 $new_array_languages = $this->array_languages;
6697 foreach ($new_array_languages as $key => $value) {
6698 $attributeKey = $key;
6699 $attributeType = $this->fields[$attributeKey][
'type'];
6700 $attributeLabel = $this->fields[$attributeKey][
'label'];
6705 switch ($attributeType) {
6707 if (!is_numeric($value) && $value !=
'') {
6708 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6710 } elseif ($value ==
'') {
6711 $new_array_languages[$key] =
null;
6716 if (!is_numeric($value) && $value !=
'') {
6717 dol_syslog($langs->trans(
"ExtraLanguageHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6718 $this->errors[] = $langs->trans(
"ExtraLanguageHasWrongValue", $attributeLabel);
6720 } elseif ($value ==
'') {
6721 $new_array_languages[$key] =
null;
6723 $new_array_languages[$key] = $value;
6737 $table_element = $this->table_element;
6738 if ($table_element ==
'categorie') {
6739 $table_element =
'categories';
6742 dol_syslog(get_class($this).
"::insertExtraLanguages delete then insert", LOG_DEBUG);
6744 foreach ($new_array_languages as $key => $langcodearray) {
6745 foreach ($langcodearray as $langcode => $value) {
6746 $sql_del =
"DELETE FROM ".$this->db->prefix().
"object_lang";
6747 $sql_del .=
" WHERE fk_object = ".((int) $this->
id).
" AND property = '".$this->db->escape($key).
"' AND type_object = '".$this->db->escape($table_element).
"'";
6748 $sql_del .=
" AND lang = '".$this->db->escape($langcode).
"'";
6749 $this->db->query($sql_del);
6751 if ($value !==
'') {
6752 $sql =
"INSERT INTO ".$this->db->prefix().
"object_lang (fk_object, property, type_object, lang, value";
6753 $sql .=
") VALUES (".$this->id.
", '".$this->db->escape($key).
"', '".$this->db->escape($table_element).
"', '".$this->db->escape($langcode).
"', '".$this->db->escape($value).
"'";
6756 $resql = $this->db->query($sql);
6758 $this->error = $this->db->lasterror();
6766 if (!$error && $trigger) {
6768 $this->context = array(
'extralanguagesaddupdate'=>1);
6769 $result = $this->call_trigger($trigger, $userused);
6777 $this->db->rollback();
6780 $this->db->commit();
6800 global $conf, $langs, $user, $hookmanager;
6806 if (empty($userused)) {
6812 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
6814 $langs->load(
'admin');
6815 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6817 $extrafields->fetch_name_optionals_label($this->table_element);
6819 $value = $this->array_options[
"options_".$key];
6821 $attributeKey = $key;
6822 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
6823 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
6824 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
6825 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
6826 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6827 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
6830 if ($attributeRequired) {
6831 $mandatorypb =
false;
6832 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
6833 $mandatorypb =
true;
6835 if ($this->array_options[
"options_".$key] ===
'') {
6836 $mandatorypb =
true;
6839 $langs->load(
"errors");
6840 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
6841 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6847 $new_array_options = $this->array_options;
6851 if (!empty($attrfieldcomputed)) {
6853 $value =
dol_eval($attrfieldcomputed, 1, 0,
'2');
6854 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6856 $new_array_options[
"options_".$key] = $value;
6858 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6860 $new_array_options[
"options_".$key] =
null;
6862 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6866 switch ($attributeType) {
6868 if (!is_numeric($value) && $value !=
'') {
6869 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6871 } elseif ($value ===
'') {
6872 $new_array_options[
"options_".$key] =
null;
6874 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6880 if (!is_numeric($value) && $value !=
'') {
6881 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6882 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6884 } elseif ($value ===
'') {
6888 $new_array_options[
"options_".$key] = $value;
6890 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6902 if ($this->array_options[
"options_".$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6904 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6905 $algo = reset($tmparrays);
6911 if (is_object($this->oldcopy)) {
6913 if (isset($this->oldcopy->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] == $this->oldcopy->array_options[
"options_".$key]) {
6914 if ($algo ==
'dolcrypt') {
6915 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
6916 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
6918 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6921 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6924 if ($algo ==
'dolcrypt') {
6925 if (!preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
6926 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
6928 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6931 $new_array_options[
"options_".$key] =
dol_hash($this->array_options[
"options_".$key], $algo);
6935 if ($algo ==
'dolcrypt' && !preg_match(
'/^dolcrypt:/', $this->array_options[
"options_".$key])) {
6936 $new_array_options[
"options_".$key] =
dolEncrypt($this->array_options[
"options_".$key]);
6938 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6943 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6946 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
6949 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6953 if (empty($this->array_options[
"options_".$key])) {
6954 $new_array_options[
"options_".$key] =
null;
6956 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6958 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
6962 if (empty($this->array_options[
"options_".$key])) {
6963 $new_array_options[
"options_".$key] =
null;
6965 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6967 $new_array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
6971 if (empty($this->array_options[
"options_".$key])) {
6972 $new_array_options[
"options_".$key] =
null;
6974 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
6978 if ($this->array_options[
"options_".$key] ===
'') {
6979 $new_array_options[
"options_".$key] =
null;
6981 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7015 $new_array_options = array();
7016 if (is_array($this->array_options[
"options_".$key])) {
7017 $new_array_options[
"options_".$key] = implode(
',', $this->array_options[
"options_".$key]);
7019 $new_array_options[
"options_".$key] = $this->array_options[
"options_".$key];
7022 $this->array_options[
"options_".$key] = $new_array_options[
"options_".$key];
7028 $linealreadyfound = 0;
7031 $table_element = $this->table_element;
7032 if ($table_element ==
'categorie') {
7033 $table_element =
'categories';
7036 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
7037 $resql = $this->db->query($sql);
7039 $tmpobj = $this->db->fetch_object($resql);
7041 $linealreadyfound = $tmpobj->nb;
7046 if ($linealreadyfound) {
7047 if ($this->array_options[
"options_".$key] ===
null) {
7048 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = null";
7050 $sql =
"UPDATE ".$this->db->prefix().$table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($new_array_options[
"options_".$key]).
"'";
7052 $sql .=
" WHERE fk_object = ".((int) $this->
id);
7054 $resql = $this->db->query($sql);
7057 $this->error = $this->db->lasterror();
7060 $result = $this->insertExtraFields(
'', $user);
7067 $parameters = array(
'key'=>$key);
7068 $reshook = $hookmanager->executeHooks(
'updateExtraFieldBeforeCommit', $parameters, $this, $action);
7074 if (!$error && $trigger) {
7076 $this->context = array(
'extrafieldupdate'=>1);
7077 $result = $this->call_trigger($trigger, $userused);
7085 dol_syslog(__METHOD__.$this->error, LOG_ERR);
7086 $this->db->rollback();
7089 $this->db->commit();
7109 global $conf, $langs, $user;
7111 if (empty($userused)) {
7139 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
7141 global $conf, $langs, $form;
7143 if (!is_object($form)) {
7144 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
7145 $form =
new Form($this->db);
7148 if (!empty($this->fields)) {
7149 $val = $this->fields[$key];
7153 $fieldValidationErrorMsg =
'';
7154 $validationClass =
'';
7155 $fieldValidationErrorMsg = $this->getFieldError($key);
7156 if (!empty($fieldValidationErrorMsg)) {
7157 $validationClass =
' --error';
7159 $validationClass =
' --success';
7166 $param[
'options'] = array();
7168 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
7170 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7171 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7173 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7174 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7176 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
7177 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7179 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7180 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
7182 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7183 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7185 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
7186 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
7188 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
7189 $param[
'options'] = array($reg[1] =>
'N');
7191 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
7192 $param[
'options'] = array();
7195 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
7196 $param[
'options'] = array();
7199 $param[
'options'] = array();
7200 $type = $this->fields[$key][
'type'];
7205 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
7206 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
7207 $type = (($this->fields[$key][
'type']==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
7210 $label = $this->fields[$key][
'label'];
7212 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
7213 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
7214 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
7215 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
7216 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
7218 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
7219 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
7220 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
7222 $objectid = $this->id;
7225 if (!preg_match(
'/^search_/', $keyprefix)) {
7226 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
7233 if (empty($morecss) && !empty($val[
'css'])) {
7234 $morecss = $val[
'css'];
7235 } elseif (empty($morecss)) {
7236 if ($type ==
'date') {
7237 $morecss =
'minwidth100imp';
7238 } elseif ($type ==
'datetime' || $type ==
'link') {
7239 $morecss =
'minwidth200imp';
7240 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
7241 $morecss =
'maxwidth75';
7242 } elseif ($type ==
'url') {
7243 $morecss =
'minwidth400';
7244 } elseif ($type ==
'boolean') {
7247 if (round($size) < 12) {
7248 $morecss =
'minwidth100';
7249 } elseif (round($size) <= 48) {
7250 $morecss =
'minwidth200';
7252 $morecss =
'minwidth400';
7258 if (!empty($validationClass)) {
7259 $morecss.= $validationClass;
7262 if (in_array($type, array(
'date'))) {
7263 $tmp = explode(
',', $size);
7268 if (!$required && $value ==
'') {
7273 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
7274 } elseif (in_array($type, array(
'datetime'))) {
7275 $tmp = explode(
',', $size);
7280 if (!$required && $value ==
'') {
7285 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
7286 } elseif (in_array($type, array(
'duration'))) {
7287 $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
7288 } elseif (in_array($type, array(
'int',
'integer'))) {
7289 $tmp = explode(
',', $size);
7291 $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' :
'').
'>';
7292 } elseif (in_array($type, array(
'real'))) {
7293 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7294 } elseif (preg_match(
'/varchar/', $type)) {
7295 $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' :
'').
'>';
7296 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
7297 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7298 } elseif (preg_match(
'/^text/', $type)) {
7299 if (!preg_match(
'/search_/', $keyprefix)) {
7300 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7301 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
7302 $out = $doleditor->Create(1);
7304 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7306 } elseif (preg_match(
'/^html/', $type)) {
7307 if (!preg_match(
'/search_/', $keyprefix)) {
7308 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7309 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
7310 $out = $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
7312 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7314 } elseif ($type ==
'boolean') {
7316 if (!empty($value)) {
7317 $checked =
' checked value="1" ';
7319 $checked =
' value="1" ';
7321 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
7322 } elseif ($type ==
'price') {
7323 if (!empty($value)) {
7324 $value =
price($value);
7326 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
7327 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
7328 if (!empty($value)) {
7329 $value =
price($value);
7331 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
7332 } elseif ($type ==
'select') {
7334 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
7335 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7336 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7339 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7340 if ((!isset($this->fields[$key][
'default'])) || ($this->fields[$key][
'notnull'] != 1)) {
7341 $out .=
'<option value="0"> </option>';
7343 foreach ($param[
'options'] as $keyb => $valb) {
7344 if ((
string) $keyb ==
'') {
7347 if (strpos($valb,
"|") !==
false) {
7348 list($valb, $parent) = explode(
'|', $valb);
7350 $out .=
'<option value="'.$keyb.
'"';
7351 $out .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
7352 if (!empty($parent)) {
7355 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7356 $out .=
'>'.$langs->trans($valb).
'</option>';
7358 $out .=
'</select>';
7359 } elseif ($type ==
'sellist') {
7361 if (!empty($conf->use_javascript_ajax) && !
getDolGlobalString(
'MAIN_EXTRAFIELDS_DISABLE_SELECT2')) {
7362 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7363 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7366 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7367 if (is_array($param[
'options'])) {
7368 $param_list = array_keys($param[
'options']);
7369 $InfoFieldList = explode(
":", $param_list[0], 5);
7370 if (! empty($InfoFieldList[4])) {
7372 $parenthesisopen = 0;
7373 while (substr($InfoFieldList[4], $pos, 1) !==
'' && ($parenthesisopen || $pos == 0 || substr($InfoFieldList[4], $pos, 1) !=
':')) {
7374 if (substr($InfoFieldList[4], $pos, 1) ==
'(') {
7377 if (substr($InfoFieldList[4], $pos, 1) ==
')') {
7382 $tmpbefore = substr($InfoFieldList[4], 0, $pos);
7383 $tmpafter = substr($InfoFieldList[4], $pos+1);
7385 $InfoFieldList[4] = $tmpbefore;
7386 if ($tmpafter !==
'') {
7387 $InfoFieldList = array_merge($InfoFieldList, explode(
':', $tmpafter));
7402 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7404 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7405 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7406 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7408 $keyList = $InfoFieldList[2].
' as rowid';
7411 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7412 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7413 $keyList .=
', '.$parentField;
7416 $filter_categorie =
false;
7417 if (count($InfoFieldList) > 5) {
7418 if ($InfoFieldList[0] ==
'categorie') {
7419 $filter_categorie =
true;
7423 if ($filter_categorie ===
false) {
7424 $fields_label = explode(
'|', $InfoFieldList[1]);
7425 if (is_array($fields_label)) {
7427 $keyList .= implode(
', ', $fields_label);
7431 $sql =
"SELECT " . $keyList;
7432 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7433 if (!empty($InfoFieldList[4])) {
7435 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7436 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7440 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7441 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7443 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7448 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7449 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
7450 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2];
7456 $sqlwhere .=
' WHERE 1=1';
7459 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7460 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7466 if (isset($InfoFieldList[7]) && preg_match(
'/^[a-z0-9_\-,]+$/i', $InfoFieldList[7])) {
7467 $sql .=
" ORDER BY ".$this->db->escape($InfoFieldList[7]);
7469 $sql .=
" ORDER BY ".$this->db->sanitize(implode(
', ', $fields_label));
7472 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
7473 $resql = $this->db->query($sql);
7475 $out .=
'<option value="0"> </option>';
7476 $num = $this->db->num_rows($resql);
7480 $obj = $this->db->fetch_object($resql);
7484 $fields_label = explode(
'|', $InfoFieldList[1]);
7485 if (count($fields_label) > 1) {
7487 foreach ($fields_label as $field_toshow) {
7488 $labeltoshow .= $obj->$field_toshow .
' ';
7491 $labeltoshow = $obj->{$InfoFieldList[1]};
7493 $labeltoshow =
dol_trunc($labeltoshow, 45);
7495 if ($value == $obj->rowid) {
7496 foreach ($fields_label as $field_toshow) {
7497 $translabel = $langs->trans($obj->$field_toshow);
7498 if ($translabel != $obj->$field_toshow) {
7499 $labeltoshow =
dol_trunc($translabel) .
' ';
7501 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
7504 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7507 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7508 if ($translabel != $obj->{$InfoFieldList[1]}) {
7509 $labeltoshow =
dol_trunc($translabel, 18);
7511 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
7514 if (empty($labeltoshow)) {
7515 $labeltoshow =
'(not defined)';
7517 if ($value == $obj->rowid) {
7518 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7521 if (!empty($InfoFieldList[3]) && $parentField) {
7522 $parent = $parentName .
':' . $obj->{$parentField};
7526 $out .=
'<option value="' . $obj->rowid .
'"';
7527 $out .= ($value == $obj->rowid ?
' selected' :
'');
7528 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
7529 $out .=
'>' . $labeltoshow .
'</option>';
7534 $this->db->free($resql);
7536 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7539 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7540 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7541 $out .=
'<option value="0"> </option>';
7542 foreach ($data as $data_key => $data_value) {
7543 $out .=
'<option value="' . $data_key .
'"';
7544 $out .= ($value == $data_key ?
' selected' :
'');
7545 $out .=
'>' . $data_value .
'</option>';
7549 $out .=
'</select>';
7550 } elseif ($type ==
'checkbox') {
7551 $value_arr = explode(
',', $value);
7552 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null : $param[
'options']), $value_arr,
'', 0, $morecss, 0,
'100%');
7553 } elseif ($type ==
'radio') {
7555 foreach ($param[
'options'] as $keyopt => $valopt) {
7556 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
7557 $out .=
' value="'.$keyopt.
'"';
7558 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
7559 $out .= ($value == $keyopt ?
'checked' :
'');
7560 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
7562 } elseif ($type ==
'chkbxlst') {
7563 if (is_array($value)) {
7564 $value_arr = $value;
7566 $value_arr = explode(
',', $value);
7569 if (is_array($param[
'options'])) {
7570 $param_list = array_keys($param[
'options']);
7571 $InfoFieldList = explode(
":", $param_list[0]);
7581 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7583 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7584 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7585 $keyList .=
', '.$parentField;
7587 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7588 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7589 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7591 $keyList = $InfoFieldList[2].
' as rowid';
7595 $filter_categorie =
false;
7596 if (count($InfoFieldList) > 5) {
7597 if ($InfoFieldList[0] ==
'categorie') {
7598 $filter_categorie =
true;
7602 if ($filter_categorie ===
false) {
7603 $fields_label = explode(
'|', $InfoFieldList[1]);
7604 if (is_array($fields_label)) {
7606 $keyList .= implode(
', ', $fields_label);
7610 $sql =
"SELECT " . $keyList;
7611 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
7612 if (!empty($InfoFieldList[4])) {
7614 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7615 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7619 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7620 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7622 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7626 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7627 $sql .=
' as main, ' . $this->db->prefix() . $InfoFieldList[0] .
'_extrafields as extra';
7628 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7630 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7633 $sqlwhere .=
' WHERE 1=1';
7636 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7637 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7643 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
7644 $resql = $this->db->query($sql);
7646 $num = $this->db->num_rows($resql);
7653 $obj = $this->db->fetch_object($resql);
7657 $fields_label = explode(
'|', $InfoFieldList[1]);
7658 if (count($fields_label) > 1) {
7660 foreach ($fields_label as $field_toshow) {
7661 $labeltoshow .= $obj->$field_toshow .
' ';
7664 $labeltoshow = $obj->{$InfoFieldList[1]};
7666 $labeltoshow =
dol_trunc($labeltoshow, 45);
7668 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7669 foreach ($fields_label as $field_toshow) {
7670 $translabel = $langs->trans($obj->$field_toshow);
7671 if ($translabel != $obj->$field_toshow) {
7672 $labeltoshow =
dol_trunc($translabel, 18) .
' ';
7674 $labeltoshow =
dol_trunc($obj->$field_toshow, 18) .
' ';
7678 $data[$obj->rowid] = $labeltoshow;
7681 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7682 if ($translabel != $obj->{$InfoFieldList[1]}) {
7683 $labeltoshow =
dol_trunc($translabel, 18);
7685 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]}, 18);
7688 if (empty($labeltoshow)) {
7689 $labeltoshow =
'(not defined)';
7692 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
7693 $data[$obj->rowid] = $labeltoshow;
7696 if (!empty($InfoFieldList[3]) && $parentField) {
7697 $parent = $parentName .
':' . $obj->{$parentField};
7701 $data[$obj->rowid] = $labeltoshow;
7706 $this->db->free($resql);
7708 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr,
'', 0, $morecss, 0,
'100%');
7710 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7713 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7714 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7715 $out = $form->multiselectarray($keyprefix . $key . $keysuffix, $data, $value_arr,
'', 0, $morecss, 0,
'100%');
7718 } elseif ($type ==
'link') {
7721 $param_list = array_keys($param[
'options']);
7722 $param_list_array = explode(
':', $param_list[0], 4);
7724 $showempty = (($required && $default !=
'') ? 0 : 1);
7726 if (!preg_match(
'/search_/', $keyprefix)) {
7727 if (!empty($param_list_array[2])) {
7728 if (!empty($this->fields[$key][
'picto'])) {
7729 $morecss .=
' widthcentpercentminusxx';
7731 $morecss .=
' widthcentpercentminusx';
7734 if (!empty($this->fields[$key][
'picto'])) {
7735 $morecss .=
' widthcentpercentminusx';
7739 $objectfield = $this->element.($this->module ?
'@'.$this->module :
'').
':'.$key.$keysuffix;
7740 $out = $form->selectForForms($param_list_array[0], $keyprefix.$key.$keysuffix, $value, $showempty,
'',
'', $morecss, $moreparam, 0, (empty($val[
'disabled']) ? 0 : 1),
'', $objectfield);
7742 if (!empty($param_list_array[2])) {
7743 if ((!GETPOSTISSET(
'backtopage') || strpos(
GETPOST(
'backtopage'), $_SERVER[
'PHP_SELF']) === 0)
7744 && empty($val[
'disabled']) && empty($nonewbutton)) {
7745 list($class, $classfile) = explode(
':', $param_list[0]);
7746 if (file_exists(
dol_buildpath(dirname(dirname($classfile)).
'/card.php'))) {
7747 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/card.php', 1);
7749 $url_path =
dol_buildpath(dirname(dirname($classfile)).
'/'.strtolower($class).
'_card.php', 1);
7751 $paramforthenewlink =
'';
7752 $paramforthenewlink .= (GETPOSTISSET(
'action') ?
'&action='.GETPOST(
'action',
'aZ09') :
'');
7753 $paramforthenewlink .= (GETPOSTISSET(
'id') ?
'&id='.GETPOST(
'id',
'int') :
'');
7754 $paramforthenewlink .= (GETPOSTISSET(
'origin') ?
'&origin='.GETPOST(
'origin',
'aZ09') :
'');
7755 $paramforthenewlink .= (GETPOSTISSET(
'originid') ?
'&originid='.GETPOST(
'originid',
'int') :
'');
7756 $paramforthenewlink .=
'&fk_'.strtolower($class).
'=--IDFORBACKTOPAGE--';
7758 $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>';
7761 } elseif ($type ==
'password') {
7763 if ($keyprefix.$key.$keysuffix ==
'pass_crypted') {
7764 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="pass" id="pass" value="" '.($moreparam ? $moreparam :
'').
'>';
7765 $out .=
'<input type="hidden" name="pass_crypted" id="pass_crypted" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
7767 $out =
'<input type="'.($keyprefix ==
'search_' ?
'text' :
'password').
'" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'>';
7769 } elseif ($type ==
'array') {
7771 $newval[
'type'] =
'varchar(256)';
7774 if (!empty($value)) {
7775 foreach ($value as $option) {
7776 $out .=
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
7777 $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]', $option, $moreparam,
'',
'', $morecss).
'<br></span>';
7780 $out .=
'<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>';
7782 $newInput =
'<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).
'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> ';
7783 $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.
'[]',
'', $moreparam,
'',
'', $morecss).
'<br></span>';
7785 if (!empty($conf->use_javascript_ajax)) {
7787 <script nonce="'.getNonce().
'">
7788 $(document).ready(function() {
7789 $("a#'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_add").click(function() {
7793 $(document).on("click", "a.'.
dol_escape_js($keyprefix.$key.$keysuffix).
'_del", function() {
7794 $(this).parent().remove();
7800 if (!empty($hidden)) {
7801 $out =
'<input type="hidden" value="'.$value.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'"/>';
7804 if ($isDependList == 1) {
7805 $out .= $this->getJSListDependancies(
'_common');
7813 if (!empty($fieldValidationErrorMsg) && function_exists(
'getFieldErrorIcon')) {
7814 $out .=
' '.getFieldErrorIcon($fieldValidationErrorMsg);
7833 public function showOutputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss =
'')
7835 global $conf, $langs, $form;
7837 if (!is_object($form)) {
7838 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
7839 $form =
new Form($this->db);
7842 $label = empty($val[
'label']) ?
'' : $val[
'label'];
7843 $type = empty($val[
'type']) ?
'' : $val[
'type'];
7844 $size = empty($val[
'css']) ?
'' : $val[
'css'];
7848 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
7851 } elseif (preg_match(
'/varchar/', $type)) {
7854 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
7855 $type = (($this->fields[$key][
'type']==
'checkbox') ? $this->fields[$key][
'type'] :
'select');
7857 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
7861 $default = empty($val[
'default']) ?
'' : $val[
'default'];
7862 $computed = empty($val[
'computed']) ?
'' : $val[
'computed'];
7863 $unique = empty($val[
'unique']) ?
'' : $val[
'unique'];
7864 $required = empty($val[
'required']) ?
'' : $val[
'required'];
7866 $param[
'options'] = array();
7868 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
7869 $param[
'options'] = $val[
'arrayofkeyval'];
7871 if (preg_match(
'/^integer:([^:]*):([^:]*)/i', $val[
'type'], $reg)) {
7873 $stringforoptions = $reg[1].
':'.$reg[2];
7875 if ($reg[1] ==
'User') {
7876 $stringforoptions .=
':#getnomurlparam1=-1';
7878 $param[
'options'] = array($stringforoptions => $stringforoptions);
7879 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7880 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
7882 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
7883 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
7885 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
7886 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
7888 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
7889 $param[
'options'] = array($reg[1] =>
'N');
7893 $langfile = empty($val[
'langfile']) ?
'' : $val[
'langfile'];
7894 $list = (empty($val[
'list']) ?
'' : $val[
'list']);
7895 $help = (empty($val[
'help']) ?
'' : $val[
'help']);
7896 $hidden = (($val[
'visible'] == 0) ? 1 : 0);
7906 $value =
dol_eval($computed, 1, 0,
'2');
7909 if (empty($morecss)) {
7910 if ($type ==
'date') {
7911 $morecss =
'minwidth100imp';
7912 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
7913 $morecss =
'minwidth200imp';
7914 } elseif (in_array($type, array(
'int',
'double',
'price'))) {
7915 $morecss =
'maxwidth75';
7916 } elseif ($type ==
'url') {
7917 $morecss =
'minwidth400';
7918 } elseif ($type ==
'boolean') {
7921 if (is_numeric($size) && round($size) < 12) {
7922 $morecss =
'minwidth100';
7923 } elseif (is_numeric($size) && round($size) <= 48) {
7924 $morecss =
'minwidth200';
7926 $morecss =
'minwidth400';
7932 if (in_array($key, array(
'rowid',
'ref')) && method_exists($this,
'getNomUrl')) {
7933 if ($key !=
'rowid' || empty($this->fields[
'ref'])) {
7934 $value = $this->getNomUrl(1,
'', 0,
'', 1);
7936 } elseif ($key ==
'status' && method_exists($this,
'getLibStatut')) {
7937 $value = $this->getLibStatut(3);
7938 } elseif ($type ==
'date') {
7939 if (!empty($value)) {
7944 } elseif ($type ==
'datetime' || $type ==
'timestamp') {
7945 if (!empty($value)) {
7950 } elseif ($type ==
'duration') {
7951 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
7952 if (!is_null($value) && $value !==
'') {
7955 } elseif ($type ==
'double' || $type ==
'real') {
7956 if (!is_null($value) && $value !==
'') {
7957 $value =
price($value);
7959 } elseif ($type ==
'boolean') {
7961 if (!empty($value)) {
7962 $checked =
' checked ';
7964 $value =
'<input type="checkbox" '.$checked.
' '.($moreparam ? $moreparam :
'').
' readonly disabled>';
7965 } elseif ($type ==
'mail' || $type ==
'email') {
7967 } elseif ($type ==
'url') {
7969 } elseif ($type ==
'phone') {
7971 } elseif ($type ==
'ip') {
7973 } elseif ($type ==
'price') {
7974 if (!is_null($value) && $value !==
'') {
7975 $value =
price($value, 0, $langs, 0, 0, -1, $conf->currency);
7977 } elseif ($type ==
'select') {
7978 $value = isset($param[
'options'][$value]) ? $param[
'options'][$value] :
'';
7979 if (strpos($value,
"|") !==
false) {
7980 $value = $langs->trans(explode(
'|', $value)[0]);
7982 } elseif ($type ==
'sellist') {
7983 $param_list = array_keys($param[
'options']);
7984 $InfoFieldList = explode(
":", $param_list[0]);
7986 $selectkey =
"rowid";
7989 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7990 $selectkey = $InfoFieldList[2];
7991 $keyList = $InfoFieldList[2].
' as rowid';
7994 $fields_label = explode(
'|', $InfoFieldList[1]);
7995 if (is_array($fields_label)) {
7997 $keyList .= implode(
', ', $fields_label);
8000 $filter_categorie =
false;
8001 if (count($InfoFieldList) > 5) {
8002 if ($InfoFieldList[0] ==
'categorie') {
8003 $filter_categorie =
true;
8007 $sql =
"SELECT ".$keyList;
8008 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8009 if (strpos($InfoFieldList[4],
'extra') !==
false) {
8012 if ($selectkey ==
'rowid' && empty($value)) {
8013 $sql .=
" WHERE ".$selectkey.
" = 0";
8014 } elseif ($selectkey ==
'rowid') {
8015 $sql .=
" WHERE ".$selectkey.
" = ".((int) $value);
8017 $sql .=
" WHERE ".$selectkey.
" = '".$this->db->escape($value).
"'";
8022 dol_syslog(get_class($this).
':showOutputField:$type=sellist', LOG_DEBUG);
8023 $resql = $this->db->query($sql);
8025 if ($filter_categorie ===
false) {
8027 $numrows = $this->db->num_rows($resql);
8029 $obj = $this->db->fetch_object($resql);
8032 $fields_label = explode(
'|', $InfoFieldList[1]);
8034 if (is_array($fields_label) && count($fields_label) > 1) {
8035 foreach ($fields_label as $field_toshow) {
8037 if (!empty($obj->$field_toshow)) {
8038 $translabel = $langs->trans($obj->$field_toshow);
8040 if ($translabel != $field_toshow) {
8041 $value .=
dol_trunc($translabel, 18) .
' ';
8043 $value .= $obj->$field_toshow .
' ';
8048 if (!empty($obj->{$InfoFieldList[1]})) {
8049 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8051 if ($translabel != $obj->{$InfoFieldList[1]}) {
8054 $value = $obj->{$InfoFieldList[1]};
8059 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8062 $obj = $this->db->fetch_object($resql);
8064 $c->fetch($obj->rowid);
8065 $ways = $c->print_all_ways();
8066 foreach ($ways as $way) {
8067 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8069 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8072 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8074 } elseif ($type ==
'radio') {
8075 $value = $param[
'options'][$value];
8076 } elseif ($type ==
'checkbox') {
8077 $value_arr = explode(
',', $value);
8079 if (is_array($value_arr) && count($value_arr) > 0) {
8081 foreach ($value_arr as $keyval => $valueval) {
8082 if (!empty($valueval)) {
8083 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $param[
'options'][$valueval] .
'</li>';
8086 if (!empty($toprint)) {
8087 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(
' ', $toprint) .
'</ul></div>';
8090 } elseif ($type ==
'chkbxlst') {
8091 $value_arr = explode(
',', $value);
8093 $param_list = array_keys($param[
'options']);
8094 $InfoFieldList = explode(
":", $param_list[0]);
8096 $selectkey =
"rowid";
8099 if (count($InfoFieldList) >= 3) {
8100 $selectkey = $InfoFieldList[2];
8101 $keyList = $InfoFieldList[2].
' as rowid';
8104 $fields_label = explode(
'|', $InfoFieldList[1]);
8105 if (is_array($fields_label)) {
8107 $keyList .= implode(
', ', $fields_label);
8110 $filter_categorie =
false;
8111 if (count($InfoFieldList) > 5) {
8112 if ($InfoFieldList[0] ==
'categorie') {
8113 $filter_categorie =
true;
8117 $sql =
"SELECT ".$keyList;
8118 $sql .=
' FROM '.$this->db->prefix().$InfoFieldList[0];
8119 if (strpos($InfoFieldList[4],
'extra') !==
false) {
8125 dol_syslog(get_class($this).
':showOutputField:$type=chkbxlst', LOG_DEBUG);
8126 $resql = $this->db->query($sql);
8128 if ($filter_categorie ===
false) {
8131 while ($obj = $this->db->fetch_object($resql)) {
8133 $fields_label = explode(
'|', $InfoFieldList[1]);
8134 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8135 if (is_array($fields_label) && count($fields_label) > 1) {
8136 foreach ($fields_label as $field_toshow) {
8138 if (!empty($obj->$field_toshow)) {
8139 $translabel = $langs->trans($obj->$field_toshow);
8141 if ($translabel != $field_toshow) {
8142 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8144 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->$field_toshow .
'</li>';
8149 if (!empty($obj->{$InfoFieldList[1]})) {
8150 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
8152 if ($translabel != $obj->{$InfoFieldList[1]}) {
8153 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' .
dol_trunc($translabel, 18) .
'</li>';
8155 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj->{$InfoFieldList[1]} .
'</li>';
8161 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
8164 while ($obj = $this->db->fetch_object($resql)) {
8165 if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
8167 $c->fetch($obj->rowid);
8168 $ways = $c->print_all_ways();
8169 foreach ($ways as $way) {
8170 $toprint[] =
'<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ?
' style="background: #' . $c->color .
';"' :
' style="background: #aaa"') .
'>' .
img_object(
'',
'category') .
' ' . $way .
'</li>';
8175 $value =
'<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(
' ', $toprint).
'</ul></div>';
8177 dol_syslog(get_class($this).
'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
8179 } elseif ($type ==
'link') {
8184 $param_list = array_keys($param[
'options']);
8188 $InfoFieldList = explode(
":", $param_list[0]);
8190 $classname = $InfoFieldList[0];
8191 $classpath = $InfoFieldList[1];
8194 $getnomurlparam = 3;
8195 $getnomurlparam2 =
'';
8197 if (preg_match(
'/#getnomurlparam1=([^#]*)/', $param_list[0], $regtmp)) {
8198 $getnomurlparam = $regtmp[1];
8200 if (preg_match(
'/#getnomurlparam2=([^#]*)/', $param_list[0], $regtmp)) {
8201 $getnomurlparam2 = $regtmp[1];
8204 if (!empty($classpath)) {
8207 if ($classname && !class_exists($classname)) {
8211 if ($element_prop) {
8212 $classname = $element_prop[
'classname'];
8217 if ($classname && class_exists($classname)) {
8218 $object =
new $classname($this->db);
8219 if ($object->element ===
'product') {
8220 $result = $object->fetch($value,
'',
'',
'', 0, 1, 1);
8222 $result = $object->fetch($value);
8225 if ($object->element ===
'product') {
8226 $get_name_url_param_arr = array($getnomurlparam, $getnomurlparam2, 0, -1, 0,
'', 0);
8227 if (isset($val[
'get_name_url_params'])) {
8228 $get_name_url_params = explode(
':', $val[
'get_name_url_params']);
8229 if (!empty($get_name_url_params)) {
8230 $param_num_max = count($get_name_url_param_arr) - 1;
8231 foreach ($get_name_url_params as $param_num => $param_value) {
8232 if ($param_num > $param_num_max) {
8235 $get_name_url_param_arr[$param_num] = $param_value;
8243 $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]);
8245 $value = $object->getNomUrl($getnomurlparam, $getnomurlparam2);
8252 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
8253 return 'Error bad setup of extrafield';
8258 } elseif ($type ==
'password') {
8259 $value = preg_replace(
'/./i',
'*', $value);
8260 } elseif ($type ==
'array') {
8261 $value = implode(
'<br>', $value);
8281 unset($this->validateFieldsErrors[$fieldKey]);
8295 $msg = $langs->trans(
"UnknowError");
8298 $this->error = $this->validateFieldsErrors[$fieldKey] = $msg;
8309 if (!empty($this->validateFieldsErrors[$fieldKey])) {
8310 return $this->validateFieldsErrors[$fieldKey];
8327 if (!class_exists(
'Validate')) {
8328 require_once DOL_DOCUMENT_ROOT .
'/core/class/validate.class.php';
8331 $this->clearFieldError($fieldKey);
8333 if (!isset($fields[$fieldKey])) {
8334 $this->setFieldError($fieldKey, $langs->trans(
'FieldNotFoundInObject'));
8338 $val = $fields[$fieldKey];
8341 $param[
'options'] = array();
8342 $type = $val[
'type'];
8345 if (isset($val[
'notnull']) && $val[
'notnull'] === 1) {
8359 if (preg_match(
'/varchar\((\d+)\)/', $type, $reg)) {
8362 } elseif (preg_match(
'/varchar/', $type)) {
8366 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8370 if (!empty($val[
'type']) && preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8374 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
8375 $param[
'options'] = $val[
'arrayofkeyval'];
8378 if (preg_match(
'/^integer:(.*):(.*)/i', $val[
'type'], $reg)) {
8380 $param[
'options'] = array($reg[1].
':'.$reg[2]=>$reg[1].
':'.$reg[2]);
8381 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8382 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
8384 } elseif (preg_match(
'/^sellist:(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
8385 $param[
'options'] = array($reg[1].
':'.$reg[2].
':'.$reg[3] =>
'N');
8387 } elseif (preg_match(
'/^sellist:(.*):(.*)/i', $val[
'type'], $reg)) {
8388 $param[
'options'] = array($reg[1].
':'.$reg[2] =>
'N');
8397 $validate =
new Validate($this->db, $langs);
8407 if ($required && !$validate->isNotEmptyString($fieldValue)) {
8408 $this->setFieldError($fieldKey, $validate->error);
8410 } elseif (!$required && !$validate->isNotEmptyString($fieldValue)) {
8416 if (!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)) {
8417 $this->setFieldError($fieldKey, $validate->error);
8422 if (!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)) {
8423 $this->setFieldError($fieldKey, $validate->error);
8431 if (in_array($type, array(
'date',
'datetime',
'timestamp'))) {
8432 if (!$validate->isTimestamp($fieldValue)) {
8433 $this->setFieldError($fieldKey, $validate->error);
8438 } elseif ($type ==
'duration') {
8439 if (!$validate->isDuration($fieldValue)) {
8440 $this->setFieldError($fieldKey, $validate->error);
8445 } elseif (in_array($type, array(
'double',
'real',
'price'))) {
8447 if (!$validate->isNumeric($fieldValue)) {
8448 $this->setFieldError($fieldKey, $validate->error);
8453 } elseif ($type ==
'boolean') {
8454 if (!$validate->isBool($fieldValue)) {
8455 $this->setFieldError($fieldKey, $validate->error);
8460 } elseif ($type ==
'mail') {
8461 if (!$validate->isEmail($fieldValue)) {
8462 $this->setFieldError($fieldKey, $validate->error);
8465 } elseif ($type ==
'url') {
8466 if (!$validate->isUrl($fieldValue)) {
8467 $this->setFieldError($fieldKey, $validate->error);
8472 } elseif ($type ==
'phone') {
8473 if (!$validate->isPhone($fieldValue)) {
8474 $this->setFieldError($fieldKey, $validate->error);
8479 } elseif ($type ==
'select' || $type ==
'radio') {
8480 if (!isset($param[
'options'][$fieldValue])) {
8481 $this->error = $langs->trans(
'RequireValidValue');
8486 } elseif ($type ==
'sellist' || $type ==
'chkbxlst') {
8487 $param_list = array_keys($param[
'options']);
8488 $InfoFieldList = explode(
":", $param_list[0]);
8489 $value_arr = explode(
',', $fieldValue);
8490 $value_arr = array_map(array($this->db,
'escape'), $value_arr);
8492 $selectkey =
"rowid";
8493 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
8494 $selectkey = $InfoFieldList[2];
8497 if (!$validate->isInDb($value_arr, $InfoFieldList[0], $selectkey)) {
8498 $this->setFieldError($fieldKey, $validate->error);
8503 } elseif ($type ==
'link') {
8504 $param_list = array_keys($param[
'options']);
8505 $InfoFieldList = explode(
":", $param_list[0]);
8506 $classname = $InfoFieldList[0];
8507 $classpath = $InfoFieldList[1];
8508 if (!$validate->isFetchable($fieldValue, $classname, $classpath)) {
8509 $lastIsFetchableError = $validate->error;
8512 if ($validate->isFetchableElement($fieldValue, $classname)) {
8516 $this->setFieldError($fieldKey, $lastIsFetchableError);
8540 public function showOptionals($extrafields, $mode =
'view', $params =
null, $keysuffix =
'', $keyprefix =
'', $onetrtd =
'', $display_type =
'card')
8542 global $db, $conf, $langs, $action, $form, $hookmanager;
8544 if (!is_object($form)) {
8545 $form =
new Form($db);
8547 if (!is_object($extrafields)) {
8548 dol_syslog(
'Bad parameter extrafields for showOptionals', LOG_ERR);
8549 return 'Bad parameter extrafields for showOptionals';
8551 if (!is_array($extrafields->attributes[$this->table_element])) {
8552 dol_syslog(
"extrafields->attributes was not loaded with extrafields->fetch_name_optionals_label(table_element);", LOG_WARNING);
8557 $parameters = array(
'mode'=>$mode,
'params'=>$params,
'keysuffix'=>$keysuffix,
'keyprefix'=>$keyprefix,
'display_type'=>$display_type);
8558 $reshook = $hookmanager->executeHooks(
'showOptionals', $parameters, $this, $action);
8560 if (empty($reshook)) {
8561 if (is_array($extrafields->attributes[$this->table_element]) && key_exists(
'label', $extrafields->attributes[$this->table_element]) && is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label']) > 0) {
8563 $out .=
'<!-- commonobject:showOptionals --> ';
8566 $nbofextrafieldsshown = 0;
8569 $lastseparatorkeyfound =
'';
8570 $extrafields_collapse_num =
'';
8571 $extrafields_collapse_num_old =
'';
8574 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $label) {
8578 if (is_array($params) && array_key_exists(
'onlykey', $params) && $key != $params[
'onlykey']) {
8584 if ($enabled && isset($extrafields->attributes[$this->table_element][
'enabled'][$key])) {
8585 $enabled =
dol_eval($extrafields->attributes[$this->table_element][
'enabled'][$key], 1, 1,
'2');
8587 if (empty($enabled)) {
8592 if ($visibility && isset($extrafields->attributes[$this->table_element][
'list'][$key])) {
8593 $visibility =
dol_eval($extrafields->attributes[$this->table_element][
'list'][$key], 1, 1,
'2');
8597 if ($perms && isset($extrafields->attributes[$this->table_element][
'perms'][$key])) {
8598 $perms =
dol_eval($extrafields->attributes[$this->table_element][
'perms'][$key], 1, 1,
'2');
8601 if (($mode ==
'create') && abs($visibility) != 1 && abs($visibility) != 3) {
8603 } elseif (($mode ==
'edit') && abs($visibility) != 1 && abs($visibility) != 3 && abs($visibility) != 4) {
8605 $ef_name =
'options_' . $key;
8606 $ef_value = $this->array_options[$ef_name];
8607 $out .=
'<input type="hidden" name="' . $ef_name .
'" id="' . $ef_name .
'" value="' . $ef_value .
'" />' .
"\n";
8609 } elseif ($mode ==
'view' && empty($visibility)) {
8612 if (empty($perms)) {
8617 if (!empty($extrafields->attributes[$this->table_element][
'langfile'][$key])) {
8618 $langs->load($extrafields->attributes[$this->table_element][
'langfile'][$key]);
8622 if (is_array($params) && count($params) > 0 && $display_type==
'card') {
8623 if (array_key_exists(
'cols', $params)) {
8624 $colspan = $params[
'cols'];
8625 } elseif (array_key_exists(
'colspan', $params)) {
8627 if (preg_match(
'/colspan="(\d+)"/', $params[
'colspan'], $reg)) {
8630 $colspan = $params[
'colspan'];
8634 $colspan = intval($colspan);
8638 $value = ((!empty($this->array_options) && array_key_exists(
"options_".$key.$keysuffix, $this->array_options)) ? $this->array_options[
"options_".$key.$keysuffix] :
null);
8644 $check =
'alphanohtml';
8645 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text'))) {
8646 $check =
'restricthtml';
8648 $getposttemp =
GETPOST($keyprefix.
'options_'.$key.$keysuffix, $check, 3);
8650 if (is_array($getposttemp) || $getposttemp !=
'' || GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix)) {
8651 if (is_array($getposttemp)) {
8653 $value = implode(
",", $getposttemp);
8655 $value = $getposttemp;
8657 } elseif (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'int'))) {
8658 $value =( !empty($this->array_options[
"options_".$key]) || (isset($this->array_options[
"options_".$key]) && $this->array_options[
"options_".$key] ===
'0')) ? $this->array_options[
"options_".$key] :
'';
8660 $value = (!empty($this->array_options[
"options_".$key]) ? $this->array_options[
"options_".$key] :
'');
8666 $nbofextrafieldsshown++;
8669 if ($extrafields->attributes[$this->table_element][
'type'][$key] ==
'separate') {
8670 $extrafields_collapse_num = $key;
8688 $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type, $mode);
8690 $lastseparatorkeyfound = $key;
8692 $collapse_group = $extrafields_collapse_num.(!empty($this->
id) ?
'_'.$this->id :
'');
8694 $class = (!empty($extrafields->attributes[$this->table_element][
'hidden'][$key]) ?
'hideobject ' :
'');
8696 if (is_array($params) && count($params) > 0) {
8697 if (array_key_exists(
'class', $params)) {
8698 $class .= $params[
'class'].
' ';
8700 if (array_key_exists(
'style', $params)) {
8701 $csstyle = $params[
'style'];
8706 $domData =
' data-element="extrafield"';
8707 $domData .=
' data-targetelement="'.$this->element.
'"';
8708 $domData .=
' data-targetid="'.$this->id.
'"';
8710 $html_id = (empty($this->
id) ?
'' :
'extrarow-'.$this->element.
'_'.$key.
'_'.$this->id);
8711 if ($display_type==
'card') {
8716 if ($action ==
'selectlines') {
8722 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'date'))) {
8723 $datenotinstring =
null;
8724 if (array_key_exists(
'options_'.$key, $this->array_options)) {
8725 $datenotinstring = $this->array_options[
'options_'.$key];
8726 if (!is_numeric($this->array_options[
'options_'.$key])) {
8727 $datenotinstring = $this->db->jdate($datenotinstring);
8730 $datekey = $keyprefix.
'options_'.$key.$keysuffix;
8731 $value = (GETPOSTISSET($datekey) && $this->
id ==
GETPOST(
'elrowid',
'int')) ?
dol_mktime(12, 0, 0,
GETPOST($datekey.
'month',
'int', 3),
GETPOST($datekey.
'day',
'int', 3),
GETPOST($datekey.
'year',
'int', 3)) : $datenotinstring;
8733 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'datetime'))) {
8734 $datenotinstring =
null;
8735 if (array_key_exists(
'options_'.$key, $this->array_options)) {
8736 $datenotinstring = $this->array_options[
'options_'.$key];
8737 if (!is_numeric($this->array_options[
'options_'.$key])) {
8738 $datenotinstring = $this->db->jdate($datenotinstring);
8741 $timekey = $keyprefix.
'options_'.$key.$keysuffix;
8742 $value = (GETPOSTISSET($timekey)) ?
dol_mktime(
GETPOST($timekey.
'hour',
'int', 3),
GETPOST($timekey.
'min',
'int', 3),
GETPOST($timekey.
'sec',
'int', 3),
GETPOST($timekey.
'month',
'int', 3),
GETPOST($timekey.
'day',
'int', 3),
GETPOST($timekey.
'year',
'int', 3),
'tzuserrel') : $datenotinstring;
8745 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'price',
'double'))) {
8746 if (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) {
8748 } elseif (isset($this->array_options[
'options_'.$key])) {
8749 $value = $this->array_options[
'options_'.$key];
8754 if (in_array($extrafields->attributes[$this->table_element][
'type'][$key], array(
'html',
'text',
'varchar',
'select',
'radio',
'int',
'boolean'))) {
8755 if ($action ==
'create' || $mode ==
'create') {
8756 $value = (GETPOSTISSET($keyprefix.
'options_'.$key.$keysuffix) || $value) ? $value : $extrafields->attributes[$this->table_element][
'default'][$key];
8760 $labeltoshow = $langs->trans($label);
8761 $helptoshow = $langs->trans($extrafields->attributes[$this->table_element][
'help'][$key]);
8763 if ($display_type ==
'card') {
8764 $out .=
'<tr '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="field_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
8765 if (
getDolGlobalString(
'MAIN_VIEW_LINE_NUMBER') && ($action ==
'view' || $action ==
'valid' || $action ==
'editline' || $action ==
'confirm_valid' || $action ==
'confirm_cancel')) {
8766 $out .=
'<td></td>';
8768 $out .=
'<td class="'.(empty($params[
'tdclass']) ?
'titlefieldcreate' : $params[
'tdclass']).
' wordbreak';
8769 } elseif ($display_type ==
'line') {
8770 $out .=
'<div '.($html_id ?
'id="'.$html_id.
'" ' :
'').$csstyle.
' class="fieldline_options_'.$key.
' '.$class.$this->element.
'_extras_'.$key.
' trextrafields_collapse'.$collapse_group.
'" '.$domData.
' >';
8771 $out .=
'<div style="display: inline-block; padding-right:4px" class="wordbreak';
8776 $tpl_context = isset($params[
"tpl_context"]) ? $params[
"tpl_context"] :
"none";
8777 if ($tpl_context !=
"public") {
8778 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
8779 $out .=
' fieldrequired';
8783 if ($tpl_context ==
"public") {
8784 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
8785 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
8787 $out .= $labeltoshow;
8789 if ($mode !=
'view' && !empty($extrafields->attributes[$this->table_element][
'required'][$key])) {
8790 $out .=
' <span style="color: red">*</span>';
8793 if (!empty($extrafields->attributes[$this->table_element][
'help'][$key])) {
8794 $out .= $form->textwithpicto($labeltoshow, $helptoshow);
8796 $out .= $labeltoshow;
8800 $out .= ($display_type ==
'card' ?
'</td>' :
'</div>');
8802 $html_id = !empty($this->
id) ? $this->element.
'_extras_'.$key.
'_'.$this->id :
'';
8803 if ($display_type ==
'card') {
8805 $out .=
'<td '.($html_id ?
'id="'.$html_id.
'" ' :
'').
' class="valuefieldcreate '.$this->element.
'_extras_'.$key.
'" '.($colspan ?
' colspan="'.$colspan.
'"' :
'').
'>';
8806 } elseif ($display_type ==
'line') {
8807 $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].
'">';
8812 $out .= $extrafields->showOutputField($key, $value,
'', $this->table_element);
8815 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'', 0, $this->
id, $this->table_element);
8818 $out .= $extrafields->showInputField($key, $value,
'', $keysuffix,
'', 0, $this->
id, $this->table_element);
8822 $out .= ($display_type==
'card' ?
'</td>' :
'</div>');
8825 $out .= ($display_type==
'card' ?
'</tr>' :
'</div>');
8827 $out .= ($display_type==
'card' ?
'</tr>' :
'</div>');
8835 if (!empty($conf->use_javascript_ajax)) {
8836 $out .= $this->getJSListDependancies();
8839 $out .=
'<!-- commonobject:showOptionals end --> '.
"\n";
8841 if (empty($nbofextrafieldsshown)) {
8847 $out .= $hookmanager->resPrint;
8859 <script nonce="'.getNonce().
'">
8860 jQuery(document).ready(function() {
8861 function showOptions'.$type.
'(child_list, parent_list, orig_select)
8863 var val = $("select[name=\""+parent_list+"\"]").val();
8864 var parentVal = parent_list + ":" + val;
8865 if(typeof val == "string"){
8867 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
8868 $("select[name=\""+child_list+"\"] option[parent]").remove();
8869 $("select[name=\""+child_list+"\"]").append(options);
8871 var options = orig_select.find("option[parent]").clone();
8872 $("select[name=\""+child_list+"\"] option[parent]").remove();
8873 $("select[name=\""+child_list+"\"]").append(options);
8875 } else if(val > 0) {
8876 var options = orig_select.find("option[parent=\""+parentVal+"\"]").clone();
8877 $("select[name=\""+child_list+"\"] option[parent]").remove();
8878 $("select[name=\""+child_list+"\"]").append(options);
8880 var options = orig_select.find("option[parent]").clone();
8881 $("select[name=\""+child_list+"\"] option[parent]").remove();
8882 $("select[name=\""+child_list+"\"]").append(options);
8885 function setListDependencies'.$type.
'() {
8886 jQuery("select option[parent]").parent().each(function() {
8887 var orig_select = {};
8888 var child_list = $(this).attr("name");
8889 orig_select[child_list] = $(this).clone();
8890 var parent = $(this).find("option[parent]:first").attr("parent");
8891 var infos = parent.split(":");
8892 var parent_list = infos[0];
8894 //Hide daughters lists
8895 if ($("#"+child_list).val() == 0 && $("#"+parent_list).val() == 0){
8896 $("#"+child_list).hide();
8898 } else if ($("#"+parent_list).val() != 0){
8899 $("#"+parent_list).show();
8901 //Show the child list if the parent list value is selected
8902 $("select[name=\""+parent_list+"\"]").click(function() {
8903 if ($(this).val() != 0){
8904 $("#"+child_list).show()
8908 //When we change parent list
8909 $("select[name=\""+parent_list+"\"]").change(function() {
8910 showOptions'.$type.
'(child_list, parent_list, orig_select[child_list]);
8911 //Select the value 0 on child list after a change on the parent list
8912 $("#"+child_list).val(0).trigger("change");
8913 //Hide child lists if the parent value is set to 0
8914 if ($(this).val() == 0){
8915 $("#"+child_list).hide();
8921 setListDependencies'.$type.
'();
8936 $module = empty($this->module) ?
'' : $this->module;
8937 $element = $this->element;
8939 if ($element ==
'facturerec') {
8940 $element =
'facture';
8941 } elseif ($element ==
'invoice_supplier_rec') {
8942 return !$user->hasRight(
'fournisseur',
'facture') ? null : $user->hasRight(
'fournisseur',
'facture');
8943 } elseif ($module && $user->hasRight($module, $element)) {
8945 return $user->hasRight($module, $element);
8948 return $user->rights->$element;
8965 foreach ($tables as $table) {
8966 $sql =
'UPDATE '.$dbs->prefix().$table.
' SET fk_soc = '.((int) $dest_id).
' WHERE fk_soc = '.((int) $origin_id);
8968 if (!$dbs->
query($sql)) {
8969 if ($ignoreerrors) {
8994 foreach ($tables as $table) {
8995 $sql =
'UPDATE '.MAIN_DB_PREFIX.$table.
' SET fk_product = '.((int) $dest_id).
' WHERE fk_product = '.((int) $origin_id);
8997 if (!$dbs->
query($sql)) {
8998 if ($ignoreerrors) {
9021 public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0)
9027 if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) &&
getDolGlobalInt(
'ForceBuyingPriceIfNull') > 0)) {
9029 $buyPrice = $unitPrice * (1 - $discountPercent / 100);
9032 if (!empty($fk_product) && $fk_product > 0) {
9034 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9035 $product =
new Product($this->db);
9036 $result = $product->fetch($fk_product);
9038 $this->errors[] =
'ErrorProductIdDoesNotExists';
9041 if ($product->cost_price > 0) {
9042 $buyPrice = $product->cost_price;
9043 } elseif ($product->pmp > 0) {
9044 $buyPrice = $product->pmp;
9047 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
9048 $product =
new Product($this->db);
9049 $result = $product->fetch($fk_product);
9051 $this->errors[] =
'ErrorProductIdDoesNotExists';
9054 if ($product->pmp > 0) {
9055 $buyPrice = $product->pmp;
9059 if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array(
'1',
'pmp',
'costprice'))) {
9060 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
9062 if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) {
9063 $buyPrice = $productFournisseur->fourn_unitprice;
9064 } elseif ($result < 0) {
9065 $this->errors[] = $productFournisseur->error;
9094 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')
9097 global $conf, $user, $langs;
9099 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
9100 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
9102 $sortfield =
'position_name';
9108 $dir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9109 $pdir .=
get_exdir(0, 0, 0, 0, $this, $modulepart);
9112 if ($modulepart ==
'product') {
9114 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9115 $pdir =
'/'.get_exdir($this->
id, 2, 0, 0, $this, $modulepart).$this->id.
"/photos/";
9122 $relativedir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $dir);
9123 $relativedir = preg_replace(
'/^[\\/]/',
'', $relativedir);
9124 $relativedir = preg_replace(
'/[\\/]$/',
'', $relativedir);
9127 $dirthumb = $dir.
'thumbs/';
9128 $pdirthumb = $pdir.
'thumbs/';
9130 $return =
'<!-- Photo -->'.
"\n";
9133 $filearray =
dol_dir_list($dir,
"files", 0,
'',
'(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) ==
'desc' ? SORT_DESC : SORT_ASC), 1);
9143 if (count($filearray)) {
9144 if ($sortfield && $sortorder) {
9148 foreach ($filearray as $key => $val) {
9150 $file = $val[
'name'];
9156 $viewfilename = $file;
9158 if ($size == 1 || $size ==
'small') {
9165 $photo_vignette = basename($file);
9172 if ($nbphoto == 1) {
9173 $return .=
'<table class="valigntop center centpercent" style="border: 0; padding: 2px; border-spacing: 2px; border-collapse: separate;">';
9176 if ($nbphoto % $nbbyrow == 1) {
9177 $return .=
'<tr class="center valignmiddle" style="border: 1px">';
9179 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%" class="photo">'.
"\n";
9180 } elseif ($nbbyrow < 0) {
9181 $return .=
'<div class="inline-block">'.
"\n";
9184 $relativefile = preg_replace(
'/^\//',
'', $pdir.$photo);
9185 if (empty($nolink)) {
9188 $return .=
'<a href="'.$urladvanced.
'">';
9190 $return .=
'<a href="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'" class="aphoto" target="_blank" rel="noopener noreferrer">';
9196 $alt = $langs->transnoentitiesnoconv(
'File').
': '.$relativefile;
9197 $alt .=
' - '.$langs->transnoentitiesnoconv(
'Size').
': '.$imgarray[
'width'].
'x'.$imgarray[
'height'];
9198 if ($overwritetitle) {
9199 if (is_numeric($overwritetitle)) {
9202 $alt = $overwritetitle;
9206 if ($usesharelink) {
9207 if ($val[
'share']) {
9208 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
9209 $return .=
'<!-- Show original file (thumb not yet available with shared links) -->';
9210 $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).
'">';
9212 $return .=
'<!-- Show original file -->';
9213 $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).
'">';
9216 $return .=
'<!-- Show nophoto file (because file is not shared) -->';
9217 $return .=
'<img class="photo photowithmargin'.($addphotorefcss ?
' '.$addphotorefcss :
'').
'" height="'.$maxHeight.
'" src="'.DOL_URL_ROOT.
'/public/theme/common/nophoto.png" title="'.
dol_escape_htmltag($alt).
'">';
9220 if (empty($maxHeight) || ($photo_vignette && $imgarray[
'height'] > $maxHeight)) {
9221 $return .=
'<!-- Show thumb -->';
9222 $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).
'">';
9224 $return .=
'<!-- Show original file -->';
9225 $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).
'">';
9229 if (empty($nolink)) {
9233 if ($showfilename) {
9234 $return .=
'<br>'.$viewfilename;
9239 if ($photo_vignette && (
image_format_supported($photo) > 0) && ((isset($this->imgWidth) && $this->imgWidth > $maxWidth) || (isset($this->imgHeight) && $this->imgHeight > $maxHeight))) {
9240 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=addthumb&token='.newToken().
'&file='.urlencode($pdir.$viewfilename).
'">'.
img_picto($langs->trans(
'GenerateThumb'),
'refresh').
' </a>';
9243 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
9245 $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> ';
9248 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
9256 if (($nbphoto % $nbbyrow) == 0) {
9259 } elseif ($nbbyrow < 0) {
9260 $return .=
'</div>'.
"\n";
9265 $return .=
'<img class="photo photowithmargin" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$modulepart.
'&entity='.$this->entity.
'&file='.urlencode($pdir.$photo).
'">';
9267 if ($showfilename) {
9268 $return .=
'<br>'.$viewfilename;
9272 if ($modulepart ==
'product' && ($user->hasRight(
'produit',
'creer') || $user->hasRight(
'service',
'creer'))) {
9274 $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> ';
9277 $return .=
'<a href="'.$_SERVER[
"PHP_SELF"].
'?id='.$this->
id.
'&action=delete&token='.newToken().
'&file='.urlencode($pdir.$viewfilename).
'">';
9284 if ($nbmax && $nbphoto >= $nbmax) {
9290 if ($size == 1 || $size ==
'small') {
9293 while ($nbphoto % $nbbyrow) {
9294 $return .=
'<td style="width: '.ceil(100 / $nbbyrow).
'%"> </td>';
9299 $return .=
'</table>';
9305 $this->nbphoto = $nbphoto;
9319 if (is_array($info)) {
9320 if (isset($info[
'type']) && $info[
'type'] ==
'array') {
9337 if (isset($info[
'type']) && ($info[
'type'] ==
'date' || $info[
'type'] ==
'datetime' || $info[
'type'] ==
'timestamp')) {
9351 if (is_array($info)) {
9352 if (isset($info[
'type']) && ($info[
'type'] ==
'duration')) {
9370 if (is_array($info)) {
9371 if (isset($info[
'type']) && (preg_match(
'/(^int|int$)/i', $info[
'type']))) {
9389 if (is_array($info)) {
9390 if (isset($info[
'type']) && (preg_match(
'/^(double|real|price)/i', $info[
'type']))) {
9407 if (is_array($info)) {
9408 if (isset($info[
'type']) && $info[
'type'] ==
'text') {
9425 if (is_array($info)) {
9426 if (isset($info[
'notnull']) && $info[
'notnull'] !=
'1') {
9443 if (is_array($info)) {
9444 if (isset($info[
'notnull']) && $info[
'notnull'] ==
'-1') {
9461 if (is_array($info)) {
9462 if (isset($info[
'index']) && $info[
'index'] ==
true) {
9484 $queryarray = array();
9485 foreach ($this->fields as $field => $info) {
9487 if ($this->isDate($info)) {
9488 if (empty($this->{$field})) {
9489 $queryarray[$field] =
null;
9491 $queryarray[$field] = $this->db->idate($this->{$field});
9493 } elseif ($this->isDuration($info)) {
9495 if ((isset($this->{$field}) && $this->{$field} !=
'') || !empty($info[
'notnull'])) {
9496 if (!isset($this->{$field})) {
9497 if (!empty($info[
'default'])) {
9498 $queryarray[$field] = $info[
'default'];
9500 $queryarray[$field] = 0;
9503 $queryarray[$field] = (int) $this->{$field};
9506 $queryarray[$field] =
null;
9508 } elseif ($this->isInt($info) || $this->isFloat($info)) {
9509 if ($field ==
'entity' && is_null($this->{$field})) {
9510 $queryarray[$field] = ((int) $conf->entity);
9513 if ((isset($this->{$field}) && ((
string) $this->{$field}) !=
'') || !empty($info[
'notnull'])) {
9514 if (!isset($this->{$field})) {
9515 $queryarray[$field] = 0;
9516 } elseif ($this->isInt($info)) {
9517 $queryarray[$field] = (int) $this->{$field};
9518 } elseif ($this->isFloat($info)) {
9519 $queryarray[$field] = (float) $this->{$field};
9522 $queryarray[$field] =
null;
9528 $queryarray[$field] = $this->{$field};
9531 if ($info[
'type'] ==
'timestamp' && empty($queryarray[$field])) {
9532 unset($queryarray[$field]);
9534 if (!empty($info[
'notnull']) && $info[
'notnull'] == -1 && empty($queryarray[$field])) {
9535 $queryarray[$field] =
null;
9552 foreach ($this->fields as $field => $info) {
9553 if ($this->isDate($info)) {
9554 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') {
9557 $this->$field = $db->jdate($obj->$field);
9559 } elseif ($this->isInt($info)) {
9560 if ($field ==
'rowid') {
9561 $this->
id = (int) $obj->$field;
9563 if ($this->isForcedToNullIfZero($info)) {
9564 if (empty($obj->$field)) {
9565 $this->$field =
null;
9567 $this->$field = (float) $obj->$field;
9570 if (isset($obj->$field) && (!is_null($obj->$field) || (isset($info[
'notnull']) && $info[
'notnull'] == 1))) {
9571 $this->$field = (int) $obj->$field;
9573 $this->$field =
null;
9577 } elseif ($this->isFloat($info)) {
9578 if ($this->isForcedToNullIfZero($info)) {
9579 if (empty($obj->$field)) {
9580 $this->$field =
null;
9582 $this->$field = (float) $obj->$field;
9585 if (isset($obj->$field) && (!is_null($obj->$field) || (isset($info[
'notnull']) && $info[
'notnull'] == 1))) {
9586 $this->$field = (float) $obj->$field;
9588 $this->$field =
null;
9592 $this->$field = isset($obj->$field) ? $obj->$field :
null;
9597 if (!isset($this->fields[
'ref']) && isset($this->
id)) {
9598 $this->
ref = $this->id;
9608 foreach ($this->fields as $field => $arr) {
9609 $this->$field =
null;
9622 $keys = array_keys($this->fields);
9623 if (!empty($alias)) {
9624 $keys_with_alias = array();
9625 foreach ($keys as $fieldname) {
9626 if (!empty($excludefields)) {
9627 if (in_array($fieldname, $excludefields)) {
9631 $keys_with_alias[] = $alias .
'.' . $fieldname;
9633 return implode(
',', $keys_with_alias);
9635 return implode(
',', $keys);
9646 protected function quote($value, $fieldsentry)
9648 if (is_null($value)) {
9650 } elseif (preg_match(
'/^(int|double|real|price)/i', $fieldsentry[
'type'])) {
9652 } elseif (preg_match(
'/int$/i', $fieldsentry[
'type'])) {
9653 return (
int) $value;
9654 } elseif ($fieldsentry[
'type'] ==
'boolean') {
9661 return "'".$this->db->escape($value).
"'";
9677 dol_syslog(get_class($this).
"::createCommon create", LOG_DEBUG);
9683 $fieldvalues = $this->setSaveQuery();
9685 if (array_key_exists(
'date_creation', $fieldvalues) && empty($fieldvalues[
'date_creation'])) {
9686 $fieldvalues[
'date_creation'] = $this->db->idate($now);
9688 if (array_key_exists(
'fk_user_creat', $fieldvalues) && !($fieldvalues[
'fk_user_creat'] > 0)) {
9689 $fieldvalues[
'fk_user_creat'] = $user->id;
9691 if (array_key_exists(
'pass_crypted', $fieldvalues) && property_exists($this,
'pass')) {
9692 $fieldvalues[
'pass_crypted'] =
dol_hash($this->pass);
9694 unset($fieldvalues[
'rowid']);
9695 if (array_key_exists(
'ref', $fieldvalues)) {
9701 foreach ($fieldvalues as $k => $v) {
9703 $value = $this->fields[$k];
9704 $values[$k] = $this->quote($v, $value);
9708 foreach ($keys as $key) {
9710 if (preg_match(
'/^integer:/i', $this->fields[$key][
'type']) && $values[$key] ==
'-1') {
9713 if (!empty($this->fields[$key][
'foreignkey']) && $values[$key] ==
'-1') {
9717 if (isset($this->fields[$key][
'notnull']) && $this->fields[$key][
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && is_null($this->fields[$key][
'default'])) {
9719 $langs->load(
"errors");
9720 dol_syslog(
"Mandatory field '".$key.
"' is empty and required into ->fields definition of class");
9721 $this->errors[] = $langs->trans(
"ErrorFieldRequired", $this->fields[$key][
'label']);
9725 if (isset($this->fields[$key][
'notnull']) && $this->fields[$key][
'notnull'] == 1 && (!isset($values[$key]) || $values[$key] ===
'NULL') && !is_null($this->fields[$key][
'default'])) {
9726 $values[$key] = $this->quote($this->fields[$key][
'default'], $this->fields[$key]);
9730 if (preg_match(
'/^integer:/i', $this->fields[$key][
'type']) && empty($values[$key])) {
9731 if (isset($this->fields[$key][
'default'])) {
9732 $values[$key] = ((int) $this->fields[$key][
'default']);
9734 $values[$key] =
'null';
9737 if (!empty($this->fields[$key][
'foreignkey']) && empty($values[$key])) {
9738 $values[$key] =
'null';
9749 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element;
9750 $sql .=
" (".implode(
", ", $keys).
')';
9751 $sql .=
" VALUES (".implode(
", ", $values).
")";
9753 $res = $this->db->query($sql);
9756 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
9757 $this->errors[] =
"ErrorRefAlreadyExists";
9759 $this->errors[] = $this->db->lasterror();
9765 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
9770 if (key_exists(
'ref', $this->fields) && key_exists(
'notnull', $this->fields[
'ref']) && $this->fields[
'ref'][
'notnull'] > 0 && key_exists(
'default', $this->fields[
'ref']) && $this->fields[
'ref'][
'default'] ==
'(PROV)') {
9771 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET ref = '(PROV".((int) $this->
id).
")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->
id);
9772 $resqlupdate = $this->db->query($sql);
9774 if ($resqlupdate ===
false) {
9776 $this->errors[] = $this->db->lasterror();
9778 $this->
ref =
'(PROV'.$this->id.
')';
9785 $result = $this->insertExtraFields();
9792 if (!empty($this->table_element_line) && !empty($this->fk_element)) {
9793 foreach ($this->lines as $line) {
9794 $keyforparent = $this->fk_element;
9795 $line->$keyforparent = $this->id;
9799 if (!is_object($line)) {
9800 $line = (object) $line;
9804 if (method_exists($line,
'insert')) {
9805 $result = $line->insert($user, 1);
9806 } elseif (method_exists($line,
'create')) {
9807 $result = $line->create($user, 1);
9810 $this->error = $line->error;
9811 $this->db->rollback();
9818 if (!$error && !$notrigger) {
9820 $result = $this->call_trigger(strtoupper(get_class($this)).
'_CREATE', $user);
9829 $this->db->rollback();
9832 $this->db->commit();
9847 public function fetchCommon($id, $ref =
null, $morewhere =
'', $noextrafields = 0)
9849 if (empty($id) && empty($ref) && empty($morewhere)) {
9853 $fieldlist = $this->getFieldList(
't');
9854 if (empty($fieldlist)) {
9858 $sql =
"SELECT ".$fieldlist;
9859 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
' as t';
9862 $sql .=
' WHERE t.rowid = '.((int) $id);
9863 } elseif (!empty($ref)) {
9864 $sql .=
" WHERE t.ref = '".$this->db->escape($ref).
"'";
9866 $sql .=
' WHERE 1 = 1';
9868 if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
9869 $sql .=
' AND t.entity IN ('.getEntity($this->element).
')';
9876 $res = $this->db->query($sql);
9878 $obj = $this->db->fetch_object($res);
9880 $this->setVarsFromFetchObj($obj);
9884 if (empty($noextrafields)) {
9885 $result = $this->fetch_optionals();
9887 $this->error = $this->db->lasterror();
9888 $this->errors[] = $this->error;
9898 $this->error = $this->db->lasterror();
9899 $this->errors[] = $this->error;
9913 $objectlineclassname = get_class($this).
'Line';
9914 if (!class_exists($objectlineclassname)) {
9915 $this->error =
'Error, class '.$objectlineclassname.
' not found during call of fetchLinesCommon';
9919 $objectline =
new $objectlineclassname($this->db);
9921 $sql =
"SELECT ".$objectline->getFieldList(
'l');
9922 $sql .=
" FROM ".$this->db->prefix().$objectline->table_element.
" as l";
9923 $sql .=
" WHERE l.fk_".$this->db->escape($this->element).
" = ".((int) $this->
id);
9927 if (isset($objectline->fields[
'position'])) {
9928 $sql .= $this->db->order(
'position',
'ASC');
9931 $resql = $this->db->query($sql);
9933 $num_rows = $this->db->num_rows($resql);
9935 $this->lines = array();
9936 while ($i < $num_rows) {
9937 $obj = $this->db->fetch_object($resql);
9939 $newline =
new $objectlineclassname($this->db);
9940 $newline->setVarsFromFetchObj($obj);
9948 $this->lines[] = $newline;
9955 $this->error = $this->db->lasterror();
9956 $this->errors[] = $this->error;
9970 dol_syslog(get_class($this).
"::updateCommon update", LOG_DEBUG);
9981 $fieldvalues = $this->setSaveQuery();
9983 if (array_key_exists(
'date_modification', $fieldvalues) && empty($fieldvalues[
'date_modification'])) {
9984 $fieldvalues[
'date_modification'] = $this->db->idate($now);
9986 if (array_key_exists(
'fk_user_modif', $fieldvalues) && !($fieldvalues[
'fk_user_modif'] > 0)) {
9987 $fieldvalues[
'fk_user_modif'] = $user->id;
9989 unset($fieldvalues[
'rowid']);
9990 if (array_key_exists(
'ref', $fieldvalues)) {
9998 foreach ($fieldvalues as $k => $v) {
10000 $value = $this->fields[$k];
10001 $values[$k] = $this->quote($v, $value);
10002 $tmp[] = $k.
'='.$this->quote($v, $this->fields[$k]);
10006 foreach ($keys as $key) {
10007 if (preg_match(
'/^integer:/i', $this->fields[$key][
'type']) && $values[$key] ==
'-1') {
10008 $values[$key] =
'';
10010 if (!empty($this->fields[$key][
'foreignkey']) && $values[$key] ==
'-1') {
10011 $values[$key] =
'';
10023 $sql =
'UPDATE '.$this->db->prefix().$this->table_element.
' SET '.implode(
', ', $tmp).
' WHERE rowid='.((int) $this->
id);
10025 $this->db->begin();
10028 $res = $this->db->query($sql);
10031 $this->errors[] = $this->db->lasterror();
10037 $result = $this->insertExtraFields();
10044 if (!$error && !$notrigger) {
10046 $result = $this->call_trigger(strtoupper(get_class($this)).
'_MODIFY', $user);
10055 $this->db->rollback();
10058 $this->db->commit();
10073 dol_syslog(get_class($this).
"::deleteCommon delete", LOG_DEBUG);
10077 $this->db->begin();
10079 if ($forcechilddeletion) {
10080 foreach ($this->childtables as $table) {
10081 $sql =
"DELETE FROM ".$this->db->prefix().$table.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10082 $resql = $this->db->query($sql);
10084 $this->error = $this->db->lasterror();
10085 $this->errors[] = $this->error;
10086 $this->db->rollback();
10090 } elseif (!empty($this->childtables)) {
10091 $objectisused = $this->isObjectUsed($this->
id);
10092 if (!empty($objectisused)) {
10093 dol_syslog(get_class($this).
"::deleteCommon Can't delete record as it has some child", LOG_WARNING);
10094 $this->error =
'ErrorRecordHasChildren';
10095 $this->errors[] = $this->error;
10096 $this->db->rollback();
10102 if (is_array($this->childtablesoncascade) && !empty($this->childtablesoncascade)) {
10103 foreach ($this->childtablesoncascade as $table) {
10104 $deleteFromObject = explode(
':', $table);
10105 if (count($deleteFromObject) >= 2) {
10106 $className = str_replace(
'@',
'', $deleteFromObject[0]);
10107 $filePath = $deleteFromObject[1];
10108 $columnName = $deleteFromObject[2];
10109 $TMoreSQL = array();
10110 if (!empty($deleteFromObject[3])) {
10111 $TMoreSQL[
'customsql'] = $deleteFromObject[3];
10114 $childObject =
new $className($this->db);
10115 if (method_exists($childObject,
'deleteByParentField')) {
10116 $result = $childObject->deleteByParentField($this->
id, $columnName, $TMoreSQL);
10119 $this->errors[] = $childObject->error;
10124 $this->errors[] =
"You defined a cascade delete on an object $childObject but there is no method deleteByParentField for it";
10129 $this->errors[] =
'Cannot include child class file '.$filePath;
10134 $sql =
"DELETE FROM ".$this->db->prefix().$table.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
10136 $resql = $this->db->query($sql);
10139 $this->error = $this->db->lasterror();
10140 $this->errors[] = $this->error;
10150 $result = $this->call_trigger(strtoupper(get_class($this)).
'_DELETE', $user);
10160 $res = $this->deleteEcmFiles(1);
10167 $res = $this->deleteObjectLinked();
10172 if (!$error && !empty($this->isextrafieldmanaged)) {
10173 $result = $this->deleteExtraFields();
10180 $sql =
'DELETE FROM '.$this->db->prefix().$this->table_element.
' WHERE rowid='.((int) $this->
id);
10182 $resql = $this->db->query($sql);
10185 $this->errors[] = $this->db->lasterror();
10191 $this->db->rollback();
10194 $this->db->commit();
10216 if (!empty($parentId) && !empty($parentField)) {
10217 $this->db->begin();
10219 $sql =
"SELECT rowid FROM ".$this->db->prefix().$this->table_element;
10220 $sql .=
" WHERE ".$parentField.
" = ".(int) $parentId;
10223 $sqlwhere = array();
10224 if (count($filter) > 0) {
10225 foreach ($filter as $key => $value) {
10226 if ($key ==
'customsql') {
10227 $sqlwhere[] = $value;
10228 } elseif (strpos($value,
'%') ===
false) {
10229 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
10231 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
10235 if (count($sqlwhere) > 0) {
10236 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
10239 $resql = $this->db->query($sql);
10241 $this->errors[] = $this->db->lasterror();
10244 while ($obj = $this->db->fetch_object($resql)) {
10245 $result = $this->fetch($obj->rowid);
10248 $this->errors[] = $this->error;
10250 $result = $this->
delete($user);
10253 $this->errors[] = $this->error;
10261 if (empty($error)) {
10262 $this->db->commit();
10265 $this->error = implode(
', ', $this->errors);
10266 $this->db->rollback();
10267 return $error * -1;
10288 $tmpforobjectclass = get_class($this);
10289 $tmpforobjectlineclass = ucfirst($tmpforobjectclass).
'Line';
10291 $this->db->begin();
10294 $result = $this->call_trigger(
'LINE'.strtoupper($tmpforobjectclass).
'_DELETE', $user);
10300 if (empty($error)) {
10301 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element_line;
10302 $sql .=
" WHERE rowid = ".((int) $idline);
10304 $resql = $this->db->query($sql);
10306 $this->error =
"Error ".$this->db->lasterror();
10311 if (empty($error)) {
10313 $tmpobjectline =
new $tmpforobjectlineclass($this->db);
10314 if (!isset($tmpobjectline->isextrafieldmanaged) || !empty($tmpobjectline->isextrafieldmanaged)) {
10315 $tmpobjectline->id = $idline;
10316 $result = $tmpobjectline->deleteExtraFields();
10319 $this->error =
"Error ".get_class($this).
"::deleteLineCommon deleteExtraFields error -4 ".$tmpobjectline->error;
10324 if (empty($error)) {
10325 $this->db->commit();
10328 dol_syslog(get_class($this).
"::deleteLineCommon ERROR:".$this->error, LOG_ERR);
10329 $this->db->rollback();
10348 $this->db->begin();
10350 $statusfield =
'status';
10351 if (in_array($this->element, array(
'don',
'donation',
'shipping'))) {
10352 $statusfield =
'fk_statut';
10355 $sql =
"UPDATE ".$this->db->prefix().$this->table_element;
10356 $sql .=
" SET ".$statusfield.
" = ".((int) $status);
10357 $sql .=
" WHERE rowid = ".((int) $this->
id);
10359 if ($this->db->query($sql)) {
10361 $this->oldcopy = clone $this;
10364 if (!$error && !$notrigger) {
10366 $result = $this->call_trigger($triggercode, $user);
10373 $this->
status = $status;
10374 $this->db->commit();
10377 $this->db->rollback();
10381 $this->error = $this->db->error();
10382 $this->db->rollback();
10399 $this->specimen = 1;
10401 'label' =>
'This is label',
10402 'ref' =>
'ABCD1234',
10403 'description' =>
'This is a description',
10405 'note_public' =>
'Public note',
10406 'note_private' =>
'Private note',
10407 'date_creation' => (
dol_now() - 3600 * 48),
10408 'date_modification' => (
dol_now() - 3600 * 24),
10409 'fk_user_creat' => $user->id,
10410 'fk_user_modif' => $user->id,
10413 foreach ($fields as $key => $value) {
10414 if (array_key_exists($key, $this->fields)) {
10415 $this->{$key} = $value;
10420 if (property_exists($this,
'fields')) {
10421 foreach ($this->fields as $key => $value) {
10423 if (array_key_exists($key, $fields)) {
10427 if (!empty($value[
'default'])) {
10428 $this->$key = $value[
'default'];
10445 require_once DOL_DOCUMENT_ROOT.
'/core/class/comment.class.php';
10447 $comment =
new Comment($this->db);
10448 $result = $comment->fetchAllFor($this->element, $this->
id);
10450 $this->errors = array_merge($this->errors, $comment->errors);
10453 $this->comments = $comment->comments;
10455 return count($this->comments);
10465 return count($this->comments);
10476 if (!is_array($parameters)) {
10479 foreach ($parameters as $parameter) {
10480 if (isset($this->$parameter)) {
10481 $this->$parameter = trim($this->$parameter);
10500 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
10504 $existing = $c->containing($this->
id, $type_categ,
'id');
10524 if (!is_array($categories)) {
10525 $categories = array($categories);
10528 dol_syslog(get_class($this).
"::setCategoriesCommon Oject Id:".$this->
id.
' type_categ:'.$type_categ.
' nb tag add:'.count($categories), LOG_DEBUG);
10530 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
10532 if (empty($type_categ)) {
10533 dol_syslog(__METHOD__.
': Type '.$type_categ.
'is an unknown category type. Done nothing.', LOG_ERR);
10539 $existing = $c->containing($this->
id, $type_categ,
'id');
10540 if ($remove_existing) {
10542 if (is_array($existing)) {
10543 $to_del = array_diff($existing, $categories);
10544 $to_add = array_diff($categories, $existing);
10547 $to_add = $categories;
10551 $to_add = array_diff($categories, $existing);
10558 foreach ($to_del as $del) {
10559 if ($c->fetch($del) > 0) {
10560 $result=$c->del_type($this, $type_categ);
10563 $this->error = $c->error;
10564 $this->errors = $c->errors;
10571 foreach ($to_add as $add) {
10572 if ($c->fetch($add) > 0) {
10573 $result = $c->add_type($this, $type_categ);
10576 $this->error = $c->error;
10577 $this->errors = $c->errors;
10585 return $error ? (-1 * $error) : $ok;
10598 $this->db->begin();
10600 if (empty($type)) {
10601 $type = $this->table_element;
10604 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
10605 $categorystatic =
new Categorie($this->db);
10607 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_product)";
10608 $sql .=
" SELECT fk_categorie, $toId FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
10609 $sql .=
" WHERE fk_product = ".((int) $fromId);
10611 if (!$this->db->query($sql)) {
10612 $this->error = $this->db->lasterror();
10613 $this->db->rollback();
10617 $this->db->commit();
10631 $this->db->begin();
10635 switch ($this->element) {
10637 $element =
'propale';
10640 $element =
'produit';
10642 case 'order_supplier':
10643 $element =
'fournisseur/commande';
10645 case 'invoice_supplier':
10648 $element =
'fournisseur/facture/'.get_exdir($this->
id, 2, 0, 1, $this,
'invoice_supplier');
10651 $element =
'expedition/sending';
10654 case 'project_task':
10655 require_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
10657 $project_result = $this->fetch_projet();
10658 if ($project_result >= 0) {
10659 $element =
'projet/'.dol_sanitizeFileName($this->project->ref).
'/';
10663 $element = $this->element;
10667 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files_extrafields WHERE fk_object IN (";
10668 $sql .=
" SELECT rowid FROM ".$this->db->prefix().
"ecm_files WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
10669 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
10672 if (!$this->db->query($sql)) {
10673 $this->error = $this->db->lasterror();
10674 $this->db->rollback();
10679 $sql =
"DELETE FROM ".$this->db->prefix().
"ecm_files";
10680 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%'";
10681 $sql .=
" AND filepath = '".$this->db->escape($element).
"/".$this->db->escape($this->
ref).
"' AND entity = ".((int) $conf->entity);
10683 if (!$this->db->query($sql)) {
10684 $this->error = $this->db->lasterror();
10685 $this->db->rollback();
10692 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files_extrafields";
10693 $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).
")";
10694 $resql = $this->db->query($sql);
10696 $this->error = $this->db->lasterror();
10697 $this->db->rollback();
10701 $sql =
'DELETE FROM '.$this->db->prefix().
"ecm_files";
10702 $sql .=
" WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ?
"" :
"@".$this->module)).
"' AND src_object_id = ".((int) $this->
id);
10703 $resql = $this->db->query($sql);
10705 $this->error = $this->db->lasterror();
10706 $this->db->rollback();
10711 $this->db->commit();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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.
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
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.
deleteLineCommon(User $user, $idline, $notrigger=false)
Delete a line of object in database.
static deleteAllItemsLinkedByObjectID($fk_object_where, $field_where, $table_element)
Function used to remove all items linked to an object id in association table.
deleteByParentField($parentId=0, $parentField='', $filter=array(), $filtermode="AND")
Delete all child object from a parent ID.
setFieldError($fieldKey, $msg='')
set validation error message a field
validateField($fields, $fieldKey, $fieldValue)
Return validation test result for a field.
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.
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.
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.
setExtraParameters()
Set extra parameters.
setErrorsFromObject($object)
setErrorsFromObject
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 an object id/ref exists If you don't need/want to instantiate object and just need to know if o...
isObjectUsed($id=0, $entity=0)
Function to check if an object is used by others (by children).
createCommon(User $user, $notrigger=false)
Create object into database.
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.
getTotalWeightVolume()
Return into unit=0, the calculated total of weight and volume of all lines * qty Calculate by adding ...
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
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.
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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.
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.
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.
setBankAccount($fk_account, $notrigger=false, $userused=null)
Change the bank account.
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.
setShippingMethod($shipping_method_id, $notrigger=false, $userused=null)
Change the shipping method.
initAsSpecimenCommon()
Initialise object with example values Id must be 0 if object instance is a specimen.
printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected=0, $extrafields=null, $defaulttpldir='/core/tpl')
Return HTML content of a detail line TODO Move this into an output class file (htmlline....
copy_linked_contact($objFrom, $source='internal')
Copy contact from one element to current.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
getValueFrom($table, $id, $field)
Getter generic.
trimParameters($parameters)
Trim object parameters.
fetch_product()
Load the product with id $this->fk_product into this->product.
isIndex($info)
Function test if is indexed.
quote($value, $fieldsentry)
Add quote to field value if necessary.
formAddObjectLine($dateSelector, $seller, $buyer, $defaulttpldir='/core/tpl')
Show add free and predefined products/services form.
fetchComments()
Load comments linked with current task.
line_down($rowid, $fk_parent_line=true)
Update a line to have a higher rank.
setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif')
Setter generic.
fetch_contact($contactid=null)
Load object contact with id=$this->contact_id into $this->contact.
setRetainedWarrantyPaymentTerms($id)
Change the retained warranty payments terms.
delThumbs($file)
Delete thumbs.
show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $overwritetitle=0, $usesharelink=0, $cache='', $addphotorefcss='photoref')
Show photos of an object (nbmax maximum), into several columns.
updateCommon(User $user, $notrigger=false)
Update object into database.
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.
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.
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.
getFormatedCustomerRef($objref)
Return customer ref for screen output.
getTooltipContentArray($params)
Return array of datas 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 datas.
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=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $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($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 informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
dol_print_ip($ip, $mode=0)
Return an IP formated to be shown on screen.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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 '.
get_date_range($date_start, $date_end, $format='', $outputlangs='', $withparenthesis=1)
Format output for start and end date.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_format_address($object, $withcountry=0, $sep="\n", $outputlangs='', $mode=0, $extralangcode='')
Return a formated address (part address/zip/town/state) according to country rules.
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_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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
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.
getElementProperties($element_type)
Get an array with properties of an element.
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_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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
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.
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 symetric encryption.
dolDecrypt($chain, $key='')
Decode a string with a symetric encryption.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.