code syntax
This commit is contained in:
parent
5199e3da5b
commit
bb276566c6
@ -52,27 +52,21 @@ $maxperinit = 1000;
|
||||
*/
|
||||
|
||||
// Define barcode template for products
|
||||
if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
|
||||
{
|
||||
if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM)) {
|
||||
$dirbarcodenum = array_merge(array('/core/modules/barcode/'), $conf->modules_parts['barcode']);
|
||||
|
||||
foreach ($dirbarcodenum as $dirroot)
|
||||
{
|
||||
foreach ($dirbarcodenum as $dirroot) {
|
||||
$dir = dol_buildpath($dirroot, 0);
|
||||
|
||||
$handle = @opendir($dir);
|
||||
if (is_resource($handle))
|
||||
{
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
if (preg_match('/^mod_barcode_product_.*php$/', $file))
|
||||
{
|
||||
if (is_resource($handle)) {
|
||||
while (($file = readdir($handle)) !== false) {
|
||||
if (preg_match('/^mod_barcode_product_.*php$/', $file)) {
|
||||
$file = substr($file, 0, dol_strlen($file) - 4);
|
||||
|
||||
try {
|
||||
dol_include_once($dirroot.$file.'.php');
|
||||
} catch (Exception $e)
|
||||
{
|
||||
} catch (Exception $e) {
|
||||
dol_syslog($e->getMessage(), LOG_ERR);
|
||||
}
|
||||
|
||||
@ -85,28 +79,23 @@ if (!empty($conf->global->BARCODE_PRODUCT_ADDON_NUM))
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'initbarcodeproducts')
|
||||
{
|
||||
if (!is_object($modBarCodeProduct))
|
||||
{
|
||||
if ($action == 'initbarcodeproducts') {
|
||||
if (!is_object($modBarCodeProduct)) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans("NoBarcodeNumberingTemplateDefined"), null, 'errors');
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$productstatic = new Product($db);
|
||||
|
||||
$db->begin();
|
||||
|
||||
$nbok = 0;
|
||||
if (!empty($eraseallbarcode))
|
||||
{
|
||||
if (!empty($eraseallbarcode)) {
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
|
||||
$sql .= " SET barcode = NULL";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
setEventMessages($langs->trans("AllBarcodeReset"), null, 'mesgs');
|
||||
} else {
|
||||
$error++;
|
||||
@ -121,16 +110,13 @@ if ($action == 'initbarcodeproducts')
|
||||
|
||||
dol_syslog("codeinit", LOG_DEBUG);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
$i = 0; $nbok = $nbtry = 0;
|
||||
while ($i < min($num, $maxperinit))
|
||||
{
|
||||
while ($i < min($num, $maxperinit)) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
if ($obj) {
|
||||
$productstatic->id = $obj->rowid;
|
||||
$productstatic->ref = $obj->ref;
|
||||
$productstatic->type = $obj->fk_product_type;
|
||||
@ -140,7 +126,9 @@ if ($action == 'initbarcodeproducts')
|
||||
$result = $productstatic->setValueFrom('barcode', $nextvalue, '', '', 'text', '', $user, 'PRODUCT_MODIFY');
|
||||
|
||||
$nbtry++;
|
||||
if ($result > 0) $nbok++;
|
||||
if ($result > 0) {
|
||||
$nbok++;
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
@ -150,14 +138,12 @@ if ($action == 'initbarcodeproducts')
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
//$db->rollback();
|
||||
$db->commit();
|
||||
} else {
|
||||
@ -174,8 +160,12 @@ if ($action == 'initbarcodeproducts')
|
||||
* View
|
||||
*/
|
||||
|
||||
if (!$user->admin) accessforbidden();
|
||||
if (empty($conf->barcode->enabled)) accessforbidden();
|
||||
if (!$user->admin) {
|
||||
accessforbidden();
|
||||
}
|
||||
if (empty($conf->barcode->enabled)) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
@ -198,8 +188,7 @@ print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<br>';
|
||||
|
||||
// For thirdparty
|
||||
if ($conf->societe->enabled)
|
||||
{
|
||||
if ($conf->societe->enabled) {
|
||||
$nbno = $nbtotal = 0;
|
||||
|
||||
print load_fiche_titre($langs->trans("BarcodeInitForThirdparties"), '', 'company');
|
||||
@ -207,19 +196,21 @@ if ($conf->societe->enabled)
|
||||
print '<br>'."\n";
|
||||
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."societe where barcode IS NULL or barcode = ''";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$nbno = $obj->nb;
|
||||
} else dol_print_error($db);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."societe";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$nbtotal = $obj->nb;
|
||||
} else dol_print_error($db);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
print $langs->trans("CurrentlyNWithoutBarCode", $nbno, $nbtotal, $langs->transnoentitiesnoconv("ThirdParties")).'<br>'."\n";
|
||||
|
||||
@ -231,8 +222,7 @@ if ($conf->societe->enabled)
|
||||
|
||||
|
||||
// For products
|
||||
if ($conf->product->enabled || $conf->product->service)
|
||||
{
|
||||
if ($conf->product->enabled || $conf->product->service) {
|
||||
// Example 1 : Adding jquery code
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
function confirm_erase() {
|
||||
@ -251,32 +241,32 @@ if ($conf->product->enabled || $conf->product->service)
|
||||
$sql .= " GROUP BY fk_product_type, datec";
|
||||
$sql .= " ORDER BY datec";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$num = $db->num_rows($resql);
|
||||
|
||||
$i = 0;
|
||||
while ($i < $num)
|
||||
{
|
||||
while ($i < $num) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$nbno += $obj->nb;
|
||||
|
||||
$i++;
|
||||
}
|
||||
} else dol_print_error($db);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
$sql = "SELECT count(rowid) as nb FROM ".MAIN_DB_PREFIX."product";
|
||||
$resql = $db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($resql) {
|
||||
$obj = $db->fetch_object($resql);
|
||||
$nbtotal = $obj->nb;
|
||||
} else dol_print_error($db);
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
print $langs->trans("CurrentlyNWithoutBarCode", $nbno, $nbtotal, $langs->transnoentitiesnoconv("ProductsOrServices")).'<br>'."\n";
|
||||
|
||||
if (is_object($modBarCodeProduct))
|
||||
{
|
||||
if (is_object($modBarCodeProduct)) {
|
||||
print $langs->trans("BarCodeNumberManager").": ";
|
||||
$objproduct = new Product($db);
|
||||
print '<b>'.(isset($modBarCodeProduct->name) ? $modBarCodeProduct->name : $modBarCodeProduct->nom).'</b> - '.$langs->trans("NextValue").': <b>'.$modBarCodeProduct->getNextValue($objproduct).'</b><br>';
|
||||
@ -286,8 +276,7 @@ if ($conf->product->enabled || $conf->product->service)
|
||||
$titleno = $langs->trans("NoBarcodeNumberingTemplateDefined");
|
||||
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)) {
|
||||
$disabled1 = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,9 @@
|
||||
*/
|
||||
|
||||
if (!empty($_POST['mode']) && $_POST['mode'] === 'label') { // Page is called to build a PDF and output, we must ne renew the token.
|
||||
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
|
||||
if (!defined('NOTOKENRENEWAL')) {
|
||||
define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on)
|
||||
}
|
||||
}
|
||||
|
||||
require '../main.inc.php';
|
||||
@ -59,8 +61,7 @@ $thirdpartytmp = new Societe($db);
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if (GETPOST('submitproduct') && GETPOST('submitproduct'))
|
||||
{
|
||||
if (GETPOST('submitproduct') && GETPOST('submitproduct')) {
|
||||
$action = ''; // We reset because we don't want to build doc
|
||||
if (GETPOST('productid', 'int') > 0) {
|
||||
$result = $producttmp->fetch(GETPOST('productid', 'int'));
|
||||
@ -70,62 +71,56 @@ if (GETPOST('submitproduct') && GETPOST('submitproduct'))
|
||||
$forbarcode = $producttmp->barcode;
|
||||
$fk_barcode_type = $producttmp->barcode_type;
|
||||
|
||||
if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
|
||||
if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
|
||||
$fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
|
||||
}
|
||||
|
||||
if (empty($forbarcode) || empty($fk_barcode_type))
|
||||
{
|
||||
if (empty($forbarcode) || empty($fk_barcode_type)) {
|
||||
setEventMessages($langs->trans("DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()), null, 'warnings');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GETPOST('submitthirdparty') && GETPOST('submitthirdparty'))
|
||||
{
|
||||
if (GETPOST('submitthirdparty') && GETPOST('submitthirdparty')) {
|
||||
$action = ''; // We reset because we don't want to build doc
|
||||
if (GETPOST('socid', 'int') > 0)
|
||||
{
|
||||
if (GETPOST('socid', 'int') > 0) {
|
||||
$thirdpartytmp->fetch(GETPOST('socid', 'int'));
|
||||
$forbarcode = $thirdpartytmp->barcode;
|
||||
$fk_barcode_type = $thirdpartytmp->barcode_type_code;
|
||||
|
||||
if (empty($fk_barcode_type) && !empty($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY)) $fk_barcode_type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
|
||||
if (empty($fk_barcode_type) && !empty($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY)) {
|
||||
$fk_barcode_type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
|
||||
}
|
||||
|
||||
if (empty($forbarcode) || empty($fk_barcode_type))
|
||||
{
|
||||
if (empty($forbarcode) || empty($fk_barcode_type)) {
|
||||
setEventMessages($langs->trans("DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()), null, 'warnings');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($action == 'builddoc')
|
||||
{
|
||||
if ($action == 'builddoc') {
|
||||
$result = 0; $error = 0;
|
||||
|
||||
if (empty($forbarcode)) // barcode value
|
||||
{
|
||||
if (empty($forbarcode)) { // barcode value
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BarcodeValue")), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
if (empty($fk_barcode_type)) // barcode type = barcode encoding
|
||||
{
|
||||
if (empty($fk_barcode_type)) { // barcode type = barcode encoding
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BarcodeType")), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// Get encoder (barcode_type_coder) from barcode type id (barcode_type)
|
||||
$stdobject = new GenericObject($db);
|
||||
$stdobject->barcode_type = $fk_barcode_type;
|
||||
$result = $stdobject->fetch_barcode();
|
||||
if ($result <= 0)
|
||||
{
|
||||
if ($result <= 0) {
|
||||
$error++;
|
||||
setEventMessages('Failed to get bar code type information '.$stdobject->error, $stdobject->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
$code = $forbarcode;
|
||||
$generator = $stdobject->barcode_type_coder; // coder (loaded by fetch_barcode). Engine.
|
||||
$encoding = strtoupper($stdobject->barcode_type_code); // code (loaded by fetch_barcode). Example 'ean', 'isbn', ...
|
||||
@ -136,34 +131,34 @@ if ($action == 'builddoc')
|
||||
// Generate barcode
|
||||
$dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']);
|
||||
|
||||
foreach ($dirbarcode as $reldir)
|
||||
{
|
||||
foreach ($dirbarcode as $reldir) {
|
||||
$dir = dol_buildpath($reldir, 0);
|
||||
$newdir = dol_osencode($dir);
|
||||
|
||||
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php)
|
||||
if (!is_dir($newdir)) continue;
|
||||
if (!is_dir($newdir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = @include_once $newdir.$generator.'.modules.php';
|
||||
if ($result) break;
|
||||
if ($result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Load barcode class for generating barcode image
|
||||
$classname = "mod".ucfirst($generator);
|
||||
$module = new $classname($db);
|
||||
if ($generator != 'tcpdfbarcode')
|
||||
{
|
||||
if ($generator != 'tcpdfbarcode') {
|
||||
// May be phpbarcode
|
||||
$template = 'standardlabel';
|
||||
$is2d = false;
|
||||
if ($module->encodingIsSupported($encoding))
|
||||
{
|
||||
if ($module->encodingIsSupported($encoding)) {
|
||||
$barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
|
||||
dol_delete_file($barcodeimage);
|
||||
// File is created with full name $barcodeimage = $conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
|
||||
$result = $module->writeBarCode($code, $encoding, 'Y', 4, 1);
|
||||
if ($result <= 0 || !dol_is_file($barcodeimage))
|
||||
{
|
||||
if ($result <= 0 || !dol_is_file($barcodeimage)) {
|
||||
$error++;
|
||||
setEventMessages('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), null, 'errors');
|
||||
setEventMessages($module->error, null, 'errors');
|
||||
@ -179,8 +174,7 @@ if ($action == 'builddoc')
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
if (!$error) {
|
||||
// List of values to scan for a replacement
|
||||
$substitutionarray = array(
|
||||
'%LOGIN%' => $user->login,
|
||||
@ -200,8 +194,7 @@ if ($action == 'builddoc')
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
|
||||
// For labels
|
||||
if ($mode == 'label')
|
||||
{
|
||||
if ($mode == 'label') {
|
||||
$txtforsticker = "%PHOTO%"; // Photo will be barcode image, %BARCODE% posible when using TCPDF generator
|
||||
$textleft = make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT) ? $txtforsticker : $conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray);
|
||||
$textheader = make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT) ? '' : $conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray);
|
||||
@ -210,8 +203,7 @@ if ($action == 'builddoc')
|
||||
$forceimgscalewidth = (empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH);
|
||||
$forceimgscaleheight = (empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT);
|
||||
|
||||
for ($i = 0; $i < $numberofsticker; $i++)
|
||||
{
|
||||
for ($i = 0; $i < $numberofsticker; $i++) {
|
||||
$arrayofrecords[] = array(
|
||||
'textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
@ -229,14 +221,11 @@ if ($action == 'builddoc')
|
||||
$mesg = '';
|
||||
|
||||
// Build and output PDF
|
||||
if ($mode == 'label')
|
||||
{
|
||||
if (!count($arrayofrecords))
|
||||
{
|
||||
if ($mode == 'label') {
|
||||
if (!count($arrayofrecords)) {
|
||||
$mesg = $langs->trans("ErrorRecordNotFound");
|
||||
}
|
||||
if (empty($modellabel) || $modellabel == '-1')
|
||||
{
|
||||
if (empty($modellabel) || $modellabel == '-1') {
|
||||
$mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
|
||||
}
|
||||
|
||||
@ -269,7 +258,9 @@ if ($action == 'builddoc')
|
||||
* View
|
||||
*/
|
||||
|
||||
if (empty($conf->barcode->enabled)) accessforbidden();
|
||||
if (empty($conf->barcode->enabled)) {
|
||||
accessforbidden();
|
||||
}
|
||||
|
||||
$form = new Form($db);
|
||||
|
||||
@ -300,8 +291,7 @@ print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
|
||||
print '</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
|
||||
// List of possible labels (defined into $_Avery_Labels variable set into core/lib/format_cards.lib.php)
|
||||
$arrayoflabels = array();
|
||||
foreach (array_keys($_Avery_Labels) as $codecards)
|
||||
{
|
||||
foreach (array_keys($_Avery_Labels) as $codecards) {
|
||||
$labeltoshow = $_Avery_Labels[$codecards]['name'];
|
||||
//$labeltoshow.=' ('.$_Avery_Labels[$row['code']]['paper-size'].')';
|
||||
$arrayoflabels[$codecards] = $labeltoshow;
|
||||
@ -387,8 +377,7 @@ jQuery(document).ready(function() {
|
||||
print '<input id="fillmanually" type="radio" '.((!GETPOST("selectorforbarcode") || GETPOST("selectorforbarcode") == 'fillmanually') ? 'checked ' : '').'name="selectorforbarcode" value="fillmanually" class="radiobarcodeselect"> '.$langs->trans("FillBarCodeTypeAndValueManually").' ';
|
||||
print '<br>';
|
||||
|
||||
if (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire))
|
||||
{
|
||||
if (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire)) {
|
||||
print '<input id="fillfromproduct" type="radio" '.((GETPOST("selectorforbarcode") == 'fillfromproduct') ? 'checked ' : '').'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"> '.$langs->trans("FillBarCodeTypeAndValueFromProduct").' ';
|
||||
print '<br>';
|
||||
print '<div class="showforproductselector">';
|
||||
@ -397,8 +386,7 @@ if (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire)
|
||||
print '</div>';
|
||||
}
|
||||
|
||||
if (!empty($user->rights->societe->lire))
|
||||
{
|
||||
if (!empty($user->rights->societe->lire)) {
|
||||
print '<input id="fillfromthirdparty" type="radio" '.((GETPOST("selectorforbarcode") == 'fillfromthirdparty') ? 'checked ' : '').'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"> '.$langs->trans("FillBarCodeTypeAndValueFromThirdParty").' ';
|
||||
print '<br>';
|
||||
print '<div class="showforthirdpartyselector">';
|
||||
@ -409,12 +397,10 @@ if (!empty($user->rights->societe->lire))
|
||||
|
||||
print '<br>';
|
||||
|
||||
if ($producttmp->id > 0)
|
||||
{
|
||||
if ($producttmp->id > 0) {
|
||||
print $langs->trans("BarCodeDataForProduct", '').' '.$producttmp->getNomUrl(1).'<br>';
|
||||
}
|
||||
if ($thirdpartytmp->id > 0)
|
||||
{
|
||||
if ($thirdpartytmp->id > 0) {
|
||||
print $langs->trans("BarCodeDataForThirdparty", '').' '.$thirdpartytmp->getNomUrl(1).'<br>';
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user