26 if (!empty($_POST[
'mode']) && $_POST[
'mode'] ===
'label') {
27 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL',
'1');
30 require
'../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/modules/printsheet/modules_labels.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
37 $langs->loadLangs(array(
'admin',
'members',
'errors'));
44 $forbarcode =
GETPOST(
'forbarcode',
'alphanohtml');
45 $fk_barcode_type =
GETPOST(
'fk_barcode_type',
'int');
46 $mode =
GETPOST(
'mode',
'aZ09');
47 $modellabel =
GETPOST(
"modellabel",
'aZ09');
48 $numberofsticker =
GETPOST(
'numberofsticker',
'int');
52 $action =
GETPOST(
'action',
'aZ09');
55 $thirdpartytmp =
new Societe($db);
65 if (
GETPOST(
'productid',
'int') > 0) {
66 $result = $producttmp->fetch(
GETPOST(
'productid',
'int'));
70 $forbarcode = $producttmp->barcode;
71 $fk_barcode_type = $producttmp->barcode_type;
73 if (empty($fk_barcode_type) && !empty($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE)) $fk_barcode_type = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE;
75 if (empty($forbarcode) || empty($fk_barcode_type))
77 setEventMessages($langs->trans(
"DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()), null,
'warnings');
84 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)) $fk_barcode_type = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY;
92 if (empty($forbarcode) || empty($fk_barcode_type))
94 setEventMessages($langs->trans(
"DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()), null,
'warnings');
99 if ($action ==
'builddoc')
101 $result = 0; $error = 0;
103 if (empty($forbarcode))
105 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeValue")), null,
'errors');
108 if (empty($fk_barcode_type))
110 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeType")), null,
'errors');
118 $stdobject->barcode_type = $fk_barcode_type;
119 $result = $stdobject->fetch_barcode();
123 setEventMessages(
'Failed to get bar code type information '.$stdobject->error, $stdobject->errors,
'errors');
130 $generator = $stdobject->barcode_type_coder;
131 $encoding = strtoupper($stdobject->barcode_type_code);
133 $diroutput = $conf->barcode->dir_temp;
137 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"), $conf->modules_parts[
'barcode']);
139 foreach ($dirbarcode as $reldir)
145 if (!is_dir($newdir))
continue;
147 $result = @include_once $newdir.$generator.
'.modules.php';
152 $classname =
"mod".ucfirst($generator);
153 $module =
new $classname($db);
154 if ($generator !=
'tcpdfbarcode')
157 $template =
'standardlabel';
159 if ($module->encodingIsSupported($encoding))
161 $barcodeimage = $conf->barcode->dir_temp.
'/barcode_'.$code.
'_'.$encoding.
'.png';
164 $result = $module->writeBarCode($code, $encoding,
'Y', 4, 1);
168 setEventMessages(
'Failed to generate image file of barcode for code='.$code.
' encoding='.$encoding.
' file='.basename($barcodeimage), null,
'errors');
173 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');
176 $template =
'tcpdflabel';
177 $encoding = $module->getTcpdfEncodingType($encoding);
178 $is2d = $module->is2d;
185 $substitutionarray = array(
186 '%LOGIN%' => $user->login,
187 '%COMPANY%' => $mysoc->name,
188 '%ADDRESS%' => $mysoc->address,
189 '%ZIP%' => $mysoc->zip,
190 '%TOWN%' => $mysoc->town,
191 '%COUNTRY%' => $mysoc->country,
192 '%COUNTRY_CODE%' => $mysoc->country_code,
193 '%EMAIL%' => $mysoc->email,
197 '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
198 '%SERVER%' =>
"http://".$_SERVER[
"SERVER_NAME"].
"/",
203 if ($mode ==
'label')
205 $txtforsticker =
"%PHOTO%";
206 $textleft =
make_substitutions((empty($conf->global->BARCODE_LABEL_LEFT_TEXT) ? $txtforsticker : $conf->global->BARCODE_LABEL_LEFT_TEXT), $substitutionarray);
207 $textheader =
make_substitutions((empty($conf->global->BARCODE_LABEL_HEADER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_HEADER_TEXT), $substitutionarray);
208 $textfooter =
make_substitutions((empty($conf->global->BARCODE_LABEL_FOOTER_TEXT) ?
'' : $conf->global->BARCODE_LABEL_FOOTER_TEXT), $substitutionarray);
209 $textright =
make_substitutions((empty($conf->global->BARCODE_LABEL_RIGHT_TEXT) ?
'' : $conf->global->BARCODE_LABEL_RIGHT_TEXT), $substitutionarray);
210 $forceimgscalewidth = (empty($conf->global->BARCODE_FORCEIMGSCALEWIDTH) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEWIDTH);
211 $forceimgscaleheight = (empty($conf->global->BARCODE_FORCEIMGSCALEHEIGHT) ? 1 : $conf->global->BARCODE_FORCEIMGSCALEHEIGHT);
213 for ($i = 0; $i < $numberofsticker; $i++)
215 $arrayofrecords[] = array(
216 'textleft'=>$textleft,
217 'textheader'=>$textheader,
218 'textfooter'=>$textfooter,
219 'textright'=>$textright,
221 'encoding'=>$encoding,
223 'photo'=>$barcodeimage
232 if ($mode ==
'label')
234 if (!count($arrayofrecords))
236 $mesg = $langs->trans(
"ErrorRecordNotFound");
238 if (empty($modellabel) || $modellabel ==
'-1')
240 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
246 $outputlangs = $langs;
254 if ($result <= 0 || $mesg) {
256 $mesg =
'Error '.$result;
274 $form =
new Form($db);
276 llxHeader(
'', $langs->trans(
"BarCodePrintsheet"));
281 print
'<span class="opacitymedium">'.$langs->trans(
"PageToGenerateBarCodeSheets", $langs->transnoentitiesnoconv(
"BuildPageToPrint")).
'</span><br>';
289 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
290 print
'<input type="hidden" name="mode" value="label">';
291 print
'<input type="hidden" name="action" value="builddoc">';
292 print
'<input type="hidden" name="token" value="'.currentToken().
'">';
294 print
'<div class="tagtable">';
297 print
' <div class="tagtr">';
298 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
299 print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
300 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
302 $arrayoflabels = array();
303 foreach (array_keys($_Avery_Labels) as $codecards)
305 $labeltoshow = $_Avery_Labels[$codecards][
'name'];
307 $arrayoflabels[$codecards] = $labeltoshow;
309 asort($arrayoflabels);
310 print $form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') : $conf->global->ADHERENT_ETIQUETTE_TYPE), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
311 print
'</div></div>';
314 print
' <div class="tagtr">';
315 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
316 print $langs->trans(
"NumberOfStickers").
' ';
317 print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
318 print
'<input size="4" type="text" name="numberofsticker" value="'.(GETPOST(
'numberofsticker') ?
GETPOST(
'numberofsticker',
'int') : 10).
'">';
319 print
'</div></div>';
328 print
'<script type="text/javascript" language="javascript">
329 jQuery(document).ready(function() {
330 function init_selectors()
332 if (jQuery("#fillmanually:checked").val() == "fillmanually")
334 jQuery("#submitproduct").prop("disabled", true);
335 jQuery("#submitthirdparty").prop("disabled", true);
336 jQuery("#search_productid").prop("disabled", true);
337 jQuery("#socid").prop("disabled", true);
338 jQuery(".showforproductselector").hide();
339 jQuery(".showforthirdpartyselector").hide();
341 if (jQuery("#fillfromproduct:checked").val() == "fillfromproduct")
343 jQuery("#submitproduct").removeAttr("disabled");
344 jQuery("#submitthirdparty").prop("disabled", true);
345 jQuery("#search_productid").removeAttr("disabled");
346 jQuery("#socid").prop("disabled", true);
347 jQuery(".showforproductselector").show();
348 jQuery(".showforthirdpartyselector").hide();
350 if (jQuery("#fillfromthirdparty:checked").val() == "fillfromthirdparty")
352 jQuery("#submitproduct").prop("disabled", true);
353 jQuery("#submitthirdparty").removeAttr("disabled");
354 jQuery("#search_productid").prop("disabled", true);
355 jQuery("#socid").removeAttr("disabled");
356 jQuery(".showforproductselector").hide();
357 jQuery(".showforthirdpartyselector").show();
361 jQuery(".radiobarcodeselect").click(function() {
365 function init_gendoc_button()
367 if (jQuery("#select_fk_barcode_type").val() > 0 && jQuery("#forbarcode").val())
369 jQuery("#submitformbarcodegen").removeAttr("disabled");
373 jQuery("#submitformbarcodegen").prop("disabled", true);
376 init_gendoc_button();
377 jQuery("#select_fk_barcode_type").change(function() {
378 init_gendoc_button();
380 jQuery("#forbarcode").keyup(function() {
387 print
'<input id="fillmanually" type="radio" '.((!
GETPOST(
"selectorforbarcode") ||
GETPOST(
"selectorforbarcode") ==
'fillmanually') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillmanually" class="radiobarcodeselect"> '.$langs->trans(
"FillBarCodeTypeAndValueManually").
' ';
390 if (!empty($user->rights->produit->lire) || !empty($user->rights->service->lire))
392 print
'<input id="fillfromproduct" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromproduct') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"> '.$langs->trans(
"FillBarCodeTypeAndValueFromProduct").
' ';
394 print
'<div class="showforproductselector">';
395 $form->select_produits(
GETPOST(
'productid',
'int'),
'productid',
'',
'', 0, -1, 2,
'', 0, array(), 0,
'1', 0,
'minwidth400imp', 1);
396 print
' <input type="submit" id="submitproduct" name="submitproduct" class="button" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
400 if (!empty($user->rights->societe->lire))
402 print
'<input id="fillfromthirdparty" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromthirdparty') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"> '.$langs->trans(
"FillBarCodeTypeAndValueFromThirdParty").
' ';
404 print
'<div class="showforthirdpartyselector">';
405 print $form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
406 print
' <input type="submit" id="submitthirdparty" name="submitthirdparty" class="button showforthirdpartyselector" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
412 if ($producttmp->id > 0)
414 print $langs->trans(
"BarCodeDataForProduct",
'').
' '.$producttmp->getNomUrl(1).
'<br>';
416 if ($thirdpartytmp->id > 0)
418 print $langs->trans(
"BarCodeDataForThirdparty",
'').
' '.$thirdpartytmp->getNomUrl(1).
'<br>';
421 print
'<div class="tagtable">';
424 print
' <div class="tagtr">';
425 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
426 print $langs->trans(
"BarcodeType").
' ';
427 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
428 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formbarcode.class.php';
430 print $formbarcode->selectBarcodeType($fk_barcode_type,
'fk_barcode_type', 1);
431 print
'</div></div>';
434 print
' <div class="tagtr">';
435 print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
436 print $langs->trans(
"BarcodeValue").
' ';
437 print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
438 print
'<input size="16" type="text" name="forbarcode" id="forbarcode" value="'.$forbarcode.
'">';
439 print
'</div></div>';
450 print
'<br><input class="button" type="submit" id="submitformbarcodegen" '.((GETPOST(
"selectorforbarcode") &&
GETPOST(
"selectorforbarcode")) ?
'' :
'disabled ').
'value="'.$langs->trans(
"BuildPageToPrint").
'">';
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_is_file($pathoffile)
Return if path is a file.
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.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class of a generic business object.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_htmloutput_errors($mesgstring= '', $mesgarray=array(), $keepembedded=0)
Print formated error messages to output (Used to show messages on html output).
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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...