26 if (!empty($_POST[
'mode']) && $_POST[
'mode'] ===
'label') {
27 if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
32 require
'../main.inc.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printsheet/modules_labels.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
39 $langs->loadLangs(array(
'admin',
'members',
'errors'));
46 $forbarcode =
GETPOST(
'forbarcode',
'alphanohtml');
47 $fk_barcode_type =
GETPOST(
'fk_barcode_type',
'int');
48 $mode =
GETPOST(
'mode',
'aZ09');
49 $modellabel =
GETPOST(
"modellabel",
'aZ09');
50 $numberofsticker =
GETPOST(
'numberofsticker',
'int');
54 $action =
GETPOST(
'action',
'aZ09');
57 $thirdpartytmp =
new Societe($db);
66 if (
GETPOST(
'productid',
'int') > 0) {
67 $result = $producttmp->fetch(
GETPOST(
'productid',
'int'));
71 $forbarcode = $producttmp->barcode;
72 $fk_barcode_type = $producttmp->barcode_type;
74 if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) {
75 $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
78 if (empty($forbarcode) || empty($fk_barcode_type)) {
79 setEventMessages($langs->trans(
"DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()),
null,
'warnings');
85 if (
GETPOST(
'socid',
'int') > 0) {
86 $thirdpartytmp->fetch(
GETPOST(
'socid',
'int'));
87 $forbarcode = $thirdpartytmp->barcode;
88 $fk_barcode_type = $thirdpartytmp->barcode_type_code;
90 if (empty($fk_barcode_type) && !empty($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY)) {
91 $fk_barcode_type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
94 if (empty($forbarcode) || empty($fk_barcode_type)) {
95 setEventMessages($langs->trans(
"DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()),
null,
'warnings');
100 if ($action ==
'builddoc') {
101 $result = 0; $error = 0;
103 if (empty($forbarcode)) {
104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeValue")),
null,
'errors');
107 if (empty($fk_barcode_type)) {
108 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeType")),
null,
'errors');
115 $stdobject->barcode_type = $fk_barcode_type;
116 $result = $stdobject->fetch_barcode();
119 setEventMessages(
'Failed to get bar code type information '.$stdobject->error, $stdobject->errors,
'errors');
125 $generator = $stdobject->barcode_type_coder;
126 $encoding = strtoupper($stdobject->barcode_type_code);
128 $diroutput = $conf->barcode->dir_temp;
132 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
134 foreach ($dirbarcode as $reldir) {
139 if (!is_dir($newdir)) {
143 $result = @include_once $newdir.$generator.
'.modules.php';
150 $classname =
"mod".ucfirst($generator);
151 $module =
new $classname($db);
152 if ($generator !=
'tcpdfbarcode') {
154 $template =
'standardlabel';
156 if ($module->encodingIsSupported($encoding)) {
157 $barcodeimage = $conf->barcode->dir_temp.
'/barcode_'.$code.
'_'.$encoding.
'.png';
160 $result = $module->writeBarCode($code, $encoding,
'Y', 4, 1);
163 setEventMessages(
'Failed to generate image file of barcode for code='.$code.
' encoding='.$encoding.
' file='.basename($barcodeimage),
null,
'errors');
168 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');
171 $template =
'tcpdflabel';
172 $encoding = $module->getTcpdfEncodingType($encoding);
173 $is2d = $module->is2d;
179 $substitutionarray = array(
180 '%LOGIN%' => $user->login,
181 '%COMPANY%' => $mysoc->name,
182 '%ADDRESS%' => $mysoc->address,
183 '%ZIP%' => $mysoc->zip,
184 '%TOWN%' => $mysoc->town,
185 '%COUNTRY%' => $mysoc->country,
186 '%COUNTRY_CODE%' => $mysoc->country_code,
187 '%EMAIL%' => $mysoc->email,
191 '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
192 '%SERVER%' =>
"http://".$_SERVER[
"SERVER_NAME"].
"/",
197 if ($mode ==
'label') {
198 $txtforsticker =
"%PHOTO%";
199 $textleft =
make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT) ? $txtforsticker : $conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray);
200 $textheader =
make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray);
201 $textfooter =
make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray);
202 $textright =
make_substitutions((empty($conf->global->BARCODE_LABEL_RIGHT_TEXT) ?
'' : $conf->global->BARCODE_LABEL_RIGHT_TEXT), $substitutionarray);
203 $forceimgscalewidth = (empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH);
204 $forceimgscaleheight = (empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT);
207 if ($numberofsticker <= $MAXSTICKERS) {
208 for ($i = 0; $i < $numberofsticker; $i++) {
209 $arrayofrecords[] = array(
210 'textleft'=>$textleft,
211 'textheader'=>$textheader,
212 'textfooter'=>$textfooter,
213 'textright'=>$textright,
215 'encoding'=>$encoding,
217 'photo'=>$barcodeimage
221 $mesg = $langs->trans(
"ErrorQuantityIsLimitedTo", $MAXSTICKERS);
229 if (!$error && $mode ==
'label') {
230 if (!count($arrayofrecords)) {
231 $mesg = $langs->trans(
"ErrorRecordNotFound");
233 if (empty($modellabel) || $modellabel ==
'-1') {
234 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
240 $outputlangs = $langs;
248 if ($result <= 0 || $mesg || $error) {
250 $mesg =
'Error '.$result;
266 if (empty($conf->barcode->enabled)) {
272 llxHeader(
'', $langs->trans(
"BarCodePrintsheet"));
277 print
'<span class="opacitymedium">'.$langs->trans(
"PageToGenerateBarCodeSheets", $langs->transnoentitiesnoconv(
"BuildPageToPrint")).
'</span><br>';
283 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
284 print
'<input type="hidden" name="mode" value="label">';
285 print
'<input type="hidden" name="action" value="builddoc">';
286 print
'<input type="hidden" name="token" value="'.currentToken().
'">';
288 print
'<div class="tagtable">';
291 print
' <div class="tagtr">';
292 print
' <div class="tagtd">';
293 print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
294 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
296 $arrayoflabels = array();
297 foreach (array_keys($_Avery_Labels) as $codecards) {
298 $labeltoshow = $_Avery_Labels[$codecards][
'name'];
300 $arrayoflabels[$codecards] = $labeltoshow;
302 asort($arrayoflabels);
303 print
$form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') : $conf->global->ADHERENT_ETIQUETTE_TYPE), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
304 print
'</div></div>';
307 print
' <div class="tagtr">';
308 print
' <div class="tagtd">';
309 print $langs->trans(
"NumberOfStickers").
' ';
310 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
311 print
'<input size="4" type="text" name="numberofsticker" value="'.(GETPOST(
'numberofsticker') ?
GETPOST(
'numberofsticker',
'int') : 10).
'">';
312 print
'</div></div>';
321 print
'<script type="text/javascript">
322 jQuery(document).ready(function() {
323 function init_selectors()
325 if (jQuery("#fillmanually:checked").val() == "fillmanually")
327 jQuery("#submitproduct").prop("disabled", true);
328 jQuery("#submitthirdparty").prop("disabled", true);
329 jQuery("#search_productid").prop("disabled", true);
330 jQuery("#socid").prop("disabled", true);
331 jQuery(".showforproductselector").hide();
332 jQuery(".showforthirdpartyselector").hide();
334 if (jQuery("#fillfromproduct:checked").val() == "fillfromproduct")
336 jQuery("#submitproduct").removeAttr("disabled");
337 jQuery("#submitthirdparty").prop("disabled", true);
338 jQuery("#search_productid").removeAttr("disabled");
339 jQuery("#socid").prop("disabled", true);
340 jQuery(".showforproductselector").show();
341 jQuery(".showforthirdpartyselector").hide();
343 if (jQuery("#fillfromthirdparty:checked").val() == "fillfromthirdparty")
345 jQuery("#submitproduct").prop("disabled", true);
346 jQuery("#submitthirdparty").removeAttr("disabled");
347 jQuery("#search_productid").prop("disabled", true);
348 jQuery("#socid").removeAttr("disabled");
349 jQuery(".showforproductselector").hide();
350 jQuery(".showforthirdpartyselector").show();
354 jQuery(".radiobarcodeselect").click(function() {
358 function init_gendoc_button()
360 if (jQuery("#select_fk_barcode_type").val() > 0 && jQuery("#forbarcode").val())
362 jQuery("#submitformbarcodegen").removeAttr("disabled");
366 jQuery("#submitformbarcodegen").prop("disabled", true);
369 init_gendoc_button();
370 jQuery("#select_fk_barcode_type").change(function() {
371 init_gendoc_button();
373 jQuery("#forbarcode").keyup(function() {
380 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>';
383 if (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire)) {
384 print
'<input id="fillfromproduct" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromproduct') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"><label for="fillfromproduct"> '.$langs->trans(
"FillBarCodeTypeAndValueFromProduct").
'</label>';
386 print
'<div class="showforproductselector">';
387 $form->select_produits(
GETPOST(
'productid',
'int'),
'productid',
'',
'', 0, -1, 2,
'', 0, array(), 0,
'1', 0,
'minwidth400imp', 1);
388 print
' <input type="submit" class="button small" id="submitproduct" name="submitproduct" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
392 if (!empty($user->rights->societe->lire)) {
393 print
'<input id="fillfromthirdparty" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromthirdparty') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"><label for="fillfromthirdparty"> '.$langs->trans(
"FillBarCodeTypeAndValueFromThirdParty").
'</label>';
395 print
'<div class="showforthirdpartyselector">';
396 print
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
397 print
' <input type="submit" id="submitthirdparty" name="submitthirdparty" class="button showforthirdpartyselector small" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
403 if ($producttmp->id > 0) {
404 print $langs->trans(
"BarCodeDataForProduct",
'').
' '.$producttmp->getNomUrl(1).
'<br>';
406 if ($thirdpartytmp->id > 0) {
407 print $langs->trans(
"BarCodeDataForThirdparty",
'').
' '.$thirdpartytmp->getNomUrl(1).
'<br>';
410 print
'<div class="tagtable">';
413 print
' <div class="tagtr">';
414 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
415 print $langs->trans(
"BarcodeType").
' ';
416 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
417 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formbarcode.class.php';
419 print $formbarcode->selectBarcodeType($fk_barcode_type,
'fk_barcode_type', 1);
420 print
'</div></div>';
423 print
' <div class="tagtr">';
424 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
425 print $langs->trans(
"BarcodeValue").
' ';
426 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
427 print
'<input size="16" type="text" name="forbarcode" id="forbarcode" value="'.$forbarcode.
'">';
428 print
'</div></div>';
439 print
'<br><input type="submit" class="button" id="submitformbarcodegen" '.((GETPOST(
"selectorforbarcode") &&
GETPOST(
"selectorforbarcode")) ?
'' :
'disabled ').
'value="'.$langs->trans(
"BuildPageToPrint").
'">';