30if (!empty($_POST[
'mode']) && $_POST[
'mode'] ===
'label') {
31 if (!defined(
'NOTOKENRENEWAL')) {
32 define(
'NOTOKENRENEWAL',
'1');
37require
'../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/modules/printsheet/modules_labels.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
55$langs->loadLangs(array(
'admin',
'members',
'errors'));
62$forbarcode =
GETPOST(
'forbarcode',
'alphanohtml');
63$fk_barcode_type =
GETPOSTINT(
'fk_barcode_type');
65$modellabel =
GETPOST(
"modellabel",
'aZ09');
66$numberofsticker =
GETPOSTINT(
'numberofsticker');
68$label_product_ref_option =
GETPOSTISSET(
'label_product_ref_option');
69$label_product_label_option =
GETPOSTISSET(
'label_product_label_option');
72 $security_check =
'nohtml';
74 $security_check = !
getDolGlobalString(
'MAIN_SECURITY_ALLOW_UNSECURED_LABELS_WITH_HTML') ?
'alphanohtml' :
'restricthtml';
76$label_product_ref = (
GETPOSTISSET(
'label_product_ref') ?
GETPOST(
'label_product_ref', $security_check) : null);
77$label_product_label = (
GETPOSTISSET(
'label_product_label') ?
GETPOST(
'label_product_label', $security_check) : null);
81$action =
GETPOST(
'action',
'aZ09');
92if (!$user->hasRight(
'barcode',
'read')) {
96$hookmanager->initHooks(array(
'printsheettools'));
108$parameters = array();
109$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
114if (empty($reshook)) {
115 if (
GETPOST(
'submitproduct')) {
118 $result = $producttmp->fetch(
GETPOSTINT(
'productid'));
122 $forbarcode = $producttmp->barcode;
123 $fk_barcode_type = $producttmp->barcode_type;
129 if (empty($forbarcode) || empty($fk_barcode_type)) {
130 setEventMessages($langs->trans(
"DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()),
null,
'warnings');
133 if (empty($label_product_ref) && $label_product_ref_option) {
134 $label_product_ref = $producttmp->ref;
137 if (empty($label_product_label) && $label_product_label_option) {
138 $label_product_label = $producttmp->label;
142 if (
GETPOST(
'submitthirdparty')) {
146 $forbarcode = $thirdpartytmp->barcode;
147 $fk_barcode_type = $thirdpartytmp->barcode_type_code;
149 if (empty($fk_barcode_type) &&
getDolGlobalString(
'GENBARCODE_BARCODETYPE_THIRDPARTY')) {
153 if (empty($forbarcode) || empty($fk_barcode_type)) {
154 setEventMessages($langs->trans(
"DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()),
null,
'warnings');
159 if ($action ==
'builddoc' && $user->hasRight(
'barcode',
'read')) {
163 if (empty($forbarcode)) {
164 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeValue")),
null,
'errors');
169 setEventMessages($langs->trans(
"ErrorFieldTooLong", $langs->transnoentitiesnoconv(
"BarcodeValue")).
' ('.$langs->trans(
"RequireXStringMax", $MAXLENGTH).
')',
null,
'errors');
172 if (empty($fk_barcode_type)) {
173 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeType")),
null,
'errors');
178 $result = $producttmp->fetch(
GETPOSTINT(
'productid'));
182 if (empty($label_product_ref) && $label_product_ref_option) {
183 $label_product_ref = $producttmp->ref;
186 if (empty($label_product_label) && $label_product_label_option) {
187 $label_product_label = $producttmp->label;
195 $stdobject->barcode_type = $fk_barcode_type;
196 $result = $stdobject->fetchBarCode();
199 setEventMessages(
'Failed to get bar code type information '.$stdobject->error, $stdobject->errors,
'errors');
209 if (!$error && $stdobject !==
null) {
210 $generator = $stdobject->barcode_type_coder;
211 $encoding = strtoupper($stdobject->barcode_type_code);
213 $diroutput =
$conf->barcode->dir_temp;
217 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"),
$conf->modules_parts[
'barcode']);
219 foreach ($dirbarcode as $reldir) {
224 if (!is_dir($newdir)) {
228 $result = @include_once $newdir.$generator.
'.modules.php';
235 $classname =
"mod".ucfirst($generator);
237 $module =
new $classname(
$db);
240 if ($generator !=
'tcpdfbarcode') {
241 '@phan-var-force modPhpbarcode $module';
242 $template =
'standardlabel';
243 if ($module->encodingIsSupported($encoding)) {
244 $barcodeimage =
$conf->barcode->dir_temp.
'/barcode_'.$code.
'_'.$encoding.
'.png';
247 $result = $module->writeBarCode($code, $encoding,
'Y', 4, 1);
250 setEventMessages(
'Failed to generate image file of barcode for code='.$code.
' encoding='.$encoding.
' file='.basename($barcodeimage),
null,
'errors');
255 setEventMessages(
"Error, encoding ".$encoding.
" is not supported by encoder ".$generator.
'. You must choose another barcode type or install a barcode generation engine that support '.$encoding,
null,
'errors');
258 '@phan-var-force modTcpdfbarcode $module';
259 $template =
'tcpdflabel';
260 $encoding = $module->getTcpdfEncodingType($encoding);
261 $is2d = $module->is2d;
268 $substitutionarray = array(
270 '%LOGIN%' => $user->login,
271 '%COMPANY%' =>
$mysoc->name,
272 '%ADDRESS%' =>
$mysoc->address,
275 '%COUNTRY%' =>
$mysoc->country,
276 '%COUNTRY_CODE%' =>
$mysoc->country_code,
277 '%EMAIL%' =>
$mysoc->email,
281 '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
284 '__LOGIN__' => $user->login,
285 '__COMPANY__' =>
$mysoc->name,
286 '__ADDRESS__' =>
$mysoc->address,
288 '__TOWN__' =>
$mysoc->town,
289 '__COUNTRY__' =>
$mysoc->country,
290 '__COUNTRY_CODE__' =>
$mysoc->country_code,
291 '__EMAIL__' =>
$mysoc->email,
293 '__MONTH__' => $month,
295 '__DOL_MAIN_URL_ROOT__' => DOL_MAIN_URL_ROOT,
300 $arrayofrecords = array();
302 if ($mode ==
'label') {
303 $txtforsticker =
"%PHOTO%";
305 if ((
GETPOSTINT(
'productid') > 0) && $label_product_ref_option) {
306 $textheader = $label_product_ref;
310 if ((
GETPOSTINT(
'productid') > 0) && $label_product_label_option) {
311 $textfooter = $label_product_label;
320 if ($numberofsticker <= $MAXSTICKERS) {
321 for ($i = 0; $i < $numberofsticker; $i++) {
322 $arrayofrecords[] = array(
323 'textleft' => $textleft,
324 'textheader' => $textheader,
325 'textfooter' => $textfooter,
326 'textright' => $textright,
328 'encoding' => $encoding,
330 'photo' => !empty($barcodeimage) ? $barcodeimage :
''
334 $mesg = $langs->trans(
"ErrorQuantityIsLimitedTo", $MAXSTICKERS);
340 if (!$error && $mode ==
'label') {
341 if (!count($arrayofrecords)) {
342 $mesg = $langs->trans(
"ErrorRecordNotFound");
344 if (empty($modellabel) || $modellabel ==
'-1') {
345 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
351 $outputlangs = $langs;
354 $conf->global->TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = 1;
361 $mesg = $langs->trans(
'ErrorGeneratingBarcode');
365 $conf->global->TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = $previousConf;
369 if ($result <= 0 || $mesg || $error) {
371 $mesg =
'Error '.$result;
390llxHeader(
'', $langs->trans(
"BarCodePrintsheet"),
'',
'', 0, 0,
'',
'',
'',
'mod-barcode page-printsheet');
395print
'<span class="opacitymedium">'.$langs->trans(
"PageToGenerateBarCodeSheets", $langs->transnoentitiesnoconv(
"BuildPageToPrint")).
'</span><br>';
401print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
402print
'<input type="hidden" name="mode" value="label">';
403print
'<input type="hidden" name="action" value="builddoc">';
404print
'<input type="hidden" name="token" value="'.currentToken().
'">';
406print
'<div class="tagtable">';
409print
' <div class="tagtr">';
410print
' <div class="tagtd">';
411print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
412print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
414$arrayoflabels = array();
415foreach (array_keys($_Avery_Labels) as $codecards) {
416 $labeltoshow = $_Avery_Labels[$codecards][
'name'];
418 $arrayoflabels[$codecards] = $labeltoshow;
420asort($arrayoflabels);
421print $form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') :
getDolGlobalString(
'ADHERENT_ETIQUETTE_TYPE')), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
425print
' <div class="tagtr">';
426print
' <div class="tagtd">';
427print $langs->trans(
"NumberOfStickers").
' ';
428print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
429print
'<input size="4" type="text" name="numberofsticker" value="'.(GETPOST(
'numberofsticker') ?
GETPOSTINT(
'numberofsticker') : 10).
'">';
439print
'<script type="text/javascript">
440jQuery(document).ready(function() {
441 function init_selectors()
443 if (jQuery("#fillmanually:checked").val() == "fillmanually")
445 jQuery("#submitproduct").prop("disabled", true);
446 jQuery("#submitthirdparty").prop("disabled", true);
447 jQuery("#search_productid").prop("disabled", true);
448 jQuery("#socid").prop("disabled", true);
449 jQuery(".showforproductselector").hide();
450 jQuery(".showforthirdpartyselector").hide();
452 if (jQuery("#fillfromproduct:checked").val() == "fillfromproduct")
454 jQuery("#submitproduct").removeAttr("disabled");
455 jQuery("#submitthirdparty").prop("disabled", true);
456 jQuery("#search_productid").removeAttr("disabled");
457 jQuery("#socid").prop("disabled", true);
458 jQuery(".showforproductselector").show();
459 jQuery(".showforthirdpartyselector").hide();
461 if (jQuery("#fillfromthirdparty:checked").val() == "fillfromthirdparty")
463 jQuery("#submitproduct").prop("disabled", true);
464 jQuery("#submitthirdparty").removeAttr("disabled");
465 jQuery("#search_productid").prop("disabled", true);
466 jQuery("#socid").removeAttr("disabled");
467 jQuery(".showforproductselector").hide();
468 jQuery(".showforthirdpartyselector").show();
472 jQuery(".radiobarcodeselect").click(function() {
476 function init_gendoc_button()
478 if (jQuery("#select_fk_barcode_type").val() > 0 && jQuery("#forbarcode").val())
480 jQuery("#submitformbarcodegen").removeAttr("disabled");
484 jQuery("#submitformbarcodegen").prop("disabled", true);
487 init_gendoc_button();
488 jQuery("#select_fk_barcode_type").change(function() {
489 init_gendoc_button();
491 jQuery("#forbarcode").keyup(function() {
498print
'<input id="fillmanually" type="radio" '.((!
GETPOST(
"selectorforbarcode") ||
GETPOST(
"selectorforbarcode") ==
'fillmanually') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillmanually" class="radiobarcodeselect"><label for="fillmanually"> '.$langs->trans(
"FillBarCodeTypeAndValueManually").
'</label>';
501if ($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire')) {
502 print
'<input id="fillfromproduct" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromproduct') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"><label for="fillfromproduct"> '.$langs->trans(
"FillBarCodeTypeAndValueFromProduct").
'</label>';
504 print
'<div class="showforproductselector">';
505 $form->select_produits(
GETPOSTINT(
'productid'),
'productid',
'', 0, 0, -1, 2,
'', 0, array(), 0,
'1', 0,
'minwidth400imp', 1);
506 print
' <input type="submit" class="button small" id="submitproduct" name="submitproduct" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
510if ($user->hasRight(
'societe',
'lire')) {
511 print
'<input id="fillfromthirdparty" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromthirdparty') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"><label for="fillfromthirdparty"> '.$langs->trans(
"FillBarCodeTypeAndValueFromThirdParty").
'</label>';
513 print
'<div class="showforthirdpartyselector">';
514 print $form->select_company(
GETPOSTINT(
'socid'),
'socid',
'',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
515 print
' <input type="submit" id="submitthirdparty" name="submitthirdparty" class="button showforthirdpartyselector small" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
521if ($producttmp->id > 0) {
522 print $langs->trans(
"BarCodeDataForProduct",
'').
' '.$producttmp->getNomUrl(1).
'<br>';
524if ($thirdpartytmp->id > 0) {
525 print $langs->trans(
"BarCodeDataForThirdparty",
'').
' '.$thirdpartytmp->getNomUrl(1).
'<br>';
528print
'<div class="tagtable">';
531print
' <div class="tagtr">';
532print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
533print $langs->trans(
"BarcodeType").
' ';
534print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
535require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formbarcode.class.php';
537print $formbarcode->selectBarcodeType($fk_barcode_type,
'fk_barcode_type', 1);
541print
' <div class="tagtr">';
542print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
543print $langs->trans(
"BarcodeValue").
' ';
544print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
545print
'<input size="16" type="text" name="forbarcode" id="forbarcode" value="'.$forbarcode.
'">';
550if ($producttmp->id > 0) {
551 print
' <div class="tagtr">';
552 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 500px;">';
553 print
'<input id="label_product_ref_option" name="label_product_ref_option" type="checkbox" '.(GETPOSTISSET(
"label_product_ref_option") ?
'checked ' :
'').
' class="checkforselect"><label for="label_product_ref_option"> '.$langs->trans(
"BarcodeLabelProductRef").
'</label>';
554 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 500px;">';
555 print
'<input type="text" name="label_product_ref" id="label_product_ref" placeholder="'.$langs->trans(
"BarcodeLabelProductRefPlaceholder").
'" value="'.$label_product_ref.
'">';
556 print
'</div></div>';
557 print
' <div class="tagtr">';
558 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 500px;">';
559 print
'<input id="label_product_label_option" name="label_product_label_option" type="checkbox" '.(GETPOSTISSET(
"label_product_label_option") ?
'checked ' :
'').
' class="checkforselect"><label for="label_product_label_option"> '.$langs->trans(
"BarcodeLabelProductLabel").
'</label>';
560 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 500px;">';
561 print
'<input type="text" name="label_product_label" id="label_product_label" placeholder="'.$langs->trans(
"BarcodeLabelProductLabelPlaceholder").
'" value="'.$label_product_label.
'">';
562 print
'</div></div>';
574print
'<br><input type="submit" class="button" id="submitformbarcodegen" '.(GETPOST(
"selectorforbarcode") ?
'' :
'disabled ').
'value="'.$langs->trans(
"BuildPageToPrint").
'">';
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class of a generic business object.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
doc_label_pdf_create($db, $arrayofrecords, $modele, $outputlangs, $outputdir='', $template='standardlabel', $filename='tmp_address_sheet.pdf')
Create a document onto disk according to template module.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.