More robust error management on barcode module.
This commit is contained in:
parent
e28765ff69
commit
0b6bd0bc14
@ -298,7 +298,7 @@ if ($conf->product->enabled || $conf->product->service)
|
|||||||
{
|
{
|
||||||
$disabled=1;
|
$disabled=1;
|
||||||
$titleno=$langs->trans("NoBarcodeNumberingTemplateDefined");
|
$titleno=$langs->trans("NoBarcodeNumberingTemplateDefined");
|
||||||
print '<font class="warning">'.$langs->trans("NoBarcodeNumberingTemplateDefined").'</font><br>';
|
print '<font class="warning">'.$langs->trans("NoBarcodeNumberingTemplateDefined").'</font> (<a href="'.DOL_URL_ROOT.'/admin/barcode.php">'.$langs->trans("ToGenerateCodeDefineAutomaticRuleFirst").'</a>)<br>';
|
||||||
}
|
}
|
||||||
if (empty($nbno))
|
if (empty($nbno))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -63,8 +63,6 @@ else $genbarcode_loc = $conf->global->GENBARCODE_LOCATION;
|
|||||||
* @param string $encoding Encoding
|
* @param string $encoding Encoding
|
||||||
* @param integer $scale Scale
|
* @param integer $scale Scale
|
||||||
* @param string $mode 'png' or 'jpg' ...
|
* @param string $mode 'png' or 'jpg' ...
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return array $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
|
* @return array $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
|
||||||
*/
|
*/
|
||||||
function barcode_print($code, $encoding="ANY", $scale = 2 ,$mode = "png")
|
function barcode_print($code, $encoding="ANY", $scale = 2 ,$mode = "png")
|
||||||
@ -116,8 +114,7 @@ function barcode_encode($code,$encoding)
|
|||||||
global $genbarcode_loc;
|
global $genbarcode_loc;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
((preg_match("/^ean$/i", $encoding)
|
(preg_match("/^ean$/i", $encoding))
|
||||||
&& ( strlen($code)==12 || strlen($code)==13)))
|
|
||||||
|
|
||||||
|| (($encoding) && (preg_match("/^isbn$/i", $encoding))
|
|| (($encoding) && (preg_match("/^isbn$/i", $encoding))
|
||||||
&& (( strlen($code)==9 || strlen($code)==10) ||
|
&& (( strlen($code)==9 || strlen($code)==10) ||
|
||||||
@ -140,7 +137,7 @@ function barcode_encode($code,$encoding)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print "barcode_encode needs an external programm for encodings other then EAN/ISBN<BR>\n";
|
print "barcode_encode needs an external programm for encodings other then EAN/ISBN (code=".$code.", encoding=".$encoding.")<BR>\n";
|
||||||
print "<UL>\n";
|
print "<UL>\n";
|
||||||
print "<LI>download gnu-barcode from <A href=\"http://www.gnu.org/software/barcode/\">www.gnu.org/software/barcode/</A>\n";
|
print "<LI>download gnu-barcode from <A href=\"http://www.gnu.org/software/barcode/\">www.gnu.org/software/barcode/</A>\n";
|
||||||
print "<LI>compile and install them\n";
|
print "<LI>compile and install them\n";
|
||||||
@ -151,6 +148,7 @@ function barcode_encode($code,$encoding)
|
|||||||
print "<BR>\n";
|
print "<BR>\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bars;
|
return $bars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +176,7 @@ function barcode_gen_ean_sum($ean)
|
|||||||
*
|
*
|
||||||
* @param string $ean Code
|
* @param string $ean Code
|
||||||
* @param string $encoding Encoding
|
* @param string $encoding Encoding
|
||||||
* @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
|
* @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error)
|
||||||
*/
|
*/
|
||||||
function barcode_encode_ean($ean, $encoding = "EAN-13")
|
function barcode_encode_ean($ean, $encoding = "EAN-13")
|
||||||
{
|
{
|
||||||
@ -189,7 +187,7 @@ function barcode_encode_ean($ean, $encoding = "EAN-13")
|
|||||||
$ean=trim($ean);
|
$ean=trim($ean);
|
||||||
if (preg_match("/[^0-9]/i",$ean))
|
if (preg_match("/[^0-9]/i",$ean))
|
||||||
{
|
{
|
||||||
return array("text"=>"Invalid EAN-Code");
|
return array("error"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (not a numeric)", "text"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (not a numeric)");
|
||||||
}
|
}
|
||||||
$encoding=strtoupper($encoding);
|
$encoding=strtoupper($encoding);
|
||||||
if ($encoding=="ISBN")
|
if ($encoding=="ISBN")
|
||||||
@ -199,7 +197,7 @@ function barcode_encode_ean($ean, $encoding = "EAN-13")
|
|||||||
if (preg_match("/^978/", $ean)) $encoding="ISBN";
|
if (preg_match("/^978/", $ean)) $encoding="ISBN";
|
||||||
if (strlen($ean)<12 || strlen($ean)>13)
|
if (strlen($ean)<12 || strlen($ean)>13)
|
||||||
{
|
{
|
||||||
return array("text"=>"Invalid $encoding Code (must have 12/13 numbers)");
|
return array("error"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)", "text"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)");
|
||||||
}
|
}
|
||||||
|
|
||||||
$ean=substr($ean,0,12);
|
$ean=substr($ean,0,12);
|
||||||
@ -227,6 +225,7 @@ function barcode_encode_ean($ean, $encoding = "EAN-13")
|
|||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
"error" => '',
|
||||||
"encoding" => $encoding,
|
"encoding" => $encoding,
|
||||||
"bars" => $line,
|
"bars" => $line,
|
||||||
"text" => $text
|
"text" => $text
|
||||||
|
|||||||
@ -1711,3 +1711,5 @@ TitleExampleForMaintenanceRelease=Example of message you can use to announce thi
|
|||||||
ExampleOfNewsMessageForMajorRelease=Dolibarr ERP & CRM %s is available. Version %s is a major release with a lot of new features for both users and developers. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
|
ExampleOfNewsMessageForMajorRelease=Dolibarr ERP & CRM %s is available. Version %s is a major release with a lot of new features for both users and developers. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
|
||||||
ExampleOfNewsMessageForMaintenanceRelease=Dolibarr ERP & CRM %s is available. Version %s is a maintenance version, so it contains only fixes of bugs. We recommend everybody using an older version to upgrade to this one. As any maintenance release, no new features, nor data structure change is present into this version. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
|
ExampleOfNewsMessageForMaintenanceRelease=Dolibarr ERP & CRM %s is available. Version %s is a maintenance version, so it contains only fixes of bugs. We recommend everybody using an older version to upgrade to this one. As any maintenance release, no new features, nor data structure change is present into this version. You can download it from the download area of http://www.dolibarr.org portal (subdirectory Stable versions). You can read <a href="https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog">ChangeLog</a> for complete list of changes.
|
||||||
MultiPriceRuleDesc=When option "Several level of prices per product/service" is on, you can define different prices (one per price level) for each product. To save you time, you can enter here rule to have price for each level autocalculated according to price of first level, so you will have to enter only price for first level on each product. This page is here to save you time and can be usefull only if your prices for each leve are relative to first level. You can ignore this page in most cases.
|
MultiPriceRuleDesc=When option "Several level of prices per product/service" is on, you can define different prices (one per price level) for each product. To save you time, you can enter here rule to have price for each level autocalculated according to price of first level, so you will have to enter only price for first level on each product. This page is here to save you time and can be usefull only if your prices for each leve are relative to first level. You can ignore this page in most cases.
|
||||||
|
ModelModulesProduct=Templates for product documents
|
||||||
|
ToGenerateCodeDefineAutomaticRuleFirst=To be able to generate automatically codes, you must first define a manager to auto define barcode number.
|
||||||
@ -323,7 +323,7 @@ $form=new Form($db);
|
|||||||
*/
|
*/
|
||||||
$dirproduct=array('/core/modules/product/');
|
$dirproduct=array('/core/modules/product/');
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans("ProductCodeChecker"));
|
print load_fiche_titre($langs->trans("ProductCodeChecker"), '', '');
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">'."\n";
|
print '<table class="noborder" width="100%">'."\n";
|
||||||
print '<tr class="liste_titre">'."\n";
|
print '<tr class="liste_titre">'."\n";
|
||||||
@ -400,9 +400,6 @@ foreach ($dirproduct as $dirroot)
|
|||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
|
|
||||||
print '<br>';
|
|
||||||
print_titre($langs->trans("ModelModulesProduct"));
|
|
||||||
|
|
||||||
// Load array def with activated templates
|
// Load array def with activated templates
|
||||||
$def = array();
|
$def = array();
|
||||||
$sql = "SELECT nom";
|
$sql = "SELECT nom";
|
||||||
@ -414,30 +411,30 @@ if ($resql)
|
|||||||
{
|
{
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$num_rows=$db->num_rows($resql);
|
$num_rows=$db->num_rows($resql);
|
||||||
|
if ($num_rows > 0)
|
||||||
|
{
|
||||||
|
print '<br>';
|
||||||
|
print load_fiche_titre($langs->trans("ModelModulesProduct"), '', '');
|
||||||
|
|
||||||
while ($i < $num_rows)
|
while ($i < $num_rows)
|
||||||
{
|
{
|
||||||
$array = $db->fetch_array($resql);
|
$array = $db->fetch_array($resql);
|
||||||
array_push($def, $array[0]);
|
array_push($def, $array[0]);
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dol_print_error($db);
|
|
||||||
}
|
|
||||||
|
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print '<td width="140">'.$langs->trans("Name").'</td>';
|
print '<td width="140">'.$langs->trans("Name").'</td>';
|
||||||
print '<td>'.$langs->trans("Description").'</td>';
|
print '<td>'.$langs->trans("Description").'</td>';
|
||||||
print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
|
print '<td align="center" width="80">'.$langs->trans("Status").'</td>';
|
||||||
print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
|
print '<td align="center" width="60">'.$langs->trans("ShortInfo").'</td>';
|
||||||
print '<td align="center" width="60">'.$langs->trans("Preview").'</td>';
|
print '<td align="center" width="60">'.$langs->trans("Preview").'</td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
$var=true;
|
$var=true;
|
||||||
foreach ($dirproduct as $dirroot)
|
foreach ($dirproduct as $dirroot)
|
||||||
{
|
{
|
||||||
$dir = dol_buildpath($dirroot.'core/modules/product/doc/',0);
|
$dir = dol_buildpath($dirroot.'core/modules/product/doc/',0);
|
||||||
$handle=@opendir($dir);
|
$handle=@opendir($dir);
|
||||||
if (is_resource($handle))
|
if (is_resource($handle))
|
||||||
@ -533,8 +530,15 @@ foreach ($dirproduct as $dirroot)
|
|||||||
}
|
}
|
||||||
closedir($handle);
|
closedir($handle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
print '</table>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print '</table>';
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Other conf
|
* Other conf
|
||||||
@ -542,7 +546,7 @@ print '</table>';
|
|||||||
|
|
||||||
print "<br>";
|
print "<br>";
|
||||||
|
|
||||||
print load_fiche_titre($langs->trans("ProductOtherConf"));
|
print load_fiche_titre($langs->trans("ProductOtherConf"), '', '');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -36,6 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
require '../main.inc.php';
|
require '../main.inc.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
||||||
@ -80,11 +81,21 @@ $extrafields = new ExtraFields($db);
|
|||||||
// fetch optionals attributes and labels
|
// fetch optionals attributes and labels
|
||||||
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
|
||||||
|
|
||||||
|
$object = new Product($db);
|
||||||
if ($id > 0 || ! empty($ref))
|
if ($id > 0 || ! empty($ref))
|
||||||
{
|
{
|
||||||
$object = new Product($db);
|
$result = $object->fetch($id, $ref);
|
||||||
$object->fetch($id, $ref);
|
|
||||||
|
if (! empty($conf->product->enabled)) $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
|
||||||
|
elseif (! empty($conf->service->enabled)) $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref);
|
||||||
|
|
||||||
|
if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs
|
||||||
|
{
|
||||||
|
if (! empty($conf->product->enabled)) $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
|
||||||
|
else $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2),1,1).'/'.substr(substr("000".$object->id, -2),0,1).'/'.$object->id."/photos";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$modulepart='product';
|
||||||
|
|
||||||
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
||||||
$canvas = !empty($object->canvas)?$object->canvas:GETPOST("canvas");
|
$canvas = !empty($object->canvas)?$object->canvas:GETPOST("canvas");
|
||||||
@ -769,6 +780,7 @@ else $title = $langs->trans('ProductServiceCard');
|
|||||||
llxHeader('', $title, $helpurl);
|
llxHeader('', $title, $helpurl);
|
||||||
|
|
||||||
$form = new Form($db);
|
$form = new Form($db);
|
||||||
|
$formfile = new FormFile($db);
|
||||||
$formproduct = new FormProduct($db);
|
$formproduct = new FormProduct($db);
|
||||||
if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
|
if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db);
|
||||||
|
|
||||||
@ -1678,28 +1690,6 @@ if (($action == 'clone' && (empty($conf->use_javascript_ajax) || ! empty($conf->
|
|||||||
{
|
{
|
||||||
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',250,600);
|
print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneProduct'),$langs->trans('ConfirmCloneProduct',$object->ref),'confirm_clone',$formquestionclone,'yes','action-clone',250,600);
|
||||||
}
|
}
|
||||||
print '<div class="fichecenter"><div class="fichehalfleft">';
|
|
||||||
print '<a name="builddoc"></a>'; // ancre
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Documents generes
|
|
||||||
*/
|
|
||||||
$filedir=$conf->product->dir_output.'/product/'.$object->id;
|
|
||||||
|
|
||||||
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
|
|
||||||
$genallowed=$user->rights->produit->creer;
|
|
||||||
$delallowed=$user->rights->produit->supprimer;
|
|
||||||
|
|
||||||
$var=true;
|
|
||||||
|
|
||||||
$somethingshown=$formfile->show_documents('product',$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang);
|
|
||||||
|
|
||||||
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
|
|
||||||
|
|
||||||
|
|
||||||
print '</div></div></div>';
|
|
||||||
|
|
||||||
print '<br><br>';
|
|
||||||
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
@ -1872,16 +1862,40 @@ if ($object->id && ($action == '' || $action == 'view') && $object->status)
|
|||||||
print $html;
|
print $html;
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
dol_fiche_end();
|
|
||||||
|
|
||||||
print '<div class="center">';
|
print '<div class="center">';
|
||||||
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
|
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
|
|
||||||
|
dol_fiche_end();
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Documents generes
|
||||||
|
*/
|
||||||
|
if ($action == '' || $action == 'view')
|
||||||
|
{
|
||||||
|
print '<div class="fichecenter"><div class="fichehalfleft">';
|
||||||
|
print '<a name="builddoc"></a>'; // ancre
|
||||||
|
|
||||||
|
$filedir=$upload_dir;
|
||||||
|
|
||||||
|
$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
|
||||||
|
$genallowed=$user->rights->produit->creer;
|
||||||
|
$delallowed=$user->rights->produit->supprimer;
|
||||||
|
|
||||||
|
$var=true;
|
||||||
|
|
||||||
|
$somethingshown=$formfile->show_documents($modulepart,$object->id,$filedir,$urlsource,$genallowed,$delallowed,'',0,0,0,28,0,'',0,'',$object->default_lang);
|
||||||
|
|
||||||
|
print '</div><div class="fichehalfright"><div class="ficheaddleft">';
|
||||||
|
|
||||||
|
print '</div></div></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
@ -211,7 +211,6 @@ if ($object->id)
|
|||||||
|
|
||||||
dol_fiche_end();
|
dol_fiche_end();
|
||||||
|
|
||||||
$modulepart = 'produit';
|
|
||||||
$permission = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
|
$permission = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer));
|
||||||
$param = '&id=' . $object->id;
|
$param = '&id=' . $object->id;
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2005-2016 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
|
* Copyright (C) 2005-2016 Regis Houssin <regis.houssin@capnetworks.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user