Location: PHPKode > projects > SENAYAN Library Automation > senayan3-stable5/admin/modules/system/barcode_generator.php
<?php

/*

VERSION : 3.0
CODENAME : SENAYAN
AUTHOR :
    Code and Programming : ARIE NUGRAHA (hide@address.com)
    Database Design : HENDRO WICAKSONO (hide@address.com) & WARDIYONO (hide@address.com)

SENAYAN Library Automation System
Copyright (C) 2007

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program (GPL License.txt); if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

/* Barcode generator section */

// start the session
session_start();

require '../../../sysconfig.inc.php';
require SENAYAN_BASE_DIR.'admin/default/session_check.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/template_parser/simbio_template_parser.inc.php';
require SIMBIO_BASE_DIR.'simbio_GUI/table/simbio_table.inc.php';

// privileges checking
$can_read = utility::havePrivilege('system', 'r');
$can_write = utility::havePrivilege('system', 'w');

if (!$can_read) {
    die('<div class="errorBox">'.lang_sys_common_no_privilege.'</div>');
}

$max_print = 50;

// barcode pdf download
if (isset($_SESSION['barcodes'])) {
    // include printed settings configuration file
    require SENAYAN_BASE_DIR.'admin'.DIRECTORY_SEPARATOR.'admin_template'.DIRECTORY_SEPARATOR.'printed_settings.inc.php';
    // chunk barcode array
    $chunked_barcode_arrays = array_chunk($_SESSION['barcodes'], $items_per_row);
    // create html ouput
    $html_str = '<html><head><title>Barcode Generator Print Result</title>'."\n";
    $html_str .= '<style type="text/css">'."\n";
    $html_str .= 'body { padding: 0; margin: '.$page_margin.'cm; width: '.$page_width.'cm }'."\n";
    $html_str .= '.labelStyle { width: 100%; position: relative; text-align: center; float: left; margin: '.$items_margin.'cm; border: 1px solid #000000; width: '.$cell_width.'.5cm; }'."\n";
    $html_str .= '</style>'."\n";
    $html_str .= '</head>'."\n";
    $html_str .= '<body>'."\n";
    // loop the chunked arrays to row
    foreach ($chunked_barcode_arrays as $barcode_rows) {
        $html_str .= '<div style="clear: both;">';
        foreach ($barcode_rows as $barcode) {
            $html_str .= '<div class="labelStyle">';
            $html_str .= '<img src="'.SENAYAN_WEB_ROOT_DIR.'images/barcodes/'.$barcode.'.png" border="0" />';
            $html_str .= '</div>';
        }
        $html_str .= '</div>';
    }
    $html_str .= '<script type="text/javascript">self.print();</script>'."\n";
    $html_str .= '</body></html>'."\n";
    // unset the session
    unset($_SESSION['barcodes']);
    // write to file
    $file_write = @file_put_contents(FILES_UPLOAD_DIR.'barcode_gen_print_result.html', $html_str);
    if ($file_write) {
        // open result in window
        echo '<script type="text/javascript">parent.openWin(\''.SENAYAN_WEB_ROOT_DIR.FILES_DIR.'/barcode_gen_print_result.html\', \'popBarcodeGen\', 800, 500, true)</script>';
    } else { utility::jsAlert('ERROR! Barcodes failed to generate, possibly because '.SENAYAN_BASE_DIR.FILES_DIR.' directory is not writable'); }
    exit();
}

// barcodes generator proccess
if (isset($_POST['saveData']) AND $can_write) {
    if (count($_POST['barcode']) > 0) {
        $size = intval($_POST['size']);
        // create AJAX request
        echo '<script type="text/javascript" src="'.JS_WEB_ROOT_DIR.'prototype.js"></script>';
        echo '<script type="text/javascript">';
        foreach ($_POST['barcode'] as $barcode_text) {
            if (!empty($barcode_text)) {
                $barcode_text = trim($barcode_text);
                echo 'new Ajax.Request(\''.SENAYAN_WEB_ROOT_DIR.'lib/phpbarcode/barcode.php?code='.$barcode_text.'&encoding='.$sysconf['barcode_encoding'].'&scale='.$size.'&mode=png\', { method: \'get\', onFailure: function(sendAlert) { alert(\''.lang_sys_conf_barcode_alert_print_fail.'\'); } });'."\n";
                // add to sessions
                $_SESSION['barcodes'][] = $barcode_text;
            }
        }
        echo 'alert(\''.lang_sys_conf_barcode_alert_print_ok.'\')'."\n";
        echo 'location.href = \''.$_SERVER['PHP_SELF'].'\''."\n";
        echo '</script>';
    }
    exit();
}

?>
<table id="searchForm" cellpadding="5" cellspacing="0">
<tr>
    <td class="imageLeft" valign="top" style="background-image: url(<?php echo $sysconf['admin_template']['dir'].'/'.$sysconf['admin_template']['theme'].'/barcode.png'; ?>)">
        <?php echo strtoupper(lang_sys_barcodes).' <hr />' . lang_sys_barcodes_description. ' "' .lang_sys_conf_barcode_button_print. '".'; ?>
        </td>
</tr>
</table>
<?php

// create table object
$table = new simbio_table();
$table->table_attr = 'align="center" class="border fullWidth" cellpadding="5" cellspacing="0"';

// initial row count
$row = 1;
$row_num = 6;

// submit button
$table->appendTableRow(array(lang_sys_conf_barcode_field_size.' : <select name="size"><option value="1">'.lang_sys_conf_barcode_field_option_1.'</option>
    <option value="2" selected>'.lang_sys_conf_barcode_field_option_2.'</option>
    <option value="3">'.lang_sys_conf_barcode_field_option_3.'</option></select>'));
// set cell attribute
$table->setCellAttr($row, 0, 'colspan="3" class="alterCell"');
$row++;

// barcode text fields
while ($row <= $row_num) {
    $table->appendTableRow(array('<input type="text" name="barcode[]" style="width: 100%;" />',
        '<input type="text" name="barcode[]" style="width: 100%;" />',
        '<input type="text" name="barcode[]" style="width: 100%;" />'));
    $row++;
}

// submit button
$table->appendTableRow(array('<input type="submit" name="saveData" value="'.lang_sys_conf_barcode_button_print.'" />'));
// set cell attribute
$table->setCellAttr($row_num+1, 0, 'colspan="3" class="alterCell"');

echo '<form name="barcodeForm" id="barcodeForm" target="submitExec" method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo $table->printTable();
echo '</form>';
// for debugging purpose only
// echo '<iframe name="submitExec" id="submitExec" style="width: 100%; height: 200px; visibility: visible;"></iframe>';
echo '<iframe name="submitExec" id="submitExec" style="width: 0; height: 0; visibility: hidden;"></iframe>';
?>
Return current item: SENAYAN Library Automation