2083 global $conf, $user;
2085 if (!$this->table_element) {
2086 dol_print_error(
'', get_class($this).
"::load_previous_next_ref was called on objet with property table_element not defined");
2089 if ($fieldid ==
'none') {
2094 if (in_array($this->table_element, array(
'facture_rec',
'facture_fourn_rec')) && $fieldid ==
'title') {
2100 if ($user->socid > 0) {
2101 $socid = $user->socid;
2106 $aliastablesociete =
's';
2107 if ($this->element ==
'societe') {
2108 $aliastablesociete =
'te';
2110 $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
2111 $sql =
"SELECT MAX(te.".$fieldid.
")";
2112 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2113 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2114 if (empty($user->admin) || !empty($user->entity) || $conf->entity != 1) {
2115 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ug ON ug.fk_user = te.rowid";
2118 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2119 $tmparray = explode(
'@', $this->ismultientitymanaged);
2120 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2121 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2122 $sql .=
", ".$this->db->prefix().
"societe as s";
2123 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2124 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2126 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2127 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2129 $sql .=
" WHERE te.".$fieldid.
" < '".$this->db->escape($fieldid ==
'rowid' ? $this->
id : $this->ref).
"'";
2130 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2131 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2133 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2134 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2136 if (!empty($filter)) {
2137 if (!preg_match(
'/^\s*AND/i', $filter)) {
2142 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2143 $tmparray = explode(
'@', $this->ismultientitymanaged);
2144 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2145 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2146 $sql .=
' AND te.fk_soc = s.rowid';
2148 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2149 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2150 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2151 $sql .=
" AND te.entity IS NOT NULL";
2153 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2156 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2159 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2160 $tmparray = explode(
'@', $this->ismultientitymanaged);
2161 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2163 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2164 $sql .=
' AND te.fk_soc = '.((int) $socid);
2166 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2167 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2169 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2170 $sql .=
' AND te.rowid = '.((int) $socid);
2174 $result = $this->db->query($sql);
2176 $this->error = $this->db->lasterror();
2179 $row = $this->db->fetch_row($result);
2180 $this->ref_previous = $row[0];
2182 $sql =
"SELECT MIN(te.".$fieldid.
")";
2183 $sql .=
" FROM ".(empty($nodbprefix) ?$this->db->prefix():
'').$this->table_element.
" as te";
2184 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2185 if (empty($user->admin) || !empty($user->entity) || $conf->entity != 1) {
2186 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"usergroup_user as ug ON ug.fk_user = te.rowid";
2189 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2190 $tmparray = explode(
'@', $this->ismultientitymanaged);
2191 $sql .=
", ".$this->db->prefix().$tmparray[1].
" as ".($tmparray[1] ==
'societe' ?
's' :
'parenttable');
2192 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2193 $sql .=
", ".$this->db->prefix().
"societe as s";
2194 } elseif ($restrictiononfksoc == 2 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2195 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON te.fk_soc = s.rowid";
2197 if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) {
2198 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON ".$aliastablesociete.
".rowid = sc.fk_soc";
2200 $sql .=
" WHERE te.".$fieldid.
" > '".$this->db->escape($fieldid ==
'rowid' ? $this->
id : $this->ref).
"'";
2201 if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) {
2202 $sql .=
" AND sc.fk_user = ".((int) $user->id);
2204 if ($restrictiononfksoc == 2 && empty($user->rights->societe->client->voir) && !$socid) {
2205 $sql .=
" AND (sc.fk_user = ".((int) $user->id).
' OR te.fk_soc IS NULL)';
2207 if (!empty($filter)) {
2208 if (!preg_match(
'/^\s*AND/i', $filter)) {
2213 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
2214 $tmparray = explode(
'@', $this->ismultientitymanaged);
2215 $sql .=
" AND te.".$tmparray[0].
" = ".($tmparray[1] ==
"societe" ?
"s" :
"parenttable").
".rowid";
2216 } elseif ($restrictiononfksoc == 1 && $this->element !=
'societe' && empty($user->rights->societe->client->voir) && !$socid) {
2217 $sql .=
' AND te.fk_soc = s.rowid';
2219 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
2220 if ($this->element ==
'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
2221 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
2222 $sql .=
" AND te.entity IS NOT NULL";
2224 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
")";
2227 $sql .=
' AND te.entity IN ('.getEntity($this->element).
')';
2230 if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged) && $this->element !=
'societe') {
2231 $tmparray = explode(
'@', $this->ismultientitymanaged);
2232 $sql .=
' AND parenttable.entity IN ('.getEntity($tmparray[1]).
')';
2234 if ($restrictiononfksoc == 1 && $socid && $this->element !=
'societe') {
2235 $sql .=
' AND te.fk_soc = '.((int) $socid);
2237 if ($restrictiononfksoc == 2 && $socid && $this->element !=
'societe') {
2238 $sql .=
' AND (te.fk_soc = '.((int) $socid).
' OR te.fk_soc IS NULL)';
2240 if ($restrictiononfksoc && $socid && $this->element ==
'societe') {
2241 $sql .=
' AND te.rowid = '.((int) $socid);
2246 $result = $this->db->query($sql);
2248 $this->error = $this->db->lasterror();
2251 $row = $this->db->fetch_row($result);
2252 $this->ref_next = $row[0];
3531 public function update_price($exclspec = 0, $roundingadjust =
'none', $nodatabaseupdate = 0, $seller =
null)
3534 global $conf, $hookmanager, $action;
3536 $parameters = array(
'exclspec' => $exclspec,
'roundingadjust' => $roundingadjust,
'nodatabaseupdate' => $nodatabaseupdate,
'seller' => $seller);
3537 $reshook = $hookmanager->executeHooks(
'updateTotalPrice', $parameters, $this, $action);
3540 } elseif ($reshook < 0) {
3546 if ($this->element ==
'propal') {
3547 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL";
3548 } elseif ($this->element ==
'commande' || $this->element ==
'order') {
3549 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_ORDER";
3550 } elseif ($this->element ==
'facture' || $this->element ==
'invoice') {
3551 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_INVOICE";
3552 } elseif ($this->element ==
'facture_fourn' || $this->element ==
'supplier_invoice' || $this->element ==
'invoice_supplier' || $this->element ==
'invoice_supplier_rec') {
3553 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE";
3554 } elseif ($this->element ==
'order_supplier' || $this->element ==
'supplier_order') {
3555 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER";
3556 } elseif ($this->element ==
'supplier_proposal') {
3557 $MODULE =
"MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL";
3560 if (!empty($MODULE)) {
3561 if (!empty($conf->global->$MODULE)) {
3562 $modsactivated = explode(
',', $conf->global->$MODULE);
3563 foreach ($modsactivated as $mod) {
3564 if (isModEnabled($mod)) {
3571 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3573 $forcedroundingmode = $roundingadjust;
3574 if ($forcedroundingmode ==
'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) {
3576 } elseif ($forcedroundingmode ==
'auto') {
3577 $forcedroundingmode =
'0';
3582 $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1;
3585 $fieldtva =
'total_tva';
3586 $fieldlocaltax1 =
'total_localtax1';
3587 $fieldlocaltax2 =
'total_localtax2';
3588 $fieldup =
'subprice';
3589 if ($this->element ==
'facture_fourn' || $this->element ==
'invoice_supplier') {
3593 if ($this->element ==
'invoice_supplier_rec') {
3596 if ($this->element ==
'expensereport') {
3597 $fieldup =
'value_unit';
3600 $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,";
3601 $sql .=
' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type';
3602 if ($this->table_element_line ==
'facturedet') {
3603 $sql .=
', situation_percent';
3605 $sql .=
', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
3606 $sql .=
" FROM ".$this->db->prefix().$this->table_element_line;
3607 $sql .=
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3609 $product_field =
'product_type';
3610 if ($this->table_element_line ==
'contratdet') {
3611 $product_field =
'';
3613 if ($product_field) {
3614 $sql .=
" AND ".$product_field.
" <> 9";
3617 $sql .=
' ORDER by rowid';
3619 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3621 $resql = $this->db->query($sql);
3623 $this->total_ht = 0;
3624 $this->total_tva = 0;
3625 $this->total_localtax1 = 0;
3626 $this->total_localtax2 = 0;
3627 $this->total_ttc = 0;
3628 $total_ht_by_vats = array();
3629 $total_tva_by_vats = array();
3630 $total_ttc_by_vats = array();
3631 $this->multicurrency_total_ht = 0;
3632 $this->multicurrency_total_tva = 0;
3633 $this->multicurrency_total_ttc = 0;
3637 $num = $this->db->num_rows($resql);
3640 $obj = $this->db->fetch_object($resql);
3643 $parameters = array(
'fk_element' => $obj->rowid);
3644 $reshook = $hookmanager->executeHooks(
'changeRoundingMode', $parameters, $this, $action);
3646 if (empty($reshook) && $forcedroundingmode ==
'0') {
3648 $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx);
3649 $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);
3651 $diff_when_using_price_ht =
price2num($tmpcal[1] - $obj->total_tva,
'MT', 1);
3652 $diff_on_current_total =
price2num($obj->total_ttc - $obj->total_ht - $obj->total_tva - $obj->total_localtax1 - $obj->total_localtax2,
'MT', 1);
3656 if ($diff_on_current_total) {
3658 $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);
3659 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);
3660 $resqlfix = $this->db->query($sqlfix);
3664 $obj->total_tva = $tmpcal[1];
3665 $obj->total_ttc = $tmpcal[2];
3666 } elseif ($diff_when_using_price_ht && $roundingadjust ==
'0') {
3669 $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);
3670 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);
3671 $resqlfix = $this->db->query($sqlfix);
3675 $obj->total_tva = $tmpcal[1];
3676 $obj->total_ttc = $tmpcal[2];
3680 $this->total_ht += $obj->total_ht;
3681 $this->total_tva += $obj->total_tva;
3682 $this->total_localtax1 += $obj->total_localtax1;
3683 $this->total_localtax2 += $obj->total_localtax2;
3684 $this->total_ttc += $obj->total_ttc;
3685 $this->multicurrency_total_ht += $obj->multicurrency_total_ht;
3686 $this->multicurrency_total_tva += $obj->multicurrency_total_tva;
3687 $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc;
3689 if (!isset($total_ht_by_vats[$obj->vatrate])) {
3690 $total_ht_by_vats[$obj->vatrate] = 0;
3692 if (!isset($total_tva_by_vats[$obj->vatrate])) {
3693 $total_tva_by_vats[$obj->vatrate] = 0;
3695 if (!isset($total_ttc_by_vats[$obj->vatrate])) {
3696 $total_ttc_by_vats[$obj->vatrate] = 0;
3698 $total_ht_by_vats[$obj->vatrate] += $obj->total_ht;
3699 $total_tva_by_vats[$obj->vatrate] += $obj->total_tva;
3700 $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc;
3702 if ($forcedroundingmode ==
'1') {
3703 $tmpvat =
price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100,
'MT', 1);
3704 $diff =
price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat,
'MT', 1);
3707 if (abs($diff) > (10 * pow(10, -1 *
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 0)))) {
3709 $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.';
3711 $this->error = $errmsg;
3715 $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);
3716 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);
3718 $resqlfix = $this->db->query($sqlfix);
3724 $this->total_tva = (float)
price2num($this->total_tva - $diff,
'', 1);
3725 $this->total_ttc = (float)
price2num($this->total_ttc - $diff,
'', 1);
3726 $total_tva_by_vats[$obj->vatrate] = (float)
price2num($total_tva_by_vats[$obj->vatrate] - $diff,
'', 1);
3727 $total_ttc_by_vats[$obj->vatrate] = (float)
price2num($total_ttc_by_vats[$obj->vatrate] - $diff,
'', 1);
3735 $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0;
3736 $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0;
3739 if (!empty($this->situation_cycle_ref) && $this->situation_counter > 1 && method_exists($this,
'get_prev_sits') && $this->
type != $this::TYPE_CREDIT_NOTE) {
3740 $prev_sits = $this->get_prev_sits();
3742 foreach ($prev_sits as $sit) {
3743 $this->total_ht -= $sit->total_ht;
3744 $this->total_tva -= $sit->total_tva;
3745 $this->total_localtax1 -= $sit->total_localtax1;
3746 $this->total_localtax2 -= $sit->total_localtax2;
3747 $this->total_ttc -= $sit->total_ttc;
3748 $this->multicurrency_total_ht -= $sit->multicurrency_total_ht;
3749 $this->multicurrency_total_tva -= $sit->multicurrency_total_tva;
3750 $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc;
3755 $this->total_ht = (float)
price2num($this->total_ht);
3756 $this->total_tva = (float)
price2num($this->total_tva);
3757 $this->total_localtax1 = (float)
price2num($this->total_localtax1);
3758 $this->total_localtax2 = (float)
price2num($this->total_localtax2);
3759 $this->total_ttc = (float)
price2num($this->total_ttc);
3761 $this->db->free($resql);
3764 $fieldht =
'total_ht';
3766 $fieldlocaltax1 =
'localtax1';
3767 $fieldlocaltax2 =
'localtax2';
3768 $fieldttc =
'total_ttc';
3770 if (in_array($this->element, array(
'propal',
'commande',
'facture',
'facturerec',
'supplier_proposal',
'order_supplier',
'facture_fourn',
'invoice_supplier',
'invoice_supplier_rec',
'expensereport'))) {
3771 $fieldtva =
'total_tva';
3774 if (!$error && empty($nodatabaseupdate)) {
3775 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
' SET';
3776 $sql .=
" ".$fieldht.
" = ".((float)
price2num($this->total_ht,
'MT', 1)).
",";
3777 $sql .=
" ".$fieldtva.
" = ".((float)
price2num($this->total_tva,
'MT', 1)).
",";
3778 $sql .=
" ".$fieldlocaltax1.
" = ".((float)
price2num($this->total_localtax1,
'MT', 1)).
",";
3779 $sql .=
" ".$fieldlocaltax2.
" = ".((float)
price2num($this->total_localtax2,
'MT', 1)).
",";
3780 $sql .=
" ".$fieldttc.
" = ".((float)
price2num($this->total_ttc,
'MT', 1));
3781 $sql .=
", multicurrency_total_ht = ".((float)
price2num($this->multicurrency_total_ht,
'MT', 1));
3782 $sql .=
", multicurrency_total_tva = ".((float)
price2num($this->multicurrency_total_tva,
'MT', 1));
3783 $sql .=
", multicurrency_total_ttc = ".((float)
price2num($this->multicurrency_total_ttc,
'MT', 1));
3784 $sql .=
" WHERE rowid = ".((int) $this->
id);
3786 dol_syslog(get_class($this).
"::update_price", LOG_DEBUG);
3787 $resql = $this->db->query($sql);
3791 $this->error = $this->db->lasterror();
3792 $this->errors[] = $this->db->lasterror();
3797 $this->db->commit();
3800 $this->db->rollback();
3918 public function fetchObjectLinked($sourceid =
null, $sourcetype =
'', $targetid =
null, $targettype =
'', $clause =
'OR', $alsosametype = 1, $orderby =
'sourcetype', $loadalsoobjects = 1)
3920 global $conf, $hookmanager, $action;
3924 if ($this->
id > 0 && !empty($this->linkedObjectsFullLoaded[$this->
id])) {
3928 $this->linkedObjectsIds = array();
3929 $this->linkedObjects = array();
3931 $justsource =
false;
3932 $justtarget =
false;
3933 $withtargettype =
false;
3934 $withsourcetype =
false;
3936 $parameters = array(
'sourcetype'=>$sourcetype,
'sourceid'=>$sourceid,
'targettype'=>$targettype,
'targetid'=>$targetid);
3938 $reshook = $hookmanager->executeHooks(
'setLinkedObjectSourceTargetType', $parameters, $this, $action);
3940 if (!empty($hookmanager->resArray[
'sourcetype'])) $sourcetype = $hookmanager->resArray[
'sourcetype'];
3941 if (!empty($hookmanager->resArray[
'sourceid'])) $sourceid = $hookmanager->resArray[
'sourceid'];
3942 if (!empty($hookmanager->resArray[
'targettype'])) $targettype = $hookmanager->resArray[
'targettype'];
3943 if (!empty($hookmanager->resArray[
'targetid'])) $targetid = $hookmanager->resArray[
'targetid'];
3946 if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) {
3948 if (!empty($targettype)) {
3949 $withtargettype =
true;
3952 if (!empty($targetid) && !empty($targettype) && empty($sourceid)) {
3954 if (!empty($sourcetype)) {
3955 $withsourcetype =
true;
3959 $sourceid = (!empty($sourceid) ? $sourceid : $this->id);
3960 $targetid = (!empty($targetid) ? $targetid : $this->id);
3961 $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element);
3962 $targettype = (!empty($targettype) ? $targettype : $this->element);
3971 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target, targettype";
3972 $sql .=
" FROM ".$this->db->prefix().
"element_element";
3974 if ($justsource || $justtarget) {
3976 $sql .=
"fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3977 if ($withtargettype) {
3978 $sql .=
" AND targettype = '".$this->db->escape($targettype).
"'";
3980 } elseif ($justtarget) {
3981 $sql .=
"fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"'";
3982 if ($withsourcetype) {
3983 $sql .=
" AND sourcetype = '".$this->db->escape($sourcetype).
"'";
3987 $sql .=
"(fk_source = ".((int) $sourceid).
" AND sourcetype = '".$this->db->escape($sourcetype).
"')";
3988 $sql .=
" ".$clause.
" (fk_target = ".((int) $targetid).
" AND targettype = '".$this->db->escape($targettype).
"')";
3989 if ($loadalsoobjects && $this->
id > 0 && $sourceid == $this->
id && $sourcetype == $this->element && $targetid == $this->
id && $targettype == $this->element && $clause ==
'OR') {
3990 $this->linkedObjectsFullLoaded[$this->id] =
true;
3993 $sql .=
" ORDER BY ".$orderby;
3995 dol_syslog(get_class($this).
"::fetchObjectLink", LOG_DEBUG);
3996 $resql = $this->db->query($sql);
3998 $num = $this->db->num_rows($resql);
4001 $obj = $this->db->fetch_object($resql);
4002 if ($justsource || $justtarget) {
4004 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4005 } elseif ($justtarget) {
4006 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4009 if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) {
4010 $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target;
4012 if ($obj->fk_target == $targetid && $obj->targettype == $targettype) {
4013 $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source;
4019 if (!empty($this->linkedObjectsIds)) {
4020 $tmparray = $this->linkedObjectsIds;
4021 foreach ($tmparray as $objecttype => $objectids) {
4023 $module = $element = $subelement = $objecttype;
4025 if ($objecttype !=
'supplier_proposal' && $objecttype !=
'order_supplier' && $objecttype !=
'invoice_supplier'
4026 && preg_match(
'/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
4027 $module = $element = $regs[1];
4028 $subelement = $regs[2];
4031 $classpath = $element.
'/class';
4033 if ($objecttype ==
'facture') {
4034 $classpath =
'compta/facture/class';
4035 } elseif ($objecttype ==
'facturerec') {
4036 $classpath =
'compta/facture/class';
4037 $module =
'facture';
4038 } elseif ($objecttype ==
'propal') {
4039 $classpath =
'comm/propal/class';
4040 } elseif ($objecttype ==
'supplier_proposal') {
4041 $classpath =
'supplier_proposal/class';
4042 } elseif ($objecttype ==
'shipping') {
4043 $classpath =
'expedition/class';
4044 $subelement =
'expedition';
4045 $module =
'expedition';
4046 } elseif ($objecttype ==
'delivery') {
4047 $classpath =
'delivery/class';
4048 $subelement =
'delivery';
4049 $module =
'delivery_note';
4050 } elseif ($objecttype ==
'invoice_supplier' || $objecttype ==
'order_supplier') {
4051 $classpath =
'fourn/class';
4052 $module =
'fournisseur';
4053 } elseif ($objecttype ==
'fichinter') {
4054 $classpath =
'fichinter/class';
4055 $subelement =
'fichinter';
4056 $module =
'ficheinter';
4057 } elseif ($objecttype ==
'subscription') {
4058 $classpath =
'adherents/class';
4059 $module =
'adherent';
4060 } elseif ($objecttype ==
'contact') {
4061 $module =
'societe';
4064 $classfile = strtolower($subelement);
4065 $classname = ucfirst($subelement);
4067 if ($objecttype ==
'order') {
4068 $classfile =
'commande';
4069 $classname =
'Commande';
4070 } elseif ($objecttype ==
'invoice_supplier') {
4071 $classfile =
'fournisseur.facture';
4072 $classname =
'FactureFournisseur';
4073 } elseif ($objecttype ==
'order_supplier') {
4074 $classfile =
'fournisseur.commande';
4075 $classname =
'CommandeFournisseur';
4076 } elseif ($objecttype ==
'supplier_proposal') {
4077 $classfile =
'supplier_proposal';
4078 $classname =
'SupplierProposal';
4079 } elseif ($objecttype ==
'facturerec') {
4080 $classfile =
'facture-rec';
4081 $classname =
'FactureRec';
4082 } elseif ($objecttype ==
'subscription') {
4083 $classfile =
'subscription';
4084 $classname =
'Subscription';
4085 } elseif ($objecttype ==
'project' || $objecttype ==
'projet') {
4086 $classpath =
'projet/class';
4087 $classfile =
'project';
4088 $classname =
'Project';
4089 } elseif ($objecttype ==
'conferenceorboothattendee') {
4090 $classpath =
'eventorganization/class';
4091 $classfile =
'conferenceorboothattendee';
4092 $classname =
'ConferenceOrBoothAttendee';
4093 $module =
'eventorganization';
4094 } elseif ($objecttype ==
'conferenceorbooth') {
4095 $classpath =
'eventorganization/class';
4096 $classfile =
'conferenceorbooth';
4097 $classname =
'ConferenceOrBooth';
4098 $module =
'eventorganization';
4099 } elseif ($objecttype ==
'mo') {
4100 $classpath =
'mrp/class';
4107 if (isModEnabled($module) && (($element != $this->element) || $alsosametype)) {
4108 if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) {
4111 if (class_exists($classname)) {
4112 foreach ($objectids as $i => $objectid) {
4113 $object =
new $classname($this->db);
4114 $ret = $object->fetch($objectid);
4116 $this->linkedObjects[$objecttype][$i] = $object;
4122 unset($this->linkedObjectsIds[$objecttype]);
4910 public function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0, $defaulttpldir =
'/core/tpl')
4912 global $conf, $hookmanager, $langs, $user, $form, $extrafields, $object;
4914 global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax;
4918 if (isModEnabled(
'margin') && !empty($this->element) && in_array($this->element, array(
'facture',
'facturerec',
'propal',
'commande'))) {
4922 $num = count($this->lines);
4925 if (!is_object($extrafields)) {
4926 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
4929 $extrafields->fetch_name_optionals_label($this->table_element_line);
4931 $parameters = array(
'num'=>$num,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$this->table_element_line);
4932 $reshook = $hookmanager->executeHooks(
'printObjectLineTitle', $parameters, $this, $action);
4933 if (empty($reshook)) {
4937 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
4938 foreach ($dirtpls as $module => $reldir) {
4940 if (!empty($module)) {
4943 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_title.tpl.php';
4945 if (file_exists($tpl)) {
4946 if (empty($conf->file->strict_mode)) {
4947 $res = @include $tpl;
4949 $res = include $tpl;
4960 print
"<!-- begin printObjectLines() --><tbody>\n";
4961 foreach ($this->lines as $line) {
4963 $line->fetch_optionals();
4966 if (is_object($hookmanager)) {
4967 if (empty($line->fk_parent_line)) {
4968 $parameters = array(
'line'=>$line,
'num'=>$num,
'i'=>$i,
'dateSelector'=>$dateSelector,
'seller'=>$seller,
'buyer'=>$buyer,
'selected'=>$selected,
'table_element_line'=>$line->table_element,
'defaulttpldir'=>$defaulttpldir);
4969 $reshook = $hookmanager->executeHooks(
'printObjectLine', $parameters, $this, $action);
4971 $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);
4972 $reshook = $hookmanager->executeHooks(
'printObjectSubLine', $parameters, $this, $action);
4975 if (empty($reshook)) {
4976 $this->printObjectLine($action, $line,
'', $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafields, $defaulttpldir);
4981 print
"</tbody><!-- end printObjectLines() -->\n";
5001 public function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafields =
null, $defaulttpldir =
'/core/tpl')
5003 global $conf, $langs, $user, $object, $hookmanager;
5005 global $object_rights, $disableedit, $disablemove, $disableremove;
5007 $object_rights = $this->getRights();
5013 if ($action !=
'editline' || $selected != $line->id) {
5015 if (!empty($line->fk_product) && $line->fk_product > 0) {
5016 $product_static =
new Product($this->db);
5017 $product_static->fetch($line->fk_product);
5019 $product_static->ref = $line->ref;
5020 $product_static->label = !empty($line->label) ? $line->label :
"";
5022 $text = $product_static->getNomUrl(1);
5026 if (property_exists($this,
'socid') && !is_object($this->thirdparty)) {
5027 dol_print_error(
'',
'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
5031 $prod =
new Product($this->db);
5032 $prod->fetch($line->fk_product);
5034 $outputlangs = $langs;
5036 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
5037 $newlang =
GETPOST(
'lang_id',
'aZ09');
5039 if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang) && is_object($this->thirdparty)) {
5040 $newlang = $this->thirdparty->default_lang;
5042 if (!empty($newlang)) {
5043 $outputlangs =
new Translate(
"", $conf);
5044 $outputlangs->setDefaultLang($newlang);
5047 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"label"])) ? $prod->multilangs[$outputlangs->defaultlang][
"label"] : $line->product_label;
5049 $label = $line->product_label;
5052 $text .=
' - '.(!empty($line->label) ? $line->label : $label);
5053 $description .= (
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ?
'' : (!empty($line->description) ?
dol_htmlentitiesbr($line->description) :
''));
5056 $line->pu_ttc =
price2num((!empty($line->subprice) ? $line->subprice : 0) * (1 + ((!empty($line->tva_tx) ? $line->tva_tx : 0) / 100)),
'MU');
5061 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5062 foreach ($dirtpls as $module => $reldir) {
5064 if (!empty($module)) {
5067 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_view.tpl.php';
5069 if (file_exists($tpl)) {
5070 if (empty($conf->file->strict_mode)) {
5071 $res = @include $tpl;
5073 $res = include $tpl;
5083 if ($this->
statut == 0 && $action ==
'editline' && $selected == $line->id) {
5084 $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label :
''));
5086 $line->pu_ttc =
price2num($line->subprice * (1 + ($line->tva_tx / 100)),
'MU');
5091 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5092 foreach ($dirtpls as $module => $reldir) {
5093 if (!empty($module)) {
5096 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/objectline_edit.tpl.php';
5099 if (empty($conf->file->strict_mode)) {
5100 $res = @include $tpl;
5102 $res = include $tpl;
5178 public function printOriginLine($line, $var, $restrictlist =
'', $defaulttpldir =
'/core/tpl', $selectedLines = array())
5180 global $langs, $conf;
5183 if (!empty($line->date_start)) {
5184 $date_start = $line->date_start;
5186 $date_start = $line->date_debut_prevue;
5187 if ($line->date_debut_reel) {
5188 $date_start = $line->date_debut_reel;
5191 if (!empty($line->date_end)) {
5192 $date_end = $line->date_end;
5194 $date_end = $line->date_fin_prevue;
5195 if ($line->date_fin_reel) {
5196 $date_end = $line->date_fin_reel;
5200 $this->tpl[
'id'] = $line->id;
5202 $this->tpl[
'label'] =
'';
5203 if (!empty($line->fk_parent_line)) {
5204 $this->tpl[
'label'] .=
img_picto(
'',
'rightarrow');
5207 if (($line->info_bits & 2) == 2) {
5209 $discount->fk_soc = $this->socid;
5210 $this->tpl[
'label'] .= $discount->getNomUrl(0,
'discount');
5211 } elseif (!empty($line->fk_product)) {
5212 $productstatic =
new Product($this->db);
5213 $productstatic->id = $line->fk_product;
5214 $productstatic->ref = $line->ref;
5215 $productstatic->type = $line->fk_product_type;
5216 if (empty($productstatic->ref)) {
5217 $line->fetch_product();
5218 $productstatic = $line->product;
5221 $this->tpl[
'label'] .= $productstatic->getNomUrl(1);
5222 $this->tpl[
'label'] .=
' - '.(!empty($line->label) ? $line->label : $line->product_label);
5224 if ($line->product_type == 1 && ($date_start || $date_end)) {
5228 $this->tpl[
'label'] .= ($line->product_type == -1 ?
' ' : ($line->product_type == 1 ?
img_object($langs->trans(
''),
'service') :
img_object($langs->trans(
''),
'product')));
5229 if (!empty($line->desc)) {
5230 $this->tpl[
'label'] .= $line->desc;
5232 $this->tpl[
'label'] .= ($line->label ?
' '.$line->label :
'');
5236 if ($line->product_type == 1 && ($date_start || $date_end)) {
5241 if (!empty($line->desc)) {
5242 if ($line->desc ==
'(CREDIT_NOTE)') {
5244 $discount->fetch($line->fk_remise_except);
5245 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromCreditNote", $discount->getNomUrl(0));
5246 } elseif ($line->desc ==
'(DEPOSIT)') {
5248 $discount->fetch($line->fk_remise_except);
5249 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromDeposit", $discount->getNomUrl(0));
5250 } elseif ($line->desc ==
'(EXCESS RECEIVED)') {
5252 $discount->fetch($line->fk_remise_except);
5253 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessReceived", $discount->getNomUrl(0));
5254 } elseif ($line->desc ==
'(EXCESS PAID)') {
5256 $discount->fetch($line->fk_remise_except);
5257 $this->tpl[
'description'] = $langs->transnoentities(
"DiscountFromExcessPaid", $discount->getNomUrl(0));
5259 $this->tpl[
'description'] =
dol_trunc($line->desc, 60);
5262 $this->tpl[
'description'] =
' ';
5266 $this->tpl[
'vat_rate'] =
vatrate($line->tva_tx,
true);
5267 $this->tpl[
'vat_rate'] .= (($line->info_bits & 1) == 1) ?
'*' :
'';
5268 if (!empty($line->vat_src_code) && !preg_match(
'/\(/', $this->tpl[
'vat_rate'])) {
5269 $this->tpl[
'vat_rate'] .=
' ('.$line->vat_src_code.
')';
5272 $this->tpl[
'price'] =
price($line->subprice);
5273 $this->tpl[
'total_ht'] =
price($line->total_ht);
5274 $this->tpl[
'multicurrency_price'] =
price($line->multicurrency_subprice);
5275 $this->tpl[
'qty'] = (($line->info_bits & 2) != 2) ? $line->qty :
' ';
5277 $this->tpl[
'unit'] = $langs->transnoentities($line->getLabelOfUnit(
'long'));
5279 $this->tpl[
'remise_percent'] = (($line->info_bits & 2) != 2) ?
vatrate($line->remise_percent,
true) :
' ';
5282 $this->tpl[
'strike'] = 0;
5284 $this->tpl[
'strike'] = 1;
5289 $dirtpls = array_merge($conf->modules_parts[
'tpl'], array($defaulttpldir));
5290 foreach ($dirtpls as $module => $reldir) {
5291 if (!empty($module)) {
5294 $tpl = DOL_DOCUMENT_ROOT.$reldir.
'/originproductline.tpl.php';
5297 if (empty($conf->file->strict_mode)) {
5298 $res = @include $tpl;
5300 $res = include $tpl;
5423 protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams =
null)
5425 global $conf, $langs, $user, $hookmanager, $action;
5427 $srctemplatepath =
'';
5429 $parameters = array(
'modelspath'=>$modelspath,
'modele'=>$modele,
'outputlangs'=>$outputlangs,
'hidedetails'=>$hidedetails,
'hidedesc'=>$hidedesc,
'hideref'=>$hideref,
'moreparams'=>$moreparams);
5430 $reshook = $hookmanager->executeHooks(
'commonGenerateDocument', $parameters, $this, $action);
5432 if (!empty($reshook)) {
5436 dol_syslog(
"commonGenerateDocument modele=".$modele.
" outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang :
'null'));
5438 if (empty($modele)) {
5439 $this->error =
'BadValueForParameterModele';
5444 $err = error_reporting();
5446 @set_time_limit(120);
5447 error_reporting($err);
5450 $tmp = explode(
':', $modele, 2);
5451 if (!empty($tmp[1])) {
5453 $srctemplatepath = $tmp[1];
5460 $dirmodels = array(
'/');
5461 if (is_array($conf->modules_parts[
'models'])) {
5462 $dirmodels = array_merge($dirmodels, $conf->modules_parts[
'models']);
5464 foreach ($dirmodels as $reldir) {
5465 foreach (array(
'doc',
'pdf') as $prefix) {
5466 if (in_array(get_class($this), array(
'Adherent'))) {
5468 $file = $prefix.
"_".$modele.
".class.php";
5471 $file = $prefix.
"_".$modele.
".modules.php";
5476 if (file_exists($file)) {
5478 $classname = $prefix.
'_'.$modele;
5488 $this->error = $langs->trans(
"Error").
' Failed to load doc generator with modelpaths='.$modelspath.
' - modele='.$modele;
5489 $this->errors[] = $this->error;
5499 $obj =
new $classname($this->db);
5502 if ($obj->type ==
'odt' && empty($srctemplatepath)) {
5503 $varfortemplatedir = $obj->scandir;
5504 if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) {
5505 $dirtoscan = $conf->global->$varfortemplatedir;
5507 $listoffiles = array();
5510 $listofdir = explode(
',', $dirtoscan);
5511 foreach ($listofdir as $key => $tmpdir) {
5512 $tmpdir = trim($tmpdir);
5513 $tmpdir = preg_replace(
'/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
5515 unset($listofdir[$key]);
5518 if (is_dir($tmpdir)) {
5519 $tmpfiles =
dol_dir_list($tmpdir,
'files', 0,
'\.od(s|t)$',
'',
'name', SORT_ASC, 0);
5520 if (count($tmpfiles)) {
5521 $listoffiles = array_merge($listoffiles, $tmpfiles);
5526 if (count($listoffiles)) {
5527 foreach ($listoffiles as $record) {
5528 $srctemplatepath = $record[
'fullname'];
5534 if (empty($srctemplatepath)) {
5535 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined';
5540 if ($obj->type ==
'odt' && !empty($srctemplatepath)) {
5542 dol_syslog(
"Failed to locate template file ".$srctemplatepath, LOG_WARNING);
5543 $this->error =
'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound';
5550 $sav_charset_output = empty($outputlangs->charset_output) ?
'' : $outputlangs->charset_output;
5552 if (in_array(get_class($this), array(
'Adherent'))) {
5553 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath,
'member', 1,
'tmp_cards', $moreparams);
5555 $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams);
5559 if ($resultwritefile > 0) {
5560 $outputlangs->charset_output = $sav_charset_output;
5563 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
5567 if (!empty($obj->result[
'fullpath'])) {
5568 $destfull = $obj->result[
'fullpath'];
5571 $update_main_doc_field = 0;
5572 if (!empty($obj->update_main_doc_field)) {
5573 $update_main_doc_field = 1;
5579 $this->indexFile($destfull, $update_main_doc_field);
5582 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);
5590 $outputlangs->charset_output = $sav_charset_output;
5591 $this->error = $obj->error;
5592 $this->errors = $obj->errors;
5593 dol_syslog(
"Error generating document for ".__CLASS__.
". Error: ".$obj->error, LOG_ERR);
5607 public function indexFile($destfull, $update_main_doc_field)
5609 global $conf, $user;
5611 $upload_dir = dirname($destfull);
5612 $destfile = basename($destfull);
5613 $rel_dir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $upload_dir);
5615 if (!preg_match(
'/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) {
5616 $filename = basename($destfile);
5617 $rel_dir = preg_replace(
'/[\\/]$/',
'', $rel_dir);
5618 $rel_dir = preg_replace(
'/^[\\/]/',
'', $rel_dir);
5620 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
5621 $ecmfile =
new EcmFiles($this->db);
5622 $result = $ecmfile->fetch(0,
'', ($rel_dir ? $rel_dir.
'/' :
'').$filename);
5625 $setsharekey =
false;
5626 if ($this->element ==
'propal' || $this->element ==
'proposal') {
5627 if (!isset($conf->global->PROPOSAL_ALLOW_ONLINESIGN) || !empty($conf->global->PROPOSAL_ALLOW_ONLINESIGN)) {
5628 $setsharekey =
true;
5630 if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5631 $setsharekey =
true;
5634 if ($this->element ==
'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) {
5635 $setsharekey =
true;
5637 if ($this->element ==
'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) {
5638 $setsharekey =
true;
5640 if ($this->element ==
'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) {
5641 $setsharekey =
true;
5643 if ($this->element ==
'product' && !empty($conf->global->PRODUCT_ALLOW_EXTERNAL_DOWNLOAD)) {
5644 $setsharekey =
true;
5646 if ($this->element ==
'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) {
5647 $setsharekey =
true;
5649 if ($this->element ==
'fichinter' && !empty($conf->global->FICHINTER_ALLOW_EXTERNAL_DOWNLOAD)) {
5650 $setsharekey =
true;
5652 if ($this->element ==
'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) {
5653 $setsharekey =
true;
5657 if (empty($ecmfile->share)) {
5658 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
5665 $ecmfile->fullpath_orig =
'';
5666 $ecmfile->gen_or_uploaded =
'generated';
5667 $ecmfile->description =
'';
5668 $ecmfile->keywords =
'';
5669 $result = $ecmfile->update($user);
5675 $ecmfile->entity = $conf->entity;
5676 $ecmfile->filepath = $rel_dir;
5677 $ecmfile->filename = $filename;
5679 $ecmfile->fullpath_orig =
'';
5680 $ecmfile->gen_or_uploaded =
'generated';
5681 $ecmfile->description =
'';
5682 $ecmfile->keywords =
'';
5683 $ecmfile->src_object_type = $this->table_element;
5684 $ecmfile->src_object_id = $this->id;
5686 $result = $ecmfile->create($user);
5698 if ($update_main_doc_field && !empty($this->table_element)) {
5699 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET last_main_doc = '".$this->db->escape($ecmfile->filepath.
"/".$ecmfile->filename).
"'";
5700 $sql .=
" WHERE rowid = ".((int) $this->
id);
5702 $resql = $this->db->query($sql);
5707 $this->last_main_doc = $ecmfile->filepath.
'/'.$ecmfile->filename;
6201 global $conf, $langs, $user;
6203 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6207 if (empty($userused)) {
6213 if (!empty($this->array_options)) {
6215 $langs->load(
'admin');
6216 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6218 $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element);
6221 $new_array_options = array();
6222 foreach ($this->array_options as $key => $value) {
6223 if (in_array(substr($key, 8), array_keys($target_extrafields))) {
6224 $new_array_options[$key] = $value;
6225 } elseif (in_array($key, array_keys($target_extrafields))) {
6226 $new_array_options[
'options_'.$key] = $value;
6230 foreach ($new_array_options as $key => $value) {
6231 $attributeKey = substr($key, 8);
6232 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$attributeKey];
6233 $attributeLabel = $langs->transnoentities($extrafields->attributes[$this->table_element][
'label'][$attributeKey]);
6234 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$attributeKey];
6235 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$attributeKey];
6236 $attributeUnique = $extrafields->attributes[$this->table_element][
'unique'][$attributeKey];
6237 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$attributeKey];
6241 if (!empty($this->context[
'createfromclone']) && $this->context[
'createfromclone'] ==
'createfromclone' && !empty($attributeUnique)) {
6242 $new_array_options[$key] =
null;
6246 if ($attributeRequired) {
6247 $mandatorypb =
false;
6248 if ($attributeType ==
'link' && $this->array_options[$key] ==
'-1') {
6249 $mandatorypb =
true;
6251 if ($this->array_options[$key] ===
'') {
6252 $mandatorypb =
true;
6254 if ($attributeType ==
'sellist' && $this->array_options[$key] ==
'0') {
6255 $mandatorypb =
true;
6258 $langs->load(
"errors");
6259 dol_syslog(
"Mandatory field '".$key.
"' is empty during create and set to required into definition of extrafields");
6260 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6268 if (!empty($attrfieldcomputed)) {
6269 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6270 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6271 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6272 $new_array_options[$key] = $value;
6274 $new_array_options[$key] =
null;
6278 switch ($attributeType) {
6280 if (!is_numeric($value) && $value !=
'') {
6281 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6283 } elseif ($value ==
'') {
6284 $new_array_options[$key] =
null;
6290 if (!is_numeric($value) && $value !=
'') {
6291 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" for ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6292 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6294 } elseif ($value ==
'') {
6298 $new_array_options[$key] = $value;
6308 if ($this->array_options[$key] !=
'' && is_array($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options'])) {
6310 $tmparrays = array_keys($extrafields->attributes[$this->table_element][
'param'][$attributeKey][
'options']);
6311 $algo = reset($tmparrays);
6316 if (is_object($this->oldcopy)) {
6318 if (isset($this->oldcopy->array_options[$key]) && $this->array_options[$key] == $this->oldcopy->array_options[$key]) {
6319 $new_array_options[$key] = $this->array_options[$key];
6322 $newvalue =
dol_hash($this->array_options[$key], $algo);
6323 $new_array_options[$key] = $newvalue;
6326 $new_array_options[$key] = $this->array_options[$key];
6331 $new_array_options[$key] = $this->array_options[$key];
6337 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6338 $this->array_options[$key] = strtotime($this->array_options[$key]);
6340 $new_array_options[$key] = $this->db->idate($this->array_options[$key]);
6344 if (!is_numeric($this->array_options[$key]) || $this->array_options[$key] != intval($this->array_options[$key])) {
6345 $this->array_options[$key] = strtotime($this->array_options[$key]);
6347 $new_array_options[$key] = $this->db->idate($this->array_options[$key],
'gmt');
6350 $param_list = array_keys($attributeParam[
'options']);
6353 $InfoFieldList = explode(
":", $param_list[0]);
6355 if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) {
6356 if ($value ==
'-1') {
6357 $new_array_options[$key] =
'';
6359 $object =
new $InfoFieldList[0]($this->db);
6360 if (is_numeric($value)) {
6361 $res = $object->fetch($value);
6363 $res = $object->fetch(
'', $value);
6367 $new_array_options[$key] = $object->id;
6369 $this->error =
"Id/Ref '".$value.
"' for object '".$object->element.
"' not found";
6374 dol_syslog(
'Error bad setup of extrafield', LOG_WARNING);
6379 if (is_array($this->array_options[$key])) {
6380 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6382 $new_array_options[$key] = $this->array_options[$key];
6390 $table_element = $this->table_element;
6391 if ($table_element ==
'categorie') {
6392 $table_element =
'categories';
6395 dol_syslog(get_class($this).
"::insertExtraFields delete then insert", LOG_DEBUG);
6397 $sql_del =
"DELETE FROM ".$this->db->prefix().$table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6398 $this->db->query($sql_del);
6400 $sql =
"INSERT INTO ".$this->db->prefix().$table_element.
"_extrafields (fk_object";
6401 foreach ($new_array_options as $key => $value) {
6402 $attributeKey = substr($key, 8);
6404 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6405 $sql .=
",".$attributeKey;
6409 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6410 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6411 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6412 $sql .=
",".$tmpkey;
6416 $sql .=
") VALUES (".$this->id;
6418 foreach ($new_array_options as $key => $value) {
6419 $attributeKey = substr($key, 8);
6421 if ($extrafields->attributes[$this->table_element][
'type'][$attributeKey] !=
'separate') {
6422 if ($new_array_options[$key] !=
'' || $new_array_options[$key] ==
'0') {
6423 $sql .=
",'".$this->db->escape($new_array_options[$key]).
"'";
6430 if (!empty($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities']) && is_array($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'])) {
6431 foreach ($extrafields->attributes[$this->table_element][
'mandatoryfieldsofotherentities'] as $tmpkey => $tmpval) {
6432 if (!isset($extrafields->attributes[$this->table_element][
'type'][$tmpkey])) {
6433 if (in_array($tmpval, array(
'int',
'double',
'price'))) {
6444 $resql = $this->db->query($sql);
6446 $this->error = $this->db->lasterror();
6450 if (!$error && $trigger) {
6452 $this->context = array(
'extrafieldaddupdate'=>1);
6453 $result = $this->call_trigger($trigger, $userused);
6461 $this->db->rollback();
6464 $this->db->commit();
6602 global $conf, $langs, $user;
6604 if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
6608 if (empty($userused)) {
6614 if (!empty($this->array_options) && isset($this->array_options[
"options_".$key])) {
6616 $langs->load(
'admin');
6617 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
6619 $extrafields->fetch_name_optionals_label($this->table_element);
6621 $value = $this->array_options[
"options_".$key];
6623 $attributeType = $extrafields->attributes[$this->table_element][
'type'][$key];
6624 $attributeLabel = $extrafields->attributes[$this->table_element][
'label'][$key];
6625 $attributeParam = $extrafields->attributes[$this->table_element][
'param'][$key];
6626 $attributeRequired = $extrafields->attributes[$this->table_element][
'required'][$key];
6627 $attrfieldcomputed = $extrafields->attributes[$this->table_element][
'computed'][$key];
6630 if ($attributeRequired) {
6631 $mandatorypb =
false;
6632 if ($attributeType ==
'link' && $this->array_options[
"options_".$key] ==
'-1') {
6633 $mandatorypb =
true;
6635 if ($this->array_options[
"options_".$key] ===
'') {
6636 $mandatorypb =
true;
6639 $langs->load(
"errors");
6640 dol_syslog(
"Mandatory field 'options_".$key.
"' is empty during update and set to required into definition of extrafields");
6641 $this->errors[] = $langs->trans(
'ErrorFieldRequired', $attributeLabel);
6649 if (!empty($attrfieldcomputed)) {
6650 if (!empty($conf->global->MAIN_STORE_COMPUTED_EXTRAFIELDS)) {
6651 $value =
dol_eval($attrfieldcomputed, 1, 0,
'');
6652 dol_syslog($langs->trans(
"Extrafieldcomputed").
" sur ".$attributeLabel.
"(".$value.
")", LOG_DEBUG);
6653 $this->array_options[
"options_".$key] = $value;
6655 $this->array_options[
"options_".$key] =
null;
6659 switch ($attributeType) {
6661 if (!is_numeric($value) && $value !=
'') {
6662 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6664 } elseif ($value ===
'') {
6665 $this->array_options[
"options_".$key] =
null;
6671 if (!is_numeric($value) && $value !=
'') {
6672 dol_syslog($langs->trans(
"ExtraFieldHasWrongValue").
" sur ".$attributeLabel.
"(".$value.
"is not '".$attributeType.
"')", LOG_DEBUG);
6673 $this->errors[] = $langs->trans(
"ExtraFieldHasWrongValue", $attributeLabel);
6675 } elseif ($value ===
'') {
6679 $this->array_options[
"options_".$key] = $value;
6689 if (empty($this->array_options[
"options_".$key])) {
6690 $this->array_options[
"options_".$key] =
null;
6692 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key]);
6696 if (empty($this->array_options[
"options_".$key])) {
6697 $this->array_options[
"options_".$key] =
null;
6699 $this->array_options[
"options_".$key] = $this->db->idate($this->array_options[
"options_".$key],
'gmt');
6703 if (empty($this->array_options[
"options_".$key])) {
6704 $this->array_options[
"options_".$key] =
null;
6708 if ($this->array_options[
"options_".$key] ===
'') {
6709 $this->array_options[
"options_".$key] =
null;
6743 if (is_array($this->array_options[$key])) {
6744 $new_array_options[$key] = implode(
',', $this->array_options[$key]);
6746 $new_array_options[$key] = $this->array_options[$key];
6753 $linealreadyfound = 0;
6756 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element.
"_extrafields WHERE fk_object = ".((int) $this->
id);
6757 $resql = $this->db->query($sql);
6759 $tmpobj = $this->db->fetch_object($resql);
6761 $linealreadyfound = $tmpobj->nb;
6765 if ($linealreadyfound) {
6766 if ($this->array_options[
"options_".$key] ===
null) {
6767 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = null";
6769 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
"_extrafields SET ".$key.
" = '".$this->db->escape($this->array_options[
"options_".$key]).
"'";
6771 $sql .=
" WHERE fk_object = ".((int) $this->
id);
6773 $result = $this->insertExtraFields(
'', $user);
6779 $resql = $this->db->query($sql);
6782 $this->error = $this->db->lasterror();
6784 if (!$error && $trigger) {
6786 $this->context = array(
'extrafieldupdate'=>1);
6787 $result = $this->call_trigger($trigger, $userused);
6795 dol_syslog(__METHOD__.$this->error, LOG_ERR);
6796 $this->db->rollback();
6799 $this->db->commit();
6849 public function showInputField($val, $key, $value, $moreparam =
'', $keysuffix =
'', $keyprefix =
'', $morecss = 0, $nonewbutton = 0)
6851 global $conf, $langs, $form;
6853 if (!is_object($form)) {
6854 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
6855 $form =
new Form($this->db);
6858 if (!empty($this->fields)) {
6859 $val = $this->fields[$key];
6863 $fieldValidationErrorMsg =
'';
6864 $validationClass =
'';
6865 $fieldValidationErrorMsg = $this->getFieldError($key);
6866 if (!empty($fieldValidationErrorMsg)) {
6867 $validationClass =
' --error';
6869 $validationClass =
' --success';
6876 $param[
'options'] = array();
6878 $size = !empty($this->fields[$key][
'size']) ? $this->fields[$key][
'size'] : 0;
6880 if (preg_match(
'/^(integer|link):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6881 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6883 } elseif (preg_match(
'/^(integer|link):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6884 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6886 } elseif (preg_match(
'/^(integer|link):(.*):(.*)/i', $val[
'type'], $reg)) {
6887 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6889 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6890 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4].
':'.$reg[5] =>
'N');
6892 } elseif (preg_match(
'/^(sellist):(.*):(.*):(.*)/i', $val[
'type'], $reg)) {
6893 $param[
'options'] = array($reg[2].
':'.$reg[3].
':'.$reg[4] =>
'N');
6895 } elseif (preg_match(
'/^(sellist):(.*):(.*)/i', $val[
'type'], $reg)) {
6896 $param[
'options'] = array($reg[2].
':'.$reg[3] =>
'N');
6898 } elseif (preg_match(
'/^chkbxlst:(.*)/i', $val[
'type'], $reg)) {
6899 $param[
'options'] = array($reg[1] =>
'N');
6901 } elseif (preg_match(
'/varchar\((\d+)\)/', $val[
'type'], $reg)) {
6902 $param[
'options'] = array();
6905 } elseif (preg_match(
'/varchar/', $val[
'type'])) {
6906 $param[
'options'] = array();
6909 $param[
'options'] = array();
6910 $type = $this->fields[$key][
'type'];
6914 if (!empty($this->fields[$key][
'arrayofkeyval']) && is_array($this->fields[$key][
'arrayofkeyval'])) {
6915 $param[
'options'] = $this->fields[$key][
'arrayofkeyval'];
6919 $label = $this->fields[$key][
'label'];
6921 $default = (!empty($this->fields[$key][
'default']) ? $this->fields[$key][
'default'] :
'');
6922 $computed = (!empty($this->fields[$key][
'computed']) ? $this->fields[$key][
'computed'] :
'');
6923 $unique = (!empty($this->fields[$key][
'unique']) ? $this->fields[$key][
'unique'] : 0);
6924 $required = (!empty($this->fields[$key][
'required']) ? $this->fields[$key][
'required'] : 0);
6925 $autofocusoncreate = (!empty($this->fields[$key][
'autofocusoncreate']) ? $this->fields[$key][
'autofocusoncreate'] : 0);
6927 $langfile = (!empty($this->fields[$key][
'langfile']) ? $this->fields[$key][
'langfile'] :
'');
6928 $list = (!empty($this->fields[$key][
'list']) ? $this->fields[$key][
'list'] : 0);
6929 $hidden = (in_array(abs($this->fields[$key][
'visible']), array(0, 2)) ? 1 : 0);
6931 $objectid = $this->id;
6934 if (!preg_match(
'/^search_/', $keyprefix)) {
6935 return '<span class="opacitymedium">'.$langs->trans(
"AutomaticallyCalculated").
'</span>';
6942 if (empty($morecss) && !empty($val[
'css'])) {
6943 $morecss = $val[
'css'];
6944 } elseif (empty($morecss)) {
6945 if ($type ==
'date') {
6946 $morecss =
'minwidth100imp';
6947 } elseif ($type ==
'datetime' || $type ==
'link') {
6948 $morecss =
'minwidth200imp';
6949 } elseif (in_array($type, array(
'int',
'integer',
'price')) || preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
6950 $morecss =
'maxwidth75';
6951 } elseif ($type ==
'url') {
6952 $morecss =
'minwidth400';
6953 } elseif ($type ==
'boolean') {
6956 if (round($size) < 12) {
6957 $morecss =
'minwidth100';
6958 } elseif (round($size) <= 48) {
6959 $morecss =
'minwidth200';
6961 $morecss =
'minwidth400';
6967 if (!empty($validationClass)) {
6968 $morecss.= $validationClass;
6971 if (in_array($type, array(
'date'))) {
6972 $tmp = explode(
',', $size);
6977 if (!$required && $value ==
'') {
6982 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1);
6983 } elseif (in_array($type, array(
'datetime'))) {
6984 $tmp = explode(
',', $size);
6989 if (!$required && $value ==
'') $value =
'-1';
6992 $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required,
'', 1, (($keyprefix !=
'search_' && $keyprefix !=
'search_options_') ? 1 : 0), 0, 1,
'',
'',
'', 1,
'',
'',
'tzuserrel');
6993 } elseif (in_array($type, array(
'duration'))) {
6994 $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0,
'text', 0, 1);
6995 } elseif (in_array($type, array(
'int',
'integer'))) {
6996 $tmp = explode(
',', $size);
6998 $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' :
'').
'>';
6999 } elseif (in_array($type, array(
'real'))) {
7000 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'"'.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7001 } elseif (preg_match(
'/varchar/', $type)) {
7002 $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' :
'').
'>';
7003 } elseif (in_array($type, array(
'email',
'mail',
'phone',
'url',
'ip'))) {
7004 $out =
'<input type="text" class="flat '.$morecss.
'" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').($autofocusoncreate ?
' autofocus' :
'').
'>';
7005 } elseif (preg_match(
'/^text/', $type)) {
7006 if (!preg_match(
'/search_/', $keyprefix)) {
7007 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7008 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false,
false, ROWS_5,
'90%');
7009 $out = $doleditor->Create(1);
7011 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7013 } elseif (preg_match(
'/^html/', $type)) {
7014 if (!preg_match(
'/search_/', $keyprefix)) {
7015 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
7016 $doleditor =
new DolEditor($keyprefix.$key.$keysuffix, $value,
'', 200,
'dolibarr_notes',
'In',
false,
false, isModEnabled(
'fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5,
'90%');
7017 $out = $doleditor->Create(1,
'',
true,
'',
'', $moreparam, $morecss);
7019 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.
dol_escape_htmltag($value).
'" '.($moreparam ? $moreparam :
'').
'>';
7021 } elseif ($type ==
'boolean') {
7023 if (!empty($value)) {
7024 $checked =
' checked value="1" ';
7026 $checked =
' value="1" ';
7028 $out =
'<input type="checkbox" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.$checked.
' '.($moreparam ? $moreparam :
'').
'>';
7029 } elseif ($type ==
'price') {
7030 if (!empty($value)) {
7031 $value =
price($value);
7033 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> '.$langs->getCurrencySymbol($conf->currency);
7034 } elseif (preg_match(
'/^double(\([0-9],[0-9]\)){0,1}/', $type)) {
7035 if (!empty($value)) {
7036 $value =
price($value);
7038 $out =
'<input type="text" class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" value="'.$value.
'" '.($moreparam ? $moreparam :
'').
'> ';
7039 } elseif ($type ==
'select') {
7041 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
7042 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7043 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7046 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7047 if ((!isset($this->fields[$key][
'default'])) || ($this->fields[$key][
'notnull'] != 1)) {
7048 $out .=
'<option value="0"> </option>';
7050 foreach ($param[
'options'] as $keyb => $valb) {
7051 if ((
string) $keyb ==
'') {
7054 if (strpos($valb,
"|") !==
false) {
7055 list($valb, $parent) = explode(
'|', $valb);
7057 $out .=
'<option value="'.$keyb.
'"';
7058 $out .= (((string) $value == (
string) $keyb) ?
' selected' :
'');
7059 $out .= (!empty($parent) ?
' parent="'.$parent.
'"' :
'');
7060 $out .=
'>'.$valb.
'</option>';
7062 $out .=
'</select>';
7063 } elseif ($type ==
'sellist') {
7065 if (!empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_EXTRAFIELDS_DISABLE_SELECT2)) {
7066 include_once DOL_DOCUMENT_ROOT.
'/core/lib/ajax.lib.php';
7067 $out .=
ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
7070 $out .=
'<select class="flat '.$morecss.
' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'').
'>';
7071 if (is_array($param[
'options'])) {
7072 $param_list = array_keys($param[
'options']);
7073 $InfoFieldList = explode(
":", $param_list[0]);
7083 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7085 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7086 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7087 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7089 $keyList = $InfoFieldList[2].
' as rowid';
7092 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7093 list($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7094 $keyList .=
', '.$parentField;
7097 $filter_categorie =
false;
7098 if (count($InfoFieldList) > 5) {
7099 if ($InfoFieldList[0] ==
'categorie') {
7100 $filter_categorie =
true;
7104 if ($filter_categorie ===
false) {
7105 $fields_label = explode(
'|', $InfoFieldList[1]);
7106 if (is_array($fields_label)) {
7108 $keyList .= implode(
', ', $fields_label);
7112 $sql =
"SELECT " . $keyList;
7113 $sql .=
" FROM " . $this->db->prefix() . $InfoFieldList[0];
7114 if (!empty($InfoFieldList[4])) {
7116 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7117 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7121 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7122 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7124 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7128 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7129 $sql .=
" as main, " . $this->db->prefix() . $InfoFieldList[0] .
"_extrafields as extra";
7130 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7132 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7135 $sqlwhere .=
' WHERE 1=1';
7138 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7139 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7144 $sql .=
' ORDER BY ' . implode(
', ', $fields_label);
7146 dol_syslog(get_class($this) .
'::showInputField type=sellist', LOG_DEBUG);
7147 $resql = $this->db->query($sql);
7149 $out .=
'<option value="0"> </option>';
7150 $num = $this->db->num_rows($resql);
7154 $obj = $this->db->fetch_object($resql);
7158 $fields_label = explode(
'|', $InfoFieldList[1]);
7159 if (count($fields_label) > 1) {
7161 foreach ($fields_label as $field_toshow) {
7162 $labeltoshow .= $obj->$field_toshow .
' ';
7165 $labeltoshow = $obj->{$InfoFieldList[1]};
7167 $labeltoshow =
dol_trunc($labeltoshow, 45);
7169 if ($value == $obj->rowid) {
7170 foreach ($fields_label as $field_toshow) {
7171 $translabel = $langs->trans($obj->$field_toshow);
7172 if ($translabel != $obj->$field_toshow) {
7173 $labeltoshow =
dol_trunc($translabel) .
' ';
7175 $labeltoshow =
dol_trunc($obj->$field_toshow) .
' ';
7178 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7181 $translabel = $langs->trans($obj->{$InfoFieldList[1]});
7182 if ($translabel != $obj->{$InfoFieldList[1]}) {
7183 $labeltoshow =
dol_trunc($translabel, 18);
7185 $labeltoshow =
dol_trunc($obj->{$InfoFieldList[1]});
7188 if (empty($labeltoshow)) {
7189 $labeltoshow =
'(not defined)';
7191 if ($value == $obj->rowid) {
7192 $out .=
'<option value="' . $obj->rowid .
'" selected>' . $labeltoshow .
'</option>';
7195 if (!empty($InfoFieldList[3]) && $parentField) {
7196 $parent = $parentName .
':' . $obj->{$parentField};
7200 $out .=
'<option value="' . $obj->rowid .
'"';
7201 $out .= ($value == $obj->rowid ?
' selected' :
'');
7202 $out .= (!empty($parent) ?
' parent="' . $parent .
'"' :
'');
7203 $out .=
'>' . $labeltoshow .
'</option>';
7208 $this->db->free($resql);
7210 print
'Error in request ' . $sql .
' ' . $this->db->lasterror() .
'. Check setup of extra parameters.<br>';
7213 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
7214 $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]],
'',
'parent', 64, $InfoFieldList[6], 1, 1);
7215 $out .=
'<option value="0"> </option>';
7216 foreach ($data as $data_key => $data_value) {
7217 $out .=
'<option value="' . $data_key .
'"';
7218 $out .= ($value == $data_key ?
' selected' :
'');
7219 $out .=
'>' . $data_value .
'</option>';
7223 $out .=
'</select>';
7224 } elseif ($type ==
'checkbox') {
7225 $value_arr = explode(
',', $value);
7226 $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param[
'options']) ?
null:$param[
'options']), $value_arr,
'', 0, $morecss, 0,
'100%');
7227 } elseif ($type ==
'radio') {
7229 foreach ($param[
'options'] as $keyopt => $valopt) {
7230 $out .=
'<input class="flat '.$morecss.
'" type="radio" name="'.$keyprefix.$key.$keysuffix.
'" id="'.$keyprefix.$key.$keysuffix.
'" '.($moreparam ? $moreparam :
'');
7231 $out .=
' value="'.$keyopt.
'"';
7232 $out .=
' id="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'"';
7233 $out .= ($value == $keyopt ?
'checked' :
'');
7234 $out .=
'/><label for="'.$keyprefix.$key.$keysuffix.
'_'.$keyopt.
'">'.$valopt.
'</label><br>';
7236 } elseif ($type ==
'chkbxlst') {
7237 if (is_array($value)) {
7238 $value_arr = $value;
7240 $value_arr = explode(
',', $value);
7243 if (is_array($param[
'options'])) {
7244 $param_list = array_keys($param[
'options']);
7245 $InfoFieldList = explode(
":", $param_list[0]);
7255 $keyList = (empty($InfoFieldList[2]) ?
'rowid' : $InfoFieldList[2].
' as rowid');
7257 if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
7258 list ($parentName, $parentField) = explode(
'|', $InfoFieldList[3]);
7259 $keyList .=
', '.$parentField;
7261 if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
7262 if (strpos($InfoFieldList[4],
'extra.') !==
false) {
7263 $keyList =
'main.'.$InfoFieldList[2].
' as rowid';
7265 $keyList = $InfoFieldList[2].
' as rowid';
7269 $filter_categorie =
false;
7270 if (count($InfoFieldList) > 5) {
7271 if ($InfoFieldList[0] ==
'categorie') {
7272 $filter_categorie =
true;
7276 if ($filter_categorie ===
false) {
7277 $fields_label = explode(
'|', $InfoFieldList[1]);
7278 if (is_array($fields_label)) {
7280 $keyList .= implode(
', ', $fields_label);
7284 $sql =
"SELECT " . $keyList;
7285 $sql .=
' FROM ' . $this->db->prefix() . $InfoFieldList[0];
7286 if (!empty($InfoFieldList[4])) {
7288 if (strpos($InfoFieldList[4],
'$SEL$') !==
false) {
7289 $InfoFieldList[4] = str_replace(
'$SEL$',
'SELECT', $InfoFieldList[4]);
7293 if (strpos($InfoFieldList[4],
'$ID$') !==
false && !empty($objectid)) {
7294 $InfoFieldList[4] = str_replace(
'$ID$', $objectid, $InfoFieldList[4]);
7296 $InfoFieldList[4] = str_replace(
'$ID$',
'0', $InfoFieldList[4]);
7300 if (strpos($InfoFieldList[4],
'extra') !==
false) {
7301 $sql .=
' as main, ' . $this->db->prefix() . $InfoFieldList[0] .
'_extrafields as extra';
7302 $sqlwhere .=
" WHERE extra.fk_object=main." . $InfoFieldList[2] .
" AND " . $InfoFieldList[4];
7304 $sqlwhere .=
" WHERE " . $InfoFieldList[4];
7307 $sqlwhere .=
' WHERE 1=1';
7310 if (in_array($InfoFieldList[0], array(
'tablewithentity'))) {
7311 $sqlwhere .=
" AND entity = " . ((int) $conf->entity);
7317 dol_syslog(get_class($this) .
'::showInputField type=chkbxlst', LOG_DEBUG);
7318 $resql = $this->db->query($sql);
7320 $num = $this->db->num_rows($resql);
7327 $obj = $this->db->fetch_object($resql);
7331 $fields_label = explode(
'|', $InfoFieldList[1]);
7332 if (count($fields_label) > 1) {
7334 foreach ($fields_label as $field_toshow) {
7335 $labeltoshow .= $obj->$field_toshow .
' ';
7338 $labeltoshow = $obj->{$InfoFieldList[1]};
7340 $labeltoshow =
dol_trunc($labeltoshow, 45);