/htdocs/core/class/html.form.class.php
PHP | 3267 lines | 1799 code | 306 blank | 1162 comment | 600 complexity | 82c19266cd83ba69aa57d06d8ea0ab60 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
Large files files are truncated, but you can click here to view the full file
- <?php
- /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
- * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
- * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
- * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
- * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
- * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
- * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
- * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
- * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
- * Copyright (C) 2011-2012 Herve Prot <herve.prot@symeos.com>
- * Copyright (C) 2012 Marcos GarcĂa <marcosgdf@gmail.com>
- *
- * 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
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/core/class/html.form.class.php
- * \ingroup core
- * \brief File of class with all html predefined components
- */
- /**
- * Class to manage generation of HTML components
- * Only common components must be here.
- */
- class Form {
- var $db;
- var $error;
- var $num;
- // Cache arrays
- var $cache_types_paiements = array();
- var $cache_conditions_paiements = array();
- var $cache_availability = array();
- var $cache_demand_reason = array();
- var $cache_types_fees = array();
- var $cache_currencies = array();
- var $cache_vatrates = array();
- var $tva_taux_value;
- var $tva_taux_libelle;
- /**
- * Constructor
- */
- public function __construct($db = '') {
- $this->db = $db;
- }
- /**
- * Output key field for an editable field
- *
- * @param string $text Text of label or key to translate
- * @param string $htmlname Name of select field
- * @param string $preselected Name of Value to show/edit (not used in this function)
- * @param object $object Object
- * @param boolean $perm Permission to allow button to edit parameter
- * @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select:xxx'...)
- * @param string $moreparam More param to add on a href URL
- * @return string HTML edit field
- */
- function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata = 'string', $moreparam = '') {
- global $conf, $langs;
- $ret = '';
- // TODO change for compatibility
- if (!preg_match('/^select;/', $typeofdata)) {
- if ($perm) {
- $tmp = explode(':', $typeofdata);
- $ret.= '<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ? ' ' . $tmp[1] : '') . '" id="' . $htmlname . '">';
- $ret.= $langs->trans($text);
- $ret.= '</div>' . "\n";
- } else {
- $ret.= $langs->trans($text);
- }
- } else {
- $ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
- $ret.=$langs->trans($text);
- $ret.='</td>';
- if (GETPOST('action') != 'edit' . $htmlname && $perm)
- $ret.='<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=edit' . $htmlname . '&id=' . $object->id . $moreparam . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>';
- $ret.='</tr></table>';
- }
- return $ret;
- }
- /**
- * Output val field for an editable field
- *
- * @param string $text Text of label (not used in this function)
- * @param string $htmlname Name of select field
- * @param string $value Value to show/edit
- * @param object $object Object
- * @param boolean $perm Permission to allow button to edit parameter
- * @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols', 'select:xxx'...)
- * @param string $editvalue When in edit mode, use this value as $value instead of value
- * @param object $extObject External object
- * @param string $success Success message
- * @param string $moreparam More param to add on a href URL
- * @return string HTML edit field
- */
- function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $success = null, $moreparam = '') {
- global $conf, $langs, $db;
- $ret = '';
- // When option to edit inline is activated
- $ret.=$this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $success);
- return $ret;
- }
- /**
- * Output edit in place form
- *
- * @param object $object Object
- * @param string $value Value to show/edit
- * @param string $htmlname DIV ID (field name)
- * @param int $condition Condition to edit
- * @param string $inputType Type of input ('numeric', 'datepicker', 'textarea:rows:cols', 'ckeditor:dolibarr_zzz:width:height:?:1:rows:cols', 'select:xxx')
- * @param string $editvalue When in edit mode, use this value as $value instead of value
- * @param object $extObject External object
- * @param string $success Success message
- * @return string HTML edit in place
- */
- private function editInPlace($object, $value, $htmlname, $condition, $inputType = 'text', $editvalue = null, $extObject = null, $success = null) {
- global $conf;
- $out = '';
- // Check parameters
- if (preg_match('/^text/', $inputType))
- $value = dol_nl2br($value);
- else if (preg_match('/^numeric/', $inputType))
- $value = price($value);
- else if ($inputType == 'datepicker')
- $value = dol_print_date($value, 'day');
- if ($condition) {
- $element = false;
- $table_element = false;
- $fk_element = false;
- $loadmethod = false;
- $savemethod = false;
- $ext_element = false;
- $button_only = true;
- if (is_object($object)) {
- $element = $object->element;
- $table_element = $object->table_element;
- $fk_element = $object->id;
- }
- if (is_object($extObject)) {
- $ext_element = $extObject->element;
- }
- if (preg_match('/^(string|email|numeric)/', $inputType)) {
- $tmp = explode(':', $inputType);
- $inputType = $tmp[0];
- if (!empty($tmp[1]))
- $inputOption = $tmp[1];
- if (!empty($tmp[2]))
- $savemethod = $tmp[2];
- }
- else if (preg_match('/^datepicker/', $inputType)) {
- $tmp = explode(':', $inputType);
- $inputType = $tmp[0];
- if (!empty($tmp[1]))
- $inputOption = $tmp[1];
- if (!empty($tmp[2]))
- $savemethod = $tmp[2];
- $out.= '<input id="timestamp" type="hidden"/>' . "\n"; // Use for timestamp format
- }
- else if (preg_match('/^(select|autocomplete)/', $inputType)) {
- $tmp = explode(':', $inputType);
- $inputType = $tmp[0];
- $loadmethod = $tmp[1];
- if (!empty($tmp[2]))
- $savemethod = $tmp[2];
- if (!empty($tmp[3]))
- $button_only = true;
- }
- else if (preg_match('/^text/', $inputType)) {
- $tmp = explode(':', $inputType);
- $inputType = $tmp[0];
- if (!empty($tmp[1]))
- $rows = $tmp[1];
- if (!empty($tmp[2]))
- $cols = $tmp[2];
- }
- else if (preg_match('/^ckeditor/', $inputType)) {
- $tmp = explode(':', $inputType);
- $inputType = $tmp[0];
- $toolbar = $tmp[1];
- if (!empty($tmp[2]))
- $width = $tmp[2];
- if (!empty($tmp[3]))
- $heigth = $tmp[3];
- if (!empty($tmp[4]))
- $savemethod = $tmp[4];
- $out.= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . "\n";
- }
- $out.= '<input id="element_id_' . $htmlname . '" type="hidden" value="' . $object->id . '"/>';
- $out.= '<input id="element_class_' . $htmlname . '" type="hidden" value="' . get_class($object) . '"/>';
- if (!empty($loadmethod))
- $out.= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . "\n";
- if (!empty($savemethod))
- $out.= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n";
- if (!empty($ext_element))
- $out.= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n";
- if (!empty($success))
- $out.= '<input id="success_' . $htmlname . '" value="' . $success . '" type="hidden"/>' . "\n";
- $out.= '<span id="viewval_' . $htmlname . '" class="viewval_' . $inputType . ($button_only ? ' inactive' : ' active') . '">';
- $out.= $object->print_fk_extrafields($htmlname);
- $out.= '</span>' . "\n";
- if (preg_match('/^tag/', $inputType)) {
- $out.= '<ul class="array_tag_handler" id="editval_' . $htmlname . '"></ul>';
- } else {
- $out.= '<span id="editval_' . $htmlname . '" class="editval_' . $inputType . ($button_only ? ' inactive' : ' active') . ' hideobject">';
- $out.= (!empty($editvalue) ? $editvalue : $value);
- $out.= '</span>' . "\n";
- }
- } else {
- if (preg_match('/^tag/', $inputType)) {
- $out.= $object->LibTag($value, array("key" => $htmlname));
- } else {
- $out.= $object->print_fk_extrafields($htmlname);
- }
- }
- return $out;
- }
- /**
- * Show a text and picto with tooltip on text or picto
- *
- * @param string $text Text to show
- * @param string $htmltext Content html of tooltip. Must be HTML/UTF8 encoded.
- * @param int $tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2
- * @param int $direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apres
- * @param string $img Code img du picto (use img_xxx() function to get it)
- * @param string $extracss Add a CSS style to td tags
- * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span
- * @param string $incbefore Include code before the text
- * @param int $noencodehtmltext Do not encode into html entity the htmltext
- * @return string Code html du tooltip (texte+picto)
- * @see Use function textwithpicto if you can.
- */
- function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 0, $incbefore = '', $noencodehtmltext = 0) {
- global $conf;
- if ($incbefore)
- $text = $incbefore . $text;
- if (!$htmltext)
- return $text;
- $tag = 'td';
- if ($notabs == 2)
- $tag = 'div';
- if ($notabs == 3)
- $tag = 'span';
- // Sanitize tooltip
- $htmltext = str_replace("\\", "\\\\", $htmltext);
- $htmltext = str_replace("\r", "", $htmltext);
- $htmltext = str_replace("\n", "", $htmltext);
- $htmltext = str_replace('"', """, $htmltext);
- if ($tooltipon == 2 || $tooltipon == 3)
- $paramfortooltipimg = ' class="classfortooltip' . ($extracss ? ' ' . $extracss : '') . '" title="' . ($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)) . '"'; // Attribut to put on td img tag to store tooltip
- else
- $paramfortooltipimg = ($extracss ? ' class="' . $extracss . '"' : ''); // Attribut to put on td text tag
- if ($tooltipon == 1 || $tooltipon == 3)
- $paramfortooltiptd = ' class="classfortooltip' . ($extracss ? ' ' . $extracss : '') . '" title="' . ($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)) . '"'; // Attribut to put on td tag to store tooltip
- else
- $paramfortooltiptd = ($extracss ? ' class="' . $extracss . '"' : ''); // Attribut to put on td text tag
- $s = "";
- if (empty($notabs))
- $s.='<table class="nobordernopadding" summary=""><tr>';
- if ($direction < 0)
- $s.='<' . $tag . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</' . $tag . '>';
- if ($text != '')
- $s.='<' . $tag . $paramfortooltiptd . '>' . (($direction < 0) ? ' ' : '') . $text . (($direction > 0) ? ' ' : '') . '</' . $tag . '>';
- if ($direction > 0)
- $s.='<' . $tag . $paramfortooltipimg . ' valign="top" width="14">' . $img . '</' . $tag . '>';
- if (empty($notabs))
- $s.='</tr></table>';
- return $s;
- }
- /**
- * Show a text with a picto and a tooltip on picto
- *
- * @param string $text Text to show
- * @param string $htmltext Content of tooltip
- * @param int $direction 1=Icon is after text, -1=Icon is before text, 0=no icon
- * @param string $type Type of picto (info, help, warning, superadmin...)
- * @param string $extracss Add a CSS style to td tags
- * @param int $noencodehtmltext Do not encode into html entity the htmltext
- * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span
- * @return string HTML code of text, picto, tooltip
- */
- function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 0) {
- global $conf;
- $alt = '';
- //For backwards compatibility
- if ($type == '0')
- $type = 'info';
- elseif ($type == '1')
- $type = 'help';
- // If info or help with no javascript, show only text
- if (empty($conf->use_javascript_ajax)) {
- if ($type == 'info' || $type == 'help')
- return $text;
- else {
- $alt = $htmltext;
- $htmltext = '';
- }
- }
- // If info or help with smartphone, show only text
- if (!empty($conf->browser->phone)) {
- if ($type == 'info' || $type == 'help')
- return $text;
- }
- if ($type == 'info')
- $img = img_help(0, $alt);
- elseif ($type == 'help')
- $img = img_help(1, $alt);
- elseif ($type == 'superadmin')
- $img = img_picto($alt, 'redstar');
- elseif ($type == 'admin')
- $img = img_picto($alt, 'star');
- elseif ($type == 'warning')
- $img = img_warning($alt);
- return $this->textwithtooltip($text, $htmltext, 2, $direction, $img, $extracss, $notabs, '', $noencodehtmltext);
- }
- /**
- * Return list of types of lines (product or service)
- * Example: 0=product, 1=service, 9=other (for external module)
- *
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in html form
- * @param int $showempty Add an empty field
- * @param int $hidetext Do not show label before combo box
- * @param string $forceall Force to show products and services in combo list, whatever are activated modules
- * @return void
- */
- function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0) {
- global $db, $langs, $user, $conf;
- // If product & services are enabled or both disabled.
- if ($forceall || (!empty($conf->product->enabled) && !empty($conf->service->enabled))
- || (empty($conf->product->enabled) && empty($conf->service->enabled))) {
- if (empty($hidetext))
- print $langs->trans("Type") . ': ';
- print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">';
- if ($showempty) {
- print '<option value="-1"';
- if ($selected == -1)
- print ' selected="selected"';
- print '> </option>';
- }
- print '<option value="0"';
- if (0 == $selected)
- print ' selected="selected"';
- print '>' . $langs->trans("Product");
- print '<option value="1"';
- if (1 == $selected)
- print ' selected="selected"';
- print '>' . $langs->trans("Service");
- print '</select>';
- //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
- }
- if (!$forceall && empty($conf->product->enabled) && !empty($conf->service->enabled)) {
- print '<input type="hidden" name="' . $htmlname . '" value="1">';
- }
- if (!$forceall && !empty($conf->product->enabled) && empty($conf->service->enabled)) {
- print '<input type="hidden" name="' . $htmlname . '" value="0">';
- }
- }
- /**
- * Load into cache cache_types_fees, array of types of fees
- *
- * @return int Nb of lines loaded, 0 if already loaded, <0 if ko
- * TODO move in DAO class
- */
- function load_cache_types_fees() {
- return false;
- /*
- global $langs;
- $langs->load("trips");
- if (count($this->cache_types_fees))
- return 0; // Cache already load
- $sql = "SELECT c.code, c.libelle as label";
- $sql.= " FROM " . MAIN_DB_PREFIX . "c_type_fees as c";
- $sql.= " ORDER BY lower(c.libelle) ASC";
- dol_syslog(get_class($this) . '::load_cache_types_fees sql=' . $sql, 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);
- // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
- $label = ($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
- $this->cache_types_fees[$obj->code] = $label;
- $i++;
- }
- return $num;
- } else {
- dol_print_error($this->db);
- return -1;
- }
- */
- }
- /**
- * Return list of types of notes
- *
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in form
- * @param int $showempty Add an empty field
- * @return void
- */
- function select_type_fees($selected = '', $htmlname = 'type', $showempty = 0) {
- global $user, $langs;
- dol_syslog(get_class($this) . "::select_type_fees " . $selected . ", " . $htmlname, LOG_DEBUG);
- $this->load_cache_types_fees();
- print '<select class="flat" name="' . $htmlname . '">';
- if ($showempty) {
- print '<option value="-1"';
- if ($selected == -1)
- print ' selected="selected"';
- print '> </option>';
- }
- foreach ($this->cache_types_fees as $key => $value) {
- print '<option value="' . $key . '"';
- if ($key == $selected)
- print ' selected="selected"';
- print '>';
- print $value;
- print '</option>';
- }
- print '</select>';
- if ($user->admin)
- print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"), 1);
- }
- /**
- * Output html form to select a third party
- *
- * @param string $selected Preselected type
- * @param string $htmlname Name of field in form
- * @param string $filter Optionnal filters criteras
- * @param int $showempty Add an empty field
- * @param int $showtype Show third party type in combolist (customer, prospect or supplier)
- * @param int $forcecombo Force to use combo box
- * @param array $event Event options
- * @return string HTML string with
- */
- function select_company($selected = '', $htmlname = 'socid', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = array()) {
- global $conf, $user, $langs;
- $out = '';
- $object = new Societe($this->db);
- try {
- $result = $object->getView("list");
- } catch (Exception $e) {
- $this->error = "Fetch : Something weird happened: " . $e->getMessage() . " (errcode=" . $e->getCode() . ")\n";
- dol_print_error($this->db, $this->error);
- return 0;
- }
- $out.= '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">';
- if ($showempty)
- $out.= '<option value="0"></option>';
- if (count($result->rows) > 0) {
- foreach ($result->rows as $aRow) {
- $obj = $aRow->value;
- $label = $obj->name;
- if ($showtype) {
- if ($obj->client || $obj->fournisseur)
- $label.=' (';
- if ($obj->client == 1 || $obj->client == 3)
- $label.=$langs->trans("Customer");
- if ($obj->client == 2 || $obj->client == 3)
- $label.=($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect");
- if ($obj->fournisseur)
- $label.=($obj->client ? ', ' : '') . $langs->trans("Supplier");
- if ($obj->client || $obj->fournisseur)
- $label.=')';
- }
- if ($selected > 0 && $selected == $obj->_id) {
- $out.= '<option value="' . $obj->_id . '" selected="selected">' . $label . '</option>';
- } else {
- $out.= '<option value="' . $obj->_id . '">' . $label . '</option>';
- }
- $i++;
- }
- }
- $out.= '</select>';
- return $out;
- }
- /**
- * Return HTML combo list of absolute discounts
- *
- * @param string $selected Id remise fixe pre-selectionnee
- * @param string $htmlname Nom champ formulaire
- * @param string $filter Criteres optionnels de filtre
- * @param int $socid Id of thirdparty
- * @param int $maxvalue Max value for lines that can be selected
- * @return int Return number of qualifed lines in list
- */
- function select_remises($selected, $htmlname, $filter, $socid, $maxvalue = 0) {
- global $langs, $conf, $db;
- $discount = new DiscountAbsolute($db);
- $result = $discount->getView('listAvailableDiscountsPerSociete', array('key' => $socid));
- // 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.= " WHERE fk_soc = " . $socid;
- // if ($filter)
- // $sql.= " AND " . $filter;
- // $sql.= " ORDER BY re.description ASC";
- //
- // dol_syslog(get_class($this) . "::select_remises sql=" . $sql);
- // $resql = $this->db->query($sql);
- if (true) {
- print '<select class="flat" name="' . $htmlname . '">';
- $num = count($result->rows); //$this->db->num_rows($resql);
- $qualifiedlines = $num;
- $i = 0;
- if ($num) {
- print '<option value="0"> </option>';
- while ($i < $num) {
- $obj = new DiscountAbsolute($this->db); //$this->db->fetch_object($resql);
- $obj->fetch($result->rows[$i]->id);
- $desc = dol_trunc($obj->description, 40);
- if ($desc == '(CREDIT_NOTE)')
- $desc = $langs->trans("CreditNote");
- if ($desc == '(DEPOSIT)')
- $desc = $langs->trans("Deposit");
- $selectstring = '';
- if ($selected > 0 && $selected == $obj->rowid)
- $selectstring = ' selected="selected"';
- $disabled = '';
- if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
- $qualifiedlines--;
- $disabled = ' disabled="disabled"';
- }
- print '<option value="' . $obj->id . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price($obj->amount_ht) . ' ' . $langs->trans("HT") . ' - ' . price($obj->amount_ttc) . ' ' . $langs->trans("TTC") . ')</option>';
- $i++;
- }
- }
- print '</select>';
- return $qualifiedlines;
- } else {
- dol_print_error($this->db);
- return -1;
- }
- }
- /**
- * Return list of all contacts (for a third party or all)
- *
- * @param int $socid Id ot third party or 0 for all
- * @param string $selected Id contact pre-selectionne
- * @param string $htmlname Name of HTML field ('none' for a not editable field)
- * @param int $showempty 0=no empty value, 1=add an empty value
- * @param string $exclude List of contacts id to exclude
- * @param string $limitto Disable answers that are not id in this array list
- * @param string $showfunction Add function into label
- * @param string $moreclass Add more class to class style
- * @param string $showsoc Add company into label
- * @return int <0 if KO, Nb of contact in list if OK
- */
- function select_contacts($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $showsoc = 0) {
- print $this->selectcontacts($socid, $selected, $htmlname, $showempty, $exclude, $limitto, $showfunction, $moreclass, $showsoc);
- return $this->num;
- }
- /**
- * Return list of all contacts (for a third party or all)
- *
- * @param int $socid Id ot third party or 0 for all
- * @param string $selected Id contact pre-selectionne
- * @param string $htmlname Name of HTML field ('none' for a not editable field)
- * @param int $showempty 0=no empty value, 1=add an empty value
- * @param string $exclude List of contacts id to exclude
- * @param string $limitto Disable answers that are not id in this array list
- * @param string $showfunction Add function into label
- * @param string $moreclass Add more class to class style
- * @param bool $options_only Return options only (for ajax treatment)
- * @param string $showsoc Add company into label
- * @return int <0 if KO, Nb of contact in list if OK
- */
- function selectcontacts($socid, $selected = '', $htmlname = 'contactid', $showempty = 0, $exclude = '', $limitto = '', $showfunction = 0, $moreclass = '', $options_only = false, $showsoc = 0) {
- return false;
- /*
- global $conf, $langs;
- $langs->load('companies');
- $out = '';
- // On recherche les societes
- $sql = "SELECT sp.rowid, sp.name as name, sp.firstname, sp.poste";
- if ($showsoc > 0) {
- $sql.= " , s.nom as company";
- }
- $sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as sp";
- if ($showsoc > 0) {
- $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc ";
- }
- $sql.= " WHERE sp.entity IN (" . getEntity('societe', 1) . ")";
- if ($socid > 0)
- $sql.= " AND sp.fk_soc=" . $socid;
- $sql.= " ORDER BY sp.name ASC";
- dol_syslog(get_class($this) . "::select_contacts sql=" . $sql);
- $resql = $this->db->query($sql);
- if ($resql) {
- $num = $this->db->num_rows($resql);
- if ($htmlname != 'none' || $options_only)
- $out.= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlname . '" name="' . $htmlname . '">';
- if ($showempty)
- $out.= '<option value="0"></option>';
- $num = $this->db->num_rows($resql);
- $i = 0;
- if ($num) {
- include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
- $contactstatic = new Contact($this->db);
- while ($i < $num) {
- $obj = $this->db->fetch_object($resql);
- $contactstatic->id = $obj->rowid;
- $contactstatic->name = $obj->name;
- $contactstatic->lastname = $obj->name;
- $contactstatic->firstname = $obj->firstname;
- if ($htmlname != 'none') {
- $disabled = 0;
- if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude))
- $disabled = 1;
- if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto))
- $disabled = 1;
- if ($selected && $selected == $obj->rowid) {
- $out.= '<option value="' . $obj->rowid . '"';
- if ($disabled)
- $out.= ' disabled="disabled"';
- $out.= ' selected="selected">';
- $out.= $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste)
- $out.= ' (' . $obj->poste . ')';
- if (($showsoc > 0) && $obj->company)
- $out.= ' - (' . $obj->company . ')';
- $out.= '</option>';
- }
- else {
- $out.= '<option value="' . $obj->rowid . '"';
- if ($disabled)
- $out.= ' disabled="disabled"';
- $out.= '>';
- $out.= $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste)
- $out.= ' (' . $obj->poste . ')';
- if (($showsoc > 0) && $obj->company)
- $out.= ' - (' . $obj->company . ')';
- $out.= '</option>';
- }
- }
- else {
- if ($selected == $obj->rowid) {
- $out.= $contactstatic->getFullName($langs);
- if ($showfunction && $obj->poste)
- $out.= ' (' . $obj->poste . ')';
- if (($showsoc > 0) && $obj->company)
- $out.= ' - (' . $obj->company . ')';
- }
- }
- $i++;
- }
- }
- else {
- $out.= '<option value="-1" selected="selected" disabled="disabled">' . $langs->trans("NoContactDefined") . '</option>';
- }
- if ($htmlname != 'none' || $options_only) {
- $out.= '</select>';
- }
- $this->num = $num;
- return $out;
- } else {
- dol_print_error($this->db);
- return -1;
- }
- */
- }
- /**
- * Return list of products for customer in Ajax if Ajax activated or go to select_produits_do
- *
- * @param int $selected Preselected products
- * @param string $htmlname Name of HTML seletc field (must be unique in page)
- * @param int $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param int $limit Limit on number of returned lines
- * @param int $price_level Level of price to show
- * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
- * @param int $finished 2=all, 1=finished, 0=raw material
- * @param string $selected_input_value Value of preselected input text (with ajax)
- * @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after)
- * @param array $ajaxoptions Options for ajax_autocompleter
- * @return void
- */
- function select_produits($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $status = 1, $finished = 2, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array()) {
- global $langs, $conf;
- $price_level = (!empty($price_level) ? $price_level : 0);
- if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
- $placeholder = '';
- if ($selected && empty($selected_input_value)) {
- require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
- $product = new Product($this->db);
- $product->fetch($selected);
- $selected_input_value = $product->ref;
- }
- // mode=1 means customers products
- $urloption = 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished;
- print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
- if (empty($hidelabel))
- print $langs->trans("RefOrLabel") . ' : ';
- else if ($hidelabel > 1) {
- if (!empty($conf->global->MAIN_HTML5_PLACEHOLDER))
- $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
- else
- $placeholder = ' title="' . $langs->trans("RefOrLabel") . '"';
- if ($hidelabel == 2) {
- print img_picto($langs->trans("Search"), 'search');
- }
- }
- print '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' />';
- if ($hidelabel == 3) {
- print img_picto($langs->trans("Search"), 'search');
- }
- } else {
- $this->select_produits_do($selected, $htmlname, $filtertype, $limit, $price_level, '', $status, $finished, 0);
- }
- }
- /**
- * Return list of products for a customer
- *
- * @param int $selected Preselected product
- * @param string $htmlname Name of select html
- * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param int $limit Limite sur le nombre de lignes retournees
- * @param int $price_level Level of price to show
- * @param string $filterkey Filter on product
- * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
- * @param int $finished Filter on finished field: 2=No filter
- * @param int $disableout Disable print output
- * @return array Array of keys for json
- */
- function select_produits_do($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $filterkey = '', $status = 1, $finished = 2, $disableout = 0) {
- return false;
- /*
- global $langs, $conf, $user, $db;
- $sql = "SELECT ";
- $sql.= " p.rowid, p.label, p.ref, p.description, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.stock";
- // Multilang : we add translation
- if (!empty($conf->global->MAIN_MULTILANGS)) {
- $sql.= ", pl.label as label_translated";
- }
- $sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
- // 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 AND pl.lang='" . $langs->getDefaultLang() . "'";
- }
- $sql.= ' WHERE p.entity IN (' . getEntity('product', 1) . ')';
- if ($finished == 0) {
- $sql.= " AND p.finished = " . $finished;
- } elseif ($finished == 1) {
- $sql.= " AND p.finished = " . $finished;
- if ($status >= 0)
- $sql.= " AND p.tosell = " . $status;
- }
- elseif ($status >= 0) {
- $sql.= " AND p.tosell = " . $status;
- }
- if (strval($filtertype) != '')
- $sql.=" AND p.fk_product_type=" . $filtertype;
- // Add criteria on ref/label
- if ($filterkey && $filterkey != '') {
- if (!empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) { // Can use index
- $sql.=" AND (p.ref LIKE '" . $filterkey . "%' OR p.label LIKE '" . $filterkey . "%'";
- if (!empty($conf->global->MAIN_MULTILANGS))
- $sql.=" OR pl.label LIKE '" . $filterkey . "%'";
- $sql.=")";
- }
- else {
- $sql.=" AND (p.ref LIKE '%" . $filterkey . "%' OR p.label LIKE '%" . $filterkey . "%'";
- if (!empty($conf->global->MAIN_MULTILANGS))
- $sql.=" OR pl.label LIKE '%" . $filterkey . "%'";
- $sql.=")";
- }
- if (!empty($conf->barcode->enabled)) {
- $sql .= " OR p.barcode LIKE '" . $filterkey . "'";
- }
- }
- $sql.= $db->order("p.ref");
- $sql.= $db->plimit($limit);
- // Build output string
- $outselect = '';
- $outjson = array();
- $result = $this->db->query($sql);
- if ($result) {
- $num = $this->db->num_rows($result);
- $outselect.='<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">';
- $outselect.='<option value="0" selected="selected"> </option>';
- $i = 0;
- while ($num && $i < $num) {
- $outkey = '';
- $outval = '';
- $outref = '';
- $outlabel = '';
- $outdesc = '';
- $outtype = '';
- $outprice_ht = '';
- $outprice_ttc = '';
- $outpricebasetype = '';
- $outtva_tx = '';
- $objp = $this->db->fetch_object($result);
- $label = $objp->label;
- if (!empty($objp->label_translated))
- $label = $objp->label_translated;
- if ($filterkey && $filterkey != '')
- $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
- $outkey = $objp->rowid;
- $outref = $objp->ref;
- $outlabel = $objp->label;
- $outdesc = $objp->description;
- $outtype = $objp->fk_product_type;
- $opt = '<option value="' . $objp->rowid . '"';
- $opt.= ($objp->rowid == $selected) ? ' selected="selected"' : '';
- if (!empty($conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock)) {
- if ($objp->stock > 0) {
- $opt.= ' style="background-color:#32CD32; color:#F5F5F5;"';
- } else if ($objp->stock <= 0) {
- $opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
- }
- }
- $opt.= '>';
- $opt.= $objp->ref . ' - ' . dol_trunc($label, 32) . ' - ';
- $objRef = $objp->ref;
- if ($filterkey && $filterkey != '')
- $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
- $outval.=$objRef . ' - ' . dol_trunc($label, 32) . ' - ';
- $found = 0;
- $currencytext = $langs->trans("Currency" . $conf->currency);
- $currencytextnoent = $langs->transnoentities("Currency" . $conf->currency);
- if (dol_strlen($currencytext) > 10)
- $currencytext = $conf->currency; // If text is too long, we use the short code
- if (dol_strlen($currencytextnoent) > 10)
- $currencytextnoent = $conf->currency; // If text is too long, we use the short code
- // Multiprice
- if ($price_level >= 1) { // If we need a particular price level (from 1 to 6)
- $sql = "SELECT price, price_ttc, price_base_type, tva_tx";
- $sql.= " FROM " . MAIN_DB_PREFIX . "product_price";
- $sql.= " WHERE fk_product='" . $objp->rowid . "'";
- $sql.= " AND price_level=" . $price_level;
- $sql.= " ORDER BY date_price";
- $sql.= " DESC LIMIT 1";
- dol_syslog(get_class($this) . "::select_produits_do search price for level '.$price_level.' sql=" . $sql);
- $result2 = $this->db->query($sql);
- if ($result2) {
- $objp2 = $this->db->fetch_object($result2);
- if ($objp2) {
- $found = 1;
- if ($objp2->price_base_type == 'HT') {
- $opt.= price($objp2->price, 1) . ' ' . $currencytext . ' ' . $langs->trans("HT");
- $outval.= price($objp2->price, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("HT");
- } else {
- $opt.= price($objp2->price_ttc, 1) . ' ' . $currencytext . ' ' . $langs->trans("TTC");
- $outval.= price($objp2->price_ttc, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("TTC");
- }
- $outprice_ht = price($objp2->price);
- $outprice_ttc = price($objp2->price_ttc);
- $outpricebasetype = $objp2->price_base_type;
- $outtva_tx = $objp2->tva_tx;
- }
- } else {
- dol_print_error($this->db);
- }
- }
- // If level no defined or multiprice not found, we used the default price
- if (!$found) {
- if ($objp->price_base_type == 'HT') {
- $opt.= price($objp->price, 1) . ' ' . $currencytext . ' ' . $langs->trans("HT");
- $outval.= price($objp->price, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("HT");
- } else {
- $opt.= price($objp->price_ttc, 1) . ' ' . $currencytext . ' ' . $langs->trans("TTC");
- $outval.= price($objp->price_ttc, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("TTC");
- }
- $outprice_ht = price($objp->price);
- $outprice_ttc = price($objp->price_ttc);
- $outpricebasetype = $objp->price_base_type;
- $outtva_tx = $objp->tva_tx;
- }
- if (!empty($conf->stock->enabled) && isset($objp->stock) && $objp->fk_product_type == 0) {
- $opt.= ' - ' . $langs->trans("Stock") . ':' . $objp->stock;
- $outval.=' - ' . $langs->transnoentities("Stock") . ':' . $objp->stock;
- }
- if ($objp->duration) {
- $duration_value = substr($objp->duration, 0, dol_strlen($objp->duration) - 1);
- $duration_unit = substr($objp->duration, -1);
- if ($duration_value > 1) {
- $dur = array("h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years"));
- } else {
- $dur = array("h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year"));
- }
- $opt.= ' - ' . $duration_value . ' ' . $langs->trans($dur[$duration_unit]);
- $outval.=' - ' . $duration_value . ' ' . $langs->transnoentities($dur[$duration_unit]);
- }
- $opt.= "</option>\n";
- // Add new entry
- // "key" value of json key array is used by jQuery automatically as selected value
- // "label" value of json key array is used by jQuery automatically as text for combo box
- $outselect.=$opt;
- array_push($outjson, array('key' => $outkey, 'value' => $outref, 'label' => $outval, 'label2' => $outlabel, 'desc' => $outdesc, 'type' => $outtype, 'price_ht' => $outprice_ht, 'price_ttc' => $outprice_ttc, 'pricebasetype' => $outpricebasetype, 'tva_tx' => $outtva_tx));
- $i++;
- }
- $outselect.='</select>';
- $this->db->free($result);
- if (empty($disableout))
- print $outselect;
- return $outjson;
- }
- else {
- dol_print_error($db);
- }
- */
- }
- /**
- * Return list of products for a customer
- *
- * @param int $selected Preselected product
- * @param string $htmlname Name of select html
- * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param int $limit Limite sur le nombre de lignes retournees
- * @param int $price_level Level of price to show
- * @param string $filterkey Filter on product
- * @param int $status -1=Return all products, 0=Products not on sell, 1=Products on sell
- * @param int $finished Filter on finished field: 2=No filter
- * @param int $disableout Disable print output
- * @return array Array of keys for json
- */
- function select_products($selected = '', $htmlname = 'productid', $filtertype = '', $limit = 20, $price_level = 0, $filterkey = '', $status = 1, $finished = 2, $disableout = 0) {
- global $langs, $conf, $user, $db;
- require_once(DOL_DOCUMENT_ROOT . '/product/class/product.class.php');
- $object = new Product($db);
- $result = $object->getView('list', array('startkey' => $filterkey, 'endkey' => $filterkey . 'Z'));
- // $sql = "SELECT ";
- // $sql.= " p.rowid, p.label, p.ref, p.description, p.fk_product_type, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.duration, p.stock";
- // // Multilang : we add translation
- // if (!empty($conf->global->MAIN_MULTILANGS)) {
- // $sql.= ", pl.label as label_translated";
- // }
- // $sql.= " FROM " . MAIN_DB_PREFIX . "product as p";
- // // 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 AND pl.lang='" . $langs->getDefaultLang() . "'";
- // }
- // $sql.= ' WHERE p.entity IN (' . getEntity('product', 1) . ')';
- // if ($finished == 0) {
- // $sql.= " AND p.finished = " . $finished;
- // } elseif ($finished == 1) {
- // $sql.= " AND p.finished = " . $finished;
- // if ($status >= 0)
- // $sql.= " AND p.tosell = " . $status;
- // }
- // elseif ($status >= 0) {
- // $sql.= " AND p.tosell = " . $status;
- // }
- // if (strval($filtertype) != '')
- // $sql.=" AND p.fk_product_type=" . $filtertype;
- // // Add criteria on ref/label
- // if ($filterkey && $filterkey != '') {
- // if (!empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE)) { // Can use index
- // $sql.=" AND (p.ref LIKE '" . $filterkey . "%' OR p.label LIKE '" . $filterkey . "%'";
- // if (!empty($conf->global->MAIN_MULTILANGS))
- // $sql.=" OR pl.label LIKE '" . $filterkey . "%'";
- // $sql.=")";
- // }
- // else {
- // $sql.=" AND (p.ref LIKE '%" . $filterkey . "%' OR p.label LIKE '%" . $filterkey . "%'";
- // if (!empty($conf->global->MAIN_MULTILANGS))
- // $sql.=" OR pl.label LIKE '%" . $filterkey . "%'";
- // $sql.=")";
- // }
- //
- // if (!empty($conf->barcode->enabled)) {
- // $sql .= " OR p.barcode LIKE '" . $filterkey . "'";
- // }
- // }
- // $sql.= $db->order("p.ref");
- // $sql.= $db->plimit($limit);
- //
- // // Build output string
- $outselect = '';
- $outjson = array();
- //
- // dol_syslog(get_class($this) . "::select_produits_do search product sql=" . $sql, LOG_DEBUG);
- // $result = $this->db->query($sql);
- if (!empty($result->rows)) {
- $num = count($result->rows);
- $outselect.='<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">';
- $outselect.='<option value="0" selected="selected"> </option>';
- $i = 0;
- while ($num && $i < $num) {
- $outkey = '';
- $outval = '';
- $outref = '';
- $outlabel = '';
- $outdesc = '';
- $outtype = '';
- $outprice_ht = '';
- $outprice_ttc = '';
- $outpricebasetype = '';
- $outtva_tx = '';
- // $objp = $this->db->fetch_object($result);
- $objp = new Product($db);
- $objp->fetch($result->rows[$i]->value->_id);
- $label = $objp->label;
- if (!empty($objp->label_translated))
- $label = $objp->label_translated;
- if ($filterkey && $filterkey != '')
- $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
- $outkey = $objp->id;
- $outref = $objp->name;
- $outlabel = $objp->label;
- $outdesc = isset($objp->description) ? $objp->description : '';
- $outtype = $objp->type;
- $opt = '<option value="' . $objp->id . '"';
- $opt.= ($objp->id == $selected) ? ' selected="selected"' : '';
- if (!empty($conf->stock->enabled) && $objp->type == 'PRODUCT' && isset($objp->stock)) {
- if ($objp->stock > 0) {
- $opt.= ' style="background-color:#32CD32; color:#F5F5F5;"';
- } else if ($objp->stock <= 0) {
- $opt.= ' style="background-color:#FF0000; color:#F5F5F5;"';
- }
- }
- $opt.= '>';
- $opt.= $objp->name . ' - ' . dol_trunc($label, 32) . ' - ';
- $objRef = $objp->name;
- if ($filterkey && $filterkey != '')
- $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
- $outval.=$objRef . ' - ' . dol_trunc($label, 32) . ' - ';
- $found = 0;
- $currencytext = $langs->trans("Currency" . $conf->currency);
- $currencytextnoent = $langs->transnoentities("Currency" . $conf->currency);
- if (dol_strlen($currencytext) > 10)
- $currencytext = $conf->currency; // If text is too long, we use the short code
- if (dol_strlen($currencytextnoent) > 10)
- $currencytextnoent = $conf->currency; // If text is too long, we use the short code
-
- // Multiprice
- // if ($price_level >= 1) { // If we need a particular price level (from 1 to 6)
- // $sql = "SELECT price, price_ttc, price_base_type, tva_tx";
- // $sql.= " FROM " . MAIN_DB_PREFIX . "product_price";
- // $sql.= " WHERE fk_product='" . $objp->rowid . "'";
- // $sql.= " AND price_level=" . $price_level;
- // $sql.= " ORDER BY date_price";
- // $sql.= " DESC LIMIT 1";
- //
- // dol_syslog(get_class($this) . "::select_produits_do search price for level '.$price_level.' sql=" . $sql);
- // $result2 = $this->db->query($sql);
- // if ($result2) {
- // $objp2 = $this->db->fetch_object($result2);
- // if ($objp2) {
- // $found = 1;
- // if ($objp2->price_base_type == 'HT') {
- // $opt.= price($objp2->price, 1) . ' ' . $currencytext . ' ' . $langs->trans("HT");
- // $outval.= price($objp2->price, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("HT");
- // } else {
- // $opt.= price($objp2->price_ttc, 1) . ' ' . $currencytext . ' ' . $langs->trans("TTC");
- // $outval.= price($objp2->price_ttc, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("TTC");
- // }
- // $outprice_ht = price($objp2->price);
- // $outprice_ttc = price($objp2->price_ttc);
- // $outpricebasetype = $objp2->price_base_type;
- // $outtva_tx = $objp2->tva_tx;
- // }
- // } else {
- // dol_print_error($this->db);
- // }
- // }
- // If level no defined or multiprice not found, we used the default price
- if (!$found) {
- if ($objp->price->price_base_type == 'HT') {
- $opt.= price($objp->price->price, 1) . ' ' . $currencytext . ' ' . $langs->trans("HT");
- $outval.= price($objp->price->price, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("HT");
- } else {
- $opt.= price($objp->price->price_ttc, 1) . ' ' . $currencytext . ' ' . $langs->trans("TTC");
- $outval.= price($objp->price->price_ttc, 1) . ' ' . $currencytextnoent . ' ' . $langs->transnoentities("TTC");
- }
- $outprice_ht = price($objp->price->price);
- $outprice_ttc = price($objp->price->price_ttc);
- $outpricebasetype = $objp->price->price_base_type;
- $outtva_tx = $objp->price->tva_tx;
- }
- if (!empty($conf->stock->enabled) && isset($objp->stock) && $objp->type == "PRODUCT") {
- $opt.= ' - ' . $langs->trans("Stock") . ':' . $objp->stock;
- $outval.=' - ' . $langs->transnoentities("Stock") . ':' . $objp->stock;
- }
- if ($objp->duration) {
- $duration_value = substr($objp->duration, 0, dol_strlen($objp->duration) - 1);
- $duration_unit = substr($objp->duration, -1);
- if ($duration_value > 1) {
- $dur = array("h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years"));
- } else {
- $dur = array("h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year"));
- }
- $opt.= ' - ' . $duration_value . ' ' . $langs->trans($dur[$duration_unit]);
- $outval.=' - ' . $duration_value . ' ' . $langs->transnoentities($dur[$duration_unit]);
- }
- $opt.= "</option>\n";
- // Add new entry
- // "key" value of json key array is used by jQuery automatically as selected value
- // "label" value of json key array is used by jQuery automatically as text for combo box
- $outselect.=$opt;
- array_push($outjson, array('key' => $outkey, 'value' => $outref, 'label' => $outval, 'label2' => $outlabel, 'desc' => $outdesc, 'type' => $outtype, 'price_ht' => $outprice_ht, 'price_ttc' => $outprice_ttc, 'pricebasetype' => $outpricebasetype, 'tva_tx' => $outtva_tx));
- $i++;
- }
- $outselect.='</select>';
- // $this->db->free($result);
- if (empty($disableout))
- print $outselect;
- return $outjson;
- }
- }
- /**
- * Return list of products for customer (in Ajax if Ajax activated or go to select_produits_fournisseurs_do)
- *
- * @param int $socid Id third party
- * @param string $selected Preselected product
- * @param string $htmlname Name of HTML Select
- * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
- * @param string $filtre For a SQL filter
- * @param array $ajaxopt…
Large files files are truncated, but you can click here to view the full file