--- /tmp/dsg/dolibarr/htdocs/core/modules/barcode/github_19.0.3_mod_barcode_product_standard.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/barcode/client_mod_barcode_product_standard.php @@ -4 +4 @@ - * Copyright (C) 2007-2012 Regis Houssin + * Copyright (C) 2007-2012 Regis Houssin @@ -18,2 +18,2 @@ - * 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/ @@ -36,26 +36,11 @@ - 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} @@ -67 +52 @@ - public function __construct() + function __construct() @@ -83 +68 @@ - public function info($langs) + function info($langs) @@ -90 +75 @@ - $disabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); + $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); @@ -93,14 +78,10 @@ - $texte .= '
'; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - - $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("BarCode"), $langs->transnoentities("BarCode")); - $tooltip .= $langs->trans("GenericMaskCodes3EAN"); - $tooltip .= ''.$langs->trans("Example").':
'; - $tooltip .= '04{0000000000}? (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"); @@ -110,7 +91,7 @@ - $texte .= ''; - $texte .= ''; - $texte .= ''; - $texte .= ''; - - $texte .= '
'.$langs->trans("Mask").':'.$form->textwithpicto('', $tooltip, 1, 1).' 
'; - $texte .= '
'; + $texte.= ''.$langs->trans("Mask").':'; + $texte.= ''.$form->textwithpicto('',$tooltip,1,1).''; + $texte.= '  '; + $texte.= ''; + + $texte.= ''; + $texte.= ''; @@ -129,4 +110,5 @@ - public function getExample($langs, $objproduct = 0) - { - $examplebarcode = $this->getNextValue($objproduct, ''); - if (!$examplebarcode) { + function getExample($langs,$objproduct=0) + { + $examplebarcode = $this->getNextValue($objproduct,0); + if (! $examplebarcode) + { @@ -135 +117,2 @@ - if ($examplebarcode == "ErrorBadMask") { + if($examplebarcode=="ErrorBadMask") + { @@ -137 +120 @@ - $examplebarcode = $langs->trans($examplebarcode); + $examplebarcode=$langs->trans($examplebarcode); @@ -142,30 +125 @@ - /** - * Return literal barcode type code from numerical rowid type of barcode - * - * @param Database $db Database - * @param int $type Type of barcode (EAN, ISBN, ...) as rowid - * @return string - */ - public function literalBarcodeType($db, $type = '') - { - global $conf; - $out = ''; - - $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; - $sql .= " WHERE rowid = '".$db->escape($type)."'"; - $sql .= " AND entity = ".((int) $conf->entity); - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - - if ($num > 0) { - $obj = $db->fetch_object($result); - $out .= $obj->label; //take the label corresponding to the type rowid in the database - } - } else { - dol_print_error($db); - } - - return $out; - } + @@ -176 +130 @@ - * @param string $type Type of barcode (EAN, ISBN, ...) + * @param string $type type of barcode (EAN, ISBN, ...) @@ -179,11 +133,5 @@ - public function getNextValue($objproduct, $type = '') - { - global $db, $conf; - - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) - - // Get barcode type configuration for products if $type not set - if (empty($type)) { - $type = getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE'); - } + function getNextValue($objproduct,$type='') + { + global $db,$conf; + + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; @@ -195,6 +143,5 @@ - if (getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK')) { - $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK; - } - - if (empty($mask)) { - $this->error = 'NotConfigured'; + if (! empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) $mask = $conf->global->BARCODE_STANDARD_PRODUCT_MASK; + + if (empty($mask)) + { + $this->error='NotConfigured'; @@ -204,25 +151,6 @@ - $field = 'barcode'; - $where = ''; - - $now = dol_now(); - - $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); - //Begin barcode with key: for barcode with key (EAN13...) calculate and substitute the last character (* or ?) used in the mask by the key - if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) { // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...) - $literaltype = ''; - $literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type - switch ($literaltype) { - case 'EAN13': //EAN13 rowid = 2 - if (strlen($numFinal)==13) {// be sure that the mask length is correct for EAN13 - $ean = substr($numFinal, 0, 12); //take first 12 digits - $eansum = barcode_gen_ean_sum($ean); - $ean .= $eansum; //substitute the las character by the key - $numFinal = $ean; - } - break; - // Other barcode cases with key could be written here - default: - break; - } - } - //End barcode with key + $field='barcode';$where=''; + + $now=dol_now(); + + $numFinal=get_next_value($db,$mask,'product',$field,$where,'',$now); + @@ -247 +175 @@ - public function verif($db, &$code, $product, $thirdparty_type, $type) + function verif($db, &$code, $product, $thirdparty_type, $type) @@ -253,3 +181,3 @@ - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - - $result = 0; + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; + + $result=0; @@ -258,6 +186,12 @@ - if (empty($code) && $this->code_null && !getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK')) { - $result = 0; - } elseif (empty($code) && (!$this->code_null || getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK'))) { - $result = -2; - } else { - if ($this->verif_syntax($code, $type) >= 0) { + if (empty($code) && $this->code_null && empty($conf->global->BARCODE_STANDARD_PRODUCT_MASK)) + { + $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) + { @@ -265,10 +199,18 @@ - if ($is_dispo != 0) { - $result = -3; - } else { - $result = 0; - } - } else { - if (dol_strlen($code) == 0) { - $result = -2; - } else { - $result = -1; + if ($is_dispo <> 0) + { + $result=-3; + } + else + { + $result=0; + } + } + else + { + if (dol_strlen($code) == 0) + { + $result=-2; + } + else + { + $result=-1; @@ -284,12 +226,10 @@ - // 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) + { @@ -297,10 +237,8 @@ - $sql .= " WHERE barcode = '".$db->escape($code)."'"; - $sql .= " AND entity IN (".getEntity('product').")"; - - if ($product->id > 0) { - $sql .= " AND rowid <> ".$product->id; - } - - $resql = $db->query($sql); - if ($resql) { - if ($db->num_rows($resql) == 0) { + $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) + { @@ -308 +246,3 @@ - } else { + } + else + { @@ -311 +251,3 @@ - } else { + } + else + { @@ -314,3 +256,3 @@ - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + + } + @@ -321 +263 @@ - * @param string $typefortest Type of barcode (ISBN, EAN, ...) + * @param string $typefortest Type of barcode (ISBN, EAN, ...) @@ -324,3 +266,2 @@ - public function verif_syntax($codefortest, $typefortest) - { - // phpcs:enable + function verif_syntax($codefortest, $typefortest) + { @@ -329 +270 @@ - $result = 0; + $res = 0; @@ -332,25 +273,14 @@ - $mask = !getDolGlobalString('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); @@ -359,0 +290 @@ + @@ -360,0 +292 @@ + --- /tmp/dsg/dolibarr/htdocs/core/modules/barcode/github_19.0.3_modules_barcode.class.php +++ /tmp/dsg/dolibarr/htdocs/core/modules/barcode/client_modules_barcode.class.php @@ -25 +24,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php'; @@ -33,4 +32,4 @@ - /** - * @var string Error code (or message) - */ - public $error = ''; + /** + * @var string Error code (or message) + */ + public $error = ''; @@ -39,9 +38,9 @@ - /** - * 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; + } @@ -54 +53 @@ -abstract class ModeleNumRefBarCode extends CommonNumRefGenerator +abstract class ModeleNumRefBarCode @@ -56,4 +55,4 @@ - /** - * @var int Code facultatif - */ - public $code_null; + /** + * @var string Error code (or message) + */ + public $error = ''; @@ -61,4 +60,10 @@ - /** - * @var int Automatic numbering - */ - public $code_auto; + /** 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"); + } @@ -65,0 +71,9 @@ + /** Return model name + * + * @param Translate $langs Object langs + * @return string Model name + */ + public function getNom($langs) + { + return empty($this->name) ? $this->nom : $this->name; + } @@ -67,12 +81,10 @@ - /** - * 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 a numbering example + * + * @param Translate $langs Object langs + * @return string Example + */ + public function getExample($langs) + { + $langs->load("bills"); + return $langs->trans("NoExample"); + } @@ -80,11 +92,12 @@ - /** - * 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 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"); + } @@ -92 +105,8 @@ - $langs->loadLangs(array("admin", "companies")); + /** Return version of module + * + * @return string Version + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); @@ -94,48 +114,6 @@ - $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 (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { - $s .= ''; - } - $s .= yn(!$this->code_null, 1, 2); - if (getDolGlobalString('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 (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { - $s .= ''; - } - $s .= yn(!$this->code_null, 1, 2); - if (getDolGlobalString('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 (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { - $s .= ''; - } - $s .= yn(!$this->code_null, 1, 2); - if (getDolGlobalString('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 .= '
'; + 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"); + } @@ -143,5 +121,11 @@ - $nextval = $this->getNextValue($soc, ''); - if (empty($nextval)) { - $nextval = $langs->trans("Undefined"); - } - $s .= $langs->trans("NextValue").': '.$nextval.'
'; + /** + * 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; @@ -149,2 +133,46 @@ - return $s; - } + $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.=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 .= '
'; + + $nextval = $this->getNextValue($soc, ''); + if (empty($nextval)) $nextval = $langs->trans("Undefined"); + $s .= $langs->trans("NextValue").': '.$nextval.'
'; + + return $s; + }