/**
  * Function: Generate a 2D Barcode: QRCode, DataMatrix (SemaCode), PDF417
  *
  * @param STRING 	$y_code 			The code for the BarCode Generator
  * @param ENUM 		$y_type				The BarCode Type: qrcode / semacode / pdf417
  * @param ENUM 		$y_format			The Barcode format: html, html-png, png, html-svg, svg
  * @param INTEGER+ 	$y_size				The Scale-Size for Barcode (1..4)
  * @param HEXCOLOR	$y_color			The Hexadecimal Color for the Barcode Pixels ; default is Black = #000000
  * @param MIXED		$y_extraoptions		Extra Options: for QRCode = Quality [L, M, Q, H] L as default ; for PDF417 a Ratio Integer between 1 and 17
  * @param YES/NO	$y_cache			If YES will cache the Barcode to avoid on-the-fly generation ; default is set to NO
  *
  * @return MIXED	By Type Selection: 	HTML Code / PNG Image / SVG Code
  *
  */
 public static function getBarcode($y_code, $y_type, $y_format, $y_size, $y_color = '#000000', $y_extraoptions = '', $y_cache = 'no')
 {
     //--
     switch ((string) $y_type) {
         case 'qrcode':
             switch ((string) $y_extraoptions) {
                 case 'H':
                     $y_extraoptions = 'H';
                     break;
                 case 'Q':
                     $y_extraoptions = 'Q';
                     break;
                 case 'M':
                     $y_extraoptions = 'M';
                     break;
                 case 'L':
                 default:
                     $y_extraoptions = 'L';
             }
             //end switch
             $barcode_type = 'qrcode';
             break;
         case 'semacode':
             $y_extraoptions = '';
             $barcode_type = 'semacode';
             break;
         case 'pdf417':
             $y_extraoptions = (int) (0 + $y_extraoptions);
             if ($y_extraoptions <= 0) {
                 $y_extraoptions = 1;
             }
             //end if
             if ($y_extraoptions > 17) {
                 $y_extraoptions = 17;
             }
             //end if
             $barcode_type = 'pdf417';
             break;
         default:
             $barcode_type = '???';
             Smart::log_warning('ERROR: BarCodes2D - Invalid Type Selected for getBarcode');
             return '';
     }
     //end switch
     //--
     switch ((string) $y_format) {
         case 'html':
             $barcode_format = '.htm';
             break;
         case 'html-png':
             $barcode_format = '.png.htm';
             break;
         case 'png':
             $barcode_format = '.png';
             break;
         case 'html-svg':
             $barcode_format = '.svg.htm';
             break;
         case 'svg':
             $barcode_format = '.svg';
             break;
         default:
             $barcode_format = '.unknown';
             Smart::log_warning('ERROR: BarCodes2D - Invalid Mode Selected for getBarcode');
             return '';
     }
     //end switch
     //--
     //--
     $memory_cache_url = 'memory://barcode-2d/' . $barcode_type . '/' . $barcode_format . '/' . $y_size . '/' . $y_color . '/' . $y_extraoptions . '/' . $y_code;
     $realm = 'barcode-2d/';
     //--
     //--
     if ((string) $y_cache == 'yes') {
         //--
         $out = SmartUtils::load_cached_content($barcode_format, $realm, $memory_cache_url, '');
         // (try to) get from cache
         //--
         if ((string) $out != '') {
             return $out;
             // if found in cache return it
         }
         //end if
         //--
     }
     //end if
     //--
     //--
     switch ((string) $barcode_type) {
         case 'qrcode':
             $arr_barcode = (new SmartBarcode2D_QRcode($y_code, $y_extraoptions))->getBarcodeArray();
             break;
         case 'semacode':
             $arr_barcode = (new SmartBarcode2D_DataMatrix($y_code))->getBarcodeArray();
             break;
         case 'pdf417':
             $arr_barcode = (new SmartBarcode2D_Pdf417($y_code, $y_extraoptions, -1))->getBarcodeArray();
             break;
         default:
             $arr_barcode = '';
             // not to be an array for error detection
     }
     //end switch
     //--
     switch ((string) $y_format) {
         case 'html':
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_color . ') [' . $y_extraoptions . ']' . ' :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeHTML($arr_barcode, $y_size, $y_color) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'html-png':
             // html img embedded png
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_color . ') [' . $y_extraoptions . ']' . ' :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeEmbeddedHTMLPNG($arr_barcode, $y_size, $y_color) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'png':
             // raw png
             $out = self::getBarcodePNG($arr_barcode, $y_size, $y_color);
             // needs header image/png on output
             break;
         case 'html-svg':
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_color . ') [' . $y_extraoptions . ']' . ' :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeEmbeddedHTMLSVG($arr_barcode, $y_size, $y_color) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'svg':
             $out = self::getBarcodeSVG($arr_barcode, $y_size, $y_color);
             // needs header image/svg on output
             break;
         default:
             $out = '';
     }
     //end switch
     //--
     //--
     if ((string) $y_cache == 'yes') {
         //--
         $out = SmartUtils::load_cached_content($barcode_format, $realm, $memory_cache_url, $out);
         // set + get from cache
         //--
     }
     //end if
     //--
     //--
     return $out;
     //--
 }
 /**
  * Function: Generate a 1D Barcode: 128 B, 93 E+, 39 E, KIX
  *
  * @param STRING 	$y_code 			The code for the BarCode Generator
  * @param ENUM 		$y_type				The BarCode Type: 128 / 93 / 39 / KIX
  * @param ENUM 		$y_format			The Barcode format: html, html-png, png, html-svg, svg
  * @param INTEGER+ 	$y_size				The Scale-Size for Barcode (1..4)
  * @param INTEGER+	$y_height			The Height in pixels for the Barcode
  * @param HEXCOLOR	$y_color			The Hexadecimal Color for the Barcode Bars ; default is Black = #000000
  * @param BOOLEAN	$y_display_text		If TRUE will display the Code below of BarCode Bars ; default is FALSE
  * @param YES/NO	$y_cache			If YES will cache the Barcode to avoid on-the-fly generation ; default is set to NO
  *
  * @return MIXED	By Type Selection: 	HTML Code / PNG Image / SVG Code
  *
  */
 public static function getBarcode($y_code, $y_type, $y_format, $y_size, $y_height, $y_color = '#000000', $y_display_text = false, $y_cache = 'no')
 {
     //--
     switch ((string) $y_type) {
         case '128':
             // 128 B (Extended)
             $barcode_type = '128B';
             break;
         case '93':
             // 93 Extended +Checksum
             $barcode_type = '93E+';
             break;
         case '39':
             // 39 Extended
             $barcode_type = '39E';
             break;
         case 'KIX':
             // RMS KIX Variant (Extended) :: max 11 chars :: This needs a height that divides by 3
             $barcode_type = 'KIX';
             break;
         default:
             $barcode_type = '???';
             Smart::log_warning('ERROR: BarCodes1D - Invalid Type Selected for getBarcode');
             return '';
     }
     //end switch
     //--
     switch ((string) $y_format) {
         case 'html':
             $barcode_format = '.htm';
             break;
         case 'html-png':
             $barcode_format = '.png.htm';
             break;
         case 'png':
             $barcode_format = '.png';
             break;
         case 'html-svg':
             $barcode_format = '.svg.htm';
             break;
         case 'svg':
             $barcode_format = '.svg';
             break;
         default:
             $barcode_format = '.unknown';
             Smart::log_warning('ERROR: BarCodes1D - Invalid Mode Selected for getBarcode');
             return '';
     }
     //end switch
     //--
     //--
     if ($y_display_text) {
         $barcode_show_text = 'TX';
     } else {
         $barcode_show_text = 'XX';
     }
     //end if else
     //--
     //--
     $memory_cache_url = 'memory://barcode-1d/' . $barcode_type . '/' . $barcode_format . '/' . $y_size . '/' . $y_height . '/' . $y_color . '/' . $barcode_show_text . '/' . $y_code;
     $realm = 'barcode-1d/';
     //--
     //--
     if ((string) $y_cache == 'yes') {
         //--
         $out = SmartUtils::load_cached_content($barcode_format, $realm, $memory_cache_url, '');
         // (try to) get from cache
         //--
         if ((string) $out != '') {
             return $out;
             // if found in cache return it
         }
         //end if
         //--
     }
     //end if
     //--
     //--
     switch ((string) $barcode_type) {
         case '128B':
             $arr_barcode = (new SmartBarcode1D_128($y_code, 'B'))->getBarcodeArray();
             break;
         case '93E+':
             $arr_barcode = (new SmartBarcode1D_93($y_code, true, true))->getBarcodeArray();
             break;
         case '39E':
             $arr_barcode = (new SmartBarcode1D_39($y_code, true, false))->getBarcodeArray();
             break;
         case 'KIX':
             $arr_barcode = (new SmartBarcode1D_RMS4CC($y_code, 'KIX'))->getBarcodeArray();
             break;
         default:
             $arr_barcode = '';
             // not to be an array for error detection
     }
     //end switch
     //--
     switch ((string) $y_format) {
         case 'html':
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_height . '/' . $y_color . '/' . $barcode_show_text . ') :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeHTML($arr_barcode, $y_size, $y_height, $y_color, $y_display_text) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'html-png':
             // html img embedded png
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_height . '/' . $y_color . '/' . $barcode_show_text . ') :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeEmbeddedHTMLPNG($arr_barcode, $y_size, $y_height, $y_color, $y_display_text) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'png':
             // raw png
             $out = self::getBarcodePNG($arr_barcode, $y_size, $y_height, $y_color, $y_display_text);
             // needs header image/png on output
             break;
         case 'html-svg':
             $out = '<!-- ' . Smart::escape_html(strtoupper($barcode_type) . ' (' . $y_size . '/' . $y_height . '/' . $y_color . '/' . $barcode_show_text . ') :: ' . date('YmdHis')) . ' -->' . '<div title="' . Smart::escape_html($y_code) . '">' . self::getBarcodeEmbeddedHTMLSVG($arr_barcode, $y_size, $y_height, $y_color, $y_display_text) . '</div>' . '<!-- #END :: ' . Smart::escape_html(strtoupper($barcode_type)) . ' -->';
             break;
         case 'svg':
             $out = self::getBarcodeSVG($arr_barcode, $y_size, $y_height, $y_color, $y_display_text);
             // needs header image/svg on output
             break;
         default:
             $out = '';
     }
     //end switch
     //--
     //--
     if ((string) $y_cache == 'yes') {
         //--
         $out = SmartUtils::load_cached_content($barcode_format, $realm, $memory_cache_url, $out);
         // set + get from cache
         //--
     }
     //end if
     //--
     //--
     return $out;
     //--
 }