<?php
function xtc_generate_packingslip_barcode($code,$savefile = ''){
	 define (__TRACE_ENABLED__, false);
	 define (__DEBUG_ENABLED__, false);
	 if(!function_exists('__trace__')){
		 require(DIR_FS_ADMIN."includes/modules/barcode/barcode.php");		   
		 require(DIR_FS_ADMIN."includes/modules/barcode/i25object.php");
		 require(DIR_FS_ADMIN."includes/modules/barcode/c39object.php");
		 require(DIR_FS_ADMIN."includes/modules/barcode/c128aobject.php");
		 require(DIR_FS_ADMIN."includes/modules/barcode/c128bobject.php");
		 require(DIR_FS_ADMIN."includes/modules/barcode/c128cobject.php");
	 }	 						  
	$config = parse_ini_file(DIR_FS_ADMIN."includes/barcode.conf");
	foreach($config as $k=>$v){
		$config[$k] = str_replace("'",'',$v);
	}
	/* Default value */
	if (!isset($output))  $output   = $config['barcode_output']; 
	if (!isset($barcode)) $barcode  = $code;
	if (!isset($type))    $type     = $config['barcode_type'];
	if (!isset($width))   $width    = $config['barcode_width'];
	if (!isset($height))  $height   = $config['barcode_height'];
	if (!isset($xres))    $xres     = $config['barcode_xres'];
	if (!isset($font))    $font     = $config['barcode_text_font'];
	if (!isset($border))  $border   = $config['barcode_draw_border'];
	if (!isset($drawtext))$drawtext = $config['barcode_draw_value_text'];
	if (!isset($stretchtext))$stretchtext = $config['barcode_stretch_text'];
	/*********************************/ 
										
	if (isset($barcode) && strlen($barcode)>0) {    
	  $style  = BCS_ALIGN_CENTER;					       
	  $style |= ($output  == "png" ) ? BCS_IMAGE_PNG  : 0; 
	  $style |= ($output  == "jpeg") ? BCS_IMAGE_JPEG : 0; 
	  $style |= ($border  == "on"  ) ? BCS_BORDER 	  : 0; 
	  $style |= ($drawtext== "on"  ) ? BCS_DRAW_TEXT  : 0; 
	  $style |= ($stretchtext== "on" ) ? BCS_STRETCH_TEXT  : 0; 
	  $style |= ($negative== "on"  ) ? BCS_REVERSE_COLOR  : 0; 
	  switch ($type)
	  {
	    case "I25":
				  $obj = new I25Object(250, 120, $style, $barcode);
				  break;
	    case "C39":
				  $obj = new C39Object(250, 120, $style, $barcode);
				  break;
	    case "C128A":
				  $obj = new C128AObject(250, 120, $style, $barcode);
				  break;
	    case "C128B":
				  $obj = new C128BObject(250, 120, $style, $barcode);
				  break;
	    case "C128C":
	                          $obj = new C128CObject(250, 120, $style, $barcode);
				  break;
		default:
				$obj = false;
	  }
	  if ($obj) {
	     if ($obj->DrawObject($xres)) {
		 if($savefile == ''){
		         return "<img src='".HTTP_SERVER.DIR_WS_ADMIN."includes/modules/barcode/image.php?code=".$barcode."&style=".$style."&type=".$type."&width=".$width."&height=".$height."&xres=".$xres."&font=".$font."'>";
		 }else{
			$obj->SaveObject($savefile.'BARCODE_'.$code.'.'.$output);
			return $code.'.'.$output;
		}
	     }
	  }
	}
 }
?>
