diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 954b3e632ca..fb28aa3d045 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -223,7 +223,7 @@ $tabsql[24] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFI $tabsql[25] = "SELECT rowid as rowid, code, label, active, module FROM ".MAIN_DB_PREFIX."c_type_container as t WHERE t.entity = ".getEntity($tabname[25]); //$tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units"; $tabsql[27] = "SELECT id as rowid, code, libelle, picto, active FROM ".MAIN_DB_PREFIX."c_stcomm"; -$tabsql[28] = "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid"; +$tabsql[28] = "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.block_if_negative, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid"; $tabsql[29] = "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status"; $tabsql[30] = "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards"; //$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s"; @@ -315,7 +315,7 @@ $tabfield[24] = "code,label"; $tabfield[25] = "code,label"; //$tabfield[26]= "code,label,short_label"; $tabfield[27] = "code,libelle,picto"; -$tabfield[28] = "code,label,affect,delay,newbymonth,country_id,country"; +$tabfield[28] = "code,label,affect,delay,newbymonth,country_id,country,block_if_negative"; $tabfield[29] = "code,label,percent,position"; $tabfield[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; //$tabfield[31]= "pcg_version,label"; @@ -361,7 +361,7 @@ $tabfieldvalue[24] = "code,label"; $tabfieldvalue[25] = "code,label"; //$tabfieldvalue[26]= "code,label,short_label"; $tabfieldvalue[27] = "code,libelle,picto"; -$tabfieldvalue[28] = "code,label,affect,delay,newbymonth,country"; +$tabfieldvalue[28] = "code,label,affect,delay,newbymonth,country,block_if_negative"; $tabfieldvalue[29] = "code,label,percent,position"; $tabfieldvalue[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; //$tabfieldvalue[31]= "pcg_version,label"; @@ -407,7 +407,7 @@ $tabfieldinsert[24] = "code,label"; $tabfieldinsert[25] = "code,label"; //$tabfieldinsert[26]= "code,label,short_label"; $tabfieldinsert[27] = "code,libelle,picto"; -$tabfieldinsert[28] = "code,label,affect,delay,newbymonth,fk_country"; +$tabfieldinsert[28] = "code,label,affect,delay,newbymonth,fk_country,block_if_negative"; $tabfieldinsert[29] = "code,label,percent,position"; $tabfieldinsert[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; //$tabfieldinsert[31]= "pcg_version,label"; @@ -1418,6 +1418,9 @@ if ($id) { if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') { $valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center'; } + if ($value == 'block_if_negative') { + $valuetoshow = $langs->trans('BlockHolidayIfNegative'); + } if ($id == 2) { // Special case for state page if ($value == 'region_id') { @@ -1764,6 +1767,9 @@ if ($id) { if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') { $valuetoshow = $langs->trans('TicketGroupIsPublic'); $cssprefix = 'center '; } + if ($value == 'block_if_negative') { + $valuetoshow = $langs->trans('BlockHolidayIfNegative'); + } if ($value == 'region_id' || $value == 'country_id') { $showfield = 0; @@ -1981,8 +1987,9 @@ if ($id) { } } } elseif ($value == 'fk_c_exp_tax_cat') { - $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $valuetoshow); - $valuetoshow = $langs->trans($valuetoshow); + $tmpid = $valuetoshow; + $valuetoshow = getDictionaryValue(MAIN_DB_PREFIX.'c_exp_tax_cat', 'label', $tmpid); + $valuetoshow = $langs->trans($valuetoshow ? $valuetoshow : $tmpid); } elseif ($tabname[$id] == MAIN_DB_PREFIX.'c_exp_tax_cat') { $valuetoshow = $langs->trans($valuetoshow); } elseif ($value == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_units') { @@ -1997,6 +2004,8 @@ if ($id) { } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_productbatch_qcstatus') { $langs->load("productbatch"); $valuetoshow = $langs->trans($obj->{$value}); + } elseif ($value == 'block_if_negative') { + $valuetoshow = yn($obj->{$value}); } $class .= ($class ? ' ' : '').'tddict'; if ($value == 'note' && $id == 10) { @@ -2379,6 +2388,10 @@ function fieldList($fieldlist, $obj = '', $tabname = '', $context = '') print ''; print $form->selectExpenseRanges($obj->fk_range); print ''; + } elseif ($value == 'block_if_negative') { + print ''; + print $form->selectyesno("block_if_negative", (!empty($obj->{$value}) ? $obj->{$value}:''), 1); + print ''; } else { $fieldValue = isset($obj->{$value}) ? $obj->{$value}: ''; diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php index e70e6a4cdd7..2c997d746d9 100644 --- a/htdocs/admin/ihm.php +++ b/htdocs/admin/ihm.php @@ -280,6 +280,10 @@ if ($action == 'update') { $_SESSION["mainmenu"] = ""; // The menu manager may have changed + if (GETPOST('dol_resetcache')) { + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", ((int) $conf->global->MAIN_IHM_PARAMS_REV) + 1, 'chaine', 0, '', $conf->entity); + } + header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup".'&mode='.$mode.(GETPOSTISSET('page_y') ? '&page_y='.GETPOST('page_y', 'int') : '')); exit; } @@ -309,6 +313,7 @@ print ''; print ''; print ''; print ''; +print ''; $head = ihm_prepare_head(); @@ -649,6 +654,7 @@ if ($mode == 'login') { print '
'; print ''; +print ''; print '
'; print ''; diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index 18a4ca0825f..f04bfd78abd 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -96,9 +96,9 @@ if ($action == 'update') { dolibarr_set_const($db, "MAIN_PDF_NO_RECIPENT_FRAME", GETPOST("MAIN_PDF_NO_RECIPENT_FRAME"), 'chaine', 0, '', $conf->entity); } - if (GETPOSTISSET('MAIN_PDF_HIDE_SENDER_NAME')) { + /*if (GETPOSTISSET('MAIN_PDF_HIDE_SENDER_NAME')) { dolibarr_set_const($db, "MAIN_PDF_HIDE_SENDER_NAME", GETPOST("MAIN_PDF_HIDE_SENDER_NAME"), 'chaine', 0, '', $conf->entity); - } + }*/ if (GETPOSTISSET('MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT')) { dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT", GETPOST("MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT"), 'chaine', 0, '', $conf->entity); @@ -307,6 +307,18 @@ print '
'; print ''; print ''; +// Show sender name + +/* Set option as hidden because no need of this for 99.99% of users. +print ''; +*/ + // Hide VAT Intra on address print ''; - //Invert sender and recipient print ''; -print ''; - -print ''; - // Desc print ''; +// Swicth in Bold + +print ''; + +// Swicth in Bold + +print ''; + // SHOW_SUBPRODUCT_REF_IN_PDF - Option to show the detail of product ref for kits. print ''; } + if (!empty($arrayfields['total_pa']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_margin']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print ''; + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; @@ -1392,6 +1419,18 @@ if ($resql) { if (!empty($arrayfields['sale_representative']['checked'])) { print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder); } + if (!empty($arrayfields['total_pa']['checked'])) { + print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_margin']['checked'])) { + print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } $totalarray = array( 'nbfield' => 0, 'val' => array( @@ -1437,6 +1476,17 @@ if ($resql) { $i = 0; $typenArray = null; + $with_margin_info = false; + if (!empty($conf->margin->enabled) && ( + !empty($arrayfields['total_pa']['checked']) + || !empty($arrayfields['total_margin']['checked']) + || !empty($arrayfields['total_margin_rate']['checked']) + || !empty($arrayfields['total_mark_rate']['checked']) + ) + ) { + $with_margin_info = true; + } + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -1487,6 +1537,12 @@ if ($resql) { } } + $marginInfo = array(); + if ($with_margin_info === true) { + $objectstatic->fetch_lines(); + $marginInfo = $formmargin->getMarginInfosArray($objectstatic); + } + print ''; if (!empty($arrayfields['p.ref']['checked'])) { @@ -1887,6 +1943,39 @@ if ($resql) { } } + // Total buying or cost price + if (!empty($arrayfields['total_pa']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Total margin + if (!empty($arrayfields['total_margin']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'total_margin'; + } + $totalarray['val']['total_margin'] += $marginInfo['total_margin']; + } + // Total margin rate + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Total mark rate + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index febab2d5917..8d677625040 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -40,6 +40,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +if (!empty($conf->margin->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; +} require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; @@ -187,6 +190,10 @@ $arrayfields = array( 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110), 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115), 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>116), + 'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), + 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), + 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)), + 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)), 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120), 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125), 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130), @@ -407,6 +414,10 @@ $now = dol_now(); $form = new Form($db); $formother = new FormOther($db); $formfile = new FormFile($db); +$formmargin = null; +if (!empty($conf->margin->enabled)) { + $formmargin = new FormMargin($db); +} $companystatic = new Societe($db); $formcompany = new FormCompany($db); $projectstatic = new Project($db); @@ -1193,6 +1204,22 @@ if ($resql) { if (!empty($arrayfields['sale_representative']['checked'])) { print ''; } + if (!empty($arrayfields['total_pa']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_margin']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print ''; + } + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print ''; + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; // Fields from hook @@ -1354,6 +1381,18 @@ if ($resql) { if (!empty($arrayfields['sale_representative']['checked'])) { print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder); } + if (!empty($arrayfields['total_pa']['checked'])) { + print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_margin']['checked'])) { + print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder); + } $totalarray = array( 'nbfield' => 0, @@ -1413,6 +1452,18 @@ if ($resql) { $generic_product = new Product($db); $userstatic = new User($db); $i = 0; + + $with_margin_info = false; + if (!empty($conf->margin->enabled) && ( + !empty($arrayfields['total_pa']['checked']) + || !empty($arrayfields['total_margin']['checked']) + || !empty($arrayfields['total_margin_rate']['checked']) + || !empty($arrayfields['total_mark_rate']['checked']) + ) + ) { + $with_margin_info = true; + } + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -1455,6 +1506,12 @@ if ($resql) { $projectstatic->ref = $obj->project_ref; $projectstatic->title = $obj->project_label; + $marginInfo = array(); + if ($with_margin_info === true) { + $generic_commande->fetch_lines(); + $marginInfo = $formmargin->getMarginInfosArray($generic_commande); + } + print ''; // Ref @@ -1791,6 +1848,39 @@ if ($resql) { } } + // Total buying or cost price + if (!empty($arrayfields['total_pa']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Total margin + if (!empty($arrayfields['total_margin']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + if (!$i) { + $totalarray['pos'][$totalarray['nbfield']] = 'total_margin'; + } + $totalarray['val']['total_margin'] += $marginInfo['total_margin']; + } + // Total margin rate + if (!empty($arrayfields['total_margin_rate']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Total mark rate + if (!empty($arrayfields['total_mark_rate']['checked'])) { + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5344da8d06a..cc722bafca3 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1,22 +1,23 @@ - * Copyright (C) 2004-2013 Laurent Destailleur - * Copyright (C) 2004 Sebastien Di Cintio - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2014 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2007 Franky Van Liedekerke - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2012-2014 Christophe Battarel - * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2012-2014 Raphaël Doursenaud - * Copyright (C) 2013 Cedric Gross - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2016 Ferran Marcet - * Copyright (C) 2018 Alexandre Spangaro - * Copyright (C) 2018 Nicolas ZABOURI +/* Copyright (C) 2002-2007 Rodolphe Quiedeville + * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004 Sebastien Di Cintio + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2007 Franky Van Liedekerke + * Copyright (C) 2010-2020 Juanjo Menent + * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012-2015 Marcos García + * Copyright (C) 2012 Cédric Salvador + * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2013 Cedric Gross + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Ferran Marcet + * Copyright (C) 2018 Alexandre Spangaro + * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2022 Sylvain Legrand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1166,6 +1167,9 @@ class Facture extends CommonInvoice $object->fetch($fromid); + // Load source object + $objFrom = clone $object; + // Change socid if needed if (!empty($this->socid) && $this->socid != $object->socid) { $objsoc = new Societe($this->db); @@ -1246,13 +1250,13 @@ class Facture extends CommonInvoice $this->errors = $object->errors; } else { // copy internal contacts - if ($object->copy_linked_contact($this, 'internal') < 0) { + if ($object->copy_linked_contact($objFrom, 'internal') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; - } elseif ($this->socid == $object->socid) { + } elseif ($object->socid == $objFrom->socid) { // copy external contacts if same company - if ($object->copy_linked_contact($this, 'external') < 0) { + if ($object->copy_linked_contact($objFrom, 'external') < 0) { $error++; $this->error = $object->error; $this->errors = $object->errors; @@ -1263,7 +1267,7 @@ class Facture extends CommonInvoice if (!$error) { // Hook of thirdparty module if (is_object($hookmanager)) { - $parameters = array('objFrom'=>$this); + $parameters = array('objFrom'=>$objFrom); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c244229c5f8..f526220c071 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1621,6 +1621,18 @@ if ($resql) { $totalarray['val'] = array(); $totalarray['val']['f.total_ht'] = 0; $totalarray['val']['f.total_ttc'] = 0; + + $with_margin_info = false; + if (!empty($conf->margin->enabled) && ( + !empty($arrayfields['total_pa']['checked']) + || !empty($arrayfields['total_margin']['checked']) + || !empty($arrayfields['total_margin_rate']['checked']) + || !empty($arrayfields['total_mark_rate']['checked']) + ) + ) { + $with_margin_info = true; + } + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -1706,7 +1718,7 @@ if ($resql) { $facturestatic->alreadypaid = $paiement; $marginInfo = array(); - if (!empty($conf->margin->enabled)) { + if ($with_margin_info === true) { $facturestatic->fetch_lines(); $marginInfo = $formmargin->getMarginInfosArray($facturestatic); } @@ -2194,7 +2206,7 @@ if ($resql) { $totalarray['nbfield']++; } } - // total mark rate + // Total mark rate if (!empty($arrayfields['total_mark_rate']['checked'])) { print ''; if (!$i) { diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 00cbfc4158a..bb3f2ae035d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1389,7 +1389,7 @@ class Contact extends CommonObject * Return name of contact with link (and eventually picto) * Use $this->id, $this->lastname, $this->firstname, this->civility_id * - * @param int $withpicto Include picto with link + * @param int $withpicto Include picto with link (1=picto + name, 2=picto only, -1=photo+name, -2=photo only) * @param string $option Where the link point to * @param int $maxlen Max length of * @param string $moreparam Add more param into URL @@ -1475,14 +1475,14 @@ class Contact extends CommonObject $result .= $linkstart; if ($withpicto) { - if ($withpicto == -2) { + if ($withpicto < 0) { $result .= ''.Form::showphoto('contact', $this, 0, 0, 0, 'userphoto'.($withpicto == -3 ? 'small' : ''), 'mini', 0, 1).''; } else { $result .= img_object(($notooltip ? '' : $label), ( $this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); } } if ($withpicto != 2 && $withpicto != -2) { - $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)); + $result .= ''.($maxlen ? dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)).''; } $result .= $linkend; diff --git a/htdocs/core/class/ccountry.class.php b/htdocs/core/class/ccountry.class.php index 4f448845e80..7b46b0a08b0 100644 --- a/htdocs/core/class/ccountry.class.php +++ b/htdocs/core/class/ccountry.class.php @@ -111,7 +111,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; + $sql = "INSERT INTO ".$this->db->prefix()."c_country("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "code_iso,"; @@ -135,7 +135,7 @@ class Ccountry // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_country"); } // Commit or rollback @@ -169,7 +169,7 @@ class Ccountry // extends CommonObject $sql .= " t.code_iso,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t"; + $sql .= " FROM ".$this->db->prefix()."c_country as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -235,7 +235,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET"; + $sql = "UPDATE ".$this->db->prefix()."c_country SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " code_iso=".(isset($this->code_iso) ? "'".$this->db->escape($this->code_iso)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -278,7 +278,7 @@ class Ccountry // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; + $sql = "DELETE FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index c2dd055522e..937ca6f7875 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -113,7 +113,7 @@ class Comment extends CommonObject $error = 0; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "description"; $sql .= ", datec"; $sql .= ", fk_element"; @@ -146,7 +146,7 @@ class Comment extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Call trigger @@ -195,7 +195,7 @@ class Comment extends CommonObject $sql .= " c.fk_user_modif,"; $sql .= " c.entity,"; $sql .= " c.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -254,7 +254,7 @@ class Comment extends CommonObject // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " datec=".($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").","; @@ -315,7 +315,7 @@ class Comment extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -364,7 +364,7 @@ class Comment extends CommonObject if (!empty($element_type) && !empty($fk_element)) { $sql = "SELECT"; $sql .= " c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.fk_element = ".((int) $fk_element); $sql .= " AND c.element_type = '".$this->db->escape($element_type)."'"; $sql .= " AND c.entity = ".$conf->entity; diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 5d0242657ef..8a0ce49ce00 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -653,7 +653,7 @@ abstract class CommonDocGenerator if ($columns != "") { $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT ".$columns." FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields AS ex INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); + $resql = $this->db->query("SELECT ".$columns." FROM ".$this->db->prefix()."product_fournisseur_price_extrafields AS ex INNER JOIN ".$this->db->prefix()."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); diff --git a/htdocs/core/class/commonincoterm.class.php b/htdocs/core/class/commonincoterm.class.php index d0485acc5a9..e74d1428781 100644 --- a/htdocs/core/class/commonincoterm.class.php +++ b/htdocs/core/class/commonincoterm.class.php @@ -60,7 +60,7 @@ trait CommonIncoterm $this->label_incoterms = ''; if (!empty($this->fk_incoterms)) { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $result = $this->db->query($sql); if ($result) { $res = $this->db->fetch_object($result); @@ -80,7 +80,7 @@ trait CommonIncoterm */ public function getIncotermsForPDF() { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -106,7 +106,7 @@ trait CommonIncoterm public function setIncoterms($id_incoterm, $location) { if ($this->id && $this->table_element) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null"); $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -116,7 +116,7 @@ trait CommonIncoterm $this->fk_incoterms = $id_incoterm; $this->location_incoterms = $location; - $sql = "SELECT libelle as label_incoterms FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $res = $this->db->query($sql); if ($res) { $obj = $this->db->fetch_object($res); diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 6043814dc45..29fd230a61b 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -130,8 +130,8 @@ abstract class CommonInvoice extends CommonObject $field = 'fk_facturefourn'; } - $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql = "SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix().$table; $sql .= " WHERE ".$field." = ".((int) $this->id); dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); @@ -226,10 +226,10 @@ abstract class CommonInvoice extends CommonObject { $idarray = array(); - $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); - $sql .= ' AND type = 2'; + $sql .= " AND type = 2"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -253,10 +253,10 @@ abstract class CommonInvoice extends CommonObject */ public function getIdReplacingInvoice($option = '') { - $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); - $sql .= ' AND type < 2'; + $sql .= " AND type < 2"; if ($option == 'validated') { $sql .= ' AND fk_statut = 1'; } @@ -265,7 +265,7 @@ abstract class CommonInvoice extends CommonObject // and another no, priority is given to the valid one. // Should not happen (unless concurrent access and 2 people have created a // replacement invoice for the same invoice at the same time) - $sql .= ' ORDER BY fk_statut DESC'; + $sql .= " ORDER BY fk_statut DESC"; $resql = $this->db->query($sql); if ($resql) { @@ -308,7 +308,7 @@ abstract class CommonInvoice extends CommonObject } $sql = "SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code".$field3; - $sql .= " FROM ".MAIN_DB_PREFIX.$table." as pf, ".MAIN_DB_PREFIX.$table2." as p, ".MAIN_DB_PREFIX."c_paiement as t"; + $sql .= " FROM ".$this->db->prefix().$table." as pf, ".$this->db->prefix().$table2." as p, ".$this->db->prefix()."c_paiement as t"; $sql .= " WHERE pf.".$field." = ".((int) $this->id); $sql .= " AND pf.".$field2." = p.rowid"; $sql .= ' AND p.fk_paiement = t.id'; @@ -337,12 +337,12 @@ abstract class CommonInvoice extends CommonObject $sql = ''; if ($this->element == 'facture' || $this->element == 'invoice') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture as f'; $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } elseif ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture_fourn as f'; $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } @@ -462,7 +462,7 @@ abstract class CommonInvoice extends CommonObject $type = 'supplier_invoice'; } - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".$this->db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -601,8 +601,8 @@ abstract class CommonInvoice extends CommonObject $cdr_type = 0; $cdr_decalage = 0; - $sqltemp = 'SELECT c.type_cdr, c.nbjour, c.decalage'; - $sqltemp .= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; + $sqltemp = "SELECT c.type_cdr, c.nbjour, c.decalage"; + $sqltemp .= " FROM ".$this->db->prefix()."c_payment_term as c"; if (is_numeric($cond_reglement)) { $sqltemp .= " WHERE c.rowid=".((int) $cond_reglement); } else { @@ -697,15 +697,15 @@ abstract class CommonInvoice extends CommonObject $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $this->socid); - $sql = 'SELECT count(*)'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql = "SELECT count(*)"; + $sql .= " FROM ".$this->db->prefix()."prelevement_facture_demande"; if ($type == 'bank-transfer') { - $sql .= ' WHERE fk_facture_fourn = '.((int) $this->id); + $sql .= " WHERE fk_facture_fourn = ".((int) $this->id); } else { - $sql .= ' WHERE fk_facture = '.((int) $this->id); + $sql .= " WHERE fk_facture = ".((int) $this->id); } - $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments - $sql .= ' AND traite = 0'; + $sql .= " AND ext_payment_id IS NULL"; // To exclude record done for some online payments + $sql .= " AND traite = 0"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); @@ -728,7 +728,7 @@ abstract class CommonInvoice extends CommonObject } if (is_numeric($amount) && $amount != 0) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_facture_demande('; if ($type == 'bank-transfer') { $sql .= 'fk_facture_fourn, '; } else { @@ -800,7 +800,7 @@ abstract class CommonInvoice extends CommonObject public function demande_prelevement_delete($fuser, $did) { // phpcs:enable - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_facture_demande'; $sql .= ' WHERE rowid = '.((int) $did); $sql .= ' AND traite = 0'; if ($this->db->query($sql)) { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 58844439fc3..35db7816738 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -536,7 +536,7 @@ abstract class CommonObject global $db, $conf; $sql = "SELECT rowid, ref, ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX.$element; + $sql .= " FROM ".$db->prefix().$element; $sql .= " WHERE entity IN (".getEntity($element).")"; if ($id > 0) { @@ -1041,7 +1041,7 @@ abstract class CommonObject } else { // We look for id type_contact $sql = "SELECT tc.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; $sql .= " AND tc.source='".$this->db->escape($source)."'"; $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; @@ -1079,7 +1079,7 @@ abstract class CommonObject $this->db->begin(); // Insert into database - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql = "INSERT INTO ".$this->db->prefix()."element_contact"; $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; $sql .= " VALUES (".$this->id.", ".((int) $fk_socpeople)." , "; $sql .= "'".$this->db->idate($datecreate)."'"; @@ -1148,7 +1148,7 @@ abstract class CommonObject { // phpcs:enable // Insert into database - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; + $sql = "UPDATE ".$this->db->prefix()."element_contact set"; $sql .= " statut = ".$statut; if ($type_contact_id) { $sql .= ", fk_c_type_contact = ".((int) $type_contact_id); @@ -1182,7 +1182,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); @@ -1226,7 +1226,7 @@ abstract class CommonObject $listId = implode(",", $temp); } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE element_id = ".((int) $this->id); if (!empty($listId)) { $sql .= " AND fk_c_type_contact IN (".$this->db->sanitize($listId).")"; @@ -1267,13 +1267,13 @@ abstract class CommonObject } $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact tc"; + $sql .= ", ".$this->db->prefix()."element_contact ec"; if ($source == 'internal') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."user t on ec.fk_socpeople = t.rowid"; } if ($source == 'external' || $source == 'thirdparty') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."socpeople t on ec.fk_socpeople = t.rowid"; } $sql .= " WHERE ec.element_id = ".((int) $this->id); $sql .= " AND ec.fk_c_type_contact = tc.rowid"; @@ -1348,7 +1348,7 @@ abstract class CommonObject { $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; $sql .= " tc.code, tc.libelle"; - $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; + $sql .= " FROM (".$this->db->prefix()."element_contact as ec, ".$this->db->prefix()."c_type_contact as tc)"; $sql .= " WHERE ec.rowid =".((int) $rowid); $sql .= " AND ec.fk_c_type_contact=tc.rowid"; $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; @@ -1393,7 +1393,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; if ($activeonly == 1) { $sql .= " AND tc.active=1"; // only the active types @@ -1453,7 +1453,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sqlWhere = array(); if (!empty($element)) { @@ -1551,14 +1551,14 @@ abstract class CommonObject } $sql = "SELECT ec.fk_socpeople"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; + $sql .= " FROM ".$this->db->prefix()."element_contact as ec,"; if ($source == 'internal') { - $sql .= " ".MAIN_DB_PREFIX."user as c,"; + $sql .= " ".$this->db->prefix()."user as c,"; } if ($source == 'external') { - $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; + $sql .= " ".$this->db->prefix()."socpeople as c,"; } - $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE ec.element_id = ".((int) $id); $sql .= " AND ec.fk_socpeople = c.rowid"; if ($source == 'internal') { @@ -1674,7 +1674,7 @@ abstract class CommonObject return 0; } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; $query = $this->db->query($sql); @@ -1716,7 +1716,7 @@ abstract class CommonObject if ($idtype > 0) { if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { // If data not already loaded $sql = "SELECT rowid, code, libelle as label, coder"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; + $sql .= " FROM ".$this->db->prefix()."c_barcode_type"; $sql .= " WHERE rowid = ".((int) $idtype); dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); $resql = $this->db->query($sql); @@ -1853,7 +1853,7 @@ abstract class CommonObject $result = false; - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT rowid FROM ".$this->db->prefix().$table; $sql .= " WHERE ".$field." = '".$this->db->escape($key)."'"; if (!empty($element)) { $sql .= " AND entity IN (".getEntity($element).")"; @@ -1886,7 +1886,7 @@ abstract class CommonObject { $result = false; if (!empty($id) && !empty($field) && !empty($table)) { - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT ".$field." FROM ".$this->db->prefix().$table; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); @@ -1944,7 +1944,7 @@ abstract class CommonObject $fk_user_field = 'fk_user_mod'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; + $sql = "UPDATE ".$this->db->prefix().$table." SET "; if ($format == 'text') { $sql .= $field." = '".$this->db->escape($value)."'"; @@ -2044,20 +2044,20 @@ abstract class CommonObject } $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc; $sql = "SELECT MAX(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2114,20 +2114,20 @@ abstract class CommonObject $this->ref_previous = $row[0]; $sql = "SELECT MIN(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2226,7 +2226,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; if (!empty($this->fields['fk_project'])) { // Common case if ($projectid) { $sql .= " SET fk_project = ".((int) $projectid); @@ -2291,7 +2291,7 @@ abstract class CommonObject $fieldname = 'fk_typepayment'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2304,7 +2304,11 @@ abstract class CommonObject // Triggers if (!$error && !$notrigger) { // Call triggers - $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); + if (get_class($this) == 'Commande') { + $result = $this->call_trigger('ORDER_MODIFY', $user); + } else { + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); + } if ($result < 0) { $error++; } @@ -2335,7 +2339,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_code'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = '".$this->db->escape($code)."'"; $sql .= ' WHERE rowid='.((int) $this->id); @@ -2373,7 +2377,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_tx'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((float) $rate); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2581,7 +2585,7 @@ abstract class CommonObject $fieldname = 'cond_reglement_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2623,7 +2627,7 @@ abstract class CommonObject $fieldname = 'transport_mode_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2658,7 +2662,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'retained_warranty_fk_cond_reglement'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((int) $id); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2691,7 +2695,7 @@ abstract class CommonObject $fieldname = 'fk_address'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".((int) $id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ".$fieldname." = ".((int) $id); $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = 0"; if ($this->db->query($sql)) { @@ -2736,7 +2740,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_shipping_method = ".((int) $shipping_method_id); $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -2783,7 +2787,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_warehouse = ".((int) $warehouse_id); $sql .= " WHERE rowid=".((int) $this->id); @@ -2814,7 +2818,7 @@ abstract class CommonObject $newmodelpdf = dol_trunc($modelpdf, 255); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; $sql .= " WHERE rowid = ".((int) $this->id); @@ -2860,7 +2864,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_account = ".((int) $fk_account); $sql .= " WHERE rowid=".((int) $this->id); @@ -2917,7 +2921,7 @@ abstract class CommonObject // Count number of lines to reorder (according to choice $renum) $nl = 0; - $sql = "SELECT count(rowid) FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if (!$renum) { $sql .= ' AND rang = 0'; @@ -2939,7 +2943,7 @@ abstract class CommonObject $rows = array(); // We first search all lines that are parent lines (for multilevel details lines) - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($fk_parent_line) { $sql .= ' AND fk_parent_line IS NULL'; @@ -2987,7 +2991,7 @@ abstract class CommonObject { $rows = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND fk_parent_line = '.((int) $id); $sql .= ' ORDER BY rang ASC'; @@ -3065,7 +3069,7 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= ' WHERE rowid = '.((int) $rowid); dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); @@ -3111,11 +3115,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang - 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3142,11 +3146,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang + 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3165,7 +3169,7 @@ abstract class CommonObject */ public function getRangOfLine($rowid) { - $sql = "SELECT rang FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rang FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); @@ -3184,7 +3188,7 @@ abstract class CommonObject */ public function getIdOfLine($rang) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND rang = ".((int) $rang); $resql = $this->db->query($sql); @@ -3211,7 +3215,7 @@ abstract class CommonObject // Search the last rang with fk_parent_line if ($fk_parent_line) { - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND fk_parent_line = ".((int) $fk_parent_line); @@ -3227,7 +3231,7 @@ abstract class CommonObject } } else { // If not, search the last rang of element - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this)."::line_max", LOG_DEBUG); @@ -3254,7 +3258,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".((int) $this->id); @@ -3305,7 +3309,7 @@ abstract class CommonObject } else { $fieldusermod = "fk_user_modif"; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET note".$newsuffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); $sql .= ", ".$fieldusermod." = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); @@ -3429,7 +3433,7 @@ abstract class CommonObject $sql .= ', situation_percent'; } $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($exclspec) { $product_field = 'product_type'; @@ -3477,7 +3481,7 @@ abstract class CommonObject //var_dump($diff_when_using_price_ht.' '.$diff_on_current_total); if ($diff_when_using_price_ht && $diff_on_current_total) { - $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".price2num((float) $tmpcal[1]).", total_ttc = ".price2num((float) $tmpcal[2])." WHERE rowid = ".((int) $obj->rowid); + $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); dol_syslog('We found unconsistent 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, LOG_WARNING); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3521,7 +3525,7 @@ abstract class CommonObject dol_print_error('', $errmsg); exit; } - $sqlfix = "UPDATE ".MAIN_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); + $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); 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); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3589,7 +3593,7 @@ abstract class CommonObject } if (empty($nodatabaseupdate)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = "UPDATE ".$this->db->prefix().$this->table_element.' SET'; $sql .= " ".$fieldht." = ".((float) price2num($this->total_ht)).","; $sql .= " ".$fieldtva." = ".((float) price2num($this->total_tva)).","; $sql .= " ".$fieldlocaltax1." = ".((float) price2num($this->total_localtax1)).","; @@ -3670,7 +3674,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element ("; + $sql = "INSERT INTO " . $this->db->prefix() . "element_element ("; $sql .= "fk_source"; $sql .= ", sourcetype"; $sql .= ", fk_target"; @@ -3777,8 +3781,8 @@ abstract class CommonObject }*/ // Links between objects are stored in table element_element - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; + $sql = "SELECT rowid, fk_source, sourcetype, fk_target, targettype"; + $sql .= " FROM ".$this->db->prefix()."element_element"; $sql .= " WHERE "; if ($justsource || $justtarget) { if ($justsource) { @@ -3796,7 +3800,7 @@ abstract class CommonObject $sql .= "(fk_source = ".((int) $sourceid)." AND sourcetype = '".$this->db->escape($sourcetype)."')"; $sql .= " ".$clause." (fk_target = ".((int) $targetid)." AND targettype = '".$this->db->escape($targettype)."')"; } - $sql .= ' ORDER BY '.$orderby; + $sql .= " ORDER BY ".$orderby; dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); $resql = $this->db->query($sql); @@ -3964,7 +3968,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "UPDATE " . MAIN_DB_PREFIX . "element_element SET "; + $sql = "UPDATE " . $this->db->prefix() . "element_element SET "; if ($updatesource) { $sql .= "fk_source = " . ((int) $sourceid); $sql .= ", sourcetype = '" . $this->db->escape($sourcetype) . "'"; @@ -4053,7 +4057,7 @@ abstract class CommonObject } if (!$error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element"; + $sql = "DELETE FROM " . $this->db->prefix() . "element_element"; $sql .= " WHERE"; if ($rowid > 0) { $sql .= " rowid = " . ((int) $rowid); @@ -4105,7 +4109,7 @@ abstract class CommonObject global $db; - $sql = "SELECT ".$field_select." FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "SELECT ".$field_select." FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); $TRes = array(); @@ -4134,7 +4138,7 @@ abstract class CommonObject global $db; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "DELETE FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); if (empty($resql)) { @@ -4187,7 +4191,7 @@ abstract class CommonObject $fieldstatus = 'status'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; + $sql = "UPDATE ".$this->db->prefix().$elementTable; $sql .= " SET ".$fieldstatus." = ".((int) $status); // If status = 1 = validated, update also fk_user_valid // TODO Replace the test on $elementTable by doing a test on existence of the field in $this->fields @@ -4288,7 +4292,7 @@ abstract class CommonObject $ref = trim($ref); $sql = "SELECT rowid, canvas"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE entity IN (".getEntity($this->element).")"; if (!empty($id)) { $sql .= " AND rowid = ".((int) $id); @@ -4321,7 +4325,7 @@ abstract class CommonObject */ public function getSpecialCode($lineid) { - $sql = "SELECT special_code FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT special_code FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $lineid); $resql = $this->db->query($sql); if ($resql) { @@ -4363,7 +4367,7 @@ abstract class CommonObject foreach ($arraytoscan as $table => $elementname) { //print $id.'-'.$table.'-'.$elementname.'
'; // Check if third party can be deleted - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; + $sql = "SELECT COUNT(*) as nb from ".$this->db->prefix().$table; $sql .= " WHERE ".$this->fk_element." = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { @@ -4439,7 +4443,7 @@ abstract class CommonObject $total_discount = 0.00; $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); @@ -4579,7 +4583,7 @@ abstract class CommonObject $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -5074,7 +5078,7 @@ abstract class CommonObject // phpcs:enable $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; + $sql = "INSERT INTO ".$this->db->prefix()."element_resources ("; $sql .= "resource_id"; $sql .= ", resource_type"; $sql .= ", element_id"; @@ -5117,7 +5121,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; + $sql = "DELETE FROM ".$this->db->prefix()."element_resources"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); @@ -5437,7 +5441,7 @@ abstract class CommonObject //var_dump($obj->update_main_doc_field);exit; if ($update_main_doc_field && !empty($this->table_element)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; $sql .= " WHERE rowid = ".((int) $this->id); $resql = $this->db->query($sql); @@ -5601,7 +5605,7 @@ abstract class CommonObject // Request to get translation values for object $sql = "SELECT rowid, property, lang , value"; - $sql .= " FROM ".MAIN_DB_PREFIX."object_lang"; + $sql .= " FROM ".$this->db->prefix()."object_lang"; $sql .= " WHERE type_object = '".$this->db->escape($element)."'"; $sql .= " AND fk_object = ".((int) $this->id); @@ -5806,7 +5810,7 @@ abstract class CommonObject $sql .= ", ".$name; } } - $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; + $sql .= " FROM ".$this->db->prefix().$table_element."_extrafields"; $sql .= " WHERE fk_object = ".((int) $rowid); //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose @@ -5880,7 +5884,7 @@ abstract class CommonObject dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql_del); if (!$resql) { @@ -6080,10 +6084,10 @@ abstract class CommonObject dol_syslog(get_class($this)."::insertExtraFields delete then insert", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; + $sql = "INSERT INTO ".$this->db->prefix().$table_element."_extrafields (fk_object"; foreach ($new_array_options as $key => $value) { $attributeKey = substr($key, 8); // Remove 'options_' prefix // Add field of attribut @@ -6231,13 +6235,13 @@ abstract class CommonObject foreach ($new_array_languages as $key => $langcodearray) { // $key = 'name', 'town', ... foreach ($langcodearray as $langcode => $value) { - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."object_lang"; + $sql_del = "DELETE FROM ".$this->db->prefix()."object_lang"; $sql_del .= " WHERE fk_object = ".((int) $this->id)." AND property = '".$this->db->escape($key)."' AND type_object = '".$this->db->escape($table_element)."'"; $sql_del .= " AND lang = '".$this->db->escape($langcode)."'"; $this->db->query($sql_del); if ($value !== '') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."object_lang (fk_object, property, type_object, lang, value"; + $sql = "INSERT INTO ".$this->db->prefix()."object_lang (fk_object, property, type_object, lang, value"; $sql .= ") VALUES (".$this->id.", '".$this->db->escape($key)."', '".$this->db->escape($table_element)."', '".$this->db->escape($langcode)."', '".$this->db->escape($value)."'"; $sql .= ")"; @@ -6421,7 +6425,7 @@ abstract class CommonObject $linealreadyfound = 0; // Check if there is already a line for this object (in most cases, it is, but sometimes it is not, for example when extra field has been created after), so we must keep this overload) - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql = "SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $tmpobj = $this->db->fetch_object($resql); @@ -6432,9 +6436,9 @@ abstract class CommonObject if ($linealreadyfound) { if ($this->array_options["options_".$key] === null) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = null"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = null"; } else { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; } $sql .= " WHERE fk_object = ".((int) $this->id); } else { @@ -6763,7 +6767,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6779,7 +6783,7 @@ abstract class CommonObject //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= " as main, ".MAIN_DB_PREFIX.$InfoFieldList[0]."_extrafields as extra"; + $sql .= " as main, ".$this->db->prefix().$InfoFieldList[0]."_extrafields as extra"; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -6915,7 +6919,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6931,7 +6935,7 @@ abstract class CommonObject // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -7276,7 +7280,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -7359,7 +7363,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -8052,7 +8056,7 @@ abstract class CommonObject public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { foreach ($tables as $table) { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); + $sql = 'UPDATE '.$db->prefix().$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); if (!$db->query($sql)) { if ($ignoreerrors) { @@ -8776,7 +8780,7 @@ abstract class CommonObject $this->db->begin(); if (!$error) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element; $sql .= " (".implode(", ", $keys).')'; $sql .= " VALUES (".implode(", ", $values).")"; // $values can contains 'abc' or 123 @@ -8792,13 +8796,13 @@ abstract class CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); } // If we have a field ref with a default value of (PROV) if (!$error) { if (key_exists('ref', $this->fields) && $this->fields['ref']['notnull'] > 0 && key_exists('default', $this->fields['ref']) && $this->fields['ref']['default'] == '(PROV)') { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); $resqlupdate = $this->db->query($sql); if ($resqlupdate === false) { @@ -8883,7 +8887,7 @@ abstract class CommonObject } $sql = "SELECT ".$fieldlist; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element.' as t'; if (!empty($id)) { $sql .= ' WHERE t.rowid = '.((int) $id); @@ -8938,7 +8942,7 @@ abstract class CommonObject $objectline = new $objectlineclassname($this->db); $sql = "SELECT ".$objectline->getFieldList('l'); - $sql .= " FROM ".MAIN_DB_PREFIX.$objectline->table_element." as l"; + $sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l"; $sql .= " WHERE l.fk_".$this->db->escape($this->element)." = ".((int) $this->id); if ($morewhere) { $sql .= $morewhere; @@ -9028,7 +9032,7 @@ abstract class CommonObject }*/ } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); $this->db->begin(); if (!$error) { @@ -9085,7 +9089,7 @@ abstract class CommonObject if ($forcechilddeletion) { // Force also delete of childtables that should lock deletion in standard case when option force is off foreach ($this->childtables as $table) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9139,7 +9143,7 @@ abstract class CommonObject } } else { // Delete record in child table - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9179,7 +9183,7 @@ abstract class CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9218,7 +9222,7 @@ abstract class CommonObject if (!empty($parentId) && !empty($parentField)) { $this->db->begin(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE ".$parentField." = ".(int) $parentId; // Manage filters @@ -9303,7 +9307,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $idline); dol_syslog(get_class($this)."::deleteLineCommon", LOG_DEBUG); @@ -9357,7 +9361,7 @@ abstract class CommonObject $statusfield = 'fk_statut'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$statusfield." = ".((int) $status); $sql .= " WHERE rowid = ".((int) $this->id); @@ -9594,8 +9598,8 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $categorystatic = new Categorie($this->db); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; - $sql .= " SELECT fk_categorie, $toId FROM ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); + $sql = "INSERT INTO ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; + $sql .= " SELECT fk_categorie, $toId FROM ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); $sql .= " WHERE fk_product = ".((int) $fromId); if (!$this->db->query($sql)) { @@ -9643,8 +9647,8 @@ abstract class CommonObject } // Delete ecm_files extrafields - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files_extrafields WHERE fk_object IN ("; - $sql .= " SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files_extrafields WHERE fk_object IN ("; + $sql .= " SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here $sql .= ")"; @@ -9655,7 +9659,7 @@ abstract class CommonObject } // Delete ecm_files - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here @@ -9668,8 +9672,8 @@ abstract class CommonObject // Delete in database with mode 1 if ($mode == 1) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files_extrafields"; - $sql .= " WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files_extrafields"; + $sql .= " WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9677,7 +9681,7 @@ abstract class CommonObject return false; } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files"; $sql .= " WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index d93d0b67ff9..487482a9b3c 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -93,7 +93,7 @@ abstract class CommonObjectLine extends CommonObject $label_type = 'code'; } - $sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit); + $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit); $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 33510186646..91b176f899d 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -183,7 +183,7 @@ class CoreObject extends CommonObject $this->{$className} = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "SELECT rowid FROM ".$this->db->prefix().$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); $res = $this->db->query($sql); if ($res) { diff --git a/htdocs/core/class/cproductnature.class.php b/htdocs/core/class/cproductnature.class.php index 5b343b21dbc..d0c8a5d3933 100644 --- a/htdocs/core/class/cproductnature.class.php +++ b/htdocs/core/class/cproductnature.class.php @@ -102,7 +102,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element."("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -125,7 +125,7 @@ class CProductNature // extends CommonObject $this->db->rollback(); return -1; } else { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); $this->db->commit(); return $this->id; } @@ -148,7 +148,7 @@ class CProductNature // extends CommonObject $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -197,12 +197,12 @@ class CProductNature // extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -267,7 +267,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code=".(isset($this->code) ? ((int) $this->code) : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape(trim($this->label))."'" : "null").","; $sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null"); @@ -302,7 +302,7 @@ class CProductNature // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".(int) $this->id; $this->db->begin(); diff --git a/htdocs/core/class/cstate.class.php b/htdocs/core/class/cstate.class.php index 2b9b1d6880e..36c3cb2c0fe 100644 --- a/htdocs/core/class/cstate.class.php +++ b/htdocs/core/class/cstate.class.php @@ -106,7 +106,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; + $sql = "INSERT INTO ".$this->db->prefix()."c_departements("; $sql .= "rowid,"; $sql .= "code_departement,"; $sql .= "nom,"; @@ -128,7 +128,7 @@ class Cstate // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_departements"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_departements"); } // Commit or rollback @@ -161,7 +161,7 @@ class Cstate // extends CommonObject $sql .= " t.code_departement,"; $sql .= " t.nom,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_departements as t"; + $sql .= " FROM ".$this->db->prefix()."c_departements as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -219,7 +219,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_departements SET"; + $sql = "UPDATE ".$this->db->prefix()."c_departements SET"; $sql .= " code_departement=".(isset($this->code_departement) ? "'".$this->db->escape($this->code_departement)."'" : "null").","; $sql .= " nom=".(isset($this->nom) ? "'".$this->db->escape($this->nom)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").""; @@ -260,7 +260,7 @@ class Cstate // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; + $sql = "DELETE FROM ".$this->db->prefix()."c_departements"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/ctypent.class.php b/htdocs/core/class/ctypent.class.php index c8421c54b1f..6de7de7d5cb 100644 --- a/htdocs/core/class/ctypent.class.php +++ b/htdocs/core/class/ctypent.class.php @@ -105,7 +105,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent("; + $sql = "INSERT INTO ".$this->db->prefix()."c_typent("; $sql .= "id,"; $sql .= "code,"; @@ -135,7 +135,7 @@ class Ctypent // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_typent"); } // Commit or rollback @@ -170,7 +170,7 @@ class Ctypent // extends CommonObject $sql .= " t.fk_country as country_id,"; $sql .= " t.active,"; $sql .= " t.module"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t"; + $sql .= " FROM ".$this->db->prefix()."c_typent as t"; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -232,7 +232,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET"; + $sql = "UPDATE ".$this->db->prefix()."c_typent SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").","; @@ -275,7 +275,7 @@ class Ctypent // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent"; + $sql = "DELETE FROM ".$this->db->prefix()."c_typent"; $sql .= " WHERE id=".$this->id; $this->db->begin(); diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 891bf6bea10..32fe3164ad8 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -99,7 +99,7 @@ class Ctyperesource // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'code,'; $sql .= 'label'; @@ -125,7 +125,7 @@ class Ctyperesource } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. @@ -163,12 +163,12 @@ class Ctyperesource { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -228,12 +228,12 @@ class Ctyperesource { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; // Manage filter $sqlwhere = array(); @@ -307,7 +307,7 @@ class Ctyperesource // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; @@ -376,7 +376,7 @@ class Ctyperesource // If you need to delete child tables to, you can insert them here if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 7219f901c9f..d7571b8ca90 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -112,7 +112,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_units("; + $sql = "INSERT INTO ".$this->db->prefix()."c_units("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -138,7 +138,7 @@ class CUnits // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_units"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_units"); } // Commit or rollback @@ -178,7 +178,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t"; + $sql .= " FROM ".$this->db->prefix()."c_units as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -237,7 +237,7 @@ class CUnits // extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.sortorder,"; @@ -246,7 +246,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'c_units as t'; + $sql .= " FROM ".$this->db->prefix()."c_units as t"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -343,7 +343,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_units SET"; + $sql = "UPDATE ".$this->db->prefix()."c_units SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " sortorder=".(isset($this->sortorder) ? "'".$this->db->escape($this->sortorder)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -389,7 +389,7 @@ class CUnits // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_units"; + $sql = "DELETE FROM ".$this->db->prefix()."c_units"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); @@ -471,7 +471,7 @@ class CUnits // extends CommonObject { $base = 10; // TODO : add base col into unit dictionary table - $unit = $this->db->getRow('SELECT scale, unit_type from '.MAIN_DB_PREFIX.'c_units WHERE rowid = '.intval($id)); + $unit = $this->db->getRow("SELECT scale, unit_type from ".$this->db->prefix()."c_units WHERE rowid = ".intval($id)); if ($unit) { // TODO : if base exist in unit dictionary table remove this convertion exception and update convertion infos in database exemple time hour currently scale 3600 will become scale 2 base 60 if ($unit->unit_type == 'time') { diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index f6edb58207c..278b5d5e0e6 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -259,10 +259,10 @@ class DefaultValues extends CommonObject $records = array(); - $sql = 'SELECT '; + $sql = "SELECT "; $sql .= $this->getFieldList(); - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE 1 = 1'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE 1 = 1"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 46789352bd7..7939965828a 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -139,9 +139,9 @@ class DiscountAbsolute $sql .= " sr.datec,"; $sql .= " f.ref as ref_facture_source, f.type as type_facture_source,"; $sql .= " fsup.ref as ref_invoice_supplier_source, fsup.type as type_invoice_supplier_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as sr"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture as f ON sr.fk_facture_source = f.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; $sql .= " WHERE sr.entity IN (".getEntity('invoice').")"; if ($rowid) { $sql .= " AND sr.rowid = ".((int) $rowid); @@ -251,7 +251,7 @@ class DiscountAbsolute } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "INSERT INTO ".$this->db->prefix()."societe_remise_except"; $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,"; $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx, vat_src_code,"; $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,"; @@ -267,7 +267,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); + $this->id = $this->db->last_insert_id($this->db->prefix()."societe_remise_except"); return $this->id; } else { $this->error = $this->db->lasterror().' - sql='.$sql; @@ -289,7 +289,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_facture_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_facture_source = ".((int) $this->fk_facture_source); @@ -312,7 +312,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_invoice_supplier_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_invoice_supplier_source = ".((int) $this->fk_invoice_supplier_source); @@ -335,7 +335,7 @@ class DiscountAbsolute $this->db->begin(); // Delete but only if not used - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; + $sql = "DELETE FROM ".$this->db->prefix()."societe_remise_except "; if ($this->fk_facture_source) { $sql .= " WHERE fk_facture_source = ".((int) $this->fk_facture_source); // Delete all lines of same serie } elseif ($this->fk_invoice_supplier_source) { @@ -353,7 +353,7 @@ class DiscountAbsolute if ($result) { // If source of discount was a credit note or deposit, we change source statut. if ($this->fk_facture_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql = "UPDATE ".$this->db->prefix()."facture"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_facture_source); @@ -368,7 +368,7 @@ class DiscountAbsolute return -1; } } elseif ($this->fk_invoice_supplier_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn"; + $sql = "UPDATE ".$this->db->prefix()."facture_fourn"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_invoice_supplier_source); @@ -418,7 +418,7 @@ class DiscountAbsolute return -2; } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { if ($rowidline) { $sql .= " SET fk_invoice_supplier_line = ".((int) $rowidline); @@ -464,7 +464,7 @@ class DiscountAbsolute public function unlink_invoice() { // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { $sql .= " SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL"; } else { @@ -501,7 +501,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG); $sql = "SELECT SUM(rc.amount_ttc) as amount, SUM(rc.multicurrency_amount_ttc) as multicurrency_amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; $sql .= " WHERE rc.entity = ".$conf->entity; $sql .= " AND rc.discount_type=".((int) $discount_type); if (!empty($discount_type)) { @@ -553,15 +553,15 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); - $sql .= ' AND f.type = 3'; + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture as f"; + $sql .= " WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id); + $sql .= " AND f.type = 3"; } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); - $sql .= ' AND f.type = 3'; + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture_fourn as f"; + $sql .= " WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id); + $sql .= " AND f.type = 3"; } else { $this->error = get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; dol_print_error($this->error); @@ -594,15 +594,15 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); - $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE.", ".$invoice::TYPE_SITUATION).')'; // Find discount coming from credit note or excess received + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture as f"; + $sql .= " WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id); + $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE.", ".$invoice::TYPE_SITUATION).")"; // Find discount coming from credit note or excess received } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); - $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE).')'; // Find discount coming from credit note or excess paid + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture_fourn as f"; + $sql .= " WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id); + $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE).")"; // Find discount coming from credit note or excess paid } else { $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; dol_print_error($this->error); @@ -634,13 +634,13 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; - $sql .= ' WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = '.((int) $invoice->id); + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; + $sql .= " WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = ".((int) $invoice->id); } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; - $sql .= ' WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = '.((int) $invoice->id); + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; + $sql .= " WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = ".((int) $invoice->id); } else { $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; dol_print_error($this->error); diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 9db069ab290..7653fd24437 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -242,9 +242,9 @@ class dolReceiptPrinter extends Printer $error = 0; $line = 0; $obj = array(); - $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; - $sql .= ' WHERE entity = '.$conf->entity; + $sql = "SELECT rowid, name, fk_type, fk_profile, parameter"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt"; + $sql .= " WHERE entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -310,9 +310,9 @@ class dolReceiptPrinter extends Printer $error = 0; $line = 0; $obj = array(); - $sql = 'SELECT rowid, name, template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; - $sql .= ' WHERE entity = '.$conf->entity; + $sql = "SELECT rowid, name, template"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt_template"; + $sql .= " WHERE entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -391,7 +391,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt"; $sql .= " (name, fk_type, fk_profile, parameter, entity)"; $sql .= " VALUES ('".$this->db->escape($name)."', ".((int) $type).", ".((int) $profile).", '".$this->db->escape($parameter)."', ".((int) $conf->entity).")"; $resql = $this->db->query($sql); @@ -417,7 +417,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", fk_type=".((int) $type); $sql .= ", fk_profile=".((int) $profile); @@ -442,7 +442,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt'; $sql .= ' WHERE rowid='.((int) $printerid); $resql = $this->db->query($sql); if (!$resql) { @@ -463,7 +463,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt_template"; $sql .= " (name, template, entity) VALUES ('".$this->db->escape($name)."'"; $sql .= ", '".$this->db->escape($template)."', ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -484,7 +484,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt_template'; $sql .= " WHERE rowid = ".((int) $templateid); $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); @@ -508,7 +508,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt_template"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", template='".$this->db->escape($template)."'"; $sql .= " WHERE rowid=".((int) $templateid); @@ -807,8 +807,8 @@ class dolReceiptPrinter extends Printer case 'DOL_PRINT_PAYMENT': $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql .= " cp.code"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql .= " FROM ".$this->db->prefix()."paiement_facture as pf, ".$this->db->prefix()."paiement as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_paiement as cp ON p.fk_paiement = cp.id"; $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id); $sql .= " ORDER BY p.datep"; $resql = $this->db->query($sql); @@ -834,7 +834,7 @@ class dolReceiptPrinter extends Printer } break; case 'DOL_VALUE_PLACE': - $sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); + $sql = "SELECT floor, label FROM ".$this->db->prefix()."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); $resql = $this->db->query($sql); $obj = $this->db->fetch_object($resql); if ($obj) { @@ -873,10 +873,10 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'SELECT template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; - $sql .= ' WHERE rowid = '.((int) $templateid); - $sql .= ' AND entity = '.$conf->entity; + $sql = "SELECT template"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt_template"; + $sql .= " WHERE rowid = ".((int) $templateid); + $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_array($resql); @@ -910,10 +910,10 @@ class dolReceiptPrinter extends Printer return; } $error = 0; - $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; - $sql .= ' WHERE rowid = '.((int) $printerid); - $sql .= ' AND entity = '.((int) $conf->entity); + $sql = "SELECT rowid, name, fk_type, fk_profile, parameter"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt"; + $sql .= " WHERE rowid = ".((int) $printerid); + $sql .= " AND entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_array($resql); diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index 0ee7eb118ac..517fc953830 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -347,9 +347,9 @@ class EmailSenderProfile extends CommonObject */ public function info($id) { - $sql = 'SELECT rowid, date_creation as datec, tms as datem'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql = "SELECT rowid, date_creation as datec, tms as datem"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE t.rowid = ".((int) $id); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { diff --git a/htdocs/core/class/events.class.php b/htdocs/core/class/events.class.php index c8799ebbd5e..104f1567d44 100644 --- a/htdocs/core/class/events.class.php +++ b/htdocs/core/class/events.class.php @@ -152,7 +152,7 @@ class Events // extends CommonObject } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; + $sql = "INSERT INTO ".$this->db->prefix()."events("; $sql .= "type,"; $sql .= "entity,"; $sql .= "ip,"; @@ -175,7 +175,7 @@ class Events // extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); + $this->id = $this->db->last_insert_id($this->db->prefix()."events"); return $this->id; } else { $this->error = "Error ".$this->db->lasterror(); @@ -202,7 +202,7 @@ class Events // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."events SET"; + $sql = "UPDATE ".$this->db->prefix()."events SET"; $sql .= " type='".$this->db->escape($this->type)."',"; $sql .= " dateevent='".$this->db->idate($this->dateevent)."',"; $sql .= " description='".$this->db->escape($this->description)."'"; @@ -237,7 +237,7 @@ class Events // extends CommonObject $sql .= " t.ip,"; $sql .= " t.user_agent,"; $sql .= " t.prefix_session"; - $sql .= " FROM ".MAIN_DB_PREFIX."events as t"; + $sql .= " FROM ".$this->db->prefix()."events as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -274,7 +274,7 @@ class Events // extends CommonObject */ public function delete($user) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."events"; + $sql = "DELETE FROM ".$this->db->prefix()."events"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a6f09493a74..abd2c7dd502 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -265,10 +265,10 @@ class ExtraFields 'default' => $default_value ); - $result = $this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLAddField($this->db->prefix().$table, $attrname, $field_desc); if ($result > 0) { if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; $resql = $this->db->query($sql, 1, 'dml'); } return 1; @@ -353,7 +353,7 @@ class ExtraFields $params = ''; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; $sql .= " label,"; $sql .= " type,"; @@ -447,7 +447,7 @@ class ExtraFields if (!$error) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; $sql .= " AND name = '".$this->db->escape($attrname)."'"; //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table @@ -455,7 +455,7 @@ class ExtraFields if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj->nb <= 0) { - $result = $this->db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname); // This also drop the unique key + $result = $this->db->DDLDropField($this->db->prefix().$table, $attrname); // This also drop the unique key if ($result < 0) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); @@ -492,7 +492,7 @@ class ExtraFields } if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql .= " AND entity IN (0,".$conf->entity.')'; $sql .= " AND elementtype = '".$this->db->escape($elementtype)."'"; @@ -597,7 +597,7 @@ class ExtraFields } if ($type != 'separate') { // No table update when separate type - $result = $this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLUpdateField($this->db->prefix().$table, $attrname, $field_desc); } if ($result > 0 || $type == 'separate') { if ($label) { @@ -606,9 +606,9 @@ class ExtraFields if ($result > 0) { $sql = ''; if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; } else { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; + $sql = "ALTER TABLE ".$this->db->prefix().$table." DROP INDEX uk_".$table."_".$attrname; } dol_syslog(get_class($this).'::update', LOG_DEBUG); $resql = $this->db->query($sql, 1, 'dml'); @@ -699,20 +699,20 @@ class ExtraFields if ($entity === '' || $entity != '0') { // We dont want on all entities, we delete all and current - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity IN (0, ".($entity === '' ? $conf->entity : $entity).")"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } else { // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity = 0"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } $resql1 = $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; // This is code $sql .= " entity,"; $sql .= " label,"; @@ -809,7 +809,7 @@ class ExtraFields // We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode $sql = "SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later if ($elementtype) { $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; // Filed with object->table_element @@ -1136,7 +1136,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use curent entity filter if (strpos($InfoFieldList[4], '$ENTITY$') !== false) { @@ -1155,7 +1155,7 @@ class ExtraFields } //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1304,7 +1304,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -1367,7 +1367,7 @@ class ExtraFields // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra.') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1592,7 +1592,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -1696,7 +1696,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 0edae298f46..772c67ff282 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -134,7 +134,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; + $sql = "INSERT INTO ".$this->db->prefix()."accounting_fiscalyear ("; $sql .= "label"; $sql .= ", date_start"; $sql .= ", date_end"; @@ -155,7 +155,7 @@ class Fiscalyear extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); + $this->id = $this->db->last_insert_id($this->db->prefix()."accounting_fiscalyear"); $result = $this->update($user); if ($result > 0) { @@ -191,7 +191,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql = "UPDATE ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " SET label = '".$this->db->escape($this->label)."'"; $sql .= ", date_start = '".$this->db->idate($this->date_start)."'"; $sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null"); @@ -221,7 +221,7 @@ class Fiscalyear extends CommonObject public function fetch($id) { $sql = "SELECT rowid, label, date_start, date_end, statut"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -253,7 +253,7 @@ class Fiscalyear extends CommonObject { $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".((int) $id); + $sql = "DELETE FROM ".$this->db->prefix()."accounting_fiscalyear WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); @@ -414,10 +414,10 @@ class Fiscalyear extends CommonObject */ public function info($id) { - $sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,'; - $sql .= ' fy.tms'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy'; - $sql .= ' WHERE fy.rowid = '.((int) $id); + $sql = "SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,"; + $sql .= " fy.tms"; + $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear as fy"; + $sql .= " WHERE fy.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); $result = $this->db->query($sql); @@ -464,7 +464,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(DISTINCT piece_num) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping"; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; @@ -498,7 +498,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping "; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 417f6201594..3375e9f7cc4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -204,7 +204,7 @@ class Form */ public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id') { - global $conf, $langs, $db; + global $conf, $langs; $ret = ''; @@ -886,7 +886,7 @@ class Form $atleastonefavorite = 0; $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; + $sql .= " FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; @@ -1009,7 +1009,7 @@ class Form $incotermArray = array(); $sql = "SELECT rowid, code"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms"; + $sql .= " FROM ".$this->db->prefix()."c_incoterms"; $sql .= " WHERE active > 0"; $sql .= " ORDER BY code ASC"; @@ -1088,7 +1088,7 @@ class Form public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0) { // phpcs:enable - global $db, $langs, $user, $conf; + global $langs, $conf; // If product & services are enabled or both disabled. if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled)) @@ -1155,7 +1155,7 @@ class Form $langs->load("trips"); $sql = "SELECT c.code, c.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; + $sql .= " FROM ".$this->db->prefix()."c_type_fees as c"; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -1344,12 +1344,12 @@ class Form $sql .= ", s.address, s.zip, s.town"; $sql .= ", dictp.code as country_code"; } - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."societe as s"; if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_country as dictp ON dictp.rowid = s.fk_pays"; } if (empty($user->rights->societe->client->voir) && !$user->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE s.entity IN (".getEntity('societe').")"; if (!empty($user->socid)) { @@ -1523,7 +1523,7 @@ class Form // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql .= " re.description, re.fk_facture_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as re"; $sql .= " WHERE re.fk_soc = ".(int) $socid; $sql .= " AND re.entity = ".$conf->entity; if ($filter) { @@ -1668,9 +1668,9 @@ class Form if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { $sql .= ", s.nom as company, s.town AS company_town"; } - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; + $sql .= " FROM ".$this->db->prefix()."socpeople as sp"; if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc"; + $sql .= " LEFT OUTER JOIN ".$this->db->prefix()."societe as s ON s.rowid=sp.fk_soc"; } $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; if ($socid > 0 || $socid == -1) { @@ -1922,9 +1922,9 @@ class Form if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { $sql .= ", e.label"; } - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " FROM ".$this->db->prefix()."user as u"; if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid = u.entity"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entity as e ON e.rowid = u.entity"; if ($force_entity) { $sql .= " WHERE u.entity IN (0, ".$this->db->sanitize($force_entity).")"; } else { @@ -1932,7 +1932,7 @@ class Form } } else { if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= " LEFT JOIN ".$this->db->prefix()."usergroup_user as ug"; $sql .= " ON ug.fk_user = u.rowid"; $sql .= " WHERE ug.entity = ".$conf->entity; } else { @@ -2458,7 +2458,7 @@ class Form public function select_produits_list($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $filterkey = '', $status = 1, $finished = 2, $outputmode = 0, $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $hidepriceinlabel = 0, $warehouseStatus = '') { // phpcs:enable - global $langs, $conf, $user, $db; + global $langs, $conf; $out = ''; $outarray = array(); @@ -2494,9 +2494,9 @@ class Form if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) { //Product category - $sql .= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie - FROM ".MAIN_DB_PREFIX."categorie_product - WHERE ".MAIN_DB_PREFIX."categorie_product.fk_product=p.rowid + $sql .= ", (SELECT ".$this->db->prefix()."categorie_product.fk_categorie + FROM ".$this->db->prefix()."categorie_product + WHERE ".$this->db->prefix()."categorie_product.fk_product=p.rowid LIMIT 1 ) AS categorie_product_id "; } @@ -2522,13 +2522,13 @@ class Form } // Price by quantity if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { - $sql .= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; + $sql .= ", (SELECT pp.rowid FROM ".$this->db->prefix()."product_price as pp WHERE pp.fk_product = p.rowid"; if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { $sql .= " AND price_level = ".((int) $price_level); } $sql .= " ORDER BY date_price"; $sql .= " DESC LIMIT 1) as price_rowid"; - $sql .= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable + $sql .= ", (SELECT pp.price_by_qty FROM ".$this->db->prefix()."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { $sql .= " AND price_level = ".((int) $price_level); } @@ -2536,32 +2536,32 @@ class Form $sql .= " DESC LIMIT 1) as price_by_qty"; $selectFields .= ", price_rowid, price_by_qty"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; if (count($warehouseStatusArray)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.fk_product = p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e on ps.fk_entrepot = e.rowid AND e.entity IN (".getEntity('stock').")"; $sql .= ' AND e.statut IN ('.$this->db->sanitize($this->db->escape(implode(',', $warehouseStatusArray))).')'; // Return line if product is inside the selected stock. If not, an empty line will be returned so we will count 0. } // include search in supplier ref if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; } //Price by customer if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".((int) $socid)." AND pcp.fk_product=p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_customer_price as pcp ON pcp.fk_soc=".((int) $socid)." AND pcp.fk_product=p.rowid"; } // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_units u ON u.rowid = p.fk_unit"; } // Multilang : we add translation if (!empty($conf->global->MAIN_MULTILANGS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid "; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_lang as pl ON pl.fk_product = p.rowid "; if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && !empty($socid)) { require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; - $soc = new Societe($db); + $soc = new Societe($this->db); $result = $soc->fetch($socid); if ($result > 0 && !empty($soc->default_lang)) { $sql .= " AND pl.lang = '".$this->db->escape($soc->default_lang)."'"; @@ -2574,7 +2574,7 @@ class Form } if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; } $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; @@ -2702,7 +2702,7 @@ class Form if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product $sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $objp->price_rowid); $sql .= " ORDER BY quantity ASC"; @@ -2775,7 +2775,7 @@ class Form } return $outarray; } else { - dol_print_error($db); + dol_print_error($this->db); } } @@ -2796,7 +2796,7 @@ class Form */ protected function constructProductListOption(&$objp, &$opt, &$optJson, $price_level, $selected, $hidepriceinlabel = 0, $filterkey = '', $novirtualstock = 0) { - global $langs, $conf, $user, $db; + global $langs, $conf, $user; $outkey = ''; $outval = ''; @@ -2942,7 +2942,7 @@ class Form // If we need a particular price level (from 1 to n) if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) { $sql = "SELECT price, price_ttc, price_base_type, tva_tx, default_vat_code"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $objp->rowid); $sql .= " AND entity IN (".getEntity('productprice').")"; $sql .= " AND price_level = ".((int) $price_level); @@ -3173,7 +3173,7 @@ class Form public function select_produits_fournisseurs_list($socid, $selected = '', $htmlname = 'productid', $filtertype = '', $filtre = '', $filterkey = '', $statut = -1, $outputmode = 0, $limit = 100, $alsoproductwithnosupplierprice = 0, $morecss = '', $showstockinlist = 0, $placeholder = '') { // phpcs:enable - global $langs, $conf, $db, $user; + global $langs, $conf, $user; $out = ''; $outarray = array(); @@ -3203,15 +3203,15 @@ class Form if (!empty($conf->barcode->enabled)) { $sql .= ", pfp.barcode"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )"; + $sql .= " FROM ".$this->db->prefix()."product as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON ( p.rowid = pfp.fk_product AND pfp.entity IN (".getEntity('product').") )"; if ($socid > 0) { $sql .= " AND pfp.fk_soc = ".((int) $socid); } - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON pfp.fk_soc = s.rowid"; // Units if (!empty($conf->global->PRODUCT_USE_UNITS)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units u ON u.rowid = p.fk_unit"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_units u ON u.rowid = p.fk_unit"; } $sql .= " WHERE p.entity IN (".getEntity('product').")"; if ($statut != -1) { @@ -3553,9 +3553,9 @@ class Form $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, pfp.fk_soc,"; $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice,"; $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; + $sql .= " FROM ".$this->db->prefix()."product as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON pfp.fk_soc = s.rowid"; $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; $sql .= " AND p.tobuy = 1"; $sql .= " AND s.fournisseur = 1"; @@ -3651,7 +3651,7 @@ class Form // phpcs:enable // looking for users $sql = "SELECT a.rowid, a.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_address as a"; + $sql .= " FROM ".$this->db->prefix()."societe_address as a"; $sql .= " WHERE a.fk_soc = ".((int) $socid); $sql .= " ORDER BY a.label ASC"; @@ -3703,7 +3703,7 @@ class Form dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; + $sql .= " FROM ".$this->db->prefix().'c_payment_term'; $sql .= " WHERE entity IN (".getEntity('c_payment_term').")"; $sql .= " AND active > 0"; $sql .= " ORDER BY sortorder"; @@ -3752,7 +3752,7 @@ class Form $langs->load('propal'); $sql = "SELECT rowid, code, label, position"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_availability'; + $sql .= " FROM ".$this->db->prefix().'c_availability'; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -3832,7 +3832,7 @@ class Form } $sql = "SELECT rowid, code, label"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; + $sql .= " FROM ".$this->db->prefix().'c_input_reason'; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -3932,7 +3932,7 @@ class Form $this->cache_types_paiements = array(); $sql = "SELECT id, code, libelle as label, type, active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement"; + $sql .= " FROM ".$this->db->prefix()."c_paiement"; $sql .= " WHERE entity IN (".getEntity('c_paiement').")"; $resql = $this->db->query($sql); @@ -4194,7 +4194,7 @@ class Form $this->cache_transport_mode = array(); $sql = "SELECT rowid, code, label, active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_transport_mode"; + $sql .= " FROM ".$this->db->prefix()."c_transport_mode"; $sql .= " WHERE entity IN (".getEntity('c_transport_mode').")"; $resql = $this->db->query($sql); @@ -4312,7 +4312,7 @@ class Form $langs->load("deliveries"); $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; + $sql .= " FROM ".$this->db->prefix()."c_shipment_mode"; $sql .= " WHERE active > 0"; if ($filtre) { $sql .= " AND ".$filtre; @@ -4365,7 +4365,7 @@ class Form */ public function formSelectShippingMethod($page, $selected = '', $htmlname = 'shipping_method_id', $addempty = 0) { - global $langs, $db; + global $langs; $langs->load("deliveries"); @@ -4378,7 +4378,7 @@ class Form print ''; } else { if ($selected) { - $code = $langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); + $code = $langs->getLabelFromKey($this->db, $selected, 'c_shipment_mode', 'rowid', 'code'); print $langs->trans("SendingMethod".strtoupper($code)); } else { print " "; @@ -4400,9 +4400,9 @@ class Form $langs->load('bills'); - $opt = ''; - $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; + $opt = ''; + $sql = "SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc"; + $sql .= ' FROM '.$this->db->prefix().'facture'; $sql .= ' WHERE entity IN ('.getEntity('invoice').')'; $sql .= ' AND situation_counter >= 1'; $sql .= ' AND fk_soc = '.(int) $socid; @@ -4457,7 +4457,7 @@ class Form $return = ''; if ($useempty) { $out .= ''; } - while ($obj = $db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) { $out .= ''; } $out .= ''; @@ -9448,11 +9441,11 @@ class Form } if (!empty($target)) { - $sql = "SELECT c.id FROM ".MAIN_DB_PREFIX."c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; - $resql = $db->query($sql); + $sql = "SELECT c.id FROM ".$this->db->prefix()."c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; + $resql = $this->db->query($sql); if ($resql) { - if ($db->num_rows($resql) > 0) { - $obj = $db->fetch_object($resql); + if ($this->db->num_rows($resql) > 0) { + $obj = $this->db->fetch_object($resql); $out .= ''; } $out .= ''; - } else // In most cases, this is not used. We used instead function with no specific list of colors - { + } else { // In most cases, this is not used. We used instead function with no specific list of colors if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) { $out .= ''; $out .= ''; @@ -1398,7 +1397,7 @@ class FormOther $langs->load("admin"); $sql = "SELECT rowid, ".$keyfield.", ".$labelfield; - $sql .= " FROM ".MAIN_DB_PREFIX.$dictionarytable; + $sql .= " FROM ".$this->db->prefix().$dictionarytable; $sql .= " ORDER BY ".$labelfield; dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG); diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 5f2029410ab..aa7a38969be 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -164,8 +164,8 @@ class FormProjets } // Search all projects - $sql = 'SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc'; + $sql = "SELECT p.rowid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, s.nom as name, s.name_alias"; + $sql .= " FROM ".$this->db->prefix()."projet as p LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = p.fk_soc"; $sql .= " WHERE p.entity IN (".getEntity('project').")"; if ($projectsListId !== false) { $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; @@ -338,12 +338,12 @@ class FormProjets } // Search all projects - $sql = 'SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,'; - $sql .= ' p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,'; - $sql .= ' s.nom as name'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,'; - $sql .= ' '.MAIN_DB_PREFIX.'projet_task as t'; + $sql = "SELECT t.rowid, t.ref as tref, t.label as tlabel, t.progress,"; + $sql .= " p.rowid as pid, p.ref, p.title, p.fk_soc, p.fk_statut, p.public, p.usage_task,"; + $sql .= " s.nom as name"; + $sql .= " FROM ".$this->db->prefix()."projet as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = p.fk_soc,"; + $sql .= " ".$this->db->prefix()."projet_task as t"; $sql .= " WHERE p.entity IN (".getEntity('project').")"; $sql .= " AND t.fk_projet = p.rowid"; if ($projectsListId) { @@ -566,7 +566,7 @@ class FormProjets $sql = "SELECT t.rowid, t.ref"; break; case 'stock_mouvement': - $sql = 'SELECT t.rowid, t.label as ref'; + $sql = "SELECT t.rowid, t.label as ref"; $projectkey = 'fk_origin'; break; case "payment_salary": @@ -583,9 +583,9 @@ class FormProjets if ($linkedtothirdparty) { $sql .= ", s.nom as name"; } - $sql .= " FROM ".MAIN_DB_PREFIX.$table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$table_element." as t"; if ($linkedtothirdparty) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= ", ".$this->db->prefix()."societe as s"; } $sql .= " WHERE ".$projectkey." is null"; if (!empty($socid) && $linkedtothirdparty) { @@ -666,7 +666,7 @@ class FormProjets global $conf, $langs, $user; $sql = "SELECT rowid, code, label, percent"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_lead_status'; + $sql .= " FROM ".$this->db->prefix().'c_lead_status'; $sql .= " WHERE active = 1"; $sql .= " ORDER BY position"; diff --git a/htdocs/core/class/html.formpropal.class.php b/htdocs/core/class/html.formpropal.class.php index 733f7a0c478..87919141727 100644 --- a/htdocs/core/class/html.formpropal.class.php +++ b/htdocs/core/class/html.formpropal.class.php @@ -81,7 +81,7 @@ class FormPropal } else { $prefix = "PropalStatus"; - $sql = "SELECT id, code, label, active FROM ".MAIN_DB_PREFIX."c_propalst"; + $sql = "SELECT id, code, label, active FROM ".$this->db->prefix()."c_propalst"; $sql .= " WHERE active = 1"; dol_syslog(get_class($this)."::selectProposalStatus", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index 4f5557279f4..82e4f0c96dd 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -321,7 +321,7 @@ class FormSetup */ public function addItemsFromParamsArray($params) { - if (!array($params)) { return false; } + if (!is_array($params) || empty($params)) { return false; } foreach ($params as $confKey => $param) { $this->addItemFromParams($confKey, $param); // todo manage error } diff --git a/htdocs/core/class/html.formsocialcontrib.class.php b/htdocs/core/class/html.formsocialcontrib.class.php index 3455b572888..ea325a4b591 100644 --- a/htdocs/core/class/html.formsocialcontrib.class.php +++ b/htdocs/core/class/html.formsocialcontrib.class.php @@ -74,13 +74,13 @@ class FormSocialContrib if (!empty($mysoc->country_id)) { $sql = "SELECT c.id, c.libelle as type"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; + $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c"; $sql .= " WHERE c.active = 1"; $sql .= " AND c.fk_pays = ".((int) $mysoc->country_id); $sql .= " ORDER BY c.libelle ASC"; } else { $sql = "SELECT c.id, c.libelle as type"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_country as co"; + $sql .= " FROM ".$this->db->prefix()."c_chargesociales as c, ".$this->db->prefix()."c_country as co"; $sql .= " WHERE c.active = 1 AND c.fk_pays = co.rowid"; $sql .= " AND co.code = '".$this->db->escape($mysoc->country_code)."'"; $sql .= " ORDER BY c.libelle ASC"; diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 6866bfa8356..ad83c706c12 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -762,13 +762,13 @@ class FormTicket $child_id=GETPOST($htmlname.'_child_id', 'aZ09')?GETPOST($htmlname.'_child_id', 'aZ09'):0; if (!empty($groupticket)) { $tmpgroupticket = $groupticket; - $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc WHERE ctc.code = '".$this->db->escape($tmpgroupticket)."'"; + $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".$this->db->prefix()."c_ticket_category as ctc WHERE ctc.code = '".$this->db->escape($tmpgroupticket)."'"; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); $selectedgroups[] = $obj->code; while ($obj->fk_parent > 0) { - $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc WHERE ctc.rowid ='".$this->db->escape($obj->fk_parent)."'"; + $sql = "SELECT ctc.rowid, ctc.fk_parent, ctc.code FROM ".$this->db->prefix()."c_ticket_category as ctc WHERE ctc.rowid ='".$this->db->escape($obj->fk_parent)."'"; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -788,7 +788,7 @@ class FormTicket $sql = "SELECT ctc.rowid, ctc.code, ctc.label, ctc.fk_parent, ctc.public, "; $sql .= $this->db->ifsql("ctc.rowid NOT IN (SELECT ctcfather.rowid FROM llx_c_ticket_category as ctcfather JOIN llx_c_ticket_category as ctcjoin ON ctcfather.rowid = ctcjoin.fk_parent)", "'NOTPARENT'", "'PARENT'")." as isparent"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc"; + $sql .= " FROM ".$this->db->prefix()."c_ticket_category as ctc"; $sql .= " WHERE ctc.active > 0 AND ctc.entity = ".((int) $conf->entity); if ($filtertype == 'public=1') { $sql .= " AND ctc.public = 1"; @@ -847,8 +847,8 @@ class FormTicket $stringtoprint .= ''; $sql = "SELECT ctc.rowid, ctc.code, ctc.label, ctc.fk_parent, ctc.public, ctcjoin.code as codefather"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as ctc"; - $sql .= " JOIN ".MAIN_DB_PREFIX."c_ticket_category as ctcjoin ON ctc.fk_parent = ctcjoin.rowid"; + $sql .= " FROM ".$this->db->prefix()."c_ticket_category as ctc"; + $sql .= " JOIN ".$this->db->prefix()."c_ticket_category as ctcjoin ON ctc.fk_parent = ctcjoin.rowid"; $sql .= " WHERE ctc.active > 0 AND ctc.entity = ".((int) $conf->entity); $sql .= " AND ctc.rowid NOT IN (".$this->db->sanitize(join(',', $arrayidusedconcat)).")"; diff --git a/htdocs/core/class/html.formwebsite.class.php b/htdocs/core/class/html.formwebsite.class.php index 4210113f990..083e571cf35 100644 --- a/htdocs/core/class/html.formwebsite.class.php +++ b/htdocs/core/class/html.formwebsite.class.php @@ -64,7 +64,7 @@ class FormWebsite $out = ''; $sql = "SELECT rowid, ref"; - $sql .= " FROM ".MAIN_DB_PREFIX."website"; + $sql .= " FROM ".$this->db->prefix()."website"; $sql .= " WHERE 1 = 1"; $sql .= " ORDER BY rowid"; $result = $this->db->query($sql); @@ -104,16 +104,17 @@ class FormWebsite * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries. * @param string $moreattrib More attributes on HTML select tag * @param int $addjscombo Add js combo + * @param string $morecss More CSS * @return void */ - public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0) + public function selectTypeOfContainer($htmlname, $selected = '', $useempty = 0, $moreattrib = '', $addjscombo = 0, $morecss = 'minwidth200') { global $langs, $conf, $user; $langs->load("admin"); $sql = "SELECT rowid, code, label, entity"; - $sql .= " FROM ".MAIN_DB_PREFIX.'c_type_container'; + $sql .= " FROM ".$this->db->prefix().'c_type_container'; $sql .= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")"; $sql .= " ORDER BY label"; @@ -123,7 +124,7 @@ class FormWebsite $num = $this->db->num_rows($result); $i = 0; if ($num) { - print ''; if ($useempty == 1 || ($useempty == 2 && $num > 1)) { print ''; } diff --git a/htdocs/core/class/infobox.class.php b/htdocs/core/class/infobox.class.php index 0cd34e13193..f3f28abe149 100644 --- a/htdocs/core/class/infobox.class.php +++ b/htdocs/core/class/infobox.class.php @@ -83,7 +83,7 @@ class InfoBox /** * Return array of boxes qualified for area and user * - * @param DoliDB $dbs Database handler + * @param DoliDB $dbs Database handler * @param string $mode 'available' or 'activated' * @param int $zone Name or area (-1 for all, 0 for Homepage, 1 for Accountancy, 2 for xxx, ...) * @param User|null $user Object user to filter @@ -100,7 +100,7 @@ class InfoBox if ($mode == 'activated') { // activated $sql = "SELECT b.rowid, b.position, b.box_order, b.fk_user,"; $sql .= " d.rowid as box_id, d.file, d.note, d.tms"; - $sql .= " FROM ".MAIN_DB_PREFIX."boxes as b, ".MAIN_DB_PREFIX."boxes_def as d"; + $sql .= " FROM ".$dbs->prefix()."boxes as b, ".$dbs->prefix()."boxes_def as d"; $sql .= " WHERE b.box_id = d.rowid"; $sql .= " AND b.entity IN (0,".$conf->entity.")"; if ($zone >= 0) { @@ -114,7 +114,7 @@ class InfoBox $sql .= " ORDER BY b.box_order"; } else { // available $sql = "SELECT d.rowid as box_id, d.file, d.note, d.tms"; - $sql .= " FROM ".MAIN_DB_PREFIX."boxes_def as d"; + $sql .= " FROM ".$dbs->prefix()."boxes_def as d"; $sql .= " WHERE d.entity IN (0, ".$conf->entity.")"; } @@ -251,7 +251,7 @@ class InfoBox } // Delete all lines - $sql = "DELETE FROM ".MAIN_DB_PREFIX."boxes"; + $sql = "DELETE FROM ".$dbs->prefix()."boxes"; $sql .= " WHERE entity = ".$conf->entity; $sql .= " AND fk_user = ".((int) $userid); $sql .= " AND position = ".((int) $zone); @@ -274,7 +274,7 @@ class InfoBox $i++; $ii = sprintf('%02d', $i); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."boxes"; + $sql = "INSERT INTO ".$dbs->prefix()."boxes"; $sql .= "(box_id, position, box_order, fk_user, entity)"; $sql .= " values ("; $sql .= " ".((int) $id).","; diff --git a/htdocs/core/class/link.class.php b/htdocs/core/class/link.class.php index f69dcb2874d..239c527ec53 100644 --- a/htdocs/core/class/link.class.php +++ b/htdocs/core/class/link.class.php @@ -97,7 +97,7 @@ class Link extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."links (entity, datea, url, label, objecttype, objectid)"; + $sql = "INSERT INTO ".$this->db->prefix()."links (entity, datea, url, label, objecttype, objectid)"; $sql .= " VALUES (".$conf->entity.", '".$this->db->idate($this->datea)."'"; $sql .= ", '".$this->db->escape($this->url)."'"; $sql .= ", '".$this->db->escape($this->label)."'"; @@ -107,7 +107,7 @@ class Link extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."links"); + $this->id = $this->db->last_insert_id($this->db->prefix()."links"); if ($this->id > 0) { // Call trigger @@ -175,7 +175,7 @@ class Link extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."links SET "; + $sql = "UPDATE ".$this->db->prefix()."links SET "; $sql .= "entity = ".$conf->entity; $sql .= ", datea = '".$this->db->idate(dol_now())."'"; $sql .= ", url = '".$this->db->escape($this->url)."'"; @@ -233,7 +233,7 @@ class Link extends CommonObject { global $conf; - $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".MAIN_DB_PREFIX."links"; + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix()."links"; $sql .= " WHERE objecttype = '".$this->db->escape($objecttype)."' AND objectid = ".((int) $objectid); if ($conf->entity != 0) { $sql .= " AND entity = ".$conf->entity; @@ -274,7 +274,7 @@ class Link extends CommonObject /** * Return nb of links * - * @param DoliDb $dbs Database handler + * @param DoliDb $dbs Database handler * @param string $objecttype Type of the associated object in dolibarr * @param int $objectid Id of the associated object in dolibarr * @return int Nb of links, -1 if error @@ -283,7 +283,7 @@ class Link extends CommonObject { global $conf; - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."links"; + $sql = "SELECT COUNT(rowid) as nb FROM ".$dbs->prefix()."links"; $sql .= " WHERE objecttype = '".$dbs->escape($objecttype)."' AND objectid = ".((int) $objectid); if ($conf->entity != 0) { $sql .= " AND entity = ".$conf->entity; @@ -313,7 +313,7 @@ class Link extends CommonObject $rowid = $this->id; } - $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".MAIN_DB_PREFIX."links"; + $sql = "SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix()."links"; $sql .= " WHERE rowid = ".((int) $rowid); if ($conf->entity != 0) { $sql .= " AND entity = ".$conf->entity; @@ -364,7 +364,7 @@ class Link extends CommonObject // End call triggers // Remove link - $sql = "DELETE FROM ".MAIN_DB_PREFIX."links"; + $sql = "DELETE FROM ".$this->db->prefix()."links"; $sql .= " WHERE rowid = ".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 6f024c91b0b..6b45cd08f98 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -213,7 +213,7 @@ class Menubase // may use an already used value because its internal cursor does not increase when we do // an insert with a forced id. if (in_array($this->db->type, array('pgsql'))) { - $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu"; + $sql = "SELECT MAX(rowid) as maxrowid FROM ".$this->db->prefix()."menu"; $resqlrowid = $this->db->query($sql); if ($resqlrowid) { $obj = $this->db->fetch_object($resqlrowid); @@ -224,7 +224,7 @@ class Menubase $maxrowid = 1; } - $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")"; + $sql = "SELECT setval('".$this->db->prefix()."menu_rowid_seq', ".($maxrowid).")"; //print $sql; exit; $resqlrowidset = $this->db->query($sql); if (!$resqlrowidset) { @@ -237,7 +237,7 @@ class Menubase // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql $sql = "SELECT count(*)"; - $sql .= " FROM ".MAIN_DB_PREFIX."menu"; + $sql .= " FROM ".$this->db->prefix()."menu"; $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'"; $sql .= " AND fk_menu = ".((int) $this->fk_menu); $sql .= " AND position = ".((int) $this->position); @@ -250,7 +250,7 @@ class Menubase if ($row[0] == 0) { // If not found // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu("; + $sql = "INSERT INTO ".$this->db->prefix()."menu("; $sql .= "menu_handler,"; $sql .= "entity,"; $sql .= "module,"; @@ -293,7 +293,7 @@ class Menubase dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu"); + $this->id = $this->db->last_insert_id($this->db->prefix()."menu"); dol_syslog(get_class($this)."::create record added has rowid=".((int) $this->id), LOG_DEBUG); return $this->id; @@ -346,7 +346,7 @@ class Menubase // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; + $sql = "UPDATE ".$this->db->prefix()."menu SET"; $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',"; $sql .= " module='".$this->db->escape($this->module)."',"; $sql .= " type='".$this->db->escape($this->type)."',"; @@ -409,7 +409,7 @@ class Menubase $sql .= " t.enabled,"; $sql .= " t.usertype as user,"; $sql .= " t.tms"; - $sql .= " FROM ".MAIN_DB_PREFIX."menu as t"; + $sql .= " FROM ".$this->db->prefix()."menu as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -460,7 +460,7 @@ class Menubase { //global $conf, $langs; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; + $sql = "DELETE FROM ".$this->db->prefix()."menu"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -635,7 +635,7 @@ class Menubase $leftmenu = $myleftmenu; // To export to dol_eval function $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.prefix, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position"; - $sql .= " FROM ".MAIN_DB_PREFIX."menu as m"; + $sql .= " FROM ".$this->db->prefix()."menu as m"; $sql .= " WHERE m.entity IN (0,".$conf->entity.")"; $sql .= " AND m.menu_handler IN ('".$this->db->escape($menu_handler)."','all')"; if ($type_user == 0) { diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 85b622f62ad..853de6d0a41 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -208,10 +208,10 @@ class Notify if (!$error) { if ($socid >= 0 && in_array('thirdparty', $scope)) { $sql = "SELECT a.code, c.email, c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; - $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."notify_def as n,"; + $sql .= " ".$this->db->prefix()."socpeople as c,"; + $sql .= " ".$this->db->prefix()."c_action_trigger as a,"; + $sql .= " ".$this->db->prefix()."societe as s"; $sql .= " WHERE n.fk_contact = c.rowid"; $sql .= " AND a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = s.rowid"; @@ -248,9 +248,9 @@ class Notify if (!$error) { if ($userid >= 0 && in_array('user', $scope)) { $sql = "SELECT a.code, c.email, c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."user as c,"; - $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a"; + $sql .= " FROM ".$this->db->prefix()."notify_def as n,"; + $sql .= " ".$this->db->prefix()."user as c,"; + $sql .= " ".$this->db->prefix()."c_action_trigger as a"; $sql .= " WHERE n.fk_user = c.rowid"; $sql .= " AND a.rowid = n.fk_action"; $sql .= $sqlnotifcode; @@ -395,10 +395,10 @@ class Notify if (!empty($object->socid) && $object->socid > 0) { $sql .= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; - $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; - $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; - $sql .= " ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."socpeople as c,"; + $sql .= " ".$this->db->prefix()."c_action_trigger as a,"; + $sql .= " ".$this->db->prefix()."notify_def as n,"; + $sql .= " ".$this->db->prefix()."societe as s"; $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; $sql .= " AND n.fk_soc = s.rowid"; $sql .= " AND c.statut = 1"; @@ -415,9 +415,9 @@ class Notify // Check notification per user $sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as c,"; - $sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; - $sql .= " ".MAIN_DB_PREFIX."notify_def as n"; + $sql .= " FROM ".$this->db->prefix()."user as c,"; + $sql .= " ".$this->db->prefix()."c_action_trigger as a,"; + $sql .= " ".$this->db->prefix()."notify_def as n"; $sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; $sql .= " AND c.statut = 1"; if (is_numeric($notifcode)) { @@ -644,10 +644,10 @@ class Notify if ($mailfile->sendfile()) { if ($obj->type_target == 'touserid') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; + $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", ".((int) $obj->cid).", '".$this->db->escape($obj->type)."', '".$this->db->escape($object_type)."', '".$this->db->escape($obj->type_target)."', ".((int) $object->id).", '".$this->db->escape($obj->email)."')"; } else { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; + $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", ".((int) $obj->cid).", '".$this->db->escape($obj->type)."', '".$this->db->escape($object_type)."', '".$this->db->escape($obj->type_target)."', ".((int) $object->id).", '".$this->db->escape($obj->email)."')"; } if (!$this->db->query($sql)) { @@ -879,7 +879,7 @@ class Notify ); if ($mailfile->sendfile()) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; + $sql = "INSERT INTO ".$this->db->prefix()."notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; $sql .= " VALUES ('".$this->db->idate(dol_now())."', ".((int) $notifcodedefid).", ".($object->socid > 0 ? ((int) $object->socid) : 'null').", null, 'email', 'tofixedemail', '".$this->db->escape($object_type)."', ".((int) $object->id).", '".$this->db->escape($conf->global->$param)."')"; if (!$this->db->query($sql)) { dol_print_error($this->db); diff --git a/htdocs/core/class/openid.class.php b/htdocs/core/class/openid.class.php index dd7f864b4d6..79cf9137a99 100644 --- a/htdocs/core/class/openid.class.php +++ b/htdocs/core/class/openid.class.php @@ -323,43 +323,6 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * CURL_Request - * - * @param string $url URL - * @param string $method Method - * @param string $params Params - * @return string - */ - public function CURL_Request($url, $method = "GET", $params = "") - { - // phpcs:enable - // Remember, SSL MUST BE SUPPORTED - if (is_array($params)) { - $params = $this->array2url($params); - } - - $curl = curl_init($url.($method == "GET" && $params != "" ? "?".$params : "")); - @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($curl, CURLOPT_HEADER, false); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curl, CURLOPT_HTTPGET, ($method == "GET")); - curl_setopt($curl, CURLOPT_POST, ($method == "POST")); - if ($method == "POST") { - curl_setopt($curl, CURLOPT_POSTFIELDS, $params); - } - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - $response = curl_exec($curl); - - if (curl_errno($curl) == 0) { - $response; - } else { - $this->ErrorStore('OPENID_CURL', curl_error($curl)); - } - return $response; - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * HTML2OpenIDServer @@ -372,6 +335,8 @@ class SimpleOpenID // phpcs:enable $get = array(); + $matches1 = array(); $matches2 = array(); + // Get details of their OpenID server and (optional) delegate preg_match_all('/]*rel=[\'"]openid.server[\'"][^>]*href=[\'"]([^\'"]+)[\'"][^>]*\/?>/i', $content, $matches1); preg_match_all('/]*href=\'"([^\'"]+)[\'"][^>]*rel=[\'"]openid.server[\'"][^>]*\/?>/i', $content, $matches2); @@ -495,7 +460,15 @@ class SimpleOpenID if ($openid_server == false) { return false; } - $response = $this->CURL_Request($openid_server, 'POST', $params); + + if (is_array($params)) { + $params = $this->array2url($params); + } + + $result = getURLContent($openid_server, 'POST', $params); + + $response = $result['content']; + $data = $this->splitResponse($response); if ($data['is_valid'] == "true") { return true; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index f881447cd67..8be6f77251c 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -480,7 +480,7 @@ class Translate if (!$found && !empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) { // Overwrite translation with database read - $sql = "SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."' OR lang IS NULL"; + $sql = "SELECT transkey, transvalue FROM ".$db->prefix()."overwrite_trans where lang='".$db->escape($this->defaultlang)."' OR lang IS NULL"; $sql .= " AND entity IN (0, ".getEntity('overwrite_trans').")"; $sql .= $db->order("lang", "DESC"); $resql = $db->query($sql); @@ -980,7 +980,7 @@ class Translate // Not found in loaded language file nor in cache. So we will take the label into database. $sql = "SELECT ".$fieldlabel." as label"; - $sql .= " FROM ".MAIN_DB_PREFIX.$tablename; + $sql .= " FROM ".$db->prefix().$tablename; $sql .= " WHERE ".$fieldkey." = '".$db->escape($keyforselect ? $keyforselect : $key)."'"; if ($filteronentity) { $sql .= " AND entity IN (".getEntity($tablename).')'; @@ -1067,7 +1067,7 @@ class Translate } $sql = "SELECT code_iso, label, unicode"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies"; + $sql .= " FROM ".$db->prefix()."c_currencies"; $sql .= " WHERE active = 1"; if (!empty($currency_code)) { $sql .= " AND code_iso = '".$db->escape($currency_code)."'"; diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index b408985a92d..2fa329406fb 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -241,8 +241,15 @@ class Utils // MYSQL if ($type == 'mysql' || $type == 'mysqli') { - $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP; - + if (empty($conf->global->SYSTEMTOOLS_MYSQLDUMP)) { + $cmddump = $db->getPathOfDump(); + } else { + $cmddump = $conf->global->SYSTEMTOOLS_MYSQLDUMP; + } + if (empty($cmddump)) { + $this->error = "Failed to detect command to use for mysqldump. Try a manual backup before to set path of command."; + return -1; + } $outputfile = $outputdir.'/'.$file; // for compression format, we add extension diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index 61251167c21..d3aa5707c05 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -262,7 +262,7 @@ class Validate * Check for all values in db * * @param array $values Boolean to validate - * @param string $table the db table name without MAIN_DB_PREFIX + * @param string $table the db table name without $this->db->prefix() * @param string $col the target col * @return boolean Validity is ok or not * @throws Exception @@ -281,7 +281,7 @@ class Validate } foreach ($value_arr as $val) { - $sql = "SELECT ".$col." FROM ".MAIN_DB_PREFIX.$table." WHERE ".$col." = '".$this->db->escape($val)."'"; // nore quick than count(*) to check existing of a row + $sql = "SELECT ".$col." FROM ".$this->db->prefix().$table." WHERE ".$col." = '".$this->db->escape($val)."'"; // nore quick than count(*) to check existing of a row $resql = $this->db->getRow($sql); if ($resql) { continue; diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 68bb8236d72..1e9b53b1424 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -562,7 +562,7 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke value: value }, function() { /* handler for success of post */ - console.log("url request success forcereload="+forcereload+" value="+value); + console.log("Ajax url request to set constant is a success. Make complementary actions and then forcereload="+forcereload+" value="+value); if (value == 0) { $("#set_" + code).show(); $("#del_" + code).hide(); @@ -615,9 +615,19 @@ function setConstant(url, code, input, entity, strict, forcereload, userid, toke } }); if (forcereload) { - location.reload(); + var url = window.location.href; + if (url.indexOf('dol_resetcache') < 0) { + if (url.indexOf('?') > -1) { + url = url + "&dol_resetcache=1"; + } else { + url = url + "?dol_resetcache=1"; + } + } + window.location.href = url; + //location.reload(); + return false; } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ + }).fail(function(error) { console.log("Error, we force reload"); location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ } /* @@ -642,7 +652,7 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke token: token }, function() { - console.log("url request success forcereload="+forcereload); + console.log("Ajax url request to delete constant is success. Make complementary actions and then forcereload="+forcereload); $("#del_" + code).hide(); $("#set_" + code).show(); $.each(input, function(type, data) { @@ -686,9 +696,19 @@ function delConstant(url, code, input, entity, strict, forcereload, userid, toke } }); if (forcereload) { - location.reload(); + var url = window.location.href; + if (url.indexOf('dol_resetcache') < 0) { + if (url.indexOf('?') > -1) { + url = url + "&dol_resetcache=1"; + } else { + url = url + "?dol_resetcache=1"; + } + } + window.location.href = url; + //location.reload(); + return false; } - }).fail(function(error) { location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ + }).fail(function(error) { console.log("Error, we force reload"); location.reload(); }); /* When it fails, we always force reload to have setEventErrorMessages in session visible */ } /* diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 903bb08f655..e7bea722e0c 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -563,9 +563,9 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof if (empty($conf->use_javascript_ajax) || $forcenoajax) { if (empty($conf->global->$code)) { - print ''.img_picto($langs->trans("Disabled"), 'off').''; + print ''.img_picto($langs->trans("Disabled"), 'off').''; } else { - print ''.img_picto($langs->trans("Enabled"), 'on').''; + print ''.img_picto($langs->trans("Enabled"), 'on').''; } } else { $out = "\n".' @@ -573,10 +573,10 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof $(document).ready(function() { var input = '.json_encode($input).'; var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\'; - var code = \''.$code.'\'; - var entity = \''.$entity.'\'; - var strict = \''.$strict.'\'; - var userid = \''.$user->id.'\'; + var code = \''.dol_escape_js($code).'\'; + var entity = \''.dol_escape_js($entity).'\'; + var strict = \''.dol_escape_js($strict).'\'; + var userid = \''.dol_escape_js($user->id).'\'; var yesButton = \''.dol_escape_js($langs->transnoentities("Yes")).'\'; var noButton = \''.dol_escape_js($langs->transnoentities("No")).'\'; var token = \''.currentToken().'\'; @@ -588,7 +588,7 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof if (input.alert.set.noButton) noButton = input.alert.set.noButton; confirmConstantAction("set", url, code, input, input.alert.set, entity, yesButton, noButton, strict, userid, token); } else { - setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token); + setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token); } }); @@ -600,9 +600,9 @@ function ajax_constantonoff($code, $input = array(), $entity = null, $revertonof confirmConstantAction("del", url, code, input, input.alert.del, entity, yesButton, noButton, strict, userid, token); } else {'; if (empty($setzeroinsteadofdel)) { - $out .=' delConstant(url, code, input, entity, 0, '.$forcereload.', userid, token);'; + $out .=' delConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token);'; } else { - $out .=' setConstant(url, code, input, entity, 0, '.$forcereload.', userid, token, 0);'; + $out .=' setConstant(url, code, input, entity, 0, '.((int) $forcereload).', userid, token, 0);'; } $out .= ' } }); diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2902430bf82..2d46ee2a239 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -201,8 +201,7 @@ function societe_prepare_head(Societe $object) $foundonexternalonlinesystem = 0; $langs->load("banks"); - //$title = $langs->trans("BankAccounts"); - $title = $langs->trans("PaymentInformation"); + $title = $langs->trans("PaymentModes"); if (!empty($conf->stripe->enabled)) { //$langs->load("stripe"); @@ -1710,7 +1709,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $out .= ''; $out .= ''; $out .= ''; $out .= ''; $out .= ''; @@ -1782,7 +1781,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $out .= ''; // Author of event - $out .= ''; - // Title - $out .= ''; @@ -1888,13 +1889,8 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $out .= ''; // Contact(s) for action - if (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) { - $contactstatic->lastname = $histo[$key]['lastname']; - $contactstatic->firstname = $histo[$key]['firstname']; - $contactstatic->id = $histo[$key]['contact_id']; - $out .= ''; - } elseif (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) { - $out .= ''; + } elseif (empty($objcon->id) && isset($histo[$key]['contact_id']) && $histo[$key]['contact_id'] > 0) { + $contactstatic->lastname = $histo[$key]['lastname']; + $contactstatic->firstname = $histo[$key]['firstname']; + $contactstatic->id = $histo[$key]['contact_id']; + $contactstatic->photo = $histo[$key]['contact_photo']; + $out .= ''; } else { $out .= ''; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 54320ddf928..4439a38509b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4851,6 +4851,7 @@ function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin if ($field1 && ($sortfield1 == $field1 || $sortfield1 == preg_replace("/^[^\.]+\./", "", $field1))) { $liste_titre = 'liste_titre_sel'; } + $out .= '<'.$tag.' class="'.$prefix.$liste_titre.'" '.$moreattrib; //$out .= (($field && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && preg_match('/^[a-zA-Z_0-9\s\.\-:&;]*$/', $name)) ? ' title="'.dol_escape_htmltag($langs->trans($name)).'"' : ''); $out .= ($name && empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) && empty($forcenowrapcolumntitle) && !dol_textishtml($name)) ? ' title="'.dol_escape_htmltag($langs->trans($name)).'"' : ''; @@ -4885,7 +4886,6 @@ function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin //$out .= (empty($conf->global->MAIN_DISABLE_WRAPPING_ON_COLUMN_TITLE) ? ' title="'.dol_escape_htmltag($langs->trans($name)).'"' : ''); $out .= '>'; } - if ($tooltip) { // You can also use 'TranslationString:keyfortooltiponlick' for a tooltip on click. $tmptooltip = explode(':', $tooltip); @@ -9148,12 +9148,15 @@ function natural_search($fields, $value, $mode = 0, $nofirstand = 0) if (preg_match('/\.(id|rowid)$/', $field)) { // Special case for rowid that is sometimes a ref so used as a search field $newres .= $field." = ".(is_numeric(trim($tmpcrit)) ? ((float) trim($tmpcrit)) : '0'); } else { - $newres .= $field." LIKE '"; - $tmpcrit = trim($tmpcrit); $tmpcrit2 = $tmpcrit; $tmpbefore = '%'; $tmpafter = '%'; + if (preg_match('/^!/', $tmpcrit)) { + $newres .= $field." NOT LIKE '"; // ! as exclude character + $tmpcrit2 = preg_replace('/^!/', '', $tmpcrit2); + } else $newres .= $field." LIKE '"; + if (preg_match('/^[\^\$]/', $tmpcrit)) { $tmpbefore = ''; $tmpcrit2 = preg_replace('/^[\^\$]/', '', $tmpcrit2); @@ -9357,7 +9360,7 @@ function dolIsAllowedForPreview($file) /** - * Return mime type of a file + * Return MIME type of a file from its name with extension. * * @param string $file Filename we looking for MIME type * @param string $default Default mime type if extension not found in known list diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php index 8f9942d8108..3eb8448fcde 100644 --- a/htdocs/core/lib/geturl.lib.php +++ b/htdocs/core/lib/geturl.lib.php @@ -36,7 +36,7 @@ * @param string[] $allowedschemes List of schemes that are allowed ('http' + 'https' only by default) * @param int $localurl 0=Only external URL are possible, 1=Only local URL, 2=Both external and local URL are allowed. * @param int $ssl_verifypeer -1=Auto (no ssl check on dev, check on prod), 0=No ssl check, 1=Always ssl check - * @return array Returns an associative array containing the response from the server array('content'=>response, 'curl_error_no'=>errno, 'curl_error_msg'=>errmsg...) + * @return array Returns an associative array containing the response from the server array('http_code'=>http response code, 'content'=>response, 'curl_error_no'=>errno, 'curl_error_msg'=>errmsg...) */ function getURLContent($url, $postorget = 'GET', $param = '', $followlocation = 1, $addheaders = array(), $allowedschemes = array('http', 'https'), $localurl = 0, $ssl_verifypeer = -1) { diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index d95b240993d..dcf9fafd103 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -12,7 +12,7 @@ * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2019 Lenin Rivas * Copyright (C) 2020 Nicolas ZABOURI - * Copyright (C) 2021 Anthony Berton + * Copyright (C) 2021-2022 Anthony Berton * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -713,6 +713,7 @@ function pdf_pagehead(&$pdf, $outputlangs, $page_height) if (file_exists($filepath)) { $pdf->SetAutoPageBreak(0, 0); // Disable auto pagebreak before adding image $pdf->Image($filepath, (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_X) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_X : 0), (isset($conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y) ? $conf->global->MAIN_USE_BACKGROUND_ON_PDF_Y : 0), 0, $page_height); + $pdf->SetPageMark(); // This option avoid to have the images missing on some pages $pdf->SetAutoPageBreak(1, 0); // Restore pagebreak } } @@ -1415,8 +1416,14 @@ function pdf_getlinedesc($object, $i, $outputlangs, $hideref = 0, $hidedesc = 0, $prodser->get_sousproduits_arbo(); if (!empty($prodser->sousprods) && is_array($prodser->sousprods) && count($prodser->sousprods)) { $tmparrayofsubproducts = reset($prodser->sousprods); - foreach ($tmparrayofsubproducts as $subprodval) { - $libelleproduitservice = dol_concatdesc($libelleproduitservice, " * ".$subprodval[5].(($subprodval[5] && $subprodval[3]) ? ' - ' : '').$subprodval[3].' ('.$subprodval[1].')'); + if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF)) { + foreach ($tmparrayofsubproducts as $subprodval) { + $libelleproduitservice = dol_concatdesc($libelleproduitservice, " * ".$subprodval[3].' ('.$subprodval[1].')'); + } + } else { + foreach ($tmparrayofsubproducts as $subprodval) { + $libelleproduitservice = dol_concatdesc($libelleproduitservice, " * ".$subprodval[5].(($subprodval[5] && $subprodval[3]) ? ' - ' : '').$subprodval[3].' ('.$subprodval[1].')'); + } } } } diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 1f990bd955d..2792b6d9997 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -407,7 +407,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) } else { $title = $langs->trans("ShowPreview"); } - print ''.$title.''; + print ''.dol_escape_htmltag($title).''; print '
'; if ($subdir == $selected_theme) { print ''; @@ -440,6 +440,9 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) $colorbacklinepairhover = ''; $colorbacklinepairhover = ''; $colorbacklinepairchecked = ''; + $butactionbg = ''; + $textbutaction = ''; + // Set the variables with the default value if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php')) { include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; } @@ -503,6 +506,27 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) print '
'; } + // BorderTableActive + /* Disabled because not supported by md theme + if ($foruserprofile) { + } else { + $default = $langs->trans('No'); + print ''; + print ''; + print ''; + print ''; + } + */ + // Background color THEME_ELDY_BACKBODY if ($foruserprofile) { /* @@ -935,7 +959,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) print ''; print ''; } - // Text btn action + // Text btn action if ($foruserprofile) { /* print ''; @@ -981,7 +1005,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) print ''; print ''; + print ''; } else { if ($i == 1) { if (is_null($limit) || $num < $limit) { diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 88c1428e8f9..c07e01570c2 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -34,6 +34,8 @@ if (empty($conf) || !is_object($conf)) { $size = (int) $_SERVER['CONTENT_LENGTH']; if ($size > 10000) { http_response_code(413); + $langs->loadLangs(array("errors", "install")); + accessforbidden('
'.$langs->trans("ErrorRequestTooLarge").'.
'.$langs->trans("ClickHereToGoToApp").'
', 0, 0, 1); exit; } diff --git a/htdocs/core/tpl/passwordforgotten.tpl.php b/htdocs/core/tpl/passwordforgotten.tpl.php index b61ef22739a..6d52cfff267 100644 --- a/htdocs/core/tpl/passwordforgotten.tpl.php +++ b/htdocs/core/tpl/passwordforgotten.tpl.php @@ -31,6 +31,8 @@ if (empty($conf) || !is_object($conf)) { $size = (int) $_SERVER['CONTENT_LENGTH']; if ($size > 10000) { http_response_code(413); + $langs->loadLangs(array("errors", "install")); + accessforbidden('
'.$langs->trans("ErrorRequestTooLarge").'
'.$langs->trans("ClickHereToGoToApp").'
', 0, 0, 1); exit; } diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index d710d7cd6cc..c61fa4b1393 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -7,6 +7,7 @@ * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2021 Frédéric France + * Copyright (C) 2022 Charlène Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -739,6 +740,7 @@ if ($resql) { $totalarray['nbfield']++; } if (!$i) { + $totalarray['type'][$totalarray['nbfield']] = 'duration'; $totalarray['pos'][$totalarray['nbfield']] = 'fd.duree'; } $totalarray['val']['fd.duree'] += $obj->duree; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 9a45a735716..29e7c41bb5f 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -704,6 +704,17 @@ class Holiday extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error = 0; + $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type); + + if ($checkBalance > 0) { + $balance = $this->getCPforUser($this->fk_user, $this->fk_type); + + if ($balance < 0) { + $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative'; + return -1; + } + } + // Define new ref if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) { $num = $this->getNextNumRef(null); @@ -806,6 +817,17 @@ class Holiday extends CommonObject global $conf, $langs; $error = 0; + $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type); + + if ($checkBalance > 0) { + $balance = $this->getCPforUser($this->fk_user, $this->fk_type); + + if ($balance < 0) { + $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative'; + return -1; + } + } + // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET"; @@ -914,6 +936,17 @@ class Holiday extends CommonObject global $conf, $langs; $error = 0; + $checkBalance = getDictionaryValue(MAIN_DB_PREFIX.'c_holiday_types', 'block_if_negative', $this->fk_type); + + if ($checkBalance > 0 && $this->statut != self::STATUS_DRAFT) { + $balance = $this->getCPforUser($this->fk_user, $this->fk_type); + + if ($balance < 0) { + $this->error = 'LeaveRequestCreationBlockedBecauseBalanceIsNegative'; + return -1; + } + } + // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."holiday SET"; diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php index bd31311f4bf..2401791bb5f 100644 --- a/htdocs/hrm/class/position.class.php +++ b/htdocs/hrm/class/position.class.php @@ -59,7 +59,7 @@ class Position extends CommonObject /** * @var int Does object support extrafields ? 0=No, 1=Yes */ - public $isextrafieldmanaged = 1; + public $isextrafieldmanaged = 0; /** * @var string String with name of icon for position. Must be the part after the 'object_' into object_position.png diff --git a/htdocs/hrm/position_card.php b/htdocs/hrm/position_card.php index 3287091dcdb..c26d981a324 100644 --- a/htdocs/hrm/position_card.php +++ b/htdocs/hrm/position_card.php @@ -276,7 +276,7 @@ function DisplayPositionCard(&$object) $morehtmlref = '
'; $u_position = new User(($db)); $u_position->fetch($object->fk_user); - $morehtmlref .= $langs->trans('Employee').' : '.$u_position->getNomUrl(1); + $morehtmlref .= $langs->trans('Employee').' : '.($u_position->id > 0 ? $u_position->getNomUrl(1) : ''); $job = new Job($db); $job->fetch($object->fk_job); $morehtmlref .= '
'.$langs->trans('Job').' : '.$job->getNomUrl(1); diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index 12b0b92a13e..7a84c622b47 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -192,7 +192,7 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (14 -- MALI (id country=147) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1471, 147, '0','0','VAT rate 0', 1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1471, 147, '18','0','VAT rate - standard', 1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (1472, 147, '18','0','VAT rate - standard', 1); -- MONACO (id country=27) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 271, 27, '0','0','VAT rate 0 ou non applicable',1); diff --git a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql index 9af52c8700a..e68f0497a88 100644 --- a/htdocs/install/mysql/migration/14.0.0-15.0.0.sql +++ b/htdocs/install/mysql/migration/14.0.0-15.0.0.sql @@ -184,6 +184,9 @@ INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2010', ' INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2011', 'Ideell förening'); INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2012', 'Stiftelse'); +ALTER TABLE llx_c_holiday_types ADD COLUMN block_if_negative integer NOT NULL DEFAULT 0 AFTER fk_country; + + -- START GRH/HRM MODULE diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 9a903fdf4eb..d0aac914cb9 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -94,3 +94,5 @@ CREATE TABLE llx_stock_mouvement_extrafields ( fk_object integer NOT NULL, import_key varchar(14) )ENGINE=innodb; + +ALTER TABLE llx_mrp_mo ADD COLUMN fk_parent_line integer; diff --git a/htdocs/install/mysql/tables/llx_c_holiday_types.sql b/htdocs/install/mysql/tables/llx_c_holiday_types.sql index b602ee1d330..63a6e522822 100644 --- a/htdocs/install/mysql/tables/llx_c_holiday_types.sql +++ b/htdocs/install/mysql/tables/llx_c_holiday_types.sql @@ -24,5 +24,6 @@ CREATE TABLE llx_c_holiday_types ( delay integer NOT NULL, -- Minimum delay to be allowed to make request newbymonth double(8,5) DEFAULT 0 NOT NULL, -- Amount of new days for each user each month fk_country integer DEFAULT NULL, -- This type is dedicated to a country + block_if_negative integer NOT NULL DEFAULT 0, active integer DEFAULT 1 ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_deplacement.sql b/htdocs/install/mysql/tables/llx_deplacement-deplacement.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_deplacement.sql rename to htdocs/install/mysql/tables/llx_deplacement-deplacement.sql diff --git a/htdocs/install/mysql/tables/llx_don.sql b/htdocs/install/mysql/tables/llx_don-don.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_don.sql rename to htdocs/install/mysql/tables/llx_don-don.sql diff --git a/htdocs/install/mysql/tables/llx_don_extrafields.key.sql b/htdocs/install/mysql/tables/llx_don_extrafields-don.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_don_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_don_extrafields-don.key.sql diff --git a/htdocs/install/mysql/tables/llx_don_extrafields.sql b/htdocs/install/mysql/tables/llx_don_extrafields-don.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_don_extrafields.sql rename to htdocs/install/mysql/tables/llx_don_extrafields-don.sql diff --git a/htdocs/install/mysql/tables/llx_intracommreport.sql b/htdocs/install/mysql/tables/llx_intracommreport-intracommreport.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_intracommreport.sql rename to htdocs/install/mysql/tables/llx_intracommreport-intracommreport.sql diff --git a/htdocs/install/mysql/tables/llx_inventory.key.sql b/htdocs/install/mysql/tables/llx_inventory-stock.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_inventory.key.sql rename to htdocs/install/mysql/tables/llx_inventory-stock.key.sql diff --git a/htdocs/install/mysql/tables/llx_inventory.sql b/htdocs/install/mysql/tables/llx_inventory-stock.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_inventory.sql rename to htdocs/install/mysql/tables/llx_inventory-stock.sql diff --git a/htdocs/install/mysql/tables/llx_inventorydet.key.sql b/htdocs/install/mysql/tables/llx_inventorydet-stock.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_inventorydet.key.sql rename to htdocs/install/mysql/tables/llx_inventorydet-stock.key.sql diff --git a/htdocs/install/mysql/tables/llx_inventorydet.sql b/htdocs/install/mysql/tables/llx_inventorydet-stock.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_inventorydet.sql rename to htdocs/install/mysql/tables/llx_inventorydet-stock.sql diff --git a/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord.key.sql b/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord-knowledgemanagement.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord.key.sql rename to htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord-knowledgemanagement.key.sql diff --git a/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord.sql b/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord-knowledgemanagement.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord.sql rename to htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord-knowledgemanagement.sql diff --git a/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields.key.sql b/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields-knowledgemanagement.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields-knowledgemanagement.key.sql diff --git a/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields.sql b/htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields-knowledgemanagement.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields.sql rename to htdocs/install/mysql/tables/llx_knowledgemanagement_knowledgerecord_extrafields-knowledgemanagement.sql diff --git a/htdocs/install/mysql/tables/llx_loan.sql b/htdocs/install/mysql/tables/llx_loan-loan.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_loan.sql rename to htdocs/install/mysql/tables/llx_loan-loan.sql diff --git a/htdocs/install/mysql/tables/llx_loan_schedule.sql b/htdocs/install/mysql/tables/llx_loan_schedule-loan.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_loan_schedule.sql rename to htdocs/install/mysql/tables/llx_loan_schedule-loan.sql diff --git a/htdocs/install/mysql/tables/llx_mrp_mo.sql b/htdocs/install/mysql/tables/llx_mrp_mo.sql index 88dc5d42789..14cfdf36c1e 100644 --- a/htdocs/install/mysql/tables/llx_mrp_mo.sql +++ b/htdocs/install/mysql/tables/llx_mrp_mo.sql @@ -40,6 +40,7 @@ CREATE TABLE llx_mrp_mo( date_end_planned datetime, fk_bom integer, fk_project integer, - last_main_doc varchar(255) - -- END MODULEBUILDER FIELDS + last_main_doc varchar(255), + fk_parent_line integer + -- END MODULEBUILDER FIELDS ) ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_partnership.key.sql b/htdocs/install/mysql/tables/llx_partnership-partnership.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_partnership.key.sql rename to htdocs/install/mysql/tables/llx_partnership-partnership.key.sql diff --git a/htdocs/install/mysql/tables/llx_partnership.sql b/htdocs/install/mysql/tables/llx_partnership-partnership.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_partnership.sql rename to htdocs/install/mysql/tables/llx_partnership-partnership.sql diff --git a/htdocs/install/mysql/tables/llx_partnership_extrafields.key.sql b/htdocs/install/mysql/tables/llx_partnership_extrafields-partnership.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_partnership_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_partnership_extrafields-partnership.key.sql diff --git a/htdocs/install/mysql/tables/llx_partnership_extrafields.sql b/htdocs/install/mysql/tables/llx_partnership_extrafields-partnership.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_partnership_extrafields.sql rename to htdocs/install/mysql/tables/llx_partnership_extrafields-partnership.sql diff --git a/htdocs/install/mysql/tables/llx_product_perentity.key.sql b/htdocs/install/mysql/tables/llx_product_perentity-multicompany.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_product_perentity.key.sql rename to htdocs/install/mysql/tables/llx_product_perentity-multicompany.key.sql diff --git a/htdocs/install/mysql/tables/llx_product_perentity.sql b/htdocs/install/mysql/tables/llx_product_perentity-multicompany.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_product_perentity.sql rename to htdocs/install/mysql/tables/llx_product_perentity-multicompany.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature.key.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature.key.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.key.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields.key.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields-recruitment.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields-recruitment.key.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields-recruitment.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature_extrafields-recruitment.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition.key.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition-recruitment.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition.key.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition-recruitment.key.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition-recruitment.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition-recruitment.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields.key.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields-recruitment.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields.key.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields-recruitment.key.sql diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields-recruitment.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields.sql rename to htdocs/install/mysql/tables/llx_recruitment_recruitmentjobposition_extrafields-recruitment.sql diff --git a/htdocs/install/mysql/tables/llx_societe_perentity.key.sql b/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_societe_perentity.key.sql rename to htdocs/install/mysql/tables/llx_societe_perentity-multicompany.key.sql diff --git a/htdocs/install/mysql/tables/llx_societe_perentity.sql b/htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_societe_perentity.sql rename to htdocs/install/mysql/tables/llx_societe_perentity-multicompany.sql diff --git a/htdocs/install/mysql/tables/llx_workstation_workstation.key.sql b/htdocs/install/mysql/tables/llx_workstation_workstation-workstation.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_workstation_workstation.key.sql rename to htdocs/install/mysql/tables/llx_workstation_workstation-workstation.key.sql diff --git a/htdocs/install/mysql/tables/llx_workstation_workstation.sql b/htdocs/install/mysql/tables/llx_workstation_workstation-workstation.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_workstation_workstation.sql rename to htdocs/install/mysql/tables/llx_workstation_workstation-workstation.sql diff --git a/htdocs/install/mysql/tables/llx_workstation_workstation_resource.sql b/htdocs/install/mysql/tables/llx_workstation_workstation_resource-workstation.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_workstation_workstation_resource.sql rename to htdocs/install/mysql/tables/llx_workstation_workstation_resource-workstation.sql diff --git a/htdocs/install/mysql/tables/llx_workstation_workstation_usergroup.sql b/htdocs/install/mysql/tables/llx_workstation_workstation_usergroup-workstation.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_workstation_workstation_usergroup.sql rename to htdocs/install/mysql/tables/llx_workstation_workstation_usergroup-workstation.sql diff --git a/htdocs/install/mysql/tables/llx_zapier_hook.key.sql b/htdocs/install/mysql/tables/llx_zapier_hook-zapier.key.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_zapier_hook.key.sql rename to htdocs/install/mysql/tables/llx_zapier_hook-zapier.key.sql diff --git a/htdocs/install/mysql/tables/llx_zapier_hook.sql b/htdocs/install/mysql/tables/llx_zapier_hook-zapier.sql similarity index 100% rename from htdocs/install/mysql/tables/llx_zapier_hook.sql rename to htdocs/install/mysql/tables/llx_zapier_hook-zapier.sql diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 64c9cf5e0d7..6b46d42fbc6 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1,6 +1,6 @@ # Dolibarr language file - Source file is en_US - admin -BoldRefAndPeriodOnPDF=Bold reference and period in PDF -BoldLabelOnPDF=Bold label in PDF +BoldRefAndPeriodOnPDF=Print reference and period of product item in PDF +BoldLabelOnPDF=Print label of product item in Bold in PDF Foundation=Foundation Version=Version Publisher=Publisher @@ -1917,6 +1917,7 @@ ConfFileMustContainCustom=Installing or building an external module from applica HighlightLinesOnMouseHover=Highlight table lines when mouse move passes over HighlightLinesColor=Highlight color of the line when the mouse passes over (use 'ffffff' for no highlight) HighlightLinesChecked=Highlight color of the line when it is checked (use 'ffffff' for no highlight) +UseBorderOnTable=Active border on tables BtnActionColor=Color of the action button TextBtnActionColor=Text color of the action button TextTitleColor=Text color of Page title diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 4f3308a6bf4..f7d0155f41e 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -81,13 +81,14 @@ PaymentsReports=Payments reports PaymentsAlreadyDone=Payments already done PaymentsBackAlreadyDone=Refunds already done PaymentRule=Payment rule -PaymentMode=Payment Type -DefaultPaymentMode=Default Payment Type +PaymentMode=Payment method +PaymentModes=Payment methods +DefaultPaymentMode=Default Payment method DefaultBankAccount=Default Bank Account -IdPaymentMode=Payment Type (id) -CodePaymentMode=Payment Type (code) -LabelPaymentMode=Payment Type (label) -PaymentModeShort=Payment Type +IdPaymentMode=Payment method (id) +CodePaymentMode=Payment method (code) +LabelPaymentMode=Payment method (label) +PaymentModeShort=Payment method PaymentTerm=Payment Term PaymentConditions=Payment Terms PaymentConditionsShort=Payment Terms diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 6dbc9943586..cbce9a6a264 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -276,6 +276,7 @@ ErrorNotInDictionaryPaymentConditions=Not in Payment Terms Dictionary, please mo ErrorIsNotADraft=%s is not a draft ErrorExecIdFailed=Can't execute command "id" ErrorBadCharIntoLoginName=Unauthorized character in the login name +ErrorRequestTooLarge=Error, request too large # Warnings WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup. diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index dceaef59081..3d0ae64be0f 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -134,4 +134,6 @@ HolidaysToApprove=Holidays to approve NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays HolidayBalanceMonthlyUpdate=Monthly update of holiday balance XIsAUsualNonWorkingDay=%s is usualy a NON working day +BlockHolidayIfNegative=Block if balance negative +LeaveRequestCreationBlockedBecauseBalanceIsNegative=The creation of this leave request is blocked because your balance is negative ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted=Leave request %s must be draft, canceled or refused to be deleted diff --git a/htdocs/mailmanspip/class/mailmanspip.class.php b/htdocs/mailmanspip/class/mailmanspip.class.php index 1f7e8ea6214..9635c0e2c1f 100644 --- a/htdocs/mailmanspip/class/mailmanspip.class.php +++ b/htdocs/mailmanspip/class/mailmanspip.class.php @@ -147,28 +147,9 @@ class MailmanSpip $curl_url = str_replace($patterns, $replace, $url); dol_syslog('Calling Mailman: '.$curl_url); - $ch = curl_init($curl_url); + $result = getURLContent($curl_url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FAILONERROR, true); - @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT); - curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - - $result = curl_exec($ch); - dol_syslog('result curl_exec='.$result); - - //An error was found, we store it in $this->error for later - if ($result === false || curl_errno($ch) > 0) { - $this->error = curl_errno($ch).' '.curl_error($ch); - dol_syslog('Error using curl '.$this->error, LOG_ERR); - } - - curl_close($ch); - - return $result; + return $result['content']; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 5cfe859f2df..0547eba7782 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1512,12 +1512,14 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr if (GETPOST('version', 'int')) { $ext = 'version='.GETPOST('version', 'int'); // usefull to force no cache on css/js } + // Refresh value of MAIN_IHM_PARAMS_REV before forging the parameter line. + if (GETPOST('dol_resetcache')) { + dolibarr_set_const($db, "MAIN_IHM_PARAMS_REV", ((int) $conf->global->MAIN_IHM_PARAMS_REV) + 1, 'chaine', 0, '', $conf->entity); + } $themeparam = '?lang='.$langs->defaultlang.'&theme='.$conf->theme.(GETPOST('optioncss', 'aZ09') ? '&optioncss='.GETPOST('optioncss', 'aZ09', 1) : '').'&userid='.$user->id.'&entity='.$conf->entity; + $themeparam .= ($ext ? '&'.$ext : '').'&revision='.getDolGlobalInt("MAIN_IHM_PARAMS_REV"); - if (!empty($_SESSION['dol_resetcache'])) { - $themeparam .= '&dol_resetcache='.$_SESSION['dol_resetcache']; - } if (GETPOSTISSET('dol_hide_topmenu')) { $themeparam .= '&dol_hide_topmenu='.GETPOST('dol_hide_topmenu', 'int'); } diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index c9eb9043084..eeca8b77358 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -95,7 +95,7 @@ $setupnotempty = 0; // Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only $useFormSetup = 0; // Convert arrayofparameter into a formSetup object -if (!empty($arrayofparameters) && $useFormSetup && (float) DOL_VERSION >= 15) { +if ($useFormSetup && (float) DOL_VERSION >= 15) { require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php'; $formSetup = new FormSetup($db); diff --git a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php index 80cee0a35b3..13e34593bba 100644 --- a/htdocs/modulebuilder/template/core/modules/modMyModule.class.php +++ b/htdocs/modulebuilder/template/core/modules/modMyModule.class.php @@ -411,6 +411,7 @@ class modMyModule extends DolibarrModules { global $conf, $langs; + //$result = $this->_load_tables('/install/mysql/tables/', 'mymodule'); $result = $this->_load_tables('/mymodule/sql/'); if ($result < 0) { return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') diff --git a/htdocs/modulebuilder/template/myobject_card.php b/htdocs/modulebuilder/template/myobject_card.php index 66279849abb..f1ca7ce2747 100644 --- a/htdocs/modulebuilder/template/myobject_card.php +++ b/htdocs/modulebuilder/template/myobject_card.php @@ -558,8 +558,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $relativepath = $objref.'/'.$objref.'.pdf'; $filedir = $conf->mymodule->dir_output.'/'.$object->element.'/'.$objref; $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed = $user->rights->mymodule->myobject->read; // If you can read, you can build the PDF to read content - $delallowed = $user->rights->mymodule->myobject->write; // If you can create/edit, you can remove a file on card + $genallowed = $permissiontoread; // If you can read, you can build the PDF to read content + $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card print $formfile->showdocuments('mymodule:MyObject', $object->element.'/'.$objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); } diff --git a/htdocs/paypal/lib/paypal.lib.php b/htdocs/paypal/lib/paypal.lib.php index 16e728512f6..01f8ea2c72f 100644 --- a/htdocs/paypal/lib/paypal.lib.php +++ b/htdocs/paypal/lib/paypal.lib.php @@ -498,8 +498,19 @@ function hash_call($methodName, $nvpStr) // TLSv1 by default or change to TLSv1.2 in module configuration curl_setopt($ch, CURLOPT_SSLVERSION, (empty($conf->global->PAYPAL_SSLVERSION) ? 1 : $conf->global->PAYPAL_SSLVERSION)); + $ssl_verifypeer = -1; + + // Turning on or off the ssl target certificate + if ($ssl_verifypeer < 0) { + global $dolibarr_main_prod; + $ssl_verifypeer = ($dolibarr_main_prod ? true : false); + } + if (!empty($conf->global->MAIN_CURL_DISABLE_VERIFYPEER)) { + $ssl_verifypeer = 0; + } + //turning off the server and peer verification(TrustManager Concept). - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ? true : false)); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 5 : $conf->global->MAIN_USE_CONNECT_TIMEOUT); diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 91edbe5eaff..64db556a1d6 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -188,21 +188,21 @@ class Products extends DolibarrApi $socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : ''; $sql = "SELECT t.rowid, t.ref, t.ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as t"; + $sql .= " FROM ".$this->db->prefix()."product as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as c"; + $sql .= ", ".$this->db->prefix()."categorie_product as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; if ($variant_filter == 1) { - $sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)'; - $sql .= ' AND t.rowid not in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid not in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)'; + $sql .= ' AND t.rowid not in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)'; } if ($variant_filter == 2) { - $sql .= ' AND t.rowid in (select distinct fk_product_parent from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid in (select distinct fk_product_parent from '.$this->db->prefix().'product_attribute_combination)'; } if ($variant_filter == 3) { - $sql .= ' AND t.rowid in (select distinct fk_product_child from '.MAIN_DB_PREFIX.'product_attribute_combination)'; + $sql .= ' AND t.rowid in (select distinct fk_product_child from '.$this->db->prefix().'product_attribute_combination)'; } // Select products of given category @@ -861,11 +861,11 @@ class Products extends DolibarrApi } $sql = "SELECT t.rowid, t.ref, t.ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as t"; + $sql .= " FROM ".$this->db->prefix()."product as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_product as c"; + $sql .= ", ".$this->db->prefix()."categorie_product as c"; } - $sql .= ", ".MAIN_DB_PREFIX."product_fournisseur_price as s"; + $sql .= ", ".$this->db->prefix()."product_fournisseur_price as s"; $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; @@ -1013,7 +1013,7 @@ class Products extends DolibarrApi } $sql = "SELECT t.rowid, t.ref, t.ref_ext, t.label, t.rang, t.entity"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_attribute as t"; + $sql .= " FROM ".$this->db->prefix()."product_attribute as t"; $sql .= ' WHERE t.entity IN ('.getEntity('product').')'; // Add sql filters @@ -1094,8 +1094,8 @@ class Products extends DolibarrApi } } - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1122,7 +1122,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1140,8 +1140,8 @@ class Products extends DolibarrApi $attr['rang'] = $result->rang; $attr['entity'] = $result->entity; - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1169,7 +1169,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".$this->db->prefix()."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1187,8 +1187,8 @@ class Products extends DolibarrApi $attr['rang'] = $result->rang; $attr['entity'] = $result->entity; - $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v"; - $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; + $sql = "SELECT COUNT(*) as nb FROM ".$this->db->prefix()."product_attribute_combination2val as pac2v"; + $sql .= " JOIN ".$this->db->prefix()."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid"; $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -1322,7 +1322,7 @@ class Products extends DolibarrApi throw new RestException(401); } - $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1365,7 +1365,7 @@ class Products extends DolibarrApi $ref = trim($ref); - $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".MAIN_DB_PREFIX."product_attribute_value"; + $sql = "SELECT rowid, fk_product_attribute, ref, value FROM ".$this->db->prefix()."product_attribute_value"; $sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1408,7 +1408,7 @@ class Products extends DolibarrApi $ref = trim($ref); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_value"; + $sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_value"; $sql .= " WHERE ref LIKE '".$this->db->escape($ref)."' AND fk_product_attribute = ".((int) $id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -1484,9 +1484,9 @@ class Products extends DolibarrApi $return = array(); - $sql = 'SELECT '; - $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v'; - $sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')"; + $sql = "SELECT "; + $sql .= "v.fk_product_attribute, v.rowid, v.ref, v.value FROM ".$this->db->prefix()."product_attribute_value as v"; + $sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".$this->db->prefix()."product_attribute WHERE ref LIKE '".$this->db->escape($ref)."')"; $resql = $this->db->query($sql); diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index 3c080f159f8..bac6c958d24 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -102,12 +102,12 @@ class FormProduct } elseif ($sumStock) { $sql .= ", sum(ps.reel) as stock"; } - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_entrepot = e.rowid"; + $sql .= " FROM ".$this->db->prefix()."entrepot as e"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.fk_entrepot = e.rowid"; if (!empty($fk_product) && $fk_product > 0) { $sql .= " AND ps.fk_product = ".((int) $fk_product); if (!empty($batch)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$this->db->escape($batch)."'"; } } $sql .= " WHERE e.entity IN (".getEntity('stock').")"; @@ -701,9 +701,9 @@ class FormProduct $this->cache_lot = array(); $productIdList = implode(',', $productIdArray); $sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.rowid = pb.fk_product_stock"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")"; + $sql .= " FROM ".$this->db->prefix()."product_batch as pb"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock"; + $sql .= " LEFT JOIN ".$this->db->prefix()."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")"; if (!empty($productIdList)) { $sql .= " WHERE ps.fk_product IN (".$this->db->sanitize($productIdList).")"; } diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f6a201108ad..562c622e214 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -689,7 +689,7 @@ class Product extends CommonObject if ($result >= 0) { $sql = "SELECT count(*) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product"; + $sql .= " FROM ".$this->db->prefix()."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; $sql .= " AND ref = '".$this->db->escape($this->ref)."'"; @@ -698,7 +698,7 @@ class Product extends CommonObject $obj = $this->db->fetch_object($result); if ($obj->nb == 0) { // Produit non deja existant - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product ("; + $sql = "INSERT INTO ".$this->db->prefix()."product ("; $sql .= "datec"; $sql .= ", entity"; $sql .= ", ref"; @@ -761,7 +761,7 @@ class Product extends CommonObject dol_syslog(get_class($this)."::Create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."product"); + $id = $this->db->last_insert_id($this->db->prefix()."product"); if ($id > 0) { $this->id = $id; @@ -782,9 +782,9 @@ class Product extends CommonObject // update accountancy for this entity if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { - $this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity)); + $this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " .((int) $this->id) . " AND entity = " . ((int) $conf->entity)); - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity ("; + $sql = "INSERT INTO " . $this->db->prefix() . "product_perentity ("; $sql .= " fk_product"; $sql .= ", entity"; $sql .= ", accountancy_code_buy"; @@ -1074,7 +1074,7 @@ class Product extends CommonObject foreach ($ObjW->detail_batch as $detail) { // Each lines of detail in product_batch of the current $ObjW = product_stock if ($detail->batch == $valueforundefinedlot || $detail->batch == 'Undefined') { // We discard this line, we will create it later - $sqlclean = "DELETE FROM ".MAIN_DB_PREFIX."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id); + $sqlclean = "DELETE FROM ".$this->db->prefix()."product_batch WHERE batch in('Undefined', '".$this->db->escape($valueforundefinedlot)."') AND fk_product_stock = ".((int) $ObjW->id); $result = $this->db->query($sqlclean); if (!$result) { dol_print_error($this->db); @@ -1106,7 +1106,7 @@ class Product extends CommonObject $this->barcode = $this->get_barcode($this, $this->barcode_type_code); } - $sql = "UPDATE ".MAIN_DB_PREFIX."product"; + $sql = "UPDATE ".$this->db->prefix()."product"; $sql .= " SET label = '".$this->db->escape($this->label)."'"; if ($updatetype && ($this->isProduct() || $this->isService())) { @@ -1194,9 +1194,9 @@ class Product extends CommonObject // update accountancy for this entity if (!$error && !empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { - $this->db->query("DELETE FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity)); + $this->db->query("DELETE FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = " . ((int) $this->id) . " AND entity = " . ((int) $conf->entity)); - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_perentity ("; + $sql = "INSERT INTO " . $this->db->prefix() . "product_perentity ("; $sql .= " fk_product"; $sql .= ", entity"; $sql .= ", accountancy_code_buy"; @@ -1339,9 +1339,9 @@ class Product extends CommonObject // Delete from product_batch on product delete if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.'product_batch'; + $sql = "DELETE FROM ".$this->db->prefix().'product_batch'; $sql .= " WHERE fk_product_stock IN ("; - $sql .= "SELECT rowid FROM ".MAIN_DB_PREFIX.'product_stock'; + $sql .= "SELECT rowid FROM ".$this->db->prefix().'product_stock'; $sql .= " WHERE fk_product = ".((int) $this->id).")"; $result = $this->db->query($sql); @@ -1356,7 +1356,7 @@ class Product extends CommonObject $elements = array('product_fournisseur_price', 'product_price', 'product_lang', 'categorie_product', 'product_stock', 'product_customer_price', 'product_lot'); // product_batch is done before foreach ($elements as $table) { if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql = "DELETE FROM ".$this->db->prefix().$table; $sql .= " WHERE fk_product = ".(int) $this->id; $result = $this->db->query($sql); @@ -1389,7 +1389,7 @@ class Product extends CommonObject // Delete from product_association if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "DELETE FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".(int) $this->id." OR fk_product_fils = ".(int) $this->id; $result = $this->db->query($sql); @@ -1410,7 +1410,7 @@ class Product extends CommonObject // Delete product if (!$error) { - $sqlz = "DELETE FROM ".MAIN_DB_PREFIX."product"; + $sqlz = "DELETE FROM ".$this->db->prefix()."product"; $sqlz .= " WHERE rowid = ".(int) $this->id; $resultz = $this->db->query($sqlz); @@ -1468,14 +1468,14 @@ class Product extends CommonObject foreach ($langs_available as $key => $value) { if ($key == $current_lang) { $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " AND lang = '".$this->db->escape($key)."'"; $result = $this->db->query($sql); if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang"; + $sql2 = "UPDATE ".$this->db->prefix()."product_lang"; $sql2 .= " SET "; $sql2 .= " label='".$this->db->escape($this->label)."',"; $sql2 .= " description='".$this->db->escape($this->description)."'"; @@ -1484,7 +1484,7 @@ class Product extends CommonObject } $sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'"; } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description"; + $sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description"; if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2 .= ", note"; } @@ -1508,14 +1508,14 @@ class Product extends CommonObject } $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " AND lang = '".$this->db->escape($key)."'"; $result = $this->db->query($sql); if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_lang"; + $sql2 = "UPDATE ".$this->db->prefix()."product_lang"; $sql2 .= " SET "; $sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',"; $sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'"; @@ -1524,7 +1524,7 @@ class Product extends CommonObject } $sql2 .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'"; } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_lang (fk_product, lang, label, description"; + $sql2 = "INSERT INTO ".$this->db->prefix()."product_lang (fk_product, lang, label, description"; if (!empty($conf->global->PRODUCT_USE_OTHER_FIELD_IN_TRANSLATION)) { $sql2 .= ", note"; } @@ -1570,7 +1570,7 @@ class Product extends CommonObject */ public function delMultiLangs($langtodelete, $user) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_lang"; + $sql = "DELETE FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'"; dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG); @@ -1624,7 +1624,7 @@ class Product extends CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET "; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET "; $sql .= "$field = '".$this->db->escape($value)."'"; $sql .= " WHERE rowid = ".((int) $this->id); @@ -1667,7 +1667,7 @@ class Product extends CommonObject $current_lang = $langs->getDefaultLang(); $sql = "SELECT lang, label, description, note as other"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql .= " FROM ".$this->db->prefix()."product_lang"; $sql .= " WHERE fk_product = ".((int) $this->id); $result = $this->db->query($sql); @@ -1743,7 +1743,7 @@ class Product extends CommonObject } // Add new price - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,"; + $sql = "INSERT INTO ".$this->db->prefix()."product_price(price_level,date_price, fk_product, fk_user_author, price, price_ttc, price_base_type,tosell, tva_tx, default_vat_code, recuperableonly,"; $sql .= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) "; $sql .= " VALUES(".($level ? ((int) $level) : 1).", '".$this->db->idate($now)."', ".((int) $this->id).", ".((int) $user->id).", ".((float) price2num($this->price)).", ".((float) price2num($this->price_ttc)).",'".$this->db->escape($this->price_base_type)."',".((int) $this->status).", ".((float) price2num($this->tva_tx)).", ".($this->default_vat_code ? ("'".$this->db->escape($this->default_vat_code)."'") : "null").", ".((int) $this->tva_npr).","; $sql .= " ".price2num($this->localtax1_tx).", ".price2num($this->localtax2_tx).", '".$this->db->escape($this->localtax1_type)."', '".$this->db->escape($this->localtax2_type)."', ".price2num($this->price_min).", ".price2num($this->price_min_ttc).", ".price2num($this->price_by_qty).", ".((int) $conf->entity).",".($this->fk_price_expression > 0 ? ((int) $this->fk_price_expression) : 'null'); @@ -1772,11 +1772,11 @@ class Product extends CommonObject public function log_price_delete($user, $rowid) { // phpcs:enable - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql = "DELETE FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $rowid); $resql = $this->db->query($sql); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price"; + $sql = "DELETE FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE rowid=".((int) $rowid); $resql = $this->db->query($sql); if ($resql) { @@ -1924,7 +1924,7 @@ class Product extends CommonObject if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= ", pfp.packaging"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp"; $sql .= " WHERE pfp.rowid = ".((int) $prodfournprice); if ($qty > 0) { $sql .= " AND pfp.quantity <= ".((float) $qty); @@ -1978,7 +1978,7 @@ class Product extends CommonObject $sql .= " pfp.default_vat_code,"; $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code,"; $sql .= " pfp.packaging"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as pfp"; $sql .= " WHERE pfp.fk_product = ".((int) $product_id); if ($fourn_ref != 'none') { $sql .= " AND pfp.ref_fourn = '".$this->db->escape($fourn_ref)."'"; @@ -2158,7 +2158,7 @@ class Product extends CommonObject // Ne pas mettre de quote sur les numeriques decimaux. // Ceci provoque des stockages avec arrondis en base au lieu des valeurs exactes. - $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; + $sql = "UPDATE ".$this->db->prefix()."product SET"; $sql .= " price_base_type='".$this->db->escape($newpricebase)."',"; $sql .= " price=".$price.","; $sql .= " price_ttc=".$price_ttc.","; @@ -2288,7 +2288,7 @@ class Product extends CommonObject $separatedStock = false; // Set to true will count stock from subtable llx_product_stock. It is slower than using denormalized field 'stock', but it is required when using multientity and shared warehouses. if (!empty($conf->global->MULTICOMPANY_PRODUCT_SHARING_ENABLED)) { if (!empty($conf->global->MULTICOMPANY_PMP_PER_ENTITY_ENABLED)) { - $checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . MAIN_DB_PREFIX . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity); + $checkPMPPerEntity = $this->db->query("SELECT pmp FROM " . $this->db->prefix() . "product_perentity WHERE fk_product = ".((int) $id)." AND entity = ".(int) $conf->entity); if ($this->db->num_rows($checkPMPPerEntity)>0) { $separatedEntityPMP = true; } @@ -2312,12 +2312,12 @@ class Product extends CommonObject } else { $sql .= " p.stock"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) || $separatedEntityPMP) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); + $sql .= " LEFT JOIN " . $this->db->prefix() . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); } if ($separatedStock) { - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".MAIN_DB_PREFIX."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))"; + $sql .= " LEFT JOIN " . $this->db->prefix() . "product_stock as sp ON sp.fk_product = p.rowid AND sp.fk_entrepot IN (SELECT rowid FROM ".$this->db->prefix()."entrepot WHERE entity IN (".$this->db->sanitize($visibleWarehousesEntities)."))"; } if ($id) { @@ -2467,7 +2467,7 @@ class Product extends CommonObject for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE entity IN (".getEntity('productprice').")"; $sql .= " AND price_level=".((int) $i); $sql .= " AND fk_product = ".((int) $this->id); @@ -2494,7 +2494,7 @@ class Product extends CommonObject if ($this->prices_by_qty[$i] == 1) { $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql.= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql.= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]); $sql.= " ORDER BY quantity ASC"; $resultat=array(); @@ -2531,7 +2531,7 @@ class Product extends CommonObject } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && empty($ignore_price_load)) { // prices per quantity $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $this->id); $sql .= " ORDER BY date_price DESC, rowid DESC"; $sql .= " LIMIT 1"; @@ -2545,7 +2545,7 @@ class Product extends CommonObject // Récuperation de la liste des prix selon qty si flag positionné if ($this->prices_by_qty[0] == 1) { $sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[0]); $sql .= " ORDER BY quantity ASC"; $resultat = array(); @@ -2577,7 +2577,7 @@ class Product extends CommonObject for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; $sql .= " price_base_type, tva_tx, default_vat_code, tosell, price_by_qty, rowid, recuperableonly"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE entity IN (".getEntity('productprice').")"; $sql .= " AND price_level=".((int) $i); $sql .= " AND fk_product = ".((int) $this->id); @@ -2602,7 +2602,7 @@ class Product extends CommonObject // Récuperation de la liste des prix selon qty si flag positionné if ($this->prices_by_qty[$i] == 1) { $sql = "SELECT rowid, price, unitprice, quantity, remise_percent, remise, price_base_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; + $sql .= " FROM ".$this->db->prefix()."product_price_by_qty"; $sql .= " WHERE fk_product_price = ".((int) $this->prices_by_qty_id[$i]); $sql .= " ORDER BY quantity ASC"; $resultat = array(); @@ -2680,10 +2680,10 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " SUM(mp.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."mrp_production as mp ON mp.fk_mo=c.rowid"; + $sql .= " FROM ".$this->db->prefix()."mrp_mo as c"; + $sql .= " INNER JOIN ".$this->db->prefix()."mrp_production as mp ON mp.fk_mo=c.rowid"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id); + $sql .= "INNER JOIN ".$this->db->prefix()."societe_commerciaux as sc ON sc.fk_soc=c.fk_soc AND sc.fk_user = ".((int) $user->id); } $sql .= " WHERE "; $sql .= " c.entity IN (".getEntity('mo').")"; @@ -2740,8 +2740,8 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT b.rowid) as nb_toproduce,"; $sql .= " SUM(b.qty) as qty_toproduce"; - $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid"; + $sql .= " FROM ".$this->db->prefix()."bom_bom as b"; + $sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid"; $sql .= " WHERE "; $sql .= " b.entity IN (".getEntity('bom').")"; $sql .= " AND b.fk_product =".((int) $this->id); @@ -2759,8 +2759,8 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT bl.rowid) as nb_toconsume,"; $sql .= " SUM(bl.qty) as qty_toconsume"; - $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as b"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."bom_bomline as bl ON bl.fk_bom=b.rowid"; + $sql .= " FROM ".$this->db->prefix()."bom_bom as b"; + $sql .= " INNER JOIN ".$this->db->prefix()."bom_bomline as bl ON bl.fk_bom=b.rowid"; $sql .= " WHERE "; $sql .= " b.entity IN (".getEntity('bom').")"; $sql .= " AND bl.fk_product =".((int) $this->id); @@ -2802,11 +2802,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_customers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as pd"; - $sql .= ", ".MAIN_DB_PREFIX."propal as p"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."propaldet as pd"; + $sql .= ", ".$this->db->prefix()."propal as p"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_propal"; $sql .= " AND p.fk_soc = s.rowid"; @@ -2877,11 +2877,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT p.fk_soc) as nb_suppliers, COUNT(DISTINCT p.rowid) as nb,"; $sql .= " COUNT(pd.rowid) as nb_rows, SUM(pd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as pd"; - $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as pd"; + $sql .= ", ".$this->db->prefix()."supplier_proposal as p"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = pd.fk_supplier_proposal"; $sql .= " AND p.fk_soc = s.rowid"; @@ -2933,11 +2933,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commandedet as cd"; + $sql .= ", ".$this->db->prefix()."commande as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; @@ -2988,10 +2988,10 @@ class Product extends CommonObject if (!empty($conf->global->STOCK_CALCULATE_ON_BILL)) { if (!empty($conf->global->DECREASE_ONLY_UNINVOICEDPRODUCTS)) { $adeduire = 0; - $sql = "SELECT sum(fd.qty) as count FROM ".MAIN_DB_PREFIX."facturedet fd "; - $sql .= " JOIN ".MAIN_DB_PREFIX."facture f ON fd.fk_facture = f.rowid "; - $sql .= " JOIN ".MAIN_DB_PREFIX."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; - $sql .= " JOIN ".MAIN_DB_PREFIX."commande c ON el.fk_source = c.rowid "; + $sql = "SELECT sum(fd.qty) as count FROM ".$this->db->prefix()."facturedet fd "; + $sql .= " JOIN ".$this->db->prefix()."facture f ON fd.fk_facture = f.rowid "; + $sql .= " JOIN ".$this->db->prefix()."element_element el ON el.fk_target = f.rowid and el.targettype = 'facture' and sourcetype = 'commande'"; + $sql .= " JOIN ".$this->db->prefix()."commande c ON el.fk_source = c.rowid "; $sql .= " WHERE c.fk_statut IN (".$this->db->sanitize($filtrestatut).") AND c.facture = 0 AND fd.fk_product = ".((int) $this->id); dol_syslog(__METHOD__.":: sql $sql", LOG_NOTICE); @@ -3035,11 +3035,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as cd"; + $sql .= ", ".$this->db->prefix()."commande_fournisseur as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_commande"; $sql .= " AND c.fk_soc = s.rowid"; @@ -3093,13 +3093,13 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT e.fk_soc) as nb_customers, COUNT(DISTINCT e.rowid) as nb,"; $sql .= " COUNT(ed.rowid) as nb_rows, SUM(ed.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; - $sql .= ", ".MAIN_DB_PREFIX."commandedet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."commande as c"; - $sql .= ", ".MAIN_DB_PREFIX."expedition as e"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."expeditiondet as ed"; + $sql .= ", ".$this->db->prefix()."commandedet as cd"; + $sql .= ", ".$this->db->prefix()."commande as c"; + $sql .= ", ".$this->db->prefix()."expedition as e"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE e.rowid = ed.fk_expedition"; $sql .= " AND c.rowid = cd.fk_commande"; @@ -3178,11 +3178,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT cf.fk_soc) as nb_suppliers, COUNT(DISTINCT cf.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as fd"; - $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseur_dispatch as fd"; + $sql .= ", ".$this->db->prefix()."commande_fournisseur as cf"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE cf.rowid = fd.fk_commande"; $sql .= " AND cf.fk_soc = s.rowid"; @@ -3235,11 +3235,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT m.fk_soc) as nb_customers, COUNT(DISTINCT m.rowid) as nb,"; $sql .= " COUNT(mp.rowid) as nb_rows, SUM(mp.qty) as qty, role"; - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_production as mp"; - $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as m"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = m.fk_soc"; + $sql .= " FROM ".$this->db->prefix()."mrp_production as mp"; + $sql .= ", ".$this->db->prefix()."mrp_mo as m"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON s.rowid = m.fk_soc"; if (empty($user->rights->societe->client->voir) && !$socid && !$forVirtualStock) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE m.rowid = mp.fk_mo"; $sql .= " AND m.entity IN (".getEntity($forVirtualStock && !empty($conf->global->STOCK_CALCULATE_VIRTUAL_STOCK_TRANSVERSE_MODE) ? 'stock' : 'mrp').")"; @@ -3328,11 +3328,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,"; $sql .= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; - $sql .= ", ".MAIN_DB_PREFIX."contrat as c"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."contratdet as cd"; + $sql .= ", ".$this->db->prefix()."contrat as c"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = cd.fk_contrat"; $sql .= " AND c.fk_soc = s.rowid"; @@ -3402,11 +3402,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_customers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(".$this->db->ifsql('f.type != 2', 'fd.qty', 'fd.qty * -1').") as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; - $sql .= ", ".MAIN_DB_PREFIX."facture as f"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facturedet as fd"; + $sql .= ", ".$this->db->prefix()."facture as f"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture"; $sql .= " AND f.fk_soc = s.rowid"; @@ -3476,11 +3476,11 @@ class Product extends CommonObject $sql = "SELECT COUNT(DISTINCT f.fk_soc) as nb_suppliers, COUNT(DISTINCT f.rowid) as nb,"; $sql .= " COUNT(fd.rowid) as nb_rows, SUM(fd.qty) as qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as fd"; - $sql .= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facture_fourn_det as fd"; + $sql .= ", ".$this->db->prefix()."facture_fourn as f"; + $sql .= ", ".$this->db->prefix()."societe as s"; if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = fd.fk_facture_fourn"; $sql .= " AND f.fk_soc = s.rowid"; @@ -3607,12 +3607,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as d, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facturedet as d, ".$this->db->prefix()."facture as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture"; if ($this->id > 0) { @@ -3660,12 +3660,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT f.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn_det as d, ".MAIN_DB_PREFIX."facture_fourn as f, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."facture_fourn_det as d, ".$this->db->prefix()."facture_fourn as f, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE f.rowid = d.fk_facture_fourn"; if ($this->id > 0) { @@ -3711,12 +3711,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."propaldet as d, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."propaldet as d, ".$this->db->prefix()."propal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as prod"; + $sql .= ", ".$this->db->prefix()."product as prod"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_propal"; if ($this->id > 0) { @@ -3763,12 +3763,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT p.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposaldet as d, ".MAIN_DB_PREFIX."supplier_proposal as p, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."supplier_proposaldet as d, ".$this->db->prefix()."supplier_proposal as p, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as prod"; + $sql .= ", ".$this->db->prefix()."product as prod"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE p.rowid = d.fk_supplier_proposal"; if ($this->id > 0) { @@ -3814,12 +3814,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as d, ".MAIN_DB_PREFIX."commande as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commandedet as d, ".$this->db->prefix()."commande as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; if ($this->id > 0) { @@ -3865,12 +3865,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as d, ".MAIN_DB_PREFIX."commande_fournisseur as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."commande_fournisseurdet as d, ".$this->db->prefix()."commande_fournisseur as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.rowid = d.fk_commande"; if ($this->id > 0) { @@ -3916,12 +3916,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT c.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."contratdet as d, ".$this->db->prefix()."contrat as c, ".$this->db->prefix()."societe as s"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE c.entity IN (".getEntity('contract').")"; @@ -3970,12 +3970,12 @@ class Product extends CommonObject if ($mode == 'bynumber') { $sql .= ", count(DISTINCT d.rowid)"; } - $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as d LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON d.fk_soc = s.rowid"; + $sql .= " FROM ".$this->db->prefix()."mrp_mo as d LEFT JOIN ".$this->db->prefix()."societe as s ON d.fk_soc = s.rowid"; if ($filteronproducttype >= 0) { - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= ", ".$this->db->prefix()."product as p"; } if (empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE d.entity IN (".getEntity('mo').")"; @@ -4033,21 +4033,21 @@ class Product extends CommonObject } // Check not already father of id_pere (to avoid father -> child -> father links) - $sql = "SELECT fk_product_pere from ".MAIN_DB_PREFIX."product_association"; + $sql = "SELECT fk_product_pere from ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $id_fils)." AND fk_product_fils = ".((int) $id_pere); if (!$this->db->query($sql)) { dol_print_error($this->db); return -1; } else { //Selection of the highest row - $sql = "SELECT MAX(rang) as max_rank FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "SELECT MAX(rang) as max_rank FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $id_pere); $resql = $this->db->query($sql); if ($resql > 0) { $obj = $this->db->fetch_object($resql); $rank = $obj->max_rank + 1; //Addition of a product with the highest rank +1 - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)"; + $sql = "INSERT INTO ".$this->db->prefix()."product_association(fk_product_pere,fk_product_fils,qty,incdec,rang)"; $sql .= " VALUES (".((int) $id_pere).", ".((int) $id_fils).", ".price2num($qty, 'MS').", ".price2num($incdec, 'MS').", ".((int) $rank).")"; if (! $this->db->query($sql)) { dol_print_error($this->db); @@ -4089,7 +4089,7 @@ class Product extends CommonObject $qty = 1; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.'product_association SET '; + $sql = 'UPDATE '.$this->db->prefix().'product_association SET '; $sql .= 'qty = '.price2num($qty, 'MS'); $sql .= ',incdec = '.price2num($incdec, 'MS'); $sql .= ' WHERE fk_product_pere = '.((int) $id_pere).' AND fk_product_fils = '.((int) $id_fils); @@ -4120,7 +4120,7 @@ class Product extends CommonObject $fk_child = 0; } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_association"; + $sql = "DELETE FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fk_parent); $sql .= " AND fk_product_fils = ".((int) $fk_child); @@ -4131,7 +4131,7 @@ class Product extends CommonObject } // Updated ranks so that none are missing - $sqlrank = "SELECT rowid, rang FROM ".MAIN_DB_PREFIX."product_association"; + $sqlrank = "SELECT rowid, rang FROM ".$this->db->prefix()."product_association"; $sqlrank.= " WHERE fk_product_pere = ".((int) $fk_parent); $sqlrank.= " ORDER BY rang"; $resqlrank = $this->db->query($sqlrank); @@ -4139,7 +4139,7 @@ class Product extends CommonObject $cpt = 0; while ($objrank = $this->db->fetch_object($resqlrank)) { $cpt++; - $sql = "UPDATE ".MAIN_DB_PREFIX."product_association"; + $sql = "UPDATE ".$this->db->prefix()."product_association"; $sql.= " SET rang = ".((int) $cpt); $sql.= " WHERE rowid = ".((int) $objrank->rowid); if (! $this->db->query($sql)) { @@ -4163,7 +4163,7 @@ class Product extends CommonObject { // phpcs:enable $sql = "SELECT fk_product_pere, qty, incdec"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association"; + $sql .= " FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fk_parent); $sql .= " AND fk_product_fils = ".((int) $fk_child); @@ -4213,7 +4213,7 @@ class Product extends CommonObject if ($ref_fourn) { $sql = "SELECT rowid, fk_product"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_soc = ".((int) $id_fourn); $sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'"; $sql .= " AND fk_product <> ".((int) $this->id); @@ -4232,7 +4232,7 @@ class Product extends CommonObject } $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_soc = ".((int) $id_fourn); if ($ref_fourn) { $sql .= " AND ref_fourn = '".$this->db->escape($ref_fourn)."'"; @@ -4249,7 +4249,7 @@ class Product extends CommonObject // The reference supplier does not exist, we create it for this product. if (empty($obj)) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price("; + $sql = "INSERT INTO ".$this->db->prefix()."product_fournisseur_price("; $sql .= "datec"; $sql .= ", entity"; $sql .= ", fk_product"; @@ -4270,7 +4270,7 @@ class Product extends CommonObject $sql .= ")"; if ($this->db->query($sql)) { - $this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price"); + $this->product_fourn_price_id = $this->db->last_insert_id($this->db->prefix()."product_fournisseur_price"); return 1; } else { $this->error = $this->db->lasterror(); @@ -4302,7 +4302,7 @@ class Product extends CommonObject $list = array(); $sql = "SELECT DISTINCT p.fk_soc"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as p"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price as p"; $sql .= " WHERE p.fk_product = ".((int) $this->id); $sql .= " AND p.entity = ".((int) $conf->entity); @@ -4337,7 +4337,7 @@ class Product extends CommonObject $this->db->begin(); // prices - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price ("; + $sql = "INSERT INTO ".$this->db->prefix()."product_price ("; $sql .= " entity"; $sql .= ", fk_product"; $sql .= ", date_price"; @@ -4390,7 +4390,7 @@ class Product extends CommonObject $sql .= ", multicurrency_tx"; $sql .= ", multicurrency_price"; $sql .= ", multicurrency_price_ttc"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; + $sql .= " FROM ".$this->db->prefix()."product_price"; $sql .= " WHERE fk_product = ".((int) $fromId); $sql .= " ORDER BY date_price DESC"; if ($conf->global->PRODUIT_MULTIPRICES_LIMIT > 0) { @@ -4421,8 +4421,8 @@ class Product extends CommonObject // phpcs:enable $this->db->begin(); - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'product_association (fk_product_pere, fk_product_fils, qty)'; - $sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".MAIN_DB_PREFIX."product_association"; + $sql = 'INSERT INTO '.$this->db->prefix().'product_association (fk_product_pere, fk_product_fils, qty)'; + $sql .= " SELECT ".$toId.", fk_product_fils, qty FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $fromId); dol_syslog(get_class($this).'::clone_association', LOG_DEBUG); @@ -4451,10 +4451,10 @@ class Product extends CommonObject $now = dol_now(); // les fournisseurs - /*$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur (" + /*$sql = "INSERT ".$this->db->prefix()."product_fournisseur (" . " datec, fk_product, fk_soc, ref_fourn, fk_user_author )" . " SELECT '".$this->db->idate($now)."', ".$toId.", fk_soc, ref_fourn, fk_user_author" - . " FROM ".MAIN_DB_PREFIX."product_fournisseur" + . " FROM ".$this->db->prefix()."product_fournisseur" . " WHERE fk_product = ".((int) $fromId); if ( ! $this->db->query($sql ) ) @@ -4464,10 +4464,10 @@ class Product extends CommonObject }*/ // les prix de fournisseurs. - $sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur_price ("; + $sql = "INSERT ".$this->db->prefix()."product_fournisseur_price ("; $sql .= " datec, fk_product, fk_soc, price, quantity, fk_user)"; $sql .= " SELECT '".$this->db->idate($now)."', ".((int) $toId).", fk_soc, price, quantity, fk_user"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql .= " FROM ".$this->db->prefix()."product_fournisseur_price"; $sql .= " WHERE fk_product = ".((int) $fromId); dol_syslog(get_class($this).'::clone_fournisseurs', LOG_DEBUG); @@ -4585,7 +4585,7 @@ class Product extends CommonObject $nb = 0; $sql = "SELECT COUNT(pa.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa"; + $sql .= " FROM ".$this->db->prefix()."product_association as pa"; if ($mode == 0) { $sql .= " WHERE pa.fk_product_fils = ".((int) $this->id)." OR pa.fk_product_pere = ".((int) $this->id); } elseif ($mode == -1) { @@ -4615,7 +4615,7 @@ class Product extends CommonObject public function hasVariants() { $nb = 0; - $sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id); + $sql = "SELECT count(rowid) as nb FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_parent = ".((int) $this->id); $sql .= " AND entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); @@ -4639,7 +4639,7 @@ class Product extends CommonObject { global $conf; if (!empty($conf->variants->enabled)) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")"; + $sql = "SELECT rowid FROM ".$this->db->prefix()."product_attribute_combination WHERE fk_product_child = ".((int) $this->id)." AND entity IN (".getEntity('product').")"; $query = $this->db->query($sql); @@ -4667,8 +4667,8 @@ class Product extends CommonObject { $sql = "SELECT p.rowid, p.label as label, p.ref as ref, pa.fk_product_pere as id, p.fk_product_type, pa.qty, pa.incdec, p.entity"; $sql .= ", p.tosell as status, p.tobuy as status_buy"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association as pa,"; - $sql .= " ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_association as pa,"; + $sql .= " ".$this->db->prefix()."product as p"; $sql .= " WHERE p.rowid = pa.fk_product_pere"; $sql .= " AND pa.fk_product_fils = ".((int) $this->id); @@ -4714,8 +4714,8 @@ class Product extends CommonObject $sql = "SELECT p.rowid, p.ref, p.label as label, p.fk_product_type,"; $sql .= " pa.qty as qty, pa.fk_product_fils as id, pa.incdec,"; $sql .= " pa.rowid as fk_association, pa.rang"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p,"; - $sql .= " ".MAIN_DB_PREFIX."product_association as pa"; + $sql .= " FROM ".$this->db->prefix()."product as p,"; + $sql .= " ".$this->db->prefix()."product_association as pa"; $sql .= " WHERE p.rowid = pa.fk_product_fils"; $sql .= " AND pa.fk_product_pere = ".((int) $id); $sql .= " AND pa.fk_product_fils <> ".((int) $id); // This should not happens, it is to avoid infinite loop if it happens @@ -5100,7 +5100,7 @@ class Product extends CommonObject $langs->load('products'); if (isset($this->finished) && $this->finished >= 0) { - $sql = "SELECT label, code FROM ".MAIN_DB_PREFIX."c_product_nature where code = ".((int) $this->finished)." AND active=1"; + $sql = "SELECT label, code FROM ".$this->db->prefix()."c_product_nature where code = ".((int) $this->finished)." AND active=1"; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { $res = $this->db->fetch_array($resql); @@ -5273,8 +5273,8 @@ class Product extends CommonObject } $sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."entrepot as w"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."entrepot as w"; $sql .= " WHERE w.entity IN (".getEntity('stock').")"; $sql .= " AND w.rowid = ps.fk_entrepot"; $sql .= " AND ps.fk_product = ".((int) $this->id); @@ -5370,7 +5370,20 @@ class Product extends CommonObject } $stock_commande_fournisseur = $this->stats_commande_fournisseur['qty']; } + if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && empty($conf->reception->enabled)) { + // Case module reception is not used + $filterStatus = '4'; + if (isset($includedraftpoforvirtual)) { + $filterStatus = '0,'.$filterStatus; + } + $result = $this->load_stats_reception(0, $filterStatus, 1); + if ($result < 0) { + dol_print_error($this->db, $this->error); + } + $stock_reception_fournisseur = $this->stats_reception['qty']; + } if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && !empty($conf->reception->enabled)) { + // Case module reception is used $filterStatus = '4'; if (isset($includedraftpoforvirtual)) { $filterStatus = '0,'.$filterStatus; @@ -5437,7 +5450,7 @@ class Product extends CommonObject { $result = array(); - $sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".MAIN_DB_PREFIX."product_batch as pb, ".MAIN_DB_PREFIX."product_stock as ps"; + $sql = "SELECT pb.batch, pb.eatby, pb.sellby, SUM(pb.qty) AS qty FROM ".$this->db->prefix()."product_batch as pb, ".$this->db->prefix()."product_stock as ps"; $sql .= " WHERE pb.fk_product_stock = ps.rowid AND ps.fk_product = ".((int) $this->id)." AND pb.batch = '".$this->db->escape($batch)."'"; $sql .= " GROUP BY pb.batch, pb.eatby, pb.sellby"; dol_syslog(get_class($this)."::loadBatchInfo load first entry found for lot/serial = ".$batch, LOG_DEBUG); @@ -5671,7 +5684,7 @@ class Product extends CommonObject $this->nb = array(); $sql = "SELECT count(p.rowid) as nb, fk_product_type"; - $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product as p"; $sql .= ' WHERE p.entity IN ('.getEntity($this->element, 1).')'; // Add where from hooks if (is_object($hookmanager)) { @@ -5829,7 +5842,7 @@ class Product extends CommonObject $label_type = 'short_label'; } - $sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit); + $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit); $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { @@ -5937,7 +5950,7 @@ class Product extends CommonObject { global $conf, $db; - $sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".MAIN_DB_PREFIX."product_pricerules"; + $sql = "SELECT rowid, level, fk_level, var_percent, var_min_percent FROM ".$this->db->prefix()."product_pricerules"; $query = $this->db->query($sql); $rules = array(); @@ -6010,7 +6023,7 @@ class Product extends CommonObject { $sql = "SELECT p.rowid, p.ref, p.datec as date_creation, p.tms as date_modification,"; $sql .= " p.fk_user_author, p.fk_user_modif"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as p"; $sql .= " WHERE p.rowid = ".((int) $id); $result = $this->db->query($sql); diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 9bd361858ba..5149dd2c708 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -87,7 +87,7 @@ class Productbatch extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_batch ("; + $sql = "INSERT INTO ".$this->db->prefix()."product_batch ("; $sql .= "fk_product_stock,"; $sql .= "sellby,"; // no more used $sql .= "eatby,"; // no more used @@ -111,7 +111,7 @@ class Productbatch extends CommonObject $error++; $this->errors[] = "Error ".$this->db->lasterror(); } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().self::$_table_element); } // Commit or rollback @@ -149,8 +149,8 @@ class Productbatch extends CommonObject $sql .= " pl.eatby,"; $sql .= " pl.sellby"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t INNER JOIN ".MAIN_DB_PREFIX."product_stock w on t.fk_product_stock = w.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch"; + $sql .= " FROM ".$this->db->prefix()."product_batch as t INNER JOIN ".$this->db->prefix()."product_stock w on t.fk_product_stock = w.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_lot as pl on pl.fk_product = w.fk_product and pl.batch = t.batch"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -199,7 +199,7 @@ class Productbatch extends CommonObject } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.self::$_table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().self::$_table_element." SET"; $sql .= " fk_product_stock=".(isset($this->fk_product_stock) ? $this->fk_product_stock : "null").","; $sql .= " sellby=".(dol_strlen($this->sellby) != 0 ? "'".$this->db->idate($this->sellby)."'" : 'null').","; $sql .= " eatby=".(dol_strlen($this->eatby) != 0 ? "'".$this->db->idate($this->eatby)."'" : 'null').","; @@ -245,7 +245,7 @@ class Productbatch extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element.""; + $sql = "DELETE FROM ".$this->db->prefix().self::$_table_element.""; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); @@ -383,7 +383,7 @@ class Productbatch extends CommonObject $sql .= " t.batch,"; $sql .= " t.qty,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as t"; + $sql .= " FROM ".$this->db->prefix().self::$_table_element." as t"; $sql .= " WHERE fk_product_stock=".((int) $fk_product_stock); if (!empty($eatby)) { @@ -436,7 +436,7 @@ class Productbatch extends CommonObject */ public static function findAll($db, $fk_product_stock, $with_qty = 0, $fk_product = 0) { - global $langs, $conf; + global $conf; $ret = array(); @@ -453,9 +453,9 @@ class Productbatch extends CommonObject $sql .= ", pl.rowid as lotid, pl.eatby as eatby, pl.sellby as sellby"; // TODO May add extrafields to ? } - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as t"; + $sql .= " FROM ".$db->prefix()."product_batch as t"; if ($fk_product > 0) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch"; + $sql .= " LEFT JOIN ".$db->prefix()."product_lot as pl ON pl.fk_product = ".((int) $fk_product)." AND pl.batch = t.batch"; // TODO May add extrafields to ? } $sql .= " WHERE fk_product_stock=".((int) $fk_product_stock); @@ -526,10 +526,10 @@ class Productbatch extends CommonObject $sql .= ", pl.sellby"; $sql .= ", pl.eatby"; $sql .= ", pb.qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_lot as pl"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pl.fk_product"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch AS pb ON pl.batch = pb.batch"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock AS ps ON ps.rowid = pb.fk_product_stock"; + $sql .= " FROM ".$db->prefix()."product_lot as pl"; + $sql .= " LEFT JOIN ".$db->prefix()."product as p ON p.rowid = pl.fk_product"; + $sql .= " LEFT JOIN ".$db->prefix()."product_batch AS pb ON pl.batch = pb.batch"; + $sql .= " LEFT JOIN ".$db->prefix()."product_stock AS ps ON ps.rowid = pb.fk_product_stock"; $sql .= " WHERE p.entity IN (".getEntity('product').")"; $sql .= " AND pl.fk_product = ".((int) $fk_product); if ($fk_warehouse > 0) { diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index a9444d1c569..1c91c3804d2 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -188,7 +188,7 @@ class Productcustomerprice extends CommonObject } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price("; + $sql = "INSERT INTO ".$this->db->prefix()."product_customer_price("; $sql .= "entity,"; $sql .= "datec,"; $sql .= "fk_product,"; @@ -240,7 +240,7 @@ class Productcustomerprice extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_customer_price"); + $this->id = $this->db->last_insert_id($this->db->prefix()."product_customer_price"); if (!$notrigger) { $result = $this->call_trigger('PRODUCT_CUSTOMER_PRICE_CREATE', $user); @@ -301,7 +301,7 @@ class Productcustomerprice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -392,9 +392,9 @@ class Productcustomerprice extends CommonObject $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; $sql .= " prod.ref as prodref"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t,"; - $sql .= " ".MAIN_DB_PREFIX."product as prod,"; - $sql .= " ".MAIN_DB_PREFIX."societe as soc"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t,"; + $sql .= " ".$this->db->prefix()."product as prod,"; + $sql .= " ".$this->db->prefix()."societe as soc"; $sql .= " WHERE soc.rowid=t.fk_soc "; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (".getEntity('product').")"; @@ -510,9 +510,9 @@ class Productcustomerprice extends CommonObject $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; $sql .= " prod.ref as prodref"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price_log as t"; - $sql .= " ,".MAIN_DB_PREFIX."product as prod"; - $sql .= " ,".MAIN_DB_PREFIX."societe as soc"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price_log as t"; + $sql .= " ,".$this->db->prefix()."product as prod"; + $sql .= " ,".$this->db->prefix()."societe as soc"; $sql .= " WHERE soc.rowid=t.fk_soc"; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (".getEntity('product').")"; @@ -675,7 +675,7 @@ class Productcustomerprice extends CommonObject // Do a copy of current record into log table // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_customer_price_log("; + $sql = "INSERT INTO ".$this->db->prefix()."product_customer_price_log("; $sql .= "entity,"; $sql .= "datec,"; @@ -720,7 +720,7 @@ class Productcustomerprice extends CommonObject $sql .= " t.fk_user,"; $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_customer_price as t"; + $sql .= " FROM ".$this->db->prefix()."product_customer_price as t"; $sql .= " WHERE t.rowid = ".((int) $this->id); $this->db->begin(); @@ -732,7 +732,7 @@ class Productcustomerprice extends CommonObject } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."product_customer_price SET"; + $sql = "UPDATE ".$this->db->prefix()."product_customer_price SET"; $sql .= " entity=".$conf->entity.","; $sql .= " datec='".$this->db->idate(dol_now())."',"; @@ -813,7 +813,7 @@ class Productcustomerprice extends CommonObject // Find all susidiaries $sql = "SELECT s.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."societe as s"; $sql .= " WHERE s.parent = ".((int) $this->fk_soc); $sql .= " AND s.entity IN (".getEntity('societe').")"; @@ -911,7 +911,7 @@ class Productcustomerprice extends CommonObject } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_customer_price"; + $sql = "DELETE FROM ".$this->db->prefix()."product_customer_price"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index d82d1784938..54919ac0be6 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -316,11 +316,11 @@ class ProductFournisseurPrice extends CommonObject $records = array(); - $sql = 'SELECT '; + $sql = "SELECT "; $sql .= $this->getFieldList(); - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')'; - else $sql .= ' WHERE 1 = 1'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= " WHERE t.entity IN (".getEntity($this->element).")"; + else $sql .= " WHERE 1 = 1"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -433,7 +433,7 @@ class ProductFournisseurPrice extends CommonObject if (!empty($num)) { // Validate - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ref = '".$this->db->escape($num)."',"; $sql .= " status = ".self::STATUS_VALIDATED; if (!empty($this->fields['date_validation'])) $sql .= ", date_validation = '".$this->db->idate($now)."'"; @@ -462,7 +462,7 @@ class ProductFournisseurPrice extends CommonObject // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'"; + $sql = 'UPDATE '.$this->db->prefix()."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'productfournisseurprice/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'productfournisseurprice/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); if (!$resql) { $error++; $this->error = $this->db->lasterror(); } @@ -698,10 +698,10 @@ class ProductFournisseurPrice extends CommonObject */ public function info($id) { - $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; - $sql .= ' fk_user_creat, fk_user_modif'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql = "SELECT rowid, date_creation as datec, tms as datem,"; + $sql .= " fk_user_creat, fk_user_modif"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE t.rowid = ".((int) $id); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { diff --git a/htdocs/product/class/propalmergepdfproduct.class.php b/htdocs/product/class/propalmergepdfproduct.class.php index 9663bea4756..00c492f91de 100644 --- a/htdocs/product/class/propalmergepdfproduct.class.php +++ b/htdocs/product/class/propalmergepdfproduct.class.php @@ -104,7 +104,7 @@ class Propalmergepdfproduct extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."propal_merge_pdf_product("; + $sql = "INSERT INTO ".$this->db->prefix()."propal_merge_pdf_product("; $sql .= "fk_product,"; $sql .= "file_name,"; if ($conf->global->MAIN_MULTILANGS) { @@ -132,7 +132,7 @@ class Propalmergepdfproduct extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."propal_merge_pdf_product"); + $this->id = $this->db->last_insert_id($this->db->prefix()."propal_merge_pdf_product"); } // Commit or rollback @@ -173,7 +173,7 @@ class Propalmergepdfproduct extends CommonObject $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(__METHOD__, LOG_DEBUG); @@ -231,7 +231,7 @@ class Propalmergepdfproduct extends CommonObject $sql .= " t.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product as t"; + $sql .= " FROM ".$this->db->prefix()."propal_merge_pdf_product as t"; $sql .= " WHERE t.fk_product = ".((int) $product_id); if (!empty($conf->global->MAIN_MULTILANGS) && !empty($lang)) { $sql .= " AND t.lang = '".$this->db->escape($lang)."'"; @@ -307,7 +307,7 @@ class Propalmergepdfproduct extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."propal_merge_pdf_product SET"; + $sql = "UPDATE ".$this->db->prefix()."propal_merge_pdf_product SET"; $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").","; $sql .= " file_name=".(isset($this->file_name) ? "'".$this->db->escape($this->file_name)."'" : "null").","; @@ -357,7 +357,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(__METHOD__, LOG_DEBUG); @@ -400,7 +400,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE fk_product = ".((int) $product_id); if ($conf->global->MAIN_MULTILANGS && !empty($lang_id)) { @@ -444,7 +444,7 @@ class Propalmergepdfproduct extends CommonObject $this->db->begin(); if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal_merge_pdf_product"; + $sql = "DELETE FROM ".$this->db->prefix()."propal_merge_pdf_product"; $sql .= " WHERE fk_product = ".((int) $this->fk_product)." AND file_name = '".$this->db->escape($this->file_name)."'"; dol_syslog(__METHOD__, LOG_DEBUG); diff --git a/htdocs/product/dynamic_price/class/price_expression.class.php b/htdocs/product/dynamic_price/class/price_expression.class.php index 564c2448e58..255908726d4 100644 --- a/htdocs/product/dynamic_price/class/price_expression.class.php +++ b/htdocs/product/dynamic_price/class/price_expression.class.php @@ -88,7 +88,7 @@ class PriceExpression } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "title, expression"; $sql .= ") VALUES ("; $sql .= " ".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "''").","; @@ -104,7 +104,7 @@ class PriceExpression } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); //if (! $notrigger) //{ @@ -148,7 +148,7 @@ class PriceExpression } $sql = "SELECT title, expression"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -179,7 +179,7 @@ class PriceExpression { // phpcs:enable $sql = "SELECT rowid, title, expression"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " ORDER BY title"; dol_syslog(__METHOD__, LOG_DEBUG); @@ -215,7 +215,7 @@ class PriceExpression { // phpcs:enable $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE title = '".$this->db->escape($title)."'"; dol_syslog(__METHOD__, LOG_DEBUG); @@ -254,7 +254,7 @@ class PriceExpression } // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " title = ".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "''").","; $sql .= " expression = ".(isset($this->expression) ? "'".$this->db->escape($this->expression)."'" : "''").""; $sql .= " WHERE rowid = ".((int) $this->id); @@ -326,7 +326,7 @@ class PriceExpression //} if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); diff --git a/htdocs/product/dynamic_price/class/price_global_variable.class.php b/htdocs/product/dynamic_price/class/price_global_variable.class.php index a7b22f2ef13..336fb024470 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable.class.php @@ -88,7 +88,7 @@ class PriceGlobalVariable $this->checkParameters(); // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "code, description, value"; $sql .= ") VALUES ("; $sql .= " ".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "''").","; @@ -105,7 +105,7 @@ class PriceGlobalVariable } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -142,7 +142,7 @@ class PriceGlobalVariable public function fetch($id) { $sql = "SELECT code, description, value"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -179,7 +179,7 @@ class PriceGlobalVariable $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code = ".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "''").","; $sql .= " description = ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; $sql .= " value = ".((float) $this->value); @@ -249,7 +249,7 @@ class PriceGlobalVariable } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); @@ -316,7 +316,7 @@ class PriceGlobalVariable public function listGlobalVariables() { $sql = "SELECT rowid, code, description, value"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " ORDER BY code"; dol_syslog(__METHOD__, LOG_DEBUG); diff --git a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php index 8a9c1197a7f..317bc7fb5fd 100644 --- a/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php +++ b/htdocs/product/dynamic_price/class/price_global_variable_updater.class.php @@ -100,7 +100,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "type, description, parameters, fk_variable, update_interval, next_update, last_status"; $sql .= ") VALUES ("; $sql .= " ".((int) $this->type).","; @@ -121,7 +121,7 @@ class PriceGlobalVariableUpdater } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -158,7 +158,7 @@ class PriceGlobalVariableUpdater public function fetch($id) { $sql = "SELECT type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(__METHOD__); @@ -199,7 +199,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " type = ".((int) $this->type).","; $sql .= " description = ".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "''").","; $sql .= " parameters = ".(isset($this->parameters) ? "'".$this->db->escape($this->parameters)."'" : "''").","; @@ -274,7 +274,7 @@ class PriceGlobalVariableUpdater //} if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(__METHOD__); @@ -372,7 +372,7 @@ class PriceGlobalVariableUpdater public function listUpdaters() { $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); @@ -409,7 +409,7 @@ class PriceGlobalVariableUpdater public function listPendingUpdaters() { $sql = "SELECT rowid, type, description, parameters, fk_variable, update_interval, next_update, last_status"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE next_update < ".dol_now(); dol_syslog(__METHOD__, LOG_DEBUG); @@ -568,7 +568,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " next_update = ".$this->next_update; $sql .= " WHERE rowid = ".((int) $this->id); @@ -612,7 +612,7 @@ class PriceGlobalVariableUpdater $this->checkParameters(); // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " last_status = ".(isset($this->last_status) ? "'".$this->db->escape($this->last_status)."'" : "''"); $sql .= " WHERE rowid = ".((int) $this->id); diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index bb55bc1b143..92061972e60 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -266,7 +266,7 @@ class Inventory extends CommonObject if ($this->status == self::STATUS_DRAFT) { // Delete inventory - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -275,21 +275,21 @@ class Inventory extends CommonObject } // Scan existing stock to prefill the inventory - $sql = 'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,'; - $sql .= ' pb.batch, pb.qty'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'product_stock as ps'; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb ON pb.fk_product_stock = ps.rowid,'; - $sql .= ' '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'entrepot as e'; - $sql .= ' WHERE p.entity IN ('.getEntity('product').')'; - $sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid'; + $sql = "SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,"; + $sql .= " pb.batch, pb.qty"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= " LEFT JOIN ".$this->db->prefix()."product_batch as pb ON pb.fk_product_stock = ps.rowid,"; + $sql .= " ".$this->db->prefix()."product as p, ".$this->db->prefix()."entrepot as e"; + $sql .= " WHERE p.entity IN (".getEntity('product').")"; + $sql .= " AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid"; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $sql .= " AND p.fk_product_type = 0"; } if ($this->fk_product > 0) { - $sql .= ' AND ps.fk_product = '.((int) $this->fk_product); + $sql .= " AND ps.fk_product = ".((int) $this->fk_product); } if ($this->fk_warehouse > 0) { - $sql .= ' AND ps.fk_entrepot = '.((int) $this->fk_warehouse); + $sql .= " AND ps.fk_entrepot = ".((int) $this->fk_warehouse); } $inventoryline = new InventoryLine($this->db); @@ -349,7 +349,7 @@ class Inventory extends CommonObject $this->db->begin(); // Delete inventory - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'inventorydet WHERE fk_inventory = '.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().'inventorydet WHERE fk_inventory = '.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -640,10 +640,10 @@ class Inventory extends CommonObject */ public function info($id) { - $sql = 'SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,'; - $sql .= ' fk_user_creat, fk_user_modif, fk_user_valid'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql = "SELECT rowid, date_creation as datec, tms as datem, date_validation as datev,"; + $sql .= " fk_user_creat, fk_user_modif, fk_user_valid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE t.rowid = ".((int) $id); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 23258aa1e86..e8e7bbda3cd 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -288,7 +288,7 @@ if ($resql) { if ($search_sale) { $param .= "&search_sale=".urlencode($search_sale); } - if (!empty($search_categ) && $search_categ != '-1') { + if ($search_categ > 0) { $param .= "&search_categ=".urlencode($search_categ); } if ($toolowstock) { diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index 8291e910917..544485060af 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -104,7 +104,7 @@ class StockMovements extends DolibarrApi } $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as t"; + $sql .= " FROM ".$this->db->prefix()."stock_mouvement as t"; //$sql.= ' WHERE t.entity IN ('.getEntity('stock').')'; $sql .= ' WHERE 1 = 1'; // Add sql filters @@ -156,14 +156,16 @@ class StockMovements extends DolibarrApi * $price Can be set to update AWP (Average Weighted Price) when you make a stock increase * $dlc Eat-by date. Will be used if lot does not exists yet and will be created. * $dluo Sell-by date. Will be used if lot does not exists yet and will be created. - * + * * @param int $product_id Id product id {@min 1} {@from body} {@required true} * @param int $warehouse_id Id warehouse {@min 1} {@from body} {@required true} * @param float $qty Qty to add (Use negative value for a stock decrease) {@from body} {@required true} + * @param int $type Optionally specify the type of movement. 0=input (stock increase by a stock transfer), 1=output (stock decrease by a stock transfer), 2=output (stock decrease), 3=input (stock increase). {@from body} {@type int} * @param string $lot Lot {@from body} * @param string $movementcode Movement code {@example INV123} {@from body} * @param string $movementlabel Movement label {@example Inventory number 123} {@from body} * @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). {@from body} + * @param string $datem Date of movement {@from body} {@type date} * @param string $dlc Eat-by date. {@from body} {@type date} * @param string $dluo Sell-by date. {@from body} {@type date} * @param string $origin_type Origin type (Element of source object, like 'project', 'inventory', ...) @@ -172,7 +174,7 @@ class StockMovements extends DolibarrApi * @return int ID of stock movement * @throws RestException */ - public function post($product_id, $warehouse_id, $qty, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) + public function post($product_id, $warehouse_id, $qty, $type = 2, $lot = '', $movementcode = '', $movementlabel = '', $price = '', $datem = '', $dlc = '', $dluo = '', $origin_type = '', $origin_id = 0) { if (!DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); @@ -183,17 +185,20 @@ class StockMovements extends DolibarrApi } // Type increase or decrease - $type = 2; - if ($qty >= 0) { + if ($type == 1 && $qty >= 0) { + $type = 0; + } + if ($type == 2 && $qty >= 0) { $type = 3; } require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $eatBy = empty($dluo) ? '' : dol_stringtotime($dluo); $sellBy = empty($dlc) ? '' : dol_stringtotime($dlc); + $dateMvt = empty($datem) ? '' : dol_stringtotime($datem); $this->stockmovement->setOrigin($origin_type, $origin_id); - if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', $eatBy, $sellBy, $lot) <= 0) { + if ($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, $dateMvt, $eatBy, $sellBy, $lot) <= 0) { $errormessage = $this->stockmovement->error; if (empty($errormessage)) { $errormessage = join(',', $this->stockmovement->errors); diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index 3a128a12680..0cf0e57fe3a 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -104,9 +104,9 @@ class Warehouses extends DolibarrApi } $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as t"; + $sql .= " FROM ".$this->db->prefix()."entrepot as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_societe as c"; + $sql .= ", ".$this->db->prefix()."categorie_societe as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('stock').')'; // Select warehouses of given category diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 617550c09dd..8423ebdea6f 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -204,13 +204,13 @@ class Entrepot extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)"; + $sql = "INSERT INTO ".$this->db->prefix()."entrepot (ref, entity, datec, fk_user_author, fk_parent, fk_project)"; $sql .= " VALUES ('".$this->db->escape($this->label)."', ".((int) $conf->entity).", '".$this->db->idate($now)."', ".((int) $user->id).", ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "NULL").", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "NULL").")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); + $id = $this->db->last_insert_id($this->db->prefix()."entrepot"); if ($id > 0) { $this->id = $id; @@ -293,7 +293,7 @@ class Entrepot extends CommonObject $this->town = trim($this->town); $this->country_id = ($this->country_id > 0 ? $this->country_id : 0); - $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot"; + $sql = "UPDATE ".$this->db->prefix()."entrepot"; $sql .= " SET ref = '".$this->db->escape($this->label)."'"; $sql .= ", fk_parent = ".(($this->fk_parent > 0) ? $this->fk_parent : "NULL"); $sql .= ", fk_project = ".(($this->fk_project > 0) ? $this->fk_project : "NULL"); @@ -365,7 +365,7 @@ class Entrepot extends CommonObject $elements = array('stock_mouvement', 'product_stock', 'product_warehouse_properties'); foreach ($elements as $table) { if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table; + $sql = "DELETE FROM ".$this->db->prefix().$table; $sql .= " WHERE fk_entrepot = ".((int) $this->id); $result = $this->db->query($sql); @@ -388,7 +388,7 @@ class Entrepot extends CommonObject } if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; + $sql = "DELETE FROM ".$this->db->prefix()."entrepot"; $sql .= " WHERE rowid = ".((int) $this->id); $resql1 = $this->db->query($sql); if (!$resql1) { @@ -400,7 +400,7 @@ class Entrepot extends CommonObject if (!$error) { // Update denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql - $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET stock = (SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; + $sql = "UPDATE ".$this->db->prefix()."product as p SET stock = (SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)"; $resql2 = $this->db->query($sql); if (!$resql2) { $error++; @@ -441,7 +441,7 @@ class Entrepot extends CommonObject $sql = "SELECT rowid, entity, fk_parent, fk_project, ref as label, description, statut, lieu, address, zip, town, fk_pays as country_id, phone, fax,"; $sql .= " model_pdf, import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; + $sql .= " FROM ".$this->db->prefix()."entrepot"; if ($id) { $sql .= " WHERE rowid = ".((int) $id); } else { @@ -506,7 +506,7 @@ class Entrepot extends CommonObject public function info($id) { $sql = "SELECT e.rowid, e.datec, e.tms as datem, e.fk_user_author"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; + $sql .= " FROM ".$this->db->prefix()."entrepot as e"; $sql .= " WHERE e.rowid = ".((int) $id); dol_syslog(get_class($this)."::info", LOG_DEBUG); @@ -553,7 +553,7 @@ class Entrepot extends CommonObject $liste = array(); $sql = "SELECT rowid, ref as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; + $sql .= " FROM ".$this->db->prefix()."entrepot"; $sql .= " WHERE entity IN (".getEntity('stock').")"; $sql .= " AND statut = ".((int) $status); @@ -583,8 +583,8 @@ class Entrepot extends CommonObject $ret = array(); $sql = "SELECT count(distinct p.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."product as p"; $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id); $sql .= " AND ps.fk_product = p.rowid"; @@ -625,10 +625,10 @@ class Entrepot extends CommonObject } else { $sql = "SELECT sum(ps.reel) as nb, sum(ps.reel * p.pmp) as value"; } - $sql .= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; - $sql .= ", ".MAIN_DB_PREFIX."product as p"; + $sql .= " FROM ".$this->db->prefix()."product_stock as ps"; + $sql .= ", ".$this->db->prefix()."product as p"; if ($separatedPMP) { - $sql .= ", ".MAIN_DB_PREFIX."product_perentity as pa"; + $sql .= ", ".$this->db->prefix()."product_perentity as pa"; } $sql .= " WHERE ps.fk_entrepot = ".((int) $this->id); if ($separatedPMP) { @@ -819,7 +819,7 @@ class Entrepot extends CommonObject $parentid = $this->fk_parent; // If parent_id not defined on current object, we do not start consecutive searches of parents $i = 0; while ($parentid > 0 && $i < $protection) { - $sql = "SELECT fk_parent FROM ".MAIN_DB_PREFIX."entrepot WHERE rowid = ".((int) $parentid); + $sql = "SELECT fk_parent FROM ".$this->db->prefix()."entrepot WHERE rowid = ".((int) $parentid); $resql = $this->db->query($sql); if ($resql) { $objarbo = $this->db->fetch_object($resql); @@ -852,9 +852,9 @@ class Entrepot extends CommonObject { // phpcs:enable - $sql = 'SELECT rowid - FROM '.MAIN_DB_PREFIX.'entrepot - WHERE fk_parent = '.((int) $id); + $sql = "SELECT rowid + FROM ".$this->db->prefix()."entrepot + WHERE fk_parent = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index a6bc6c2ec26..b53d67f1bd2 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -287,7 +287,7 @@ class MouvementStock extends CommonObject // If found and eatby/sellby not defined into table and provided, we update table // If found and eatby/sellby not defined into table and not provided, we do nothing // If not found, we add record - $sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".MAIN_DB_PREFIX."product_lot as pb"; + $sql = "SELECT pb.rowid, pb.batch, pb.eatby, pb.sellby FROM ".$this->db->prefix()."product_lot as pb"; $sql .= " WHERE pb.fk_product = ".((int) $fk_product)." AND pb.batch = '".$this->db->escape($batch)."'"; dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG); $resql = $this->db->query($sql); @@ -435,7 +435,7 @@ class MouvementStock extends CommonObject $origin_id = 0; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement("; + $sql = "INSERT INTO ".$this->db->prefix()."stock_mouvement("; $sql .= " datem, fk_product, batch, eatby, sellby,"; $sql .= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet"; $sql .= ")"; @@ -457,7 +457,7 @@ class MouvementStock extends CommonObject $resql = $this->db->query($sql); if ($resql) { - $mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement"); + $mvid = $this->db->last_insert_id($this->db->prefix()."stock_mouvement"); $this->id = $mvid; } else { $this->error = $this->db->lasterror(); @@ -473,7 +473,7 @@ class MouvementStock extends CommonObject // Test if there is already a record for couple (warehouse / product), so later we will make an update or create. $alreadyarecord = 0; if (!$error) { - $sql = "SELECT rowid, reel FROM ".MAIN_DB_PREFIX."product_stock"; + $sql = "SELECT rowid, reel FROM ".$this->db->prefix()."product_stock"; $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); // This is a unique key dol_syslog(get_class($this)."::_create check if a record already exists in product_stock", LOG_DEBUG); @@ -524,10 +524,10 @@ class MouvementStock extends CommonObject // Update stock quantity if (!$error) { if ($alreadyarecord > 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + ".((float) $qty); + $sql = "UPDATE ".$this->db->prefix()."product_stock SET reel = reel + ".((float) $qty); $sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); } else { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_stock"; + $sql = "INSERT INTO ".$this->db->prefix()."product_stock"; $sql .= " (reel, fk_entrepot, fk_product) VALUES "; $sql .= " (".((float) $qty).", ".((int) $entrepot_id).", ".((int) $fk_product).")"; } @@ -538,7 +538,7 @@ class MouvementStock extends CommonObject $this->errors[] = $this->db->lasterror(); $error = -3; } elseif (empty($fk_product_stock)) { - $fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock"); + $fk_product_stock = $this->db->last_insert_id($this->db->prefix()."product_stock"); } } @@ -559,11 +559,11 @@ class MouvementStock extends CommonObject if (!$error) { $newpmp = price2num($newpmp, 'MU'); - // $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; + // $sql = "UPDATE ".$this->db->prefix()."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; // $sql.= " WHERE rowid = ".((int) $fk_product); // Update pmp + denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql - $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET pmp = ".((float) $newpmp).","; - $sql .= " stock=(SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock as ps WHERE ps.fk_product = p.rowid)"; + $sql = "UPDATE ".$this->db->prefix()."product as p SET pmp = ".((float) $newpmp).","; + $sql .= " stock=(SELECT SUM(ps.reel) FROM ".$this->db->prefix()."product_stock as ps WHERE ps.fk_product = p.rowid)"; $sql .= " WHERE rowid = ".((int) $fk_product); dol_syslog(get_class($this)."::_create update AWP", LOG_DEBUG); @@ -576,7 +576,7 @@ class MouvementStock extends CommonObject // If stock is now 0, we can remove entry into llx_product_stock, but only if there is no child lines into llx_product_batch (detail of batch, because we can imagine // having a lot1/qty=X and lot2/qty=-X, so 0 but we must not loose repartition of different lot. - $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".MAIN_DB_PREFIX."product_batch as pb)"; + $sql = "DELETE FROM ".$this->db->prefix()."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".$this->db->prefix()."product_batch as pb)"; $resql = $this->db->query($sql); // We do not test error, it can fails if there is child in batch details } @@ -626,8 +626,8 @@ class MouvementStock extends CommonObject { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.tms,"; $sql .= " t.datem,"; $sql .= " t.fk_product,"; @@ -644,8 +644,8 @@ class MouvementStock extends CommonObject $sql .= " t.eatby,"; $sql .= " t.sellby,"; $sql .= " t.fk_projet as fk_project"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE t.rowid = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { @@ -721,7 +721,7 @@ class MouvementStock extends CommonObject $pqtys = array(); $sql = "SELECT fk_product_pere, fk_product_fils, qty"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_association"; + $sql .= " FROM ".$this->db->prefix()."product_association"; $sql .= " WHERE fk_product_pere = ".((int) $idProduct); $sql .= " AND incdec = 1"; @@ -824,8 +824,8 @@ class MouvementStock extends CommonObject { $nb = 0; - $sql = 'SELECT SUM(value) as nb from '.MAIN_DB_PREFIX.'stock_mouvement'; - $sql .= ' WHERE fk_product = '.((int) $productidselected); + $sql = "SELECT SUM(value) as nb from ".$this->db->prefix()."stock_mouvement"; + $sql .= " WHERE fk_product = ".((int) $productidselected); $sql .= " AND datem < '".$this->db->idate($datebefore)."'"; dol_syslog(get_class($this).__METHOD__.'', LOG_DEBUG); @@ -1203,8 +1203,8 @@ class MouvementStock extends CommonObject $cpt = 0; $sql = "SELECT sum(pb.qty) as cpt"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product_stock as ps ON ps.rowid = pb.fk_product_stock"; + $sql .= " FROM ".$this->db->prefix()."product_batch as pb"; + $sql .= " INNER JOIN ".$this->db->prefix()."product_stock as ps ON ps.rowid = pb.fk_product_stock"; $sql .= " WHERE ps.fk_product = " . ((int) $fk_product); $sql .= " AND pb.batch = '" . $this->db->escape($batch) . "'"; diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 360978ac736..fdb82800067 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -188,7 +188,7 @@ class Productlot extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'entity,'; $sql .= 'fk_product,'; $sql .= 'batch,'; @@ -230,7 +230,7 @@ class Productlot extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); // Actions on extra fields if (!$error) { @@ -279,8 +279,8 @@ class Productlot extends CommonObject global $conf; dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.entity,"; $sql .= " t.fk_product,"; $sql .= " t.batch,"; @@ -296,11 +296,11 @@ class Productlot extends CommonObject $sql .= " t.fk_user_creat,"; $sql .= " t.fk_user_modif,"; $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if ($product_id > 0 && $batch != '') { $sql .= " WHERE t.batch = '".$this->db->escape($batch)."' AND t.fk_product = ".((int) $product_id); } else { - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql .= " WHERE t.rowid = ".((int) $id); } $resql = $this->db->query($sql); @@ -394,7 +394,7 @@ class Productlot extends CommonObject } // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' entity = '.(isset($this->entity) ? $this->entity : "null").','; $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").','; $sql .= ' batch = '.(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").','; @@ -479,7 +479,7 @@ class Productlot extends CommonObject //} if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index 9b32fe1fe5e..95da65cd540 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -113,7 +113,7 @@ class ProductStockEntrepot extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'fk_product,'; $sql .= 'fk_entrepot,'; @@ -143,7 +143,7 @@ class ProductStockEntrepot extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); //if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you @@ -184,19 +184,19 @@ class ProductStockEntrepot extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.tms,"; $sql .= " t.fk_product,"; $sql .= " t.fk_entrepot,"; $sql .= " t.seuil_stock_alerte,"; $sql .= " t.desiredstock,"; $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if (!empty($id)) { - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql .= " WHERE t.rowid = ".((int) $id); } else { - $sql .= ' WHERE t.fk_product = '.((int) $fk_product).' AND t.fk_entrepot = '.((int) $fk_entrepot); + $sql .= " WHERE t.fk_product = ".((int) $fk_product)." AND t.fk_entrepot = ".((int) $fk_entrepot); } $resql = $this->db->query($sql); @@ -254,8 +254,8 @@ class ProductStockEntrepot extends CommonObject { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.tms,"; $sql .= " t.fk_product,"; @@ -265,9 +265,9 @@ class ProductStockEntrepot extends CommonObject $sql .= " t.import_key"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; - $sql .= ' WHERE 1=1'; + $sql .= " WHERE 1=1"; // Manage filter $sqlwhere = array(); @@ -277,13 +277,13 @@ class ProductStockEntrepot extends CommonObject } } if (count($sqlwhere) > 0) { - $sql .= ' AND '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere); + $sql .= " AND ".implode(' '.$this->db->escape($filtermode).' ', $sqlwhere); } if (!empty($fk_product) && $fk_product > 0) { - $sql .= ' AND fk_product = '.((int) $fk_product); + $sql .= " AND fk_product = ".((int) $fk_product); } elseif (!empty($fk_entrepot) && $fk_entrepot > 0) { - $sql .= ' AND fk_entrepot = '.((int) $fk_entrepot); + $sql .= " AND fk_entrepot = ".((int) $fk_entrepot); } // "elseif" used instead of "if" because getting list with specified fk_product and specified fk_entrepot would be the same as doing a fetch @@ -355,7 +355,7 @@ class ProductStockEntrepot extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'").','; $sql .= ' fk_product = '.(isset($this->fk_product) ? $this->fk_product : "null").','; @@ -425,7 +425,7 @@ class ProductStockEntrepot extends CommonObject //} if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index e83921135a2..59576b961d4 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -228,7 +228,7 @@ class Projects extends DolibarrApi * See also API /tasks * * @param int $id Id of project - * @param int $includetimespent 0=Return only list of tasks. 1=Include a summary of time spent, 2=Include details of time spent lines (2 is no implemented yet) + * @param int $includetimespent 0=Return only list of tasks. 1=Include a summary of time spent, 2=Include details of time spent lines * @return int * * @url GET {id}/tasks @@ -253,9 +253,8 @@ class Projects extends DolibarrApi if ($includetimespent == 1) { $timespent = $line->getSummaryOfTimeSpent(0); } - if ($includetimespent == 1) { - // TODO - // Add class for timespent records and loop and fill $line->lines with records of timespent + if ($includetimespent == 2) { + $timespent = $line->fetchTimeSpentOnTask(); } array_push($result, $this->_cleanObjectDatas($line)); } diff --git a/htdocs/projet/class/api_tasks.class.php b/htdocs/projet/class/api_tasks.class.php index 49a5d9d418b..cafb60f2865 100644 --- a/htdocs/projet/class/api_tasks.class.php +++ b/htdocs/projet/class/api_tasks.class.php @@ -60,7 +60,7 @@ class Tasks extends DolibarrApi * Return an array with task informations * * @param int $id ID of task - * @param int $includetimespent 0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines (2 is no implemented yet) + * @param int $includetimespent 0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines * @return array|mixed data without useless information * * @throws RestException @@ -83,9 +83,8 @@ class Tasks extends DolibarrApi if ($includetimespent == 1) { $timespent = $this->task->getSummaryOfTimeSpent(0); } - if ($includetimespent == 1) { - // TODO - // Add class for timespent records and loop and fill $line->lines with records of timespent + if ($includetimespent == 2) { + $timespent = $this->task->fetchTimeSpentOnTask(); } return $this->_cleanObjectDatas($this->task); diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 87a66279714..328361c00c3 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2014 Marcos García * Copyright (C) 2018 Frédéric France * Copyright (C) 2020 Juanjo Menent + * Copyright (C) 2022 Charlene Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,7 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; /** * Class to manage tasks */ -class Task extends CommonObject +class Task extends CommonObjectLine { /** * @var string ID to identify managed object @@ -40,7 +41,7 @@ class Task extends CommonObject public $element = 'project_task'; /** - * @var string Name of table without prefix where object is stored + * @var string Name of table without prefix where object is stored */ public $table_element = 'projet_task'; @@ -1281,6 +1282,97 @@ class Task extends CommonObject return $ret; } + /** + * Fetch records of time spent of this task + * + * @param string $morewherefilter Add more filter into where SQL request (must start with ' AND ...') + * @return int <0 if KO, array of time spent if OK + */ + public function fetchTimeSpentOnTask($morewherefilter = '') + { + global $langs; + + $arrayres = array(); + + $sql = "SELECT"; + $sql .= " s.rowid as socid,"; + $sql .= " s.nom as thirdparty_name,"; + $sql .= " s.email as thirdparty_email,"; + $sql .= " ptt.rowid,"; + $sql .= " ptt.fk_task,"; + $sql .= " ptt.task_date,"; + $sql .= " ptt.task_datehour,"; + $sql .= " ptt.task_date_withhour,"; + $sql .= " ptt.task_duration,"; + $sql .= " ptt.fk_user,"; + $sql .= " ptt.note,"; + $sql .= " ptt.thm,"; + $sql .= " pt.rowid as task_id,"; + $sql .= " pt.ref as task_ref,"; + $sql .= " pt.label as task_label,"; + $sql .= " p.rowid as project_id,"; + $sql .= " p.ref as project_ref,"; + $sql .= " p.title as project_label,"; + $sql .= " p.public as public"; + $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as ptt, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."projet as p"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid"; + $sql .= " WHERE ptt.fk_task = pt.rowid AND pt.fk_projet = p.rowid"; + $sql .= " AND pt.rowid = ".((int) $this->id); + $sql .= " AND pt.entity IN (".getEntity('project').")"; + if ($morewherefilter) { + $sql .= $morewherefilter; + } + + dol_syslog(get_class($this)."::fetchAllTimeSpent", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + $i = 0; + while ($i < $num) { + $obj = $this->db->fetch_object($resql); + + $newobj = new stdClass(); + + $newobj->socid = $obj->socid; + $newobj->thirdparty_name = $obj->thirdparty_name; + $newobj->thirdparty_email = $obj->thirdparty_email; + + $newobj->fk_project = $obj->project_id; + $newobj->project_ref = $obj->project_ref; + $newobj->project_label = $obj->project_label; + $newobj->public = $obj->project_public; + + $newobj->fk_task = $obj->task_id; + $newobj->task_ref = $obj->task_ref; + $newobj->task_label = $obj->task_label; + + $newobj->timespent_line_id = $obj->rowid; + $newobj->timespent_line_date = $this->db->jdate($obj->task_date); + $newobj->timespent_line_datehour = $this->db->jdate($obj->task_datehour); + $newobj->timespent_line_withhour = $obj->task_date_withhour; + $newobj->timespent_line_duration = $obj->task_duration; + $newobj->timespent_line_fk_user = $obj->fk_user; + $newobj->timespent_line_thm = $obj->thm; // hourly rate + $newobj->timespent_line_note = $obj->note; + + $arrayres[] = $newobj; + + $i++; + } + + $this->db->free($resql); + + $this->lines = $arrayres; + return 1; + } else { + dol_print_error($this->db); + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + /** * Calculate total of time spent for task * diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php index 51f8b19e226..32be3b3013d 100644 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -103,6 +104,10 @@ if ($user->socid) { restrictedArea($user, 'salaries', $object->id, 'salary', ''); +$permissiontoread = $user->rights->salaries->read; +$permissiontoadd = $user->rights->salaries->write; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php +$permissiontodelete = $user->rights->salaries->delete || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT); + /** * Actions @@ -434,12 +439,14 @@ if ($action == "update_extras" && !empty($user->rights->salaries->read)) { * View */ +$form = new Form($db); +$formfile = new FormFile($db); +if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); + $title = $langs->trans('Salary')." - ".$langs->trans('Card'); $help_url = ""; llxHeader("", $title, $help_url); -$form = new Form($db); -if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); if ($id > 0) { $result = $object->fetch($id); @@ -1027,6 +1034,7 @@ if ($id) { $resteapayer = price2num($resteapayer, 'MT'); + /* * Action bar */ @@ -1066,6 +1074,64 @@ if ($id) { } } print "
"; + + + + // Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } + + if ($action != 'presend') { + print '
'; + print ''; // ancre + + $includedocgeneration = 1; + + // Documents + if ($includedocgeneration) { + $objref = dol_sanitizeFileName($object->ref); + $relativepath = $objref.'/'.$objref.'.pdf'; + $filedir = $conf->salaries->dir_output.'/'.$objref; + $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; + //$genallowed = $permissiontoread; // If you can read, you can build the PDF to read content + $genallowed = 0; // If you can read, you can build the PDF to read content + $delallowed = $permissiontoadd; // If you can create/edit, you can remove a file on card + print $formfile->showdocuments('salaries', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang); + } + + // Show links to link elements + /* + $linktoelem = $form->showLinkToObjectBlock($object, null, array('salaries')); + $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); + */ + + print '
'; + + $MAXEVENT = 10; + + $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-list-alt imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id); + + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions = new FormActions($db); + //$somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter); + + print '
'; + } + + //Select mail models is same action as presend + if (GETPOST('modelselected')) { + $action = 'presend'; + } + + // Presend form + $modelmail = 'salary'; + $defaulttopic = 'InformationMessage'; + $diroutput = $conf->salaries->dir_output; + $trackid = 'salary'.$object->id; + + include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; } // End of page diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 43e9bb30314..10edb21483e 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -453,6 +453,7 @@ if (empty($reshook)) { } $object->entity = (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : $conf->entity); $object->name_alias = GETPOST('name_alias', 'alphanohtml'); + $object->parent = GETPOST('parent_company_id', 'int'); $object->address = GETPOST('address', 'alphanohtml'); $object->zip = GETPOST('zipcode', 'alphanohtml'); $object->town = GETPOST('town', 'alphanohtml'); @@ -1312,6 +1313,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print '
'; print ''; + // Parent company + if (empty($conf->global->SOCIETE_DISABLE_PARENTCOMPANY)) { + print ''; + print ''; + print ''; + } + // Prospect/Customer print ''; print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'.$langs->trans("MAIN_PDF_HIDE_SENDER_NAME").''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('MAIN_PDF_HIDE_SENDER_NAME'); +} else { + print $form->selectyesno('MAIN_PDF_HIDE_SENDER_NAME', (!empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) ? $conf->global->MAIN_PDF_HIDE_SENDER_NAME : 0, 1); +} +print '
'.$langs->trans("ShowVATIntaInAddress").''; @@ -358,16 +370,6 @@ if ($conf->use_javascript_ajax) { print $form->selectarray("MAIN_PDF_NO_RECIPENT_FRAME", $arrval, $conf->global->MAIN_PDF_NO_RECIPENT_FRAME); } -// Show sender name - -print '
'.$langs->trans("MAIN_PDF_HIDE_SENDER_NAME").''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('MAIN_PDF_HIDE_SENDER_NAME'); -} else { - print $form->selectyesno('MAIN_PDF_HIDE_SENDER_NAME', (!empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) ? $conf->global->MAIN_PDF_HIDE_SENDER_NAME : 0, 1); -} -print '
'.$langs->trans("SwapSenderAndRecipientOnPDF").''; @@ -506,22 +508,6 @@ if ($conf->use_javascript_ajax) { } print '
'.$langs->trans("BoldLabelOnPDF").''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('PDF_BOLD_PRODUCT_LABEL'); -} else { - print $form->selectyesno('PDF_BOLD_PRODUCT_LABEL', (!empty($conf->global->PDF_BOLD_PRODUCT_LABEL)) ? $conf->global->PDF_BOLD_PRODUCT_LABEL : 0, 1); -} -print '
'.$langs->trans("BoldRefAndPeriodOnPDF").''; -if ($conf->use_javascript_ajax) { - print ajax_constantonoff('PDF_BOLD_PRODUCT_REF_AND_PERIOD'); -} else { - print $form->selectyesno('PDF_BOLD_PRODUCT_REF_AND_PERIOD', (!empty($conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD)) ? $conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD : 0, 1); -} -print '
'.$langs->trans("HideDescOnPDF").''; @@ -542,6 +528,26 @@ if ($conf->use_javascript_ajax) { } print '
'.$langs->trans("BoldLabelOnPDF").''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('PDF_BOLD_PRODUCT_LABEL'); +} else { + print $form->selectyesno('PDF_BOLD_PRODUCT_LABEL', (!empty($conf->global->PDF_BOLD_PRODUCT_LABEL)) ? $conf->global->PDF_BOLD_PRODUCT_LABEL : 0, 1); +} +print '
'.$langs->trans("BoldRefAndPeriodOnPDF").''; +if ($conf->use_javascript_ajax) { + print ajax_constantonoff('PDF_BOLD_PRODUCT_REF_AND_PERIOD'); +} else { + print $form->selectyesno('PDF_BOLD_PRODUCT_REF_AND_PERIOD', (!empty($conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD)) ? $conf->global->PDF_BOLD_PRODUCT_REF_AND_PERIOD : 0, 1); +} +print '
'.$langs->trans("SHOW_SUBPRODUCT_REF_IN_PDF", $langs->transnoentitiesnoconv("AssociatedProductsAbility"), $langs->transnoentitiesnoconv("Products")).''; diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index b6977940411..e4cc6a37c1c 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -42,6 +42,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; +if (!empty($conf->margin->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; +} require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; @@ -223,6 +226,10 @@ $arrayfields = array( 'p.multicurrency_total_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedTTC', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)), 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>10), 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>-1), + 'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), + 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous ? 0 : 1)), + 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)), + 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || !$user->rights->margins->liretous || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)), 'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), 'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), 'p.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>500), @@ -486,6 +493,10 @@ $form = new Form($db); $formother = new FormOther($db); $formfile = new FormFile($db); $formpropal = new FormPropal($db); +$formmargin = null; +if (!empty($conf->margin->enabled)) { + $formmargin = new FormMargin($db); +} $companystatic = new Societe($db); $projectstatic = new Project($db); $formcompany = new FormCompany($db); @@ -1244,6 +1255,22 @@ if ($resql) { if (!empty($arrayfields['sale_representative']['checked'])) { print ''; + print ''; + print ''; + print ''; + print '
'.price($marginInfo['pa_total']).''.price($marginInfo['total_margin']).''.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').''.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').''; + print ''; + print ''; + print ''; + print '
'.price($marginInfo['pa_total']).''.price($marginInfo['total_margin']).''.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').''.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').''.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').''; - $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, (empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 0 : 1), 1); + $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, (empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 0 : 1), 1, 'minwidth200'); $out .= ''; @@ -1741,14 +1740,14 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } $out .= getTitleFieldOfList($tmp); } - $out .= getTitleFieldOfList($langs->trans("Ref"), 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder); - $out .= getTitleFieldOfList($langs->trans("Owner")); - $out .= getTitleFieldOfList($langs->trans("Type")); - $out .= getTitleFieldOfList($langs->trans("Label"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); - $out .= getTitleFieldOfList($langs->trans("Date"), 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, 'align="center"', $sortfield, $sortorder); - $out .= getTitleFieldOfList($langs->trans("RelatedObjects"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); - $out .= getTitleFieldOfList($langs->trans("ActionOnContact"), 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); - $out .= getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, 'align="center"', $sortfield, $sortorder); + $out .= getTitleFieldOfList("Ref", 0, $_SERVER["PHP_SELF"], 'a.id', '', $param, '', $sortfield, $sortorder); + $out .= getTitleFieldOfList("Owner"); + $out .= getTitleFieldOfList("Type"); + $out .= getTitleFieldOfList("Label", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); + $out .= getTitleFieldOfList("Date", 0, $_SERVER["PHP_SELF"], 'a.datep,a.id', '', $param, '', $sortfield, $sortorder, 'center '); + $out .= getTitleFieldOfList("RelatedObjects", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder); + $out .= getTitleFieldOfList("ActionOnContact", 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'tdoverflowmax125 ', 0, '', 0); + $out .= getTitleFieldOfList("Status", 0, $_SERVER["PHP_SELF"], 'a.percent', '', $param, '', $sortfield, $sortorder, 'center '); $out .= getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'maxwidthsearch '); $out .= '
'; + $out .= ''; //$userstatic->id=$histo[$key]['userid']; //$userstatic->login=$histo[$key]['login']; //$out.=$userstatic->getLoginUrl(1); @@ -1813,25 +1812,27 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $labeltype .= ' - '.$arraylist[$actionstatic->code]; // Use code in priority on type_code } } - $out .= ''; + $out .= ''; $out .= $actionstatic->getTypePicto(); $out .= $labeltype; $out .= ''; + // Title/Label of event + $out .= 'trans("Action".$histo[$key]['acode']); $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : $histo[$key]['alabel']); //$actionstatic->libelle=$libelle; $libelle = $histo[$key]['note']; $actionstatic->id = $histo[$key]['id']; + $out .= ' title="'.dol_escape_htmltag($libelle).'">'; $out .= dol_trunc($libelle, 120); } if (isset($histo[$key]['type']) && $histo[$key]['type'] == 'mailing') { $out .= ''.img_object($langs->trans("ShowEMailing"), "email").' '; $transcode = $langs->trans("Action".$histo[$key]['acode']); $libelle = ($transcode != "Action".$histo[$key]['acode'] ? $transcode : 'Send mass mailing'); + $out .= ' title="'.dol_escape_htmltag($libelle).'">'; $out .= dol_trunc($libelle, 120); } $out .= ''.$contactstatic->getNomUrl(1, '', 10).''; + if (isset($histo[$key]['socpeopleassigned']) && is_array($histo[$key]['socpeopleassigned']) && count($histo[$key]['socpeopleassigned']) > 0) { + $out .= ''; $contact = new Contact($db); foreach ($histo[$key]['socpeopleassigned'] as $cid => $value) { $result = $contact->fetch($cid); @@ -1904,7 +1900,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } if ($result > 0) { - $out .= $contact->getNomUrl(1, '', 16); + $out .= $contact->getNomUrl(-3, '', 10, '', -1, 0, 'paddingright'); if (isset($histo[$key]['acode']) && $histo[$key]['acode'] == 'AC_TEL') { if (!empty($contact->phone_pro)) { $out .= '('.dol_print_phone($contact->phone_pro).')'; @@ -1914,6 +1910,12 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } } $out .= ''.$contactstatic->getNomUrl(-1, '', 10).' 
'.$langs->trans("UseBorderOnTable").''; + if ($edit) { + print ajax_constantonoff('THEME_ELDY_USEBORDERONTABLE', array(), null, 0, 0, 1); + //print $form->selectyesno('THEME_ELDY_USEBORDERONTABLE', $conf->global->THEME_ELDY_USEBORDERONTABLE, 1); + } else { + print yn($conf->global->THEME_ELDY_USEBORDERONTABLE); + } + print '   '.$langs->trans("Default").': '.$default.' '; + print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); + print '
'.$langs->trans("BtnActionColor").''; if ($edit) { - print $formother->selectColor(colorArrayToHex(colorStringToArray((!empty($conf->global->THEME_ELDY_BTNACTION) ? $conf->global->THEME_ELDY_BTNACTION : ''), array()), ''), 'THEME_ELDY_BTNACTION', '', 1, '', '', 'colorbtnaction').' '; + print $formother->selectColor(colorArrayToHex(colorStringToArray((!empty($conf->global->THEME_ELDY_BTNACTION) ? $conf->global->THEME_ELDY_BTNACTION : ''), array()), ''), 'THEME_ELDY_BTNACTION', '', 1, '', '', 'butactionbg').' '; } else { $color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_BTNACTION, array()), ''); if ($color) { @@ -952,7 +976,7 @@ function showSkins($fuser, $edit = 0, $foruserprofile = false) print '
'.$langs->trans("TextBtnActionColor").''; if ($edit) { - print $formother->selectColor(colorArrayToHex(colorStringToArray((!empty($conf->global->THEME_ELDY_TEXTBTNACTION) ? $conf->global->THEME_ELDY_TEXTBTNACTION : ''), array()), ''), 'THEME_ELDY_TEXTBTNACTION', '', 1, '', '', 'colortextbtnaction').' '; + print $formother->selectColor(colorArrayToHex(colorStringToArray((!empty($conf->global->THEME_ELDY_TEXTBTNACTION) ? $conf->global->THEME_ELDY_TEXTBTNACTION : ''), array()), ''), 'THEME_ELDY_TEXTBTNACTION', '', 1, '', '', 'textbutaction').' '; } else { $color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_TEXTBTNACTION, array()), ''); if ($color) { diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 675b0a80ab9..9f2676dfd72 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1052,12 +1052,14 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps,PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Create tables and keys required by module: - * - Files module.sql files with create table instructions - * - Then files modules.key.sql with create keys instructions + * - Files module.sql with create table instructions + * - Then modules.key.sql with create keys instructions * - Then data_xxx.sql (usualy provided by external modules only) * - Then update_xxx.sql (usualy provided by external modules only) * Files must be stored in directory defined by reldir (Example: '/install/mysql/tables' or '/module/sql/') - * This function is usually called by the this->init of module descriptors. + * This function may also be called by : + * - _load_tables('/install/mysql/tables/', 'modulename') into the this->init() of core module descriptors. + * - _load_tables('/mymodule/sql/') into the this->init() of external module descriptors. * * @param string $reldir Relative directory where to scan files. Example: '/install/mysql/tables' or '/module/sql/' * @param string $onlywithsuffix Only with the defined suffix diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index e0bf3a9bbc5..2a78baa00c9 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -350,8 +350,8 @@ class modAccounting extends DolibarrModules 'b.fk_doc'=>'const-0', 'b.fk_docdet'=>'const-0', 'b.fk_user_author'=>'user->id', - 'b.montant'=>'rule-computeMontant', - 'b.sens'=>'rule-computeSens' + 'b.montant'=>'rule-computeAmount', + 'b.sens'=>'rule-computeDirection' ); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_convertvalue_array[$r]=array( 'b.numero_compte'=>array('rule'=>'accountingaccount'), diff --git a/htdocs/core/modules/modApi.class.php b/htdocs/core/modules/modApi.class.php index 254e3f86983..6ad632c944e 100644 --- a/htdocs/core/modules/modApi.class.php +++ b/htdocs/core/modules/modApi.class.php @@ -230,8 +230,6 @@ class modApi extends DolibarrModules { $sql = array(); - $result = $this->_load_tables('/api/sql/'); - return $this->_init($sql, $options); } diff --git a/htdocs/core/modules/modBom.class.php b/htdocs/core/modules/modBom.class.php index b166166b95f..5eba97b1103 100644 --- a/htdocs/core/modules/modBom.class.php +++ b/htdocs/core/modules/modBom.class.php @@ -467,11 +467,6 @@ class modBom extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/bom/sql/'); - if ($result < 0) { - return -1; // Do not activate module if not allowed errors found on module SQL queries (the _load_table run sql with run_sql with error allowed parameter to 'default') - } - // Create extrafields //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; //$extrafields = new ExtraFields($this->db); diff --git a/htdocs/core/modules/modDataPolicy.class.php b/htdocs/core/modules/modDataPolicy.class.php index 047ff2b5a8d..1b82334a95b 100644 --- a/htdocs/core/modules/modDataPolicy.class.php +++ b/htdocs/core/modules/modDataPolicy.class.php @@ -211,8 +211,6 @@ class modDataPolicy extends DolibarrModules { { global $langs; - $this->_load_tables('/datapolicy/sql/'); - // Create extrafields include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); diff --git a/htdocs/core/modules/modDav.class.php b/htdocs/core/modules/modDav.class.php index 09f7d814553..46168280575 100644 --- a/htdocs/core/modules/modDav.class.php +++ b/htdocs/core/modules/modDav.class.php @@ -266,8 +266,6 @@ class modDav extends DolibarrModules */ public function init($options = '') { - //$this->_load_tables('/dav/sql/'); - // Create extrafields include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index f0f06395565..bceb313e120 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -159,6 +159,11 @@ class modDeplacement extends DolibarrModules */ public function init($options = '') { + $result = $this->_load_tables('/install/mysql/tables/', 'deplacement'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + // Permissions $this->remove($options); diff --git a/htdocs/core/modules/modDon.class.php b/htdocs/core/modules/modDon.class.php index da7ee6c5e82..f2564cd3cc6 100644 --- a/htdocs/core/modules/modDon.class.php +++ b/htdocs/core/modules/modDon.class.php @@ -155,6 +155,11 @@ class modDon extends DolibarrModules { global $conf; + $result = $this->_load_tables('/install/mysql/tables/', 'deplacement'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + $sql = array( "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'donation' AND entity = ".((int) $conf->entity), "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','donation',".((int) $conf->entity).")", diff --git a/htdocs/core/modules/modEventOrganization.class.php b/htdocs/core/modules/modEventOrganization.class.php index 96ee96efae2..f2dc614cb03 100644 --- a/htdocs/core/modules/modEventOrganization.class.php +++ b/htdocs/core/modules/modEventOrganization.class.php @@ -351,11 +351,6 @@ class modEventOrganization extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/eventorganization/sql/'); - if ($result < 0) { - return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') - } - // Permissions $this->remove($options); diff --git a/htdocs/core/modules/modIntracommreport.class.php b/htdocs/core/modules/modIntracommreport.class.php index 47ef889e2dd..817c893934b 100644 --- a/htdocs/core/modules/modIntracommreport.class.php +++ b/htdocs/core/modules/modIntracommreport.class.php @@ -125,4 +125,26 @@ class modIntracommreport extends DolibarrModules // Exports $r = 1; } + + /** + * Function called when module is enabled. + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. + * It also creates data directories + * + * @param string $options Options when enabling module ('', 'noboxes') + * @return int 1 if OK, 0 if KO + */ + public function init($options = '') + { + global $conf; + + $result = $this->_load_tables('/install/mysql/tables/', 'intracommreport'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + + $sql = array(); + + return $this->_init($sql, $options); + } } diff --git a/htdocs/core/modules/modKnowledgeManagement.class.php b/htdocs/core/modules/modKnowledgeManagement.class.php index b3fb24aa7b3..93b44f31204 100644 --- a/htdocs/core/modules/modKnowledgeManagement.class.php +++ b/htdocs/core/modules/modKnowledgeManagement.class.php @@ -442,7 +442,7 @@ class modKnowledgeManagement extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/knowledgemanagement/sql/'); + $result = $this->_load_tables('/install/mysql/tables/', 'knowledgemanagement'); if ($result < 0) { return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') } diff --git a/htdocs/core/modules/modLoan.class.php b/htdocs/core/modules/modLoan.class.php index b061e1b73a6..e19ec1b81f8 100644 --- a/htdocs/core/modules/modLoan.class.php +++ b/htdocs/core/modules/modLoan.class.php @@ -160,6 +160,11 @@ class modLoan extends DolibarrModules { global $conf; + $result = $this->_load_tables('/install/mysql/tables/', 'loan'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + // Clean before activation $this->remove($options); diff --git a/htdocs/core/modules/modMrp.class.php b/htdocs/core/modules/modMrp.class.php index ac300fc26e3..2bfc026d959 100644 --- a/htdocs/core/modules/modMrp.class.php +++ b/htdocs/core/modules/modMrp.class.php @@ -446,11 +446,6 @@ class modMrp extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/mrp/sql/'); - if ($result < 0) { - return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') - } - // Create extrafields during init //include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; //$extrafields = new ExtraFields($this->db); diff --git a/htdocs/core/modules/modMultiCurrency.class.php b/htdocs/core/modules/modMultiCurrency.class.php index 98d7222f082..bc7e044c7af 100644 --- a/htdocs/core/modules/modMultiCurrency.class.php +++ b/htdocs/core/modules/modMultiCurrency.class.php @@ -265,7 +265,6 @@ class modMultiCurrency extends DolibarrModules { $sql = array(); - //$this->_load_tables('/multicurrency/sql/'); $res = $this->_init($sql, $options); if ($res) { diff --git a/htdocs/core/modules/modPartnership.class.php b/htdocs/core/modules/modPartnership.class.php index 87ce98abb4a..516c2b41e13 100644 --- a/htdocs/core/modules/modPartnership.class.php +++ b/htdocs/core/modules/modPartnership.class.php @@ -408,7 +408,7 @@ class modPartnership extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/partnership/sql/'); + $result = $this->_load_tables('/install/mysql/tables/', 'partnership'); if ($result < 0) { return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') } diff --git a/htdocs/core/modules/modRecruitment.class.php b/htdocs/core/modules/modRecruitment.class.php index 239c48135d7..c4bbd573fa9 100644 --- a/htdocs/core/modules/modRecruitment.class.php +++ b/htdocs/core/modules/modRecruitment.class.php @@ -403,7 +403,7 @@ class modRecruitment extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/recruitment/sql/'); + $result = $this->_load_tables('/install/mysql/tables/', 'recruitment'); if ($result < 0) { return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') } diff --git a/htdocs/core/modules/modResource.class.php b/htdocs/core/modules/modResource.class.php index 377d5aadbc4..51117868e35 100644 --- a/htdocs/core/modules/modResource.class.php +++ b/htdocs/core/modules/modResource.class.php @@ -301,21 +301,6 @@ class modResource extends DolibarrModules { $sql = array(); - $result = $this->loadTables(); - return $this->_init($sql, $options); } - - /** - * Create tables, keys and data required by module - * Files llx_table1.sql, llx_table1.key.sql llx_data.sql with create table, create keys - * and create data commands must be stored in directory /resource/sql/ - * This function is called by this->init - * - * @return int <=0 if KO, >0 if OK - */ - protected function loadTables() - { - return $this->_load_tables('/resource/sql/'); - } } diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index b0de609a874..839a62325f3 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -434,6 +434,11 @@ class modStock extends DolibarrModules { global $conf, $langs; + $result = $this->_load_tables('/install/mysql/tables/', 'stock'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } + // Permissions $this->remove($options); diff --git a/htdocs/core/modules/modTakePos.class.php b/htdocs/core/modules/modTakePos.class.php index 5cb7a7f0c38..6c7d43a8388 100644 --- a/htdocs/core/modules/modTakePos.class.php +++ b/htdocs/core/modules/modTakePos.class.php @@ -283,8 +283,6 @@ class modTakePos extends DolibarrModules dolibarr_set_const($db, "TAKEPOS_PRINT_METHOD", "browser", 'chaine', 0, '', $conf->entity); - $this->_load_tables('/takepos/sql/'); - $sql = array(); // Remove permissions and default values diff --git a/htdocs/core/modules/modWorkstation.class.php b/htdocs/core/modules/modWorkstation.class.php index 6106c194544..854dd45b969 100644 --- a/htdocs/core/modules/modWorkstation.class.php +++ b/htdocs/core/modules/modWorkstation.class.php @@ -390,7 +390,7 @@ class modWorkstation extends DolibarrModules { global $conf, $langs; - $result = $this->_load_tables('/workstation/sql/'); + $result = $this->_load_tables('/install/mysql/tables/', 'workstation'); if ($result < 0) { return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') } diff --git a/htdocs/core/modules/modZapier.class.php b/htdocs/core/modules/modZapier.class.php index 430622465ca..e638d906693 100644 --- a/htdocs/core/modules/modZapier.class.php +++ b/htdocs/core/modules/modZapier.class.php @@ -281,9 +281,9 @@ class modZapier extends DolibarrModules */ public function init($options = '') { - $result = $this->_load_tables('/zapier/sql/'); + $result = $this->_load_tables('/install/mysql/tables/', 'zapier'); if ($result < 0) { - return -1; // Do not activate module if not allowed errors found on module SQL queries (the _load_table run sql with run_sql with error allowed parameter to 'default') + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') } // Create extrafields @@ -294,7 +294,9 @@ class modZapier extends DolibarrModules //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled'); //$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1,'', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled'); //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'zapier@zapier', '$conf->zapier->enabled'); + $sql = array(); + return $this->_init($sql, $options); } diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 0e30ec96e44..5135a1708af 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -919,6 +919,11 @@ class pdf_azur extends ModelePDFPropales } $posxval = 52; + if (!empty($conf->global->MAIN_PDF_DELIVERY_DATE_TEXT)) { + $displaydate = "daytext"; + } else { + $displaydate = "day"; + } // Show shipping date if (!empty($object->delivery_date)) { @@ -929,7 +934,7 @@ class pdf_azur extends ModelePDFPropales $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posxval, $posy); - $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true); + $dlp = dol_print_date($object->delivery_date, $displaydate, false, $outputlangs, true); $pdf->MultiCell(80, 4, $dlp, 0, 'L'); $posy = $pdf->GetY() + 1; @@ -1557,15 +1562,21 @@ class pdf_azur extends ModelePDFPropales } } - $posy += 4; - $pdf->SetXY($posx, $posy); - $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DatePropal")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R'); + if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) { + $displaydate = "daytext"; + } else { + $displaydate = "day"; + } $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : ".dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R'); + $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DatePropal")." : ".dol_print_date($object->date, $displaydate, false, $outputlangs, true), '', 'R'); + + $posy += 4; + $pdf->SetXY($posx, $posy); + $pdf->SetTextColor(0, 0, 60); + $pdf->MultiCell(100, 3, $outputlangs->transnoentities("DateEndPropal")." : ".dol_print_date($object->fin_validite, $displaydate, false, $outputlangs, true), '', 'R'); if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) { $posy += 4; diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 86e311b1306..1e48a826257 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -1038,6 +1038,11 @@ class pdf_cyan extends ModelePDFPropales } $posxval = 52; + if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) { + $displaydate = "daytext"; + } else { + $displaydate = "day"; + } // Show shipping date if (!empty($object->delivery_date)) { @@ -1048,7 +1053,7 @@ class pdf_cyan extends ModelePDFPropales $pdf->MultiCell(80, 4, $titre, 0, 'L'); $pdf->SetFont('', '', $default_font_size - 2); $pdf->SetXY($posxval, $posy); - $dlp = dol_print_date($object->delivery_date, "daytext", false, $outputlangs, true); + $dlp = dol_print_date($object->delivery_date, $displaydate, false, $outputlangs, true); $pdf->MultiCell(80, 4, $dlp, 0, 'L'); $posy = $pdf->GetY() + 1; @@ -1637,10 +1642,16 @@ class pdf_cyan extends ModelePDFPropales } } + if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) { + $displaydate = "daytext"; + } else { + $displaydate = "day"; + } + $posy += 4; $pdf->SetXY($posx, $posy); $pdf->SetTextColor(0, 0, 60); - $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, "day", false, $outputlangs, true), '', 'R'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, $displaydate, false, $outputlangs, true), '', 'R'); $posy += 4; $pdf->SetXY($posx, $posy); @@ -1650,7 +1661,7 @@ class pdf_cyan extends ModelePDFPropales if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) { $title .= ' - '.$outputlangsbis->transnoentities("DateEndPropal"); } - $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->fin_validite, "day", false, $outputlangs, true), '', 'R'); + $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->fin_validite, $displaydate, false, $outputlangs, true), '', 'R'); if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) { $posy += 4; diff --git a/htdocs/core/tpl/list_print_total.tpl.php b/htdocs/core/tpl/list_print_total.tpl.php index 929ea2df50f..b015dc51fdc 100644 --- a/htdocs/core/tpl/list_print_total.tpl.php +++ b/htdocs/core/tpl/list_print_total.tpl.php @@ -13,7 +13,13 @@ if (isset($totalarray['pos'])) { while ($i < $totalarray['nbfield']) { $i++; if (!empty($totalarray['pos'][$i])) { - print ''.price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0).''; + if ($totalarray['type'][$i] == 'duration') { + print (!empty($totalarray['val'][$totalarray['pos'][$i]])?convertSecondToTime($totalarray['val'][$totalarray['pos'][$i]], 'allhourmin'):0); + } else { + print price(!empty($totalarray['val'][$totalarray['pos'][$i]])?$totalarray['val'][$totalarray['pos'][$i]]:0); + } + print '
'.$langs->trans('ParentCompany').''; + print img_picto('', 'company', 'class="paddingrightonly"'); + print $form->select_thirdparty_list('', 'parent_company_id', '', $langs->trans("ThirdParty")); + print '
'.$form->editfieldkey('ProspectCustomer', 'customerprospect', '', $object, 0, 'string', '', 1).''; diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index fde749b7520..7a6df8e8beb 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -4953,7 +4953,7 @@ tr.visible { .websiteformtoolbar { position: sticky; - top: ; + top: ; } .exampleapachesetup { diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 2249e1e3ce5..cd6f04b43fb 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -4894,7 +4894,7 @@ tr.visible { .websiteformtoolbar { position: sticky; - top: ; + top: ; } .exampleapachesetup { diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 68aa2b650f7..b2f8085de5a 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -82,9 +82,9 @@ class Users extends DolibarrApi //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as t"; + $sql .= " FROM ".$this->db->prefix()."user as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c"; + $sql .= ", ".$this->db->prefix()."categorie_user as c"; } $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; if ($user_ids) { @@ -536,7 +536,7 @@ class Users extends DolibarrApi //$socid = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $societe; $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as t"; + $sql .= " FROM ".$this->db->prefix()."usergroup as t"; $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; if ($group_ids) { $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")"; diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index d9392ade9d7..42164ce8b2c 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -93,12 +93,12 @@ class UserBankAccount extends Account { $now = dol_now(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rib (fk_user, datec)"; + $sql = "INSERT INTO ".$this->db->prefix()."user_rib (fk_user, datec)"; $sql .= " VALUES (".$this->userid.", '".$this->db->idate($now)."')"; $resql = $this->db->query($sql); if ($resql) { if ($this->db->affected_rows($resql)) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."user_rib"); + $this->id = $this->db->last_insert_id($this->db->prefix()."user_rib"); return $this->update($user); } @@ -123,7 +123,7 @@ class UserBankAccount extends Account $this->create(); } - $sql = "UPDATE ".MAIN_DB_PREFIX."user_rib SET"; + $sql = "UPDATE ".$this->db->prefix()."user_rib SET"; $sql .= " bank = '".$this->db->escape($this->bank)."'"; $sql .= ",code_banque='".$this->db->escape($this->code_banque)."'"; $sql .= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; @@ -167,7 +167,7 @@ class UserBankAccount extends Account $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; $sql .= " owner_address, label, datec, tms as datem"; - $sql .= " FROM ".MAIN_DB_PREFIX."user_rib"; + $sql .= " FROM ".$this->db->prefix()."user_rib"; if ($id) { $sql .= " WHERE rowid = ".((int) $id); } diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index b1b3175aaa9..00e031c33f1 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -191,8 +191,8 @@ class UserGroup extends CommonObject $ret = array(); $sql = "SELECT g.rowid, ug.entity as usergroup_entity"; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g,"; - $sql .= " ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= " FROM ".$this->db->prefix()."usergroup as g,"; + $sql .= " ".$this->db->prefix()."usergroup_user as ug"; $sql .= " WHERE ug.fk_usergroup = g.rowid"; $sql .= " AND ug.fk_user = ".((int) $userid); if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) { @@ -241,9 +241,9 @@ class UserGroup extends CommonObject if (!empty($this->id)) { $sql .= ", ug.entity as usergroup_entity"; } - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " FROM ".$this->db->prefix()."user as u"; if (!empty($this->id)) { - $sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ", ".$this->db->prefix()."usergroup_user as ug"; } $sql .= " WHERE 1 = 1"; if (!empty($this->id)) { @@ -315,7 +315,7 @@ class UserGroup extends CommonObject // Si on a demande ajout d'un droit en particulier, on recupere // les caracteristiques (module, perms et subperms) de ce droit. $sql = "SELECT module, perms, subperms"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE id = ".((int) $rid); $sql .= " AND entity = ".((int) $entity); @@ -358,7 +358,7 @@ class UserGroup extends CommonObject if (!empty($whereforadd)) { //print "$module-$perms-$subperms"; $sql = "SELECT id"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE entity = ".((int) $entity); if (!empty($whereforadd) && $whereforadd != 'allmodules') { $sql .= " AND ".$whereforadd; @@ -372,11 +372,11 @@ class UserGroup extends CommonObject $obj = $this->db->fetch_object($result); $nid = $obj->id; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity); + $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights WHERE fk_usergroup = ".((int) $this->id)." AND fk_id=".((int) $nid)." AND entity = ".((int) $entity); if (!$this->db->query($sql)) { $error++; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")"; + $sql = "INSERT INTO ".$this->db->prefix()."usergroup_rights (entity, fk_usergroup, fk_id) VALUES (".((int) $entity).", ".((int) $this->id).", ".((int) $nid).")"; if (!$this->db->query($sql)) { $error++; } @@ -437,7 +437,7 @@ class UserGroup extends CommonObject // Si on a demande supression d'un droit en particulier, on recupere // les caracteristiques module, perms et subperms de ce droit. $sql = "SELECT module, perms, subperms"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE id = ".((int) $rid); $sql .= " AND entity = ".((int) $entity); @@ -485,7 +485,7 @@ class UserGroup extends CommonObject if (!empty($wherefordel)) { //print "$module-$perms-$subperms"; $sql = "SELECT id"; - $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; + $sql .= " FROM ".$this->db->prefix()."rights_def"; $sql .= " WHERE entity = ".((int) $entity); if (!empty($wherefordel) && $wherefordel != 'allmodules') { $sql .= " AND ".$wherefordel; @@ -503,7 +503,7 @@ class UserGroup extends CommonObject $nid = $obj->id; } - $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_rights"; + $sql = "DELETE FROM ".$this->db->prefix()."usergroup_rights"; $sql .= " WHERE fk_usergroup = $this->id AND fk_id=".((int) $nid); $sql .= " AND entity = ".((int) $entity); if (!$this->db->query($sql)) { @@ -564,7 +564,7 @@ class UserGroup extends CommonObject * Recuperation des droits */ $sql = "SELECT r.module, r.perms, r.subperms "; - $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as u, ".MAIN_DB_PREFIX."rights_def as r"; + $sql .= " FROM ".$this->db->prefix()."usergroup_rights as u, ".$this->db->prefix()."rights_def as r"; $sql .= " WHERE r.id = u.fk_id"; $sql .= " AND r.entity = ".((int) $conf->entity); $sql .= " AND u.entity = ".((int) $conf->entity); diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 24c41e5e927..dee62999cf4 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -229,6 +229,11 @@ $original_file = str_replace('..\\', '/', $original_file); // Find the subdirectory name as the reference $refname = basename(dirname($original_file)."/"); +// Check that file is allowed for view with viewimage.php +if (!dolIsAllowedForPreview($original_file)) { + accessforbidden('This file is not qualified for preview', 0, 0, 1); +} + // Security check if (empty($modulepart)) { accessforbidden('Bad value for parameter modulepart', 0, 0, 1); diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index 396646ac40a..0e66e01db01 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -1031,7 +1031,7 @@ class Website extends CommonObject fputs($fp, $line); // Warning: We must keep llx_ here. It is a generic SQL. - $line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias)'; + $line = 'INSERT INTO llx_website_page(rowid, fk_page, fk_website, pageurl, aliasalt, title, description, lang, image, keywords, status, date_creation, tms, import_key, grabbed_from, type_container, htmlheader, content, author_alias, allowed_in_frames)'; $line .= " VALUES("; $line .= $objectpageold->newid."__+MAX_llx_website_page__, "; @@ -1076,9 +1076,11 @@ class Website extends CommonObject $stringtoexport = str_replace('="image/'.$website->ref.'/', '="image/__WEBSITE_KEY__/', $stringtoexport); $line .= "'".$this->db->escape($stringtoexport)."', "; // Replace \r \n to have record on 1 line - $line .= "'".$this->db->escape($objectpageold->author_alias)."'"; + $line .= "'".$this->db->escape($objectpageold->author_alias)."', "; + $line .= "'".$this->db->escape($objectpageold->allowed_in_frames)."'"; $line .= ");"; $line .= "\n"; + fputs($fp, $line); // Add line to update home page id during import diff --git a/htdocs/website/index.php b/htdocs/website/index.php index dab79faee3b..610607f0321 100644 --- a/htdocs/website/index.php +++ b/htdocs/website/index.php @@ -274,27 +274,27 @@ $manifestjsoncontentdefault .= '{ "background_color": "#fff", "description": "A simple Web app.", "icons": [{ - "src": "images/'.$website->ref.'/homescreen48.png", + "src": "images/'.urlencode($website->ref).'/homescreen48.png", "sizes": "48x48", "type": "image/png" }, { - "src": "image/'.$website->ref.'/homescreen72.png", + "src": "image/'.urlencode($website->ref).'/homescreen72.png", "sizes": "72x72", "type": "image/png" }, { - "src": "image/'.$website->ref.'/homescreen96.png", + "src": "image/'.urlencode($website->ref).'/homescreen96.png", "sizes": "96x96", "type": "image/png" }, { - "src": "image/'.$website->ref.'/homescreen144.png", + "src": "image/'.urlencode($website->ref).'/homescreen144.png", "sizes": "144x144", "type": "image/png" }, { - "src": "image/'.$website->ref.'/homescreen168.png", + "src": "image/'.urlencode($website->ref).'/homescreen168.png", "sizes": "168x168", "type": "image/png" }, { - "src": "image/'.$website->ref.'/homescreen192.png", + "src": "image/'.urlencode($website->ref).'/homescreen192.png", "sizes": "192x192", "type": "image/png" }], @@ -2477,7 +2477,7 @@ $formother = new FormOther($db); // Confirm generation of website sitemaps if ($action == 'confirmgeneratesitemaps') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.$website->ref, $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?website='.urlencode($website->ref), $langs->trans('ConfirmSitemapsCreation'), $langs->trans('ConfirmGenerateSitemaps', $object->ref), 'generatesitemaps', '', "yes", 1); $action = 'preview'; } $helpurl = 'EN:Module_Website|FR:Module_Website_FR|ES:Módulo_Website'; @@ -2692,12 +2692,12 @@ if (!GETPOST('hide_websitemenu')) { print ''; // Regenerate all pages - print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'">'; + print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("RegenerateWebsiteContent")).'">'; // Generate site map - print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'">'; + print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("GenerateSitemaps")).'">'; - print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">'; + print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("ReplaceWebsiteContent")).'">'; } print ''; @@ -2705,11 +2705,11 @@ if (!GETPOST('hide_websitemenu')) { if ($websitekey && $websitekey != '-1' && ($action == 'preview' || $action == 'createfromclone' || $action == 'createpagefromclone' || $action == 'deletesite')) { print ''; //print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("MediaFiles")).'">'; - print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '', '/website/index.php?action=file_manager&website='.$website->ref, $disabled); + print dolButtonToOpenUrlInDialogPopup('file_manager', $langs->transnoentitiesnoconv("MediaFiles"), '', '/website/index.php?action=file_manager&website='.urlencode($website->ref).'§ion_dir='.urlencode('image/'.$website->ref.'/'), $disabled); if (!empty($conf->categorie->enabled)) { //print ''; - print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '', '/categories/index.php?leftmenu=website&nosearch=1&type=website_page&website='.$website->ref, $disabled); + print dolButtonToOpenUrlInDialogPopup('categories', $langs->transnoentitiesnoconv("Categories"), '', '/categories/index.php?leftmenu=website&nosearch=1&type=website_page&website='.urlencode($website->ref), $disabled); } print ''; @@ -2808,7 +2808,7 @@ if (!GETPOST('hide_websitemenu')) { print ''; print ''; - print 'ref.'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; + print 'ref).'" class="button bordertransp"'.$disabled.' title="'.dol_escape_htmltag($langs->trans("AddPage")).'">'; print ''; //print ''; @@ -2823,7 +2823,7 @@ if (!GETPOST('hide_websitemenu')) { $out .= $s; $out .= ''; - $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&website='.$website->ref; + $urltocreatenewpage = $_SERVER["PHP_SELF"].'?action=createcontainer&website='.urlencode($website->ref); if (!empty($conf->use_javascript_ajax)) { $out .= '