<?php
/**
 * cCdvb0100_scanning
 *
 * Handles scanning-part of 
 *
 * @version    1.0
 * @author     Erik Timmers, amgate <erik.timmers@amgate.com>
 * @copyright  Amgate, 2009
 * @since      19-02-2009 - initial creation
 * @package    MANAGER
 */

class cCdvb0100_scanning extends stdModule
{
    
    /**
     * cCdvb0100_scanning
     *
     * PHP4 constructor
     *
     * @access public
     * @return void
     */
    function cCdvb0100_scanning()
    {
    }

    /**
     * addCart
     *
     * add cart object to class
     *
     * @access public
     * @param  object $oCart cart object
     * @return void
     */          
    function addCart(&$oCart) 
    {
        $this->oCart = $oCart;
    }          

    /**
     * sessify
     *
     * analyse scan, count and store in btvc_scans session
     *
     * @access public
     * @param  object $oCart cart object
     * @return void
     */          
    function sessify(&$oCart) 
    {
        global $globalSettings;
        
        if (!$this->oCart) {
            $this->addCart($oCart);
        }
        
        $_SESSION['_btvc_scans'] = array();
                
        foreach ($_REQUEST['_b_val'] as $barcode) {
            $prd_code = $this->strip_prefix($barcode, $globalSettings->barcodePrefix);

            $prd_id = $this->oCart->getProductID($prd_code);

            if (is_numeric($prd_id)) {

                if (!isset($_SESSION['_btvc_scans'][$prd_id])) {
                    $_SESSION['_btvc_scans'][$prd_id] = 1;
                } else {
                    $_SESSION['_btvc_scans'][$prd_id] += 1;
                }
                
            }
            
        }
                
    }

    /**
     * strip_prefix
     *
     * strip prefix from barcode
     *
     * @access public
     * @param  string $barcode          barcode
     * @param  string $prefixToRemove   the prefix
     * @return string
     */
    function strip_prefix($barcode, $prefixToRemove) {
        return str_replace($prefixToRemove, '', $barcode);        
    }


}

?>