*/ include '../../../inc/includes.php'; if (isset($_POST['dropCache'])) { $dir = GLPI_PLUGIN_DOC_DIR . '/barcode'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file != "." && $file != ".." && $file != "logo.png") { unlink($dir . '/' . $file); } } closedir($dh); } } Session::addMessageAfterRedirect(__('The cache has been emptied.', 'barcode')); } else { if (!empty($_FILES['logo']['name'])) { if (is_file(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png')) { @unlink(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png'); } // Move rename($_FILES['logo']['tmp_name'], GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png'); } else { if (isset($_POST['type'])) { $pbconf = new PluginBarcodeConfig(); $_POST['id'] = 1; $pbconf->update($_POST); } } } Html::back();
function getConfig() { $pbconf = new PluginBarcodeConfig(); if ($pbconf->getFromDB(1)) { $type = $pbconf->fields['type']; } else { $type = 'code128'; } return $type; }
function printPDF($p_params) { $pbConfig = new PluginBarcodeConfig(); // create barcodes $ext = 'png'; $type = $p_params['type']; $size = $p_params['size']; $orientation = $p_params['orientation']; $codes = array(); if ($type == 'QRcode') { $codes = $p_params['codes']; } else { if (isset($p_params['code'])) { if (isset($p_params['nb']) and $p_params['nb'] > 1) { $this->create($p_params['code'], $type, $ext); for ($i = 1; $i <= $p_params['nb']; $i++) { $codes[] = $p_params['code']; } } else { if (!$this->create($p_params['code'], $type, $ext)) { Session::addMessageAfterRedirect(__('The generation of some bacodes produced errors.', 'barcode')); } $codes[] = $p_params['code']; } } elseif (isset($p_params['codes'])) { $codes = $p_params['codes']; foreach ($codes as $code) { if ($code != '') { $this->create($code, $type, $ext); } } } else { // TODO : erreur ? // print_r($p_params); return 0; } } // create pdf // x is horizontal axis and y is vertical // x=0 and y=0 in bottom left hand corner $config = $pbConfig->getConfigType($type); require_once GLPI_ROOT . "/plugins/barcode/lib/ezpdf/class.ezpdf.php"; $pdf = new Cezpdf($size, $orientation); $pdf->selectFont(GLPI_ROOT . "/plugins/barcode/lib/ezpdf/fonts/Helvetica.afm"); $pdf->ezStartPageNumbers($pdf->ez['pageWidth'] - 30, 10, 10, 'left', '{PAGENUM} / {TOTALPAGENUM}') . ($width = $config['maxCodeWidth']); $height = $config['maxCodeHeight']; $marginH = $config['marginHorizontal']; $marginV = $config['marginVertical']; $heightimage = $height; if (file_exists(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png')) { // Add logo to barcode $heightLogomax = 20; $imgSize = getimagesize(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png'); $logoWidth = $imgSize[0]; $logoHeight = $imgSize[1]; if ($logoHeight > $heightLogomax) { $ratio = 100 * $heightLogomax / $logoHeight; $logoHeight = $heightLogomax; $logoWidth = $logoWidth * ($ratio / 100); } if ($logoWidth > $width) { $ratio = 100 * $width / $logoWidth; $logoWidth = $width; $logoHeight = $logoHeight * ($ratio / 100); } $heightyposText = $height - $logoHeight; $heightimage = $heightyposText; } $first = true; foreach ($codes as $code) { if ($first) { $x = $pdf->ez['leftMargin']; $y = $pdf->ez['pageHeight'] - $pdf->ez['topMargin'] - $height; $first = false; } else { if ($x + $width + $marginH > $pdf->ez['pageWidth']) { // new line $x = $pdf->ez['leftMargin']; if ($y - $height - $marginV < $pdf->ez['bottomMargin']) { // new page $pdf->ezNewPage(); $y = $pdf->ez['pageHeight'] - $pdf->ez['topMargin'] - $height; } else { $y -= $height + $marginV; } } } if ($code != '') { if ($type == 'QRcode') { $imgFile = $code; } else { $imgFile = $this->docsPath . $code . '_' . $type . '.' . $ext; } if (file_exists($imgFile)) { $imgSize = getimagesize($imgFile); $imgWidth = $imgSize[0]; $imgHeight = $imgSize[1]; if ($imgWidth > $width) { $ratio = 100 * $width / $imgWidth; $imgWidth = $width; $imgHeight = $imgHeight * ($ratio / 100); } if ($imgHeight > $heightimage) { $ratio = 100 * $heightimage / $imgHeight; $imgHeight = $heightimage; $imgWidth = $imgWidth * ($ratio / 100); } $image = imagecreatefrompng($imgFile); if ($imgWidth < $width) { $pdf->addImage($image, $x + ($width - $imgWidth) / 2, $y, $imgWidth, $imgHeight); } else { $pdf->addImage($image, $x, $y, $imgWidth, $imgHeight); } if (file_exists(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png')) { $logoimg = imagecreatefrompng(GLPI_PLUGIN_DOC_DIR . '/barcode/logo.png'); $pdf->addImage($logoimg, $x + ($width - $logoWidth) / 2, $y + $heightyposText, $logoWidth, $logoHeight); } if ($p_params['border']) { $pdf->Rectangle($x, $y, $width, $height); } } } $x += $width + $marginH; $y -= 0; } $file = $pdf->ezOutput(); $pdfFile = $_SESSION['glpiID'] . '_' . $type . '.pdf'; file_put_contents($this->docsPath . $pdfFile, $file); return '/files/_plugins/barcode/' . $pdfFile; }
Plugin Barcode is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with Plugin Barcode. If not, see <http://www.gnu.org/licenses/>. ------------------------------------------------------------------------ @package Plugin Barcode @author David Durieux @co-author @copyright Copyright (c) 2009-2013 Barcode plugin Development team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.indepnet.net/projects/barscode @since 2009 ------------------------------------------------------------------------ */ // Non menu entry case //header("Location:../../central.php"); include '../../../inc/includes.php'; Session::checkRight("config", "w"); // To be available when plugin is not activated Plugin::load('barcode'); Html::header(__('Barcode', 'barcode'), $_SERVER['PHP_SELF'], "config", "plugins"); $pbConfig = new PluginBarcodeConfig(); $pbConfig->showForm(''); Html::footer();