You are here

function barcode_upce_encode in Barcode 7.2

Same name and namespace in other branches
  1. 6.2 plugins/upce.inc \barcode_upce_encode()
1 call to barcode_upce_encode()
barcode_upce_barcode in plugins/upce.inc

File

plugins/upce.inc, line 116
Barcode plugin UPC-E: Short version of UPC symbol, 6 characters

Code

function barcode_upce_encode($barnumber, $settings, $encbit, $checkdigit) {
  $left_odd = array(
    "0001101",
    "0011001",
    "0010011",
    "0111101",
    "0100011",
    "0110001",
    "0101111",
    "0111011",
    "0110111",
    "0001011",
  );
  $left_even = array(
    "0100111",
    "0110011",
    "0011011",
    "0100001",
    "0011101",
    "0111001",
    "0000101",
    "0010001",
    "0001001",
    "0010111",
  );
  $enc_table0 = array(
    "EEEOOO",
    "EEOEOO",
    "EEOOEO",
    "EEOOOE",
    "EOEEOO",
    "EOOEEO",
    "EOOOEE",
    "EOEOEO",
    "EOEOOE",
    "EOOEOE",
  );
  $enc_table1 = array(
    "OOOEEE",
    "OOEOEE",
    "OOEEOE",
    "OOEEEO",
    "OEOOEE",
    "OEEOOE",
    "OEEEOO",
    "OEOEOE",
    "OEOEEO",
    "OEEOEO",
  );
  $guards = array(
    "bab",
    "ababa",
    "b",
  );
  if ($encbit == 0) {
    $enc_table = $enc_table0;
  }
  elseif ($encbit == 1) {
    $enc_table = $enc_table1;
  }
  else {
    $settings->error = "Not an UPC-E barcode number";
    return FALSE;
  }
  $mfc_str = "";
  $prod_str = "";
  $checkdigit;
  $enc_table[$checkdigit];
  for ($i = 0; $i < strlen($barnumber); $i++) {
    $num = (int) $barnumber[$i];
    $even = substr($enc_table[$checkdigit], $i, 1) == 'E';
    if (!$even) {
      $mfc_str .= $left_odd[$num];
    }
    else {
      $mfc_str .= $left_even[$num];
    }
  }
  return $guards[0] . $mfc_str . $guards[1] . $guards[2];
}