30,997
edits
PolyglotBot (talk | contribs) m (Updating interlang links (links to translated versions of this page in other languages) triggered by origin English page "Module_Barcode_(developer)" update.) |
m (→Code PHP) Tag: 2017 source edit |
||
| Line 37: | Line 37: | ||
= Code PHP = | = Code PHP = | ||
Pour générer une image d'un code | Pour générer une image d'un bar code ou d'un QR code, vous pouvez utiliser la portion de code suivant: | ||
<syntaxhighlight lang="PHP"> | <syntaxhighlight lang="PHP"> | ||
$code = 'string_to_convert_into_qrcode'; | |||
$generator = 'tcpdfbarcode'; // Can be 'phpbarcode' or a value provided by an external module | |||
$encoding = 'QRCODE'; | |||
$dirbarcode = array_merge(array("/core/modules/barcode/doc/"), $conf->modules_parts['barcode']); | |||
$result = 0; | |||
foreach ($dirbarcode as $reldir) { | |||
$dir = dol_buildpath($reldir, 0); | |||
$newdir = dol_osencode($dir); | |||
// Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php) | |||
if (!is_dir($newdir)) { | |||
continue; | |||
} | |||
$result = @include_once $newdir.$generator.'.modules.php'; | |||
if ($result) { | |||
break; | |||
} | |||
} | |||
// Load barcode class | |||
$classname = "mod".ucfirst($generator); | |||
$module = new $classname($db); | |||
if ($module->encodingIsSupported($encoding)) { | |||
$result = $module->writeBarCode($code, $encoding, $readable); | |||
} | |||
// image is into file $conf->barcode->dir_temp . '/barcode_' . $code . '_' . $encoding . '.png'; | |||
</syntaxhighlight> | </syntaxhighlight> | ||