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);
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();
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";
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->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();
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];
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();
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';
4189 $classfile = strtolower($subelement);
4190 $classname = ucfirst($subelement);
4192 if ($objecttype ==
'order') {
4193 $classfile =
'commande';
4194 $classname =
'Commande';
4195 } elseif ($objecttype ==
'invoice_supplier') {
4196 $classfile =
'fournisseur.facture';
4197 $classname =
'FactureFournisseur';
4198 } elseif ($objecttype ==
'order_supplier') {
4199 $classfile =
'fournisseur.commande';
4200 $classname =
'CommandeFournisseur';
4201 } elseif ($objecttype ==
'supplier_proposal') {
4202 $classfile =
'supplier_proposal';
4203 $classname =
'SupplierProposal';
4204 } elseif ($objecttype ==
'facturerec') {
4205 $classfile =
'facture-rec';
4206 $classname =
'FactureRec';
4207 } elseif ($objecttype ==
'subscription') {
4208 $classfile =
'subscription';
4209 $classname =
'Subscription';
4210 } elseif ($objecttype ==
'project' || $objecttype ==
'projet') {
4211 $classpath =
'projet/class';
4212 $classfile =
'project';
4213 $classname =
'Project';
4214 } elseif ($objecttype ==
'conferenceorboothattendee') {
4215 $classpath =
'eventorganization/class';
4216 $classfile =
'conferenceorboothattendee';
4217 $classname =
'ConferenceOrBoothAttendee';
4218 $module =
'eventorganization';
4219 } elseif ($objecttype ==
'conferenceorbooth') {
4220 $classpath =
'eventorganization/class';
4221 $classfile =
'conferenceorbooth';
4222 $classname =
'ConferenceOrBooth';
4223 $module =
'eventorganization';
4224 } elseif ($objecttype ==
'mo') {
4225 $classpath =
'mrp/class';
4232 if (isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4233 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4236 if (class_exists($classname)) {
4237 foreach ($objectids as $i => $objectid) {
4238 $object =
new $classname($this->db);
4239 $ret = $object->fetch($objectid);
4241 $this->linkedObjects[$objecttype][$i] = $object;
4247 unset($this->linkedObjectsIds[$objecttype]);
4890 foreach ($this->lines as $line) {
4891 if (isset($line->qty_asked)) {
4892 if (empty($totalOrdered)) {
4895 $totalOrdered += $line->qty_asked;
4897 if (isset($line->qty_shipped)) {
4898 if (empty($totalToShip)) {
4901 $totalToShip += $line->qty_shipped;
4902 } elseif ($line->element ==
'commandefournisseurdispatch' && isset($line->qty)) {
4903 if (empty($totalToShip)) {
4906 $totalToShip += $line->qty;
4910 if ($this->element ==
'shipping') {
4912 $qty = $line->qty_shipped ? $line->qty_shipped : 0;
4914 $qty = $line->qty ? $line->qty : 0;
4917 $weight = !empty($line->weight) ? $line->weight : 0;
4918 ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0;
4919 $volume = !empty($line->volume) ? $line->volume : 0;
4920 ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0;
4922 $weight_units = !empty($line->weight_units) ? $line->weight_units : 0;
4923 ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0;
4924 $volume_units = !empty($line->volume_units) ? $line->volume_units : 0;
4925 ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0;
4929 if (!empty($weight_units)) {
4930 $weightUnit = $weight_units;
4932 if (!empty($volume_units)) {
4933 $volumeUnit = $volume_units;
4936 if (empty($totalWeight)) {
4939 if (empty($totalVolume)) {
4944 if ($weight_units < 50) {
4945 $trueWeightUnit = pow(10, $weightUnit);
4946 $totalWeight += $weight * $qty * $trueWeightUnit;
4948 if ($weight_units == 99) {
4950 $trueWeightUnit = 0.45359237;
4951 $totalWeight += $weight * $qty * $trueWeightUnit;
4952 } elseif ($weight_units == 98) {
4954 $trueWeightUnit = 0.0283495;
4955 $totalWeight += $weight * $qty * $trueWeightUnit;
4957 $totalWeight += $weight * $qty;
4960 if ($volume_units < 50) {
4962 $trueVolumeUnit = pow(10, $volumeUnit);
4964 $totalVolume += $volume * $qty * $trueVolumeUnit;
4966 $totalVolume += $volume * $qty;
4970 return array(
'weight'=>$totalWeight,
'volume'=>$totalVolume,
'ordered'=>$totalOrdered,
'toship'=>$totalToShip);
5069 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
5071 global $conf, $hookmanager, $langs, $user, $form, $extrafields, $object;
5073 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
5077 if (isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
5081 $num = count($this->lines);
5084 if (!is_object($extrafields)) {
5085 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
5088 $extrafields->fetch_name_optionals_label($this->table_element_line);
5090 $parameters = array(
'num'=>$num,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$this->table_element_line);
5091 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
5092 if (empty($reshook)) {
5096 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5097 foreach ($dirtpls as $module => $reldir) {
5099 if (!empty($module)) {
5102 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
5104 if (file_exists($tpl)) {
5105 if (empty($conf->file->strict_mode)) {
5106 $res = @include $tpl;
5108 $res = include $tpl;
5119 print
"<!-- begin printObjectLines() --><tbody>\n";
5120 foreach ($this->lines as $line) {
5122 $line->fetch_optionals();
5125 if (is_object($hookmanager)) {
5126 if (empty($line->fk_parent_line)) {
5127 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element,
'defaulttpldir'=>$defaulttpldir);
5128 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
5130 $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);
5131 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
5134 if (empty($reshook)) {
5135 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
5140 print
"</tbody><!-- end printObjectLines() -->\n";
5160 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
5162 global $conf, $langs, $user, $object, $hookmanager;
5164 global $object_rights, $disableedit, $disablemove, $disableremove;
5166 $object_rights = $this->getRights();
5173 if ($action !=
'editline' || $selected != $line->id) {
5175 if (!empty($line->fk_product) && $line->fk_product > 0) {
5176 $product_static =
new Product($this->db);
5177 $product_static->fetch($line->fk_product);
5179 $product_static->ref = $line->ref;
5180 $product_static->label = !empty($line->label) ? $line->label :
"";
5182 $text = $product_static->getNomUrl(1);
5186 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
5187 dol_print_error(
'',
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
5191 $prod =
new Product($this->db);
5192 $prod->fetch($line->fk_product);
5194 $outputlangs = $langs;
5196 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
5197 $newlang =
GETPOST(
'lang_id',
'aZ09');
5199 if (
getDolGlobalString(
'PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE') && empty($newlang) && is_object($this->thirdparty)) {
5200 $newlang = $this->thirdparty->default_lang;
5202 if (!empty($newlang)) {
5203 $outputlangs =
new Translate(
"", $conf);
5204 $outputlangs->setDefaultLang($newlang);
5207 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5209 $label = $line->product_label;
5212 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5213 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5216 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5221 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5222 foreach ($dirtpls as $module => $reldir) {
5224 if (!empty($module)) {
5227 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5230 if (file_exists($tpl)) {
5231 if (empty($conf->file->strict_mode)) {
5232 $res = @include $tpl;
5234 $res = include $tpl;
5244 if ($this->
statut == 0 && $action ==
'editline' && $selected == $line->id) {
5245 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5247 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5252 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5253 foreach ($dirtpls as $module => $reldir) {
5254 if (!empty($module)) {
5257 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5260 if (empty($conf->file->strict_mode)) {
5261 $res = @include $tpl;
5263 $res = include $tpl;
5341 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5343 global $langs, $conf;
5346 if (!empty($line->date_start)) {
5347 $date_start = $line->date_start;
5349 $date_start = $line->date_debut_prevue;
5350 if ($line->date_debut_reel) {
5351 $date_start = $line->date_debut_reel;
5354 if (!empty($line->date_end)) {
5355 $date_end = $line->date_end;
5357 $date_end = $line->date_fin_prevue;
5358 if ($line->date_fin_reel) {
5359 $date_end = $line->date_fin_reel;
5363 $this->tpl[
'id'] = $line->id;
5365 $this->tpl[
'label'] =
'';
5366 if (!empty($line->fk_parent_line)) {
5367 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5370 if (($line->info_bits & 2) == 2) {
5372 if (property_exists($this,
'socid')) {
5373 $discount->fk_soc = $this->socid;
5375 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5376 } elseif (!empty($line->fk_product)) {
5377 $productstatic =
new Product($this->db);
5378 $productstatic->id = $line->fk_product;
5379 $productstatic->ref = $line->ref;
5380 $productstatic->type = $line->fk_product_type;
5381 if (empty($productstatic->ref)) {
5382 $line->fetch_product();
5383 $productstatic = $line->product;
5386 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
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;
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;
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;
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();
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);