You are here

function barcode_convert_upca_to_upce in Barcode 6.2

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

File

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

Code

function barcode_convert_upca_to_upce($upca) {
  $upce = "";

  // If the source message string is less than 12 characters long, we make it
  // 12 characters
  if (strlen($upca) < 12) {
    $barnumber = str_pad($barnumber, 12, "0", STR_PAD_LEFT);
  }
  if (substr($upca, 0, 1) != '0' && substr($upca, 0, 1) != '1') {
    $settings->error = 'Invalid Number System (only 0 & 1 are valid)';
    return FALSE;
  }
  else {
    if (substr($upca, 3, 3) == '000' || substr($upca, 3, 3) == '100' || substr($upca, 3, 3) == '200') {
      $upce = substr($upca, 1, 2) . substr($upca, 8, 3) . substr($upca, 3, 1);
    }
    elseif (substr($upca, 4, 2) == '00') {
      $upce = substr($upca, 1, 2) . substr($upca, 9, 2) . '3';
    }
    elseif (substr($upca, 5, 1) == '0') {
      $upce = substr($upca, 1, 4) . substr($upca, 10, 1) . '4';
    }
    elseif (substr($upca, 10, 1) >= '5') {
      $upce = substr($upca, 1, 5) . substr($upca, 10, 1);
    }
    else {
      $settings->error = 'Invalid product code (00005 to 00009 are valid)';
      return FALSE;
    }
  }
  return $upce;
}