26 if (!empty($_POST[
'mode']) && $_POST[
'mode'] ===
'label') {
27 if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
33 require
'../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printsheet/modules_labels.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
40 $langs->loadLangs(array(
'admin',
'members',
'errors'));
47 $forbarcode =
GETPOST(
'forbarcode',
'alphanohtml');
48 $fk_barcode_type =
GETPOST(
'fk_barcode_type',
'int');
49 $mode =
GETPOST(
'mode',
'aZ09');
50 $modellabel =
GETPOST(
"modellabel",
'aZ09');
51 $numberofsticker =
GETPOST(
'numberofsticker',
'int');
55 $action =
GETPOST(
'action',
'aZ09');
58 $thirdpartytmp =
new Societe($db);
66 if (!$user->hasRight(
'barcode',
'read')) {
78 if (
GETPOST(
'productid',
'int') > 0) {
79 $result = $producttmp->fetch(
GETPOST(
'productid',
'int'));
83 $forbarcode = $producttmp->barcode;
84 $fk_barcode_type = $producttmp->barcode_type;
86 if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
87 $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
90 if (empty($forbarcode) || empty($fk_barcode_type)) {
91 setEventMessages($langs->trans(
"DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()),
null,
'warnings');
97 if (
GETPOST(
'socid',
'int') > 0) {
98 $thirdpartytmp->fetch(
GETPOST(
'socid',
'int'));
99 $forbarcode = $thirdpartytmp->barcode;
100 $fk_barcode_type = $thirdpartytmp->barcode_type_code;
102 if (empty($fk_barcode_type) && !empty($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY)) {
103 $fk_barcode_type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
106 if (empty($forbarcode) || empty($fk_barcode_type)) {
107 setEventMessages($langs->trans(
"DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()),
null,
'warnings');
112 if ($action ==
'builddoc') {
113 $result = 0; $error = 0;
115 if (empty($forbarcode)) {
116 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeValue")),
null,
'errors');
121 setEventMessages($langs->trans(
"ErrorFieldTooLong", $langs->transnoentitiesnoconv(
"BarcodeValue")).
' ('.$langs->trans(
"RequireXStringMax", $MAXLENGTH).
')',
null,
'errors');
124 if (empty($fk_barcode_type)) {
125 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeType")),
null,
'errors');
132 $stdobject->barcode_type = $fk_barcode_type;
133 $result = $stdobject->fetch_barcode();
136 setEventMessages(
'Failed to get bar code type information '.$stdobject->error, $stdobject->errors,
'errors');
142 $generator = $stdobject->barcode_type_coder;
143 $encoding = strtoupper($stdobject->barcode_type_code);
145 $diroutput = $conf->barcode->dir_temp;
149 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
151 foreach ($dirbarcode as $reldir) {
156 if (!is_dir($newdir)) {
160 $result = @include_once $newdir.$generator.
'.modules.php';
167 $classname =
"mod".ucfirst($generator);
168 $module =
new $classname($db);
169 if ($generator !=
'tcpdfbarcode') {
171 $template =
'standardlabel';
173 if ($module->encodingIsSupported($encoding)) {
174 $barcodeimage = $conf->barcode->dir_temp.
'/barcode_'.$code.
'_'.$encoding.
'.png';
177 $result = $module->writeBarCode($code, $encoding,
'Y', 4, 1);
180 setEventMessages(
'Failed to generate image file of barcode for code='.$code.
' encoding='.$encoding.
' file='.basename($barcodeimage),
null,
'errors');
185 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');
188 $template =
'tcpdflabel';
189 $encoding = $module->getTcpdfEncodingType($encoding);
190 $is2d = $module->is2d;
196 $substitutionarray = array(
197 '%LOGIN%' => $user->login,
198 '%COMPANY%' => $mysoc->name,
199 '%ADDRESS%' => $mysoc->address,
200 '%ZIP%' => $mysoc->zip,
201 '%TOWN%' => $mysoc->town,
202 '%COUNTRY%' => $mysoc->country,
203 '%COUNTRY_CODE%' => $mysoc->country_code,
204 '%EMAIL%' => $mysoc->email,
208 '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
209 '%SERVER%' =>
"http://".$_SERVER[
"SERVER_NAME"].
"/",
214 if ($mode ==
'label') {
215 $txtforsticker =
"%PHOTO%";
216 $textleft =
make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT) ? $txtforsticker : $conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray);
217 $textheader =
make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray);
218 $textfooter =
make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray);
219 $textright =
make_substitutions((empty($conf->global->BARCODE_LABEL_RIGHT_TEXT) ?
'' : $conf->global->BARCODE_LABEL_RIGHT_TEXT), $substitutionarray);
220 $forceimgscalewidth = (empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH);
221 $forceimgscaleheight = (empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT);
224 if ($numberofsticker <= $MAXSTICKERS) {
225 for ($i = 0; $i < $numberofsticker; $i++) {
226 $arrayofrecords[] = array(
227 'textleft'=>$textleft,
228 'textheader'=>$textheader,
229 'textfooter'=>$textfooter,
230 'textright'=>$textright,
232 'encoding'=>$encoding,
234 'photo'=>!empty($barcodeimage) ? $barcodeimage :
''
238 $mesg = $langs->trans(
"ErrorQuantityIsLimitedTo", $MAXSTICKERS);
246 if (!$error && $mode ==
'label') {
247 if (!count($arrayofrecords)) {
248 $mesg = $langs->trans(
"ErrorRecordNotFound");
250 if (empty($modellabel) || $modellabel ==
'-1') {
251 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
257 $outputlangs = $langs;
265 if ($result <= 0 || $mesg || $error) {
267 $mesg =
'Error '.$result;
285 llxHeader(
'', $langs->trans(
"BarCodePrintsheet"));
290 print
'<span class="opacitymedium">'.$langs->trans(
"PageToGenerateBarCodeSheets", $langs->transnoentitiesnoconv(
"BuildPageToPrint")).
'</span><br>';
296 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
297 print
'<input type="hidden" name="mode" value="label">';
298 print
'<input type="hidden" name="action" value="builddoc">';
299 print
'<input type="hidden" name="token" value="'.currentToken().
'">';
301 print
'<div class="tagtable">';
304 print
' <div class="tagtr">';
305 print
' <div class="tagtd">';
306 print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
307 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
309 $arrayoflabels = array();
310 foreach (array_keys($_Avery_Labels) as $codecards) {
311 $labeltoshow = $_Avery_Labels[$codecards][
'name'];
313 $arrayoflabels[$codecards] = $labeltoshow;
315 asort($arrayoflabels);
316 print
$form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') : $conf->global->ADHERENT_ETIQUETTE_TYPE), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
317 print
'</div></div>';
320 print
' <div class="tagtr">';
321 print
' <div class="tagtd">';
322 print $langs->trans(
"NumberOfStickers").
' ';
323 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
324 print
'<input size="4" type="text" name="numberofsticker" value="'.(GETPOST(
'numberofsticker') ?
GETPOST(
'numberofsticker',
'int') : 10).
'">';
325 print
'</div></div>';
334 print
'<script type="text/javascript">
335 jQuery(document).ready(function() {
336 function init_selectors()
338 if (jQuery("#fillmanually:checked").val() == "fillmanually")
340 jQuery("#submitproduct").prop("disabled", true);
341 jQuery("#submitthirdparty").prop("disabled", true);
342 jQuery("#search_productid").prop("disabled", true);
343 jQuery("#socid").prop("disabled", true);
344 jQuery(".showforproductselector").hide();
345 jQuery(".showforthirdpartyselector").hide();
347 if (jQuery("#fillfromproduct:checked").val() == "fillfromproduct")
349 jQuery("#submitproduct").removeAttr("disabled");
350 jQuery("#submitthirdparty").prop("disabled", true);
351 jQuery("#search_productid").removeAttr("disabled");
352 jQuery("#socid").prop("disabled", true);
353 jQuery(".showforproductselector").show();
354 jQuery(".showforthirdpartyselector").hide();
356 if (jQuery("#fillfromthirdparty:checked").val() == "fillfromthirdparty")
358 jQuery("#submitproduct").prop("disabled", true);
359 jQuery("#submitthirdparty").removeAttr("disabled");
360 jQuery("#search_productid").prop("disabled", true);
361 jQuery("#socid").removeAttr("disabled");
362 jQuery(".showforproductselector").hide();
363 jQuery(".showforthirdpartyselector").show();
367 jQuery(".radiobarcodeselect").click(function() {
371 function init_gendoc_button()
373 if (jQuery("#select_fk_barcode_type").val() > 0 && jQuery("#forbarcode").val())
375 jQuery("#submitformbarcodegen").removeAttr("disabled");
379 jQuery("#submitformbarcodegen").prop("disabled", true);
382 init_gendoc_button();
383 jQuery("#select_fk_barcode_type").change(function() {
384 init_gendoc_button();
386 jQuery("#forbarcode").keyup(function() {
393 print
'<input id="fillmanually" type="radio" '.((!
GETPOST(
"selectorforbarcode") ||
GETPOST(
"selectorforbarcode") ==
'fillmanually') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillmanually" class="radiobarcodeselect"><label for="fillmanually"> '.$langs->trans(
"FillBarCodeTypeAndValueManually").
'</label>';
396 if (!empty($user->rights->produit->lire) || $user->hasRight(
'service',
'lire')) {
397 print
'<input id="fillfromproduct" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromproduct') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"><label for="fillfromproduct"> '.$langs->trans(
"FillBarCodeTypeAndValueFromProduct").
'</label>';
399 print
'<div class="showforproductselector">';
400 $form->select_produits(
GETPOST(
'productid',
'int'),
'productid',
'',
'', 0, -1, 2,
'', 0, array(), 0,
'1', 0,
'minwidth400imp', 1);
401 print
' <input type="submit" class="button small" id="submitproduct" name="submitproduct" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
405 if ($user->hasRight(
'societe',
'lire')) {
406 print
'<input id="fillfromthirdparty" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromthirdparty') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"><label for="fillfromthirdparty"> '.$langs->trans(
"FillBarCodeTypeAndValueFromThirdParty").
'</label>';
408 print
'<div class="showforthirdpartyselector">';
409 print
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
410 print
' <input type="submit" id="submitthirdparty" name="submitthirdparty" class="button showforthirdpartyselector small" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
416 if ($producttmp->id > 0) {
417 print $langs->trans(
"BarCodeDataForProduct",
'').
' '.$producttmp->getNomUrl(1).
'<br>';
419 if ($thirdpartytmp->id > 0) {
420 print $langs->trans(
"BarCodeDataForThirdparty",
'').
' '.$thirdpartytmp->getNomUrl(1).
'<br>';
423 print
'<div class="tagtable">';
426 print
' <div class="tagtr">';
427 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
428 print $langs->trans(
"BarcodeType").
' ';
429 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
430 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formbarcode.class.php';
432 print $formbarcode->selectBarcodeType($fk_barcode_type,
'fk_barcode_type', 1);
433 print
'</div></div>';
436 print
' <div class="tagtr">';
437 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
438 print $langs->trans(
"BarcodeValue").
' ';
439 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
440 print
'<input size="16" type="text" name="forbarcode" id="forbarcode" value="'.$forbarcode.
'">';
441 print
'</div></div>';
452 print
'<br><input type="submit" class="button" id="submitformbarcodegen" '.((GETPOST(
"selectorforbarcode") &&
GETPOST(
"selectorforbarcode")) ?
'' :
'disabled ').
'value="'.$langs->trans(
"BuildPageToPrint").
'">';