--- /tmp/dsg/dolibarr/htdocs/core/modules/barcode/github_mod_barcode_product_standard.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/barcode/client_mod_barcode_product_standard.php @@ -1,7 +1,7 @@ * Copyright (C) 2006-2014 Laurent Destailleur - * Copyright (C) 2007-2012 Regis Houssin + * Copyright (C) 2007-2012 Regis Houssin * Copyright (C) 2011 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -15,8 +15,8 @@ * 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 . - * or see https://www.gnu.org/ + * along with this program. If not, see . + * or see http://www.gnu.org/ */ /** @@ -33,38 +33,23 @@ */ class mod_barcode_product_standard extends ModeleNumRefBarCode { - public $name = 'Standard'; // Model Name - - public $code_modifiable; // Editable code - - public $code_modifiable_invalide; // Modified code if it is invalid - - public $code_modifiable_null; // Modified code if it is null - - public $code_null; // Optional code - - /** - * Dolibarr version of the loaded document - * @var string - */ - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' - - /** - * @var int Automatic numbering - */ - public $code_auto; - - public $searchcode; // Search string - - public $numbitcounter; // Number of digits the counter - - public $prefixIsRequired; // The prefix field of third party must be filled when using {pre} + var $name='Standard'; // Model Name + var $code_modifiable; // Editable code + var $code_modifiable_invalide; // Modified code if it is invalid + var $code_modifiable_null; // Modified code if it is null + var $code_null; // Optional code + var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' + var $code_auto; // Automatic Numbering + + var $searchcode; // Search string + var $numbitcounter; // Number of digits the counter + var $prefixIsRequired; // The prefix field of third party must be filled when using {pre} /** * Constructor */ - public function __construct() + function __construct() { $this->code_null = 0; $this->code_modifiable = 1; @@ -80,39 +65,36 @@ * @param Translate $langs Object langs * @return string Description of module */ - public function info($langs) + function info($langs) { global $conf, $mc; global $form; $langs->load("products"); - $disabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); + $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); $texte = $langs->trans('GenericNumRefModelDesc')."
\n"; - $texte .= '
'; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - - $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode")); - $tooltip .= $langs->trans("GenericMaskCodes3"); - $tooltip .= ''.$langs->trans("Example").':
'; - $tooltip .= '020{000000000} (for internal use)
'; - $tooltip .= '9771234{00000} (example of ISSN code with prefix 1234)
'; - $tooltip .= '9791234{00000} (example of ISMN code with prefix 1234)
'; - //$tooltip.=$langs->trans("GenericMaskCodes5"); + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= ''; + $texte.= '
'; + + $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("BarCode"),$langs->transnoentities("BarCode")); + $tooltip.=$langs->trans("GenericMaskCodes3"); + $tooltip.=$langs->trans("GenericMaskCodes4c"); + $tooltip.=$langs->trans("GenericMaskCodes5"); // Mask parameter //$texte.= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - - $texte .= '
'.$langs->trans("Mask").' ('.$langs->trans("BarCodeModel").'):
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).' 
'; - $texte .= '
'; + $texte.= ''.$langs->trans("Mask").':'; + $texte.= ''.$form->textwithpicto('',$tooltip,1,1).''; + $texte.= '  '; + $texte.= ''; + + $texte.= ''; + $texte.= ''; return $texte; } @@ -125,17 +107,17 @@ * @param Product $objproduct Object product * @return string Return string example */ - public function getExample($langs, $objproduct = 0) - { - $examplebarcode = $this->getNextValue($objproduct, ''); - if (!$examplebarcode) + function getExample($langs,$objproduct=0) + { + $examplebarcode = $this->getNextValue($objproduct,0); + if (! $examplebarcode) { $examplebarcode = $langs->trans('NotConfigured'); } - if ($examplebarcode == "ErrorBadMask") + if($examplebarcode=="ErrorBadMask") { $langs->load("errors"); - $examplebarcode = $langs->trans($examplebarcode); + $examplebarcode=$langs->trans($examplebarcode); } return $examplebarcode; @@ -145,32 +127,32 @@ * Return next value * * @param Product $objproduct Object product - * @param string $type Type of barcode (EAN, ISBN, ...) + * @param string $type type of barcode (EAN, ISBN, ...) * @return string Value if OK, '' if module not configured, <0 if KO */ - public function getNextValue($objproduct = null, $type = '') - { - global $db, $conf; - - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + function getNextValue($objproduct,$type='') + { + global $db,$conf; + + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; // TODO // Get Mask value $mask = ''; - if (!empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK; + if (! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK; if (empty($mask)) { - $this->error = 'NotConfigured'; + $this->error='NotConfigured'; return ''; } - $field = 'barcode'; $where = ''; - - $now = dol_now(); - - $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); + $field='barcode';$where=''; + + $now=dol_now(); + + $numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now); return $numFinal; } @@ -190,39 +172,48 @@ * -3 ErrorCustomerCodeAlreadyUsed * -4 ErrorPrefixRequired */ - public function verif($db, &$code, $product, $thirdparty_type, $type) + function verif($db, &$code, $product, $thirdparty_type, $type) { global $conf; //var_dump($code.' '.$product->ref.' '.$thirdparty_type);exit; - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - - $result = 0; + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; + + $result=0; $code = strtoupper(trim($code)); if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) { - $result = 0; - } elseif (empty($code) && (!$this->code_null || !empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK))) - { - $result = -2; - } else { + $result=0; + } + else if (empty($code) && (! $this->code_null || ! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) ) + { + $result=-2; + } + else + { if ($this->verif_syntax($code, $type) >= 0) { $is_dispo = $this->verif_dispo($db, $code, $product); if ($is_dispo <> 0) { - $result = -3; - } else { - $result = 0; - } - } else { + $result=-3; + } + else + { + $result=0; + } + } + else + { if (dol_strlen($code) == 0) { - $result = -2; - } else { - $result = -1; + $result=-2; + } + else + { + $result=-1; } } } @@ -232,80 +223,70 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return if a code is used (by other element) - * - * @param DoliDB $db Handler acces base - * @param string $code Code to check - * @param Product $product Objet product - * @return int 0 if available, <0 if KO - */ - public function verif_dispo($db, $code, $product) - { - // phpcs:enable + /** + * Return if a code is used (by other element) + * + * @param DoliDB $db Handler acces base + * @param string $code Code a verifier + * @param Product $product Objet product + * @return int 0 if available, <0 if KO + */ + function verif_dispo($db, $code, $product) + { $sql = "SELECT barcode FROM ".MAIN_DB_PREFIX."product"; - $sql .= " WHERE barcode = '".$db->escape($code)."'"; - if ($product->id > 0) $sql .= " AND rowid <> ".$product->id; - - $resql = $db->query($sql); + $sql.= " WHERE barcode = '".$code."'"; + if ($product->id > 0) $sql.= " AND rowid <> ".$product->id; + + $resql=$db->query($sql); if ($resql) { if ($db->num_rows($resql) == 0) { return 0; - } else { + } + else + { return -1; } - } else { + } + else + { return -2; } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + + } + /** * Return if a barcode value match syntax * * @param string $codefortest Code to check syntax - * @param string $typefortest Type of barcode (ISBN, EAN, ...) + * @param string $typefortest Type of barcode (ISBN, EAN, ...) * @return int 0 if OK, <0 if KO */ - public function verif_syntax($codefortest, $typefortest) - { - // phpcs:enable + function verif_syntax($codefortest, $typefortest) + { global $conf; - $result = 0; + $res = 0; // Get Mask value - $mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK) ? '' : $conf->global->BARCODE_STANDARD_PRODUCT_MASK; - if (!$mask) - { - $this->error = 'NotConfigured'; - return -1; - } - - dol_syslog(get_class($this).'::verif_syntax codefortest='.$codefortest." typefortest=".$typefortest); - - $newcodefortest = $codefortest; - - // Special case, if mask is on 12 digits instead of 13, we remove last char into code to test - if (in_array($typefortest, array('EAN13', 'ISBN'))) // We remove the CRC char not included into mask - { - if (preg_match('/\{(0+)([@\+][0-9]+)?([@\+][0-9]+)?\}/i', $mask, $reg)) - { - if (strlen($reg[1]) == 12) $newcodefortest = substr($newcodefortest, 0, 12); - dol_syslog(get_class($this).'::verif_syntax newcodefortest='.$newcodefortest); - } - } - - $result = check_value($mask, $newcodefortest); - if (is_string($result)) - { - $this->error = $result; - return -1; - } + $mask = empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)?'':$conf->global->BARCODE_STANDARD_PRODUCT_MASK; + if (! $mask) + { + $this->error='NotConfigured'; + return ''; + } + + $newcodefortest=$codefortest; + if (in_array($typefortest,array('EAN13','ISBN'))) // We remove the CRC char not included into mask + { + $newcodefortest=substr($newcodefortest,0,12); + } + + $result=check_value($mask,$newcodefortest); return $result; } + } + --- /tmp/dsg/dolibarr/htdocs/core/modules/barcode/github_modules_barcode.class.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/barcode/client_modules_barcode.class.php @@ -29,21 +29,21 @@ */ abstract class ModeleBarCode { - /** - * @var string Error code (or message) - */ - public $error = ''; + /** + * @var string Error code (or message) + */ + public $error = ''; - /** - * Return if a model can be used or not - * - * @return boolean true if model can be used - */ - public function isEnabled() - { - return true; - } + /** + * Return if a model can be used or not + * + * @return boolean true if model can be used + */ + public function isEnabled() + { + return true; + } } @@ -52,128 +52,128 @@ */ abstract class ModeleNumRefBarCode { - /** - * @var string Error code (or message) - */ - public $error = ''; + /** + * @var string Error code (or message) + */ + public $error = ''; - /** Return default description of numbering model - * - * @param Translate $langs Object langs - * @return string Descriptive text - */ - public function info($langs) - { - $langs->load("bills"); - return $langs->trans("NoDescription"); - } + /** Return default description of numbering model + * + * @param Translate $langs Object langs + * @return string Descriptive text + */ + public function info($langs) + { + $langs->load("bills"); + return $langs->trans("NoDescription"); + } - /** Return model name - * - * @param Translate $langs Object langs - * @return string Model name - */ - public function getNom($langs) - { - return empty($this->name) ? $this->nom : $this->name; - } + /** Return model name + * + * @param Translate $langs Object langs + * @return string Model name + */ + public function getNom($langs) + { + return empty($this->name) ? $this->nom : $this->name; + } - /** Return a numbering example - * - * @param Translate $langs Object langs - * @return string Example - */ - public function getExample($langs) - { - $langs->load("bills"); - return $langs->trans("NoExample"); - } + /** Return a numbering example + * + * @param Translate $langs Object langs + * @return string Example + */ + public function getExample($langs) + { + $langs->load("bills"); + return $langs->trans("NoExample"); + } - /** - * Return next value available - * - * @param Product $objproduct Object Product - * @param string $type Type of barcode (EAN, ISBN, ...) - * @return string Value - */ - public function getNextValue($objproduct, $type = '') - { - global $langs; - return $langs->trans("Function_getNextValue_InModuleNotWorking"); - } + /** + * Return next value available + * + * @param Product $objproduct Object Product + * @param string $type Type of barcode (EAN, ISBN, ...) + * @return string Value + */ + public function getNextValue($objproduct, $type = '') + { + global $langs; + return $langs->trans("Function_getNextValue_InModuleNotWorking"); + } - /** Return version of module - * - * @return string Version - */ - public function getVersion() - { - global $langs; - $langs->load("admin"); + /** Return version of module + * + * @return string Version + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); - if ($this->version == 'dolibarr') return DOL_VERSION; - if ($this->version) return $this->version; - return $langs->trans("NotAvailable"); - } + if ($this->version == 'development') return $langs->trans("VersionDevelopment"); + if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); + if ($this->version == 'dolibarr') return DOL_VERSION; + if ($this->version) return $this->version; + return $langs->trans("NotAvailable"); + } - /** - * Return description of module parameters - * - * @param Translate $langs Output language - * @param Societe $soc Third party object - * @param int $type -1=Nothing, 0=Product, 1=Service - * @return string HTML translated description - */ - public function getToolTip($langs, $soc, $type) - { - global $conf; + /** + * Return description of module parameters + * + * @param Translate $langs Output language + * @param Societe $soc Third party object + * @param int $type -1=Nothing, 0=Product, 1=Service + * @return string HTML translated description + */ + public function getToolTip($langs, $soc, $type) + { + global $conf; - $langs->load("admin"); + $langs->load("admin"); - $s = ''; - $s .= $langs->trans("Name").': '.$this->name.'
'; - $s .= $langs->trans("Version").': '.$this->getVersion().'
'; - if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
'; - $s .= '
'; - $s .= ''.$langs->trans("ThisIsModuleRules").':
'; - if ($type == 0) - { - $s .= $langs->trans("RequiredIfProduct").': '; - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; - $s .= yn(!$this->code_null, 1, 2); - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; - $s .= '
'; - } - if ($type == 1) - { - $s .= $langs->trans("RequiredIfService").': '; - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; - $s .= yn(!$this->code_null, 1, 2); - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; - $s .= '
'; - } - if ($type == -1) - { - $s .= $langs->trans("Required").': '; - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; - $s .= yn(!$this->code_null, 1, 2); - if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; - $s .= '
'; - } - /*$s.=$langs->trans("CanBeModifiedIfOk").': '; + $s = ''; + $s .= $langs->trans("Name").': '.$this->name.'
'; + $s .= $langs->trans("Version").': '.$this->getVersion().'
'; + if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
'; + $s .= '
'; + $s .= ''.$langs->trans("ThisIsModuleRules").':
'; + if ($type == 0) + { + $s .= $langs->trans("RequiredIfProduct").': '; + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; + $s .= yn(!$this->code_null, 1, 2); + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; + $s .= '
'; + } + if ($type == 1) + { + $s .= $langs->trans("RequiredIfService").': '; + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; + $s .= yn(!$this->code_null, 1, 2); + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; + $s .= '
'; + } + if ($type == -1) + { + $s .= $langs->trans("Required").': '; + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ''; + $s .= yn(!$this->code_null, 1, 2); + if (!empty($conf->global->MAIN_BARCODE_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; + $s .= '
'; + } + /*$s.=$langs->trans("CanBeModifiedIfOk").': '; $s.=yn($this->code_modifiable,1,2); $s.='
'; $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'
'; */ - $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'
'; - $s .= '
'; + $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'
'; + $s .= '
'; - $nextval = $this->getNextValue($soc, ''); - if (empty($nextval)) $nextval = $langs->trans("Undefined"); - $s .= $langs->trans("NextValue").': '.$nextval.'
'; + $nextval = $this->getNextValue($soc, ''); + if (empty($nextval)) $nextval = $langs->trans("Undefined"); + $s .= $langs->trans("NextValue").': '.$nextval.'
'; - return $s; - } + return $s; + } }