29if (!empty($_POST[
'mode']) && $_POST[
'mode'] ===
'label') {
30 if (!defined(
'NOTOKENRENEWAL')) {
31 define(
'NOTOKENRENEWAL',
'1');
36require
'../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/format_cards.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/modules/printsheet/modules_labels.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/genericobject.class.php';
54$langs->loadLangs(array(
'admin',
'members',
'errors'));
61$forbarcode =
GETPOST(
'forbarcode',
'alphanohtml');
62$fk_barcode_type =
GETPOSTINT(
'fk_barcode_type');
64$modellabel =
GETPOST(
"modellabel",
'aZ09');
65$numberofsticker =
GETPOSTINT(
'numberofsticker');
69$action =
GETPOST(
'action',
'aZ09');
72$thirdpartytmp =
new Societe($db);
77if (!isModEnabled(
'barcode')) {
80if (!$user->hasRight(
'barcode',
'read')) {
84$hookmanager->initHooks(array(
'printsheettools'));
91$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
100if (empty($reshook)) {
104 $result = $producttmp->fetch(
GETPOSTINT(
'productid'));
108 $forbarcode = $producttmp->barcode;
109 $fk_barcode_type = $producttmp->barcode_type;
115 if (empty($forbarcode) || empty($fk_barcode_type)) {
116 setEventMessages($langs->trans(
"DefinitionOfBarCodeForProductNotComplete", $producttmp->getNomUrl()),
null,
'warnings');
124 $forbarcode = $thirdpartytmp->barcode;
125 $fk_barcode_type = $thirdpartytmp->barcode_type_code;
127 if (empty($fk_barcode_type) &&
getDolGlobalString(
'GENBARCODE_BARCODETYPE_THIRDPARTY')) {
131 if (empty($forbarcode) || empty($fk_barcode_type)) {
132 setEventMessages($langs->trans(
"DefinitionOfBarCodeForThirdpartyNotComplete", $thirdpartytmp->getNomUrl()),
null,
'warnings');
137 if ($action ==
'builddoc' && $user->hasRight(
'barcode',
'read')) {
141 if (empty($forbarcode)) {
142 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeValue")),
null,
'errors');
147 setEventMessages($langs->trans(
"ErrorFieldTooLong", $langs->transnoentitiesnoconv(
"BarcodeValue")).
' ('.$langs->trans(
"RequireXStringMax", $MAXLENGTH).
')',
null,
'errors');
150 if (empty($fk_barcode_type)) {
151 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"BarcodeType")),
null,
'errors');
159 $stdobject->barcode_type = $fk_barcode_type;
160 $result = $stdobject->fetchBarCode();
163 setEventMessages(
'Failed to get bar code type information '.$stdobject->error, $stdobject->errors,
'errors');
172 if (!$error && $stdobject !==
null) {
174 $generator = $stdobject->barcode_type_coder;
175 $encoding = strtoupper($stdobject->barcode_type_code);
177 $diroutput =
$conf->barcode->dir_temp;
181 $dirbarcode = array_merge(array(
"/core/modules/barcode/doc/"),
$conf->modules_parts[
'barcode']);
183 foreach ($dirbarcode as $reldir) {
188 if (!is_dir($newdir)) {
192 $result = @include_once $newdir.$generator.
'.modules.php';
199 $classname =
"mod".ucfirst($generator);
201 $module =
new $classname($db);
204 if ($generator !=
'tcpdfbarcode') {
205 '@phan-var-force modPhpbarcode $module';
206 $template =
'standardlabel';
207 if ($module->encodingIsSupported($encoding)) {
208 $barcodeimage =
$conf->barcode->dir_temp.
'/barcode_'.$code.
'_'.$encoding.
'.png';
211 $result = $module->writeBarCode($code, $encoding,
'Y', 4, 1);
214 setEventMessages(
'Failed to generate image file of barcode for code='.$code.
' encoding='.$encoding.
' file='.basename($barcodeimage),
null,
'errors');
219 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');
222 '@phan-var-force modTcpdfbarcode $module';
223 $template =
'tcpdflabel';
224 $encoding = $module->getTcpdfEncodingType($encoding);
225 $is2d = $module->is2d;
231 $substitutionarray = array(
232 '%LOGIN%' => $user->login,
233 '%COMPANY%' => $mysoc->name,
234 '%ADDRESS%' => $mysoc->address,
235 '%ZIP%' => $mysoc->zip,
236 '%TOWN%' => $mysoc->town,
237 '%COUNTRY%' => $mysoc->country,
238 '%COUNTRY_CODE%' => $mysoc->country_code,
239 '%EMAIL%' => $mysoc->email,
243 '%DOL_MAIN_URL_ROOT%' => DOL_MAIN_URL_ROOT,
244 '%SERVER%' =>
"http://".$_SERVER[
"SERVER_NAME"].
"/",
248 $arrayofrecords = array();
250 if ($mode ==
'label') {
251 $txtforsticker =
"%PHOTO%";
260 if ($numberofsticker <= $MAXSTICKERS) {
261 for ($i = 0; $i < $numberofsticker; $i++) {
262 $arrayofrecords[] = array(
263 'textleft' => $textleft,
264 'textheader' => $textheader,
265 'textfooter' => $textfooter,
266 'textright' => $textright,
268 'encoding' => $encoding,
270 'photo' => !empty($barcodeimage) ? $barcodeimage :
''
274 $mesg = $langs->trans(
"ErrorQuantityIsLimitedTo", $MAXSTICKERS);
280 if (!$error && $mode ==
'label') {
281 if (!count($arrayofrecords)) {
282 $mesg = $langs->trans(
"ErrorRecordNotFound");
284 if (empty($modellabel) || $modellabel ==
'-1') {
285 $mesg = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DescADHERENT_ETIQUETTE_TYPE"));
291 $outputlangs = $langs;
294 $conf->global->TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = 1;
301 $mesg = $langs->trans(
'ErrorGeneratingBarcode');
304 $conf->global->TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = $previousConf;
308 if ($result <= 0 || $mesg || $error) {
310 $mesg =
'Error '.$result;
327$form =
new Form($db);
329llxHeader(
'', $langs->trans(
"BarCodePrintsheet"),
'',
'', 0, 0,
'',
'',
'',
'mod-barcode page-printsheet');
334print
'<span class="opacitymedium">'.$langs->trans(
"PageToGenerateBarCodeSheets", $langs->transnoentitiesnoconv(
"BuildPageToPrint")).
'</span><br>';
340print
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
341print
'<input type="hidden" name="mode" value="label">';
342print
'<input type="hidden" name="action" value="builddoc">';
343print
'<input type="hidden" name="token" value="'.currentToken().
'">';
345print
'<div class="tagtable">';
348print
' <div class="tagtr">';
349print
' <div class="tagtd">';
350print $langs->trans(
"DescADHERENT_ETIQUETTE_TYPE").
' ';
351print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
353$arrayoflabels = array();
354foreach (array_keys($_Avery_Labels) as $codecards) {
355 $labeltoshow = $_Avery_Labels[$codecards][
'name'];
357 $arrayoflabels[$codecards] = $labeltoshow;
359asort($arrayoflabels);
360print $form->selectarray(
'modellabel', $arrayoflabels, (
GETPOST(
'modellabel') ?
GETPOST(
'modellabel') :
getDolGlobalString(
'ADHERENT_ETIQUETTE_TYPE')), 1, 0, 0,
'', 0, 0, 0,
'',
'', 1);
364print
' <div class="tagtr">';
365print
' <div class="tagtd">';
366print $langs->trans(
"NumberOfStickers").
' ';
367print
'</div><div class="tagtd maxwidthonsmartphone" style="overflow: hidden; white-space: nowrap;">';
368print
'<input size="4" type="text" name="numberofsticker" value="'.(GETPOST(
'numberofsticker') ?
GETPOSTINT(
'numberofsticker') : 10).
'">';
378print
'<script type="text/javascript">
379jQuery(document).ready(function() {
380 function init_selectors()
382 if (jQuery("#fillmanually:checked").val() == "fillmanually")
384 jQuery("#submitproduct").prop("disabled", true);
385 jQuery("#submitthirdparty").prop("disabled", true);
386 jQuery("#search_productid").prop("disabled", true);
387 jQuery("#socid").prop("disabled", true);
388 jQuery(".showforproductselector").hide();
389 jQuery(".showforthirdpartyselector").hide();
391 if (jQuery("#fillfromproduct:checked").val() == "fillfromproduct")
393 jQuery("#submitproduct").removeAttr("disabled");
394 jQuery("#submitthirdparty").prop("disabled", true);
395 jQuery("#search_productid").removeAttr("disabled");
396 jQuery("#socid").prop("disabled", true);
397 jQuery(".showforproductselector").show();
398 jQuery(".showforthirdpartyselector").hide();
400 if (jQuery("#fillfromthirdparty:checked").val() == "fillfromthirdparty")
402 jQuery("#submitproduct").prop("disabled", true);
403 jQuery("#submitthirdparty").removeAttr("disabled");
404 jQuery("#search_productid").prop("disabled", true);
405 jQuery("#socid").removeAttr("disabled");
406 jQuery(".showforproductselector").hide();
407 jQuery(".showforthirdpartyselector").show();
411 jQuery(".radiobarcodeselect").click(function() {
415 function init_gendoc_button()
417 if (jQuery("#select_fk_barcode_type").val() > 0 && jQuery("#forbarcode").val())
419 jQuery("#submitformbarcodegen").removeAttr("disabled");
423 jQuery("#submitformbarcodegen").prop("disabled", true);
426 init_gendoc_button();
427 jQuery("#select_fk_barcode_type").change(function() {
428 init_gendoc_button();
430 jQuery("#forbarcode").keyup(function() {
437print
'<input id="fillmanually" type="radio" '.((!
GETPOST(
"selectorforbarcode") ||
GETPOST(
"selectorforbarcode") ==
'fillmanually') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillmanually" class="radiobarcodeselect"><label for="fillmanually"> '.$langs->trans(
"FillBarCodeTypeAndValueManually").
'</label>';
440if ($user->hasRight(
'produit',
'lire') || $user->hasRight(
'service',
'lire')) {
441 print
'<input id="fillfromproduct" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromproduct') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromproduct" class="radiobarcodeselect"><label for="fillfromproduct"> '.$langs->trans(
"FillBarCodeTypeAndValueFromProduct").
'</label>';
443 print
'<div class="showforproductselector">';
444 $form->select_produits(
GETPOSTINT(
'productid'),
'productid',
'', 0, 0, -1, 2,
'', 0, array(), 0,
'1', 0,
'minwidth400imp', 1);
445 print
' <input type="submit" class="button small" id="submitproduct" name="submitproduct" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
449if ($user->hasRight(
'societe',
'lire')) {
450 print
'<input id="fillfromthirdparty" type="radio" '.((GETPOST(
"selectorforbarcode") ==
'fillfromthirdparty') ?
'checked ' :
'').
'name="selectorforbarcode" value="fillfromthirdparty" class="radiobarcodeselect"><label for="fillfromthirdparty"> '.$langs->trans(
"FillBarCodeTypeAndValueFromThirdParty").
'</label>';
452 print
'<div class="showforthirdpartyselector">';
453 print $form->select_company(
GETPOSTINT(
'socid'),
'socid',
'',
'SelectThirdParty', 0, 0, array(), 0,
'minwidth300');
454 print
' <input type="submit" id="submitthirdparty" name="submitthirdparty" class="button showforthirdpartyselector small" value="'.(dol_escape_htmltag($langs->trans(
"GetBarCode"))).
'">';
460if ($producttmp->id > 0) {
461 print $langs->trans(
"BarCodeDataForProduct",
'').
' '.$producttmp->getNomUrl(1).
'<br>';
463if ($thirdpartytmp->id > 0) {
464 print $langs->trans(
"BarCodeDataForThirdparty",
'').
' '.$thirdpartytmp->getNomUrl(1).
'<br>';
467print
'<div class="tagtable">';
470print
' <div class="tagtr">';
471print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
472print $langs->trans(
"BarcodeType").
' ';
473print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
474require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formbarcode.class.php';
476print $formbarcode->selectBarcodeType($fk_barcode_type,
'fk_barcode_type', 1);
480print
' <div class="tagtr">';
481print
' <div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
482print $langs->trans(
"BarcodeValue").
' ';
483print
'</div><div class="tagtd" style="overflow: hidden; white-space: nowrap; max-width: 300px;">';
484print
'<input size="16" type="text" name="forbarcode" id="forbarcode" value="'.$forbarcode.
'">';
496print
'<br><input type="submit" class="button" id="submitformbarcodegen" '.((GETPOST(
"selectorforbarcode") &&
GETPOST(
"selectorforbarcode")) ?
'' :
'disabled ').
'value="'.$langs->trans(
"BuildPageToPrint").
'">';
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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, $mode=0)
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.