New: Work on a basic print barcode page
This commit is contained in:
parent
0e3757aa5c
commit
5f15dcded7
@ -26,6 +26,7 @@ require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/format_cards.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/modules/printsheet/modules_labels.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
|
||||
|
||||
$langs->load("admin");
|
||||
$langs->load("errors");
|
||||
@ -36,124 +37,166 @@ $year=dol_print_date($now,'%Y');
|
||||
$month=dol_print_date($now,'%m');
|
||||
$day=dol_print_date($now,'%d');
|
||||
$forbarcode=GETPOST('forbarcode');
|
||||
$forbartype=GETPOST('forbartype');
|
||||
$fk_barcode_type=GETPOST('fk_barcode_type');
|
||||
$mode=GETPOST('mode');
|
||||
$model=GETPOST("model"); // Doc template to use for business cards
|
||||
$modellabel=GETPOST("modellabel"); // Doc template to use for address sheet
|
||||
$modellabel=GETPOST("modellabel"); // Doc template to use
|
||||
$numberofsticker=GETPOST('numberofsticker','int');
|
||||
|
||||
$mesg='';
|
||||
|
||||
$action=GETPOST('action');
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'builddoc' && empty($forbarcode))
|
||||
if ($action == 'builddoc')
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Barcode"));
|
||||
}
|
||||
if ($action == 'builddoc' && empty($forbartype))
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType"));
|
||||
}
|
||||
$result=0; $error=0;
|
||||
|
||||
if ((! empty($forbarcode) || ! empty($forbartype) || ! empty($mode)) && ! $mesg)
|
||||
{
|
||||
// List of values to scan for a replacement
|
||||
$substitutionarray = array (
|
||||
'%LOGIN%'=>$user->login,
|
||||
'%COMPANY%'=>$mysoc->name,
|
||||
'%ADDRESS%'=>$mysoc->address,
|
||||
'%ZIP%'=>$mysoc->zip,
|
||||
'%TOWN%'=>$mysoc->town,
|
||||
'%COUNTRY%'=>$mysoc->country,
|
||||
'%COUNTRY_CODE%'=>$mysoc->country_code,
|
||||
'%EMAIL%'=>$mysoc->email,
|
||||
'%YEAR%'=>$year,
|
||||
'%MONTH%'=>$month,
|
||||
'%DAY%'=>$day,
|
||||
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
|
||||
'%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/"
|
||||
);
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
|
||||
// For business cards
|
||||
if (empty($mode) || $mode=='card' || $mode=='cardlogin')
|
||||
if (empty($forbarcode)) // barcode value
|
||||
{
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_CARD_TEXT, $substitutionarray);
|
||||
$textheader=make_substitutions($conf->global->ADHERENT_CARD_HEADER_TEXT, $substitutionarray);
|
||||
$textfooter=make_substitutions($conf->global->ADHERENT_CARD_FOOTER_TEXT, $substitutionarray);
|
||||
$textright=make_substitutions($conf->global->ADHERENT_CARD_TEXT_RIGHT, $substitutionarray);
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeValue")),'errors');
|
||||
$error++;
|
||||
}
|
||||
if (empty($fk_barcode_type)) // barcode type = barcode encoding
|
||||
{
|
||||
setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("BarcodeType")),'errors');
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (is_numeric($forbarcode) || $forbartype)
|
||||
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)
|
||||
{
|
||||
for($j=0;$j<100;$j++)
|
||||
$error++;
|
||||
setEventMessage('Failed to get bar code type information '.$stdobject->error, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$code=$forbarcode;
|
||||
$generator=$stdobject->barcode_type_coder;
|
||||
$encoding=strtoupper($stdobject->barcode_type_code);
|
||||
$barcodeimage=$conf->barcode->dir_temp.'/barcode_'.$code.'_'.$encoding.'.png';
|
||||
|
||||
$diroutput=$conf->barcode->dir_temp;
|
||||
dol_mkdir($diroutput);
|
||||
|
||||
// Generate barcode
|
||||
$dirbarcode=array_merge(array("/core/modules/barcode/"),$conf->modules_parts['barcode']);
|
||||
|
||||
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;
|
||||
|
||||
$result=@include_once $newdir.$generator.'.modules.php';
|
||||
if ($result) break;
|
||||
}
|
||||
|
||||
// Load barcode class
|
||||
$classname = "mod".ucfirst($generator);
|
||||
$module = new $classname($db);
|
||||
if ($module->encodingIsSupported($encoding))
|
||||
{
|
||||
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);
|
||||
|
||||
if ($result <= 0 || ! dol_is_file($barcodeimage))
|
||||
{
|
||||
$error++;
|
||||
setEventMessage('Failed to generate image file of barcode for code='.$code.' encoding='.$encoding.' file='.basename($barcodeimage), 'errors');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
setEventMessage("Error, encoding ".$encoding." is not supported by encoder ".$generator.'. You must choose another barcode type or install a barcode generation engine that support '.$encoding, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// List of values to scan for a replacement
|
||||
$substitutionarray = array (
|
||||
'%LOGIN%'=>$user->login,
|
||||
'%COMPANY%'=>$mysoc->name,
|
||||
'%ADDRESS%'=>$mysoc->address,
|
||||
'%ZIP%'=>$mysoc->zip,
|
||||
'%TOWN%'=>$mysoc->town,
|
||||
'%COUNTRY%'=>$mysoc->country,
|
||||
'%COUNTRY_CODE%'=>$mysoc->country_code,
|
||||
'%EMAIL%'=>$mysoc->email,
|
||||
'%YEAR%'=>$year,
|
||||
'%MONTH%'=>$month,
|
||||
'%DAY%'=>$day,
|
||||
'%DOL_MAIN_URL_ROOT%'=>DOL_MAIN_URL_ROOT,
|
||||
'%SERVER%'=>"http://".$_SERVER["SERVER_NAME"]."/"
|
||||
);
|
||||
complete_substitutions_array($substitutionarray, $langs);
|
||||
|
||||
// For labels
|
||||
if ($mode == 'label')
|
||||
{
|
||||
if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT="%PHOTO%";
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
|
||||
$textheader='';
|
||||
$textfooter='';
|
||||
$textright='';
|
||||
$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++)
|
||||
{
|
||||
$arrayofmembers[]=array(
|
||||
'textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
'textfooter'=>$textfooter,
|
||||
'textright'=>$textright,
|
||||
'id'=>$objp->rowid,
|
||||
'photo'=>$objp->photo
|
||||
'textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
'textfooter'=>$textfooter,
|
||||
'textright'=>$textright,
|
||||
'photo'=>$barcodeimage // Photo must be a file that exists with format supported by TCPDF
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
$i++;
|
||||
$mesg='';
|
||||
|
||||
// Build and output PDF
|
||||
if ($mode == 'label')
|
||||
{
|
||||
$arrayofmembers[]=array(
|
||||
'textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
'textfooter'=>$textfooter,
|
||||
'textright'=>$textright,
|
||||
'id'=>$objp->rowid,
|
||||
'photo'=>$objp->photo
|
||||
);
|
||||
if (! count($arrayofmembers))
|
||||
{
|
||||
$mesg=$langs->trans("ErrorRecordNotFound");
|
||||
}
|
||||
if (empty($modellabel) || $modellabel == '-1')
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
|
||||
}
|
||||
if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs, $diroutput);
|
||||
}
|
||||
}
|
||||
|
||||
// For labels
|
||||
if ($mode == 'label')
|
||||
{
|
||||
if (empty($conf->global->ADHERENT_ETIQUETTE_TEXT)) $conf->global->ADHERENT_ETIQUETTE_TEXT="%FULLNAME%\n%ADDRESS%\n%ZIP% %TOWN%\n%COUNTRY%";
|
||||
$textleft=make_substitutions($conf->global->ADHERENT_ETIQUETTE_TEXT, $substitutionarray);
|
||||
$textheader='';
|
||||
$textfooter='';
|
||||
$textright='';
|
||||
|
||||
$arrayofmembers[]=array('textleft'=>$textleft,
|
||||
'textheader'=>$textheader,
|
||||
'textfooter'=>$textfooter,
|
||||
'textright'=>$textright,
|
||||
'id'=>$objp->rowid,
|
||||
'photo'=>$objp->photo);
|
||||
}
|
||||
|
||||
$i++;
|
||||
|
||||
// Build and output PDF
|
||||
if ($mode == 'label')
|
||||
{
|
||||
if (! count($arrayofmembers))
|
||||
if ($result <= 0)
|
||||
{
|
||||
$mesg=$langs->trans("ErrorRecordNotFound");
|
||||
dol_print_error('',$result);
|
||||
}
|
||||
if (empty($modellabel) || $modellabel == '-1')
|
||||
{
|
||||
$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("DescADHERENT_ETIQUETTE_TYPE"));
|
||||
}
|
||||
if (! $mesg) $result=members_label_pdf_create($db, $arrayofmembers, $modellabel, $outputlangs);
|
||||
}
|
||||
|
||||
if ($result <= 0)
|
||||
{
|
||||
dol_print_error('',$result);
|
||||
if (! $mesg)
|
||||
{
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $mesg)
|
||||
{
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -168,16 +211,25 @@ llxHeader('',$langs->trans("BarCodePrintsheet"));
|
||||
print_fiche_titre($langs->trans("BarCodePrintsheet"));
|
||||
print '<br>';
|
||||
|
||||
print $langs->trans("PageToGenerateBarCodeSheets").'<br>';
|
||||
print $langs->trans("PageToGenerateBarCodeSheets",$langs->transnoentitiesnoconv("BuildPageToPrint")).'<br>';
|
||||
print '<br>';
|
||||
|
||||
dol_htmloutput_errors($mesg);
|
||||
|
||||
print img_picto('','puce').' '.$langs->trans("BarCodePrintsheet").' ';
|
||||
//print img_picto('','puce').' '.$langs->trans("PrintsheetForOneBarCode").'<br>';
|
||||
//print '<br>';
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
||||
print '<input type="hidden" name="mode" value="label">';
|
||||
print '<input type="hidden" name="action" value="builddoc">';
|
||||
print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
|
||||
|
||||
print '<div class="tagtable">';
|
||||
|
||||
// Sheet format
|
||||
print ' <div class="tagtr">';
|
||||
print ' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print $langs->trans("DescADHERENT_ETIQUETTE_TYPE").' ';
|
||||
print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
// List of possible labels (defined into $_Avery_Labels variable set into format_cards.lib.php)
|
||||
$arrayoflabels=array();
|
||||
foreach(array_keys($_Avery_Labels) as $codecards)
|
||||
@ -185,12 +237,64 @@ foreach(array_keys($_Avery_Labels) as $codecards)
|
||||
$arrayoflabels[$codecards]=$_Avery_Labels[$codecards]['name'];
|
||||
}
|
||||
print $form->selectarray('modellabel',$arrayoflabels,(GETPOST('modellabel')?GETPOST('modellabel'):$conf->global->ADHERENT_ETIQUETTE_TYPE),1,0,0);
|
||||
print '<br>'.$langs->trans("Barcode").': <input size="10" type="text" name="forbarcode" value="'.GETPOST('forbarcode').'">';
|
||||
print '<br>'.$langs->trans("Bartype").': <input size="10" type="text" name="forbartype" value="'.GETPOST('forbartype').'">';
|
||||
print '</div></div>';
|
||||
|
||||
// Number of stickers to print
|
||||
print ' <div class="tagtr">';
|
||||
print ' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print $langs->trans("NumberOfStickers").' ';
|
||||
print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print '<input size="4" type="text" name="numberofsticker" value="'.(GETPOST('numberofsticker')?GETPOST('numberofsticker','int'):10).'">';
|
||||
print '</div></div>';
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
// Checkbox to select from free text
|
||||
print '<input id="fillmanually" type="checkbox" checked="checked"> '.$langs->trans("FillBarCodeTypeAndValueManually").' ';
|
||||
print '<br>';
|
||||
|
||||
/*
|
||||
print '<input id="fillfromproduct" type="checkbox" checked="checked" disabled="true"> '.$langs->trans("FillBarCodeTypeAndValueFromProduct").' ';
|
||||
print $form->select_produits(GETPOST('productid'), 'productid', '');
|
||||
print '<br>';
|
||||
|
||||
print '<input id="fillfromthirdparty" type="checkbox" checked="checked" disabled="true"> '.$langs->trans("FillBarCodeTypeAndValueFromThirdParty").' ';
|
||||
print $form->select_company(GETPOST('socid'), 'socid', '', 1);
|
||||
print '<br>';
|
||||
*/
|
||||
|
||||
print '<div class="tagtable">';
|
||||
|
||||
// Barcode type
|
||||
print ' <div class="tagtr">';
|
||||
print ' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print $langs->trans("BarcodeType").' ';
|
||||
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';
|
||||
$formbarcode = new FormBarCode($db);
|
||||
$formbarcode->select_barcode_type($fk_barcode_type, 'fk_barcode_type', 1);
|
||||
print '</div></div>';
|
||||
|
||||
// Barcode value
|
||||
print ' <div class="tagtr">';
|
||||
print ' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print $langs->trans("BarcodeValue").' ';
|
||||
print '</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
|
||||
print '<input size="16" type="text" name="forbarcode" value="'.GETPOST('forbarcode').'">';
|
||||
print '</div></div>';
|
||||
|
||||
/*
|
||||
$barcodestickersmask=GETPOST('barcodestickersmask');
|
||||
print '<br>'.$langs->trans("BarcodeStickersMask").': <textarea cols="40" type="text" name="barcodestickersmask" value="'.GETPOST('barcodestickersmask').'">'.$barcodestickersmask.'</textarea>';
|
||||
print '<br><input class="button" type="submit" value="'.$langs->trans("BuildDoc").'">';
|
||||
print '<br>'.$langs->trans("BarcodeStickersMask").':<br>';
|
||||
print '<textarea cols="40" type="text" name="barcodestickersmask" value="'.GETPOST('barcodestickersmask').'">'.$barcodestickersmask.'</textarea>';
|
||||
print '<br>';
|
||||
*/
|
||||
|
||||
print '<br><input class="button" type="submit" value="'.$langs->trans("BuildPageToPrint").'">';
|
||||
|
||||
print '</form>';
|
||||
print '<br>';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user