Merge pull request #9457 from frederic34/selectbarcodetype

Selectbarcodetype
This commit is contained in:
Laurent Destailleur 2018-09-12 19:02:41 +02:00 committed by GitHub
commit 7d726f9734
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 79 deletions

View File

@ -306,7 +306,7 @@ if (! empty($conf->product->enabled))
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>'; print '<td>'.$langs->trans("SetDefaultBarcodeTypeProducts").'</td>';
print '<td width="60" align="right">'; print '<td width="60" align="right">';
$formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"PRODUIT_DEFAULT_BARCODE_TYPE",1); print $formbarcode->selectBarcodeType($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE, "PRODUIT_DEFAULT_BARCODE_TYPE", 1);
print '</td></tr>'; print '</td></tr>';
} }
@ -317,7 +317,7 @@ if (! empty($conf->societe->enabled))
print '<tr class="oddeven">'; print '<tr class="oddeven">';
print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>'; print '<td>'.$langs->trans("SetDefaultBarcodeTypeThirdParties").'</td>';
print '<td width="60" align="right">'; print '<td width="60" align="right">';
print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"GENBARCODE_BARCODETYPE_THIRDPARTY",1); print $formbarcode->selectBarcodeType($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY, "GENBARCODE_BARCODETYPE_THIRDPARTY", 1);
print '</td></tr>'; print '</td></tr>';
} }

View File

@ -178,19 +178,19 @@ if ($action == 'builddoc')
{ {
// List of values to scan for a replacement // List of values to scan for a replacement
$substitutionarray = array ( $substitutionarray = array (
'%LOGIN%'=>$user->login, '%LOGIN%' => $user->login,
'%COMPANY%'=>$mysoc->name, '%COMPANY%' => $mysoc->name,
'%ADDRESS%'=>$mysoc->address, '%ADDRESS%' => $mysoc->address,
'%ZIP%'=>$mysoc->zip, '%ZIP%' => $mysoc->zip,
'%TOWN%'=>$mysoc->town, '%TOWN%' => $mysoc->town,
'%COUNTRY%'=>$mysoc->country, '%COUNTRY%' => $mysoc->country,
'%COUNTRY_CODE%'=>$mysoc->country_code, '%COUNTRY_CODE%' => $mysoc->country_code,
'%EMAIL%'=>$mysoc->email, '%EMAIL%' => $mysoc->email,
'%YEAR%'=>$year, '%YEAR%' => $year,
'%MONTH%'=>$month, '%MONTH%' => $month,
'%DAY%'=>$day, '%DAY%' => $day,
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT, '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
'%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/" '%SERVER%' => "http://".$_SERVER["SERVER_NAME"]."/",
); );
complete_substitutions_array($substitutionarray, $langs); complete_substitutions_array($substitutionarray, $langs);
@ -416,7 +416,7 @@ print $langs->trans("BarcodeType").' &nbsp; ';
print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">'; print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
$formbarcode = new FormBarCode($db); $formbarcode = new FormBarCode($db);
$formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1); print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
print '</div></div>'; print '</div></div>';
// Barcode value // Barcode value

View File

@ -1,21 +1,22 @@
<?php <?php
/* Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com> /* Copyright (C) 2007-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
* 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 * This program is free software; you can redistribute it and/or modify
* the Free Software Foundation; either version 3 of the License, or * it under the terms of the GNU General Public License as published by
* (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details. * 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/>. * 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.formbarcode.class.php * \file htdocs/core/class/html.formbarcode.class.php
@ -34,9 +35,9 @@ class FormBarCode
public $db; public $db;
/** /**
* @var string Error code (or message) * @var string Error code (or message)
*/ */
public $error=''; public $error='';
/** /**
@ -104,17 +105,33 @@ class FormBarCode
} }
/** /**
* Return form to select type of barcode * Print form to select type of barcode
* *
* @param int $selected Id code pre-selected * @param int $selected Id code pre-selected
* @param string $htmlname Name of HTML select field * @param string $htmlname Name of HTML select field
* @param int $useempty Affiche valeur vide dans liste * @param int $useempty Affiche valeur vide dans liste
* @return void * @return void
* @deprecated
*/ */
// phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps // phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
function select_barcode_type($selected='',$htmlname='barcodetype_id',$useempty=0) function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0)
{ {
global $langs,$conf; print $this->selectBarcodeType($selected, $htmlname, $useempty);
}
/**
* Return html form to select type of barcode
*
* @param int $selected Id code pre-selected
* @param string $htmlname Name of HTML select field
* @param int $useempty Display empty value in select
* @return string
*/
function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0)
{
global $langs, $conf;
$out = '';
$sql = "SELECT rowid, code, libelle"; $sql = "SELECT rowid, code, libelle";
$sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
@ -123,44 +140,37 @@ class FormBarCode
$sql.= " ORDER BY code"; $sql.= " ORDER BY code";
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result) {
{
$num = $this->db->num_rows($result); $num = $this->db->num_rows($result);
$i = 0; $i = 0;
if ($useempty && $num > 0) if ($useempty && $num > 0) {
{ $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
print '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; $out .= '<option value="0">&nbsp;</option>';
print '<option value="0">&nbsp;</option>'; } else {
}
else
{
$langs->load("errors"); $langs->load("errors");
print '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">'; $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
print '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>'; $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>';
} }
while ($i < $num) while ($i < $num) {
{
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($selected == $obj->rowid) if ($selected == $obj->rowid) {
{ $out .= '<option value="' . $obj->rowid . '" selected>';
print '<option value="'.$obj->rowid.'" selected>'; } else {
$out .= '<option value="' . $obj->rowid . '">';
} }
else $out .= $obj->libelle;
{ $out .= '</option>';
print '<option value="'.$obj->rowid.'">';
}
print $obj->libelle;
print '</option>';
$i++; $i++;
} }
print "</select>"; $out .= "</select>";
print ajax_combobox("select_".$htmlname); $out .= ajax_combobox("select_".$htmlname);
} }
else { else {
dol_print_error($this->db); dol_print_error($this->db);
} }
return $out;
} }
/** /**
@ -170,22 +180,37 @@ class FormBarCode
* @param int $selected Id condition preselected * @param int $selected Id condition preselected
* @param string $htmlname Nom du formulaire select * @param string $htmlname Nom du formulaire select
* @return void * @return void
* @deprecated
*/ */
// phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps // phpcs:ignore PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
function form_barcode_type($page, $selected='', $htmlname='barcodetype_id') function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
{ {
global $langs,$conf; print $this->formBarcodeType($page, $selected, $htmlname);
if ($htmlname != "none") }
{
print '<form method="post" action="'.$page.'">'; /**
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; * Return html form to select type of barcode
print '<input type="hidden" name="action" value="set'.$htmlname.'">'; *
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; * @param string $page Page
print '<tr><td>'; * @param int $selected Id condition preselected
$this->select_barcode_type($selected, $htmlname, 1); * @param string $htmlname Nom du formulaire select
print '</td>'; * @return string
print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">'; */
print '</td></tr></table></form>'; function formBarcodeType($page, $selected='', $htmlname='barcodetype_id')
{
global $langs, $conf;
$out = '';
if ($htmlname != "none") {
$out .= '<form method="post" action="' . $page . '">';
$out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
$out .= '<input type="hidden" name="action" value="set'.$htmlname.'">';
$out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$out .= '<tr><td>';
$out .= $this->selectBarcodeType($selected, $htmlname, 1);
$out .= '</td>';
$out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
$out .= '</td></tr></table></form>';
} }
return $out;
} }
} }

View File

@ -977,7 +977,7 @@ else
} }
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
$formbarcode = new FormBarCode($db); $formbarcode = new FormBarCode($db);
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1); print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>'; print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
$tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode; $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type); if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
@ -1343,7 +1343,7 @@ else
} }
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formbarcode.class.php';
$formbarcode = new FormBarCode($db); $formbarcode = new FormBarCode($db);
print $formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1); print $formbarcode->selectBarcodeType($fk_barcode_type, 'fk_barcode_type', 1);
print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>'; print '</td><td>'.$langs->trans("BarcodeValue").'</td><td>';
$tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode; $tmpcode=isset($_POST['barcode'])?GETPOST('barcode'):$object->barcode;
if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type); if (empty($tmpcode) && ! empty($modBarCodeProduct->code_auto)) $tmpcode=$modBarCodeProduct->getNextValue($object,$type);
@ -1639,7 +1639,7 @@ else
} }
if ($action == 'editbarcodetype') if ($action == 'editbarcodetype')
{ {
$formbarcode->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$object->id,$object->barcode_type,'fk_barcode_type'); print $formbarcode->formBarcodeType($_SERVER['PHP_SELF'].'?id='.$object->id, $object->barcode_type, 'fk_barcode_type');
} }
else else
{ {