Exemplo n.º 1
0
 public function testPreParsers()
 {
     /* set any needed session variables */
     CoreLocal::set('runningTotal', 1.99);
     CoreLocal::set('mfcoupon', 0);
     CoreLocal::set('itemPD', 0);
     CoreLocal::set('multiple', 0);
     CoreLocal::set('quantity', 0);
     CoreLocal::set('refund', 0);
     CoreLocal::set('toggletax', 0);
     CoreLocal::set('togglefoodstamp', 0);
     CoreLocal::set('toggleDiscountable', 0);
     CoreLocal::set('nd', 0);
     /* inputs and expected outputs */
     $input_output = array('MANUALCC' => '199CC', '5DI123' => '123', '7PD123' => '123', '2*4011' => '4011', '3*100DP10' => '100DP10', 'text*blah' => 'text*blah', 'RF123' => '123', '123RF' => '123', 'RF3*100DP10' => '100DP10', 'FN123' => '123', 'DN123' => '123', '1TN123' => '123', 'invalid' => 'invalid');
     $chain = PreParser::get_preparse_chain();
     foreach ($input_output as $input => $output) {
         foreach ($chain as $class) {
             $obj = new $class();
             $chk = $obj->check($input);
             $this->assertInternalType('boolean', $chk);
             if ($chk) {
                 $input = $obj->parse($input);
             }
         }
         $this->assertEquals($output, $input);
     }
     /* verify correct session values */
     $this->assertEquals(7, CoreLocal::get('itemPD'));
     $this->assertEquals(1, CoreLocal::get('multiple'));
     $this->assertEquals(3, CoreLocal::get('quantity'));
     $this->assertEquals(1, CoreLocal::get('refund'));
     $this->assertEquals(1, CoreLocal::get('toggletax'));
     $this->assertEquals(1, CoreLocal::get('togglefoodstamp'));
     $this->assertEquals(1, CoreLocal::get('toggleDiscountable'));
 }
Exemplo n.º 2
0
 public function parse($input)
 {
     $result = $this->preParser->parse($input);
     $result = $this->postParser->parse($result);
     return new Arguments($result);
 }
Exemplo n.º 3
0
 function preprocess()
 {
     $this->display = "";
     $sd = MiscLib::scaleObject();
     $entered = "";
     if (isset($_REQUEST["reginput"])) {
         $entered = strtoupper(trim($_REQUEST["reginput"]));
     }
     if (substr($entered, -2) == "CL") {
         $entered = "CL";
     }
     if ($entered == "RI") {
         $entered = CoreLocal::get("strEntered");
     }
     if (CoreLocal::get("msgrepeat") == 1 && $entered != "CL") {
         $entered = CoreLocal::get("strRemembered");
         CoreLocal::set('strRemembered', '');
     }
     CoreLocal::set("strEntered", $entered);
     $json = array();
     if ($entered != "") {
         if (in_array("Paycards", CoreLocal::get("PluginList"))) {
             /* this breaks the model a bit, but I'm putting
              * putting the CC parser first manually to minimize
              * code that potentially handles the PAN */
             if (CoreLocal::get("PaycardsCashierFacing") == "1" && substr($entered, 0, 9) == "PANCACHE:") {
                 /* cashier-facing device behavior; run card immediately */
                 $entered = substr($entered, 9);
                 CoreLocal::set("CachePanEncBlock", $entered);
             }
             $pe = new paycardEntered();
             if ($pe->check($entered)) {
                 $valid = $pe->parse($entered);
                 $entered = "PAYCARD";
                 CoreLocal::set("strEntered", "");
                 $json = $valid;
             }
             CoreLocal::set("quantity", 0);
             CoreLocal::set("multiple", 0);
         }
         /* FIRST PARSE CHAIN:
          * Objects belong in the first parse chain if they
          * modify the entered string, but do not process it
          * This chain should be used for checking prefixes/suffixes
          * to set up appropriate session variables.
          */
         $parser_lib_path = $this->page_url . "parser-class-lib/";
         if (!is_array(CoreLocal::get("preparse_chain"))) {
             CoreLocal::set("preparse_chain", PreParser::get_preparse_chain());
         }
         foreach (CoreLocal::get("preparse_chain") as $cn) {
             if (!class_exists($cn)) {
                 continue;
             }
             $p = new $cn();
             if ($p->check($entered)) {
                 $entered = $p->parse($entered);
             }
             if (!$entered || $entered == "") {
                 break;
             }
         }
         if ($entered != "" && $entered != "PAYCARD") {
             /* 
              * SECOND PARSE CHAIN
              * these parser objects should process any input
              * completely. The return value of parse() determines
              * whether to call lastpage() [list the items on screen]
              */
             if (!is_array(CoreLocal::get("parse_chain"))) {
                 CoreLocal::set("parse_chain", Parser::get_parse_chain());
             }
             $result = False;
             foreach (CoreLocal::get("parse_chain") as $cn) {
                 if (!class_exists($cn)) {
                     continue;
                 }
                 $p = new $cn();
                 if ($p->check($entered)) {
                     $result = $p->parse($entered);
                     break;
                 }
             }
             if ($result && is_array($result)) {
                 // postparse chain: modify result
                 if (!is_array(CoreLocal::get("postparse_chain"))) {
                     CoreLocal::set("postparse_chain", PostParser::getPostParseChain());
                 }
                 foreach (CoreLocal::get('postparse_chain') as $class) {
                     if (!class_exists($class)) {
                         continue;
                     }
                     $obj = new $class();
                     $result = $obj->parse($result);
                 }
                 $json = $result;
                 if (isset($result['udpmsg']) && $result['udpmsg'] !== False) {
                     if (is_object($sd)) {
                         $sd->WriteToScale($result['udpmsg']);
                     }
                 }
             } else {
                 $arr = array('main_frame' => false, 'target' => '.baseHeight', 'output' => DisplayLib::inputUnknown());
                 $json = $arr;
                 if (is_object($sd)) {
                     $sd->WriteToScale('errorBeep');
                 }
             }
         }
     }
     CoreLocal::set("msgrepeat", 0);
     if (isset($json['main_frame']) && $json['main_frame'] != False) {
         $this->change_page($json['main_frame']);
         return False;
     }
     if (isset($json['output']) && !empty($json['output'])) {
         $this->display = $json['output'];
     }
     if (isset($json['retry']) && $json['retry'] != False) {
         $this->add_onload_command("setTimeout(\"inputRetry('" . $json['retry'] . "');\", 150);\n");
     }
     if (isset($json['receipt']) && $json['receipt'] != False) {
         $ref = isset($json['trans_num']) ? $json['trans_num'] : ReceiptLib::mostRecentReceipt();
         $this->add_onload_command("receiptFetch('" . $json['receipt'] . "', '" . $ref . "');\n");
     }
     if (CoreLocal::get('CustomerDisplay') === true) {
         $child_url = MiscLib::baseURL() . 'gui-modules/posCustDisplay.php';
         $this->add_onload_command("setCustomerURL('{$child_url}');\n");
         $this->add_onload_command("reloadCustomerDisplay();\n");
     }
     return true;
 }
Exemplo n.º 4
0
         $entered = "PAYCARD";
         CoreLocal::set("strEntered", "");
         $json = $valid;
     }
 }
 CoreLocal::set("quantity", 0);
 CoreLocal::set("multiple", 0);
 /* FIRST PARSE CHAIN:
  * Objects belong in the first parse chain if they
  * modify the entered string, but do not process it
  * This chain should be used for checking prefixes/suffixes
  * to set up appropriate session variables.
  */
 $parser_lib_path = MiscLib::base_url() . "parser-class-lib/";
 if (!is_array(CoreLocal::get("preparse_chain"))) {
     CoreLocal::set("preparse_chain", PreParser::get_preparse_chain());
 }
 foreach (CoreLocal::get("preparse_chain") as $cn) {
     if (!class_exists($cn)) {
         continue;
     }
     $p = new $cn();
     if ($p->check($entered)) {
         $entered = $p->parse($entered);
     }
     if (!$entered || $entered == "") {
         break;
     }
 }
 if ($entered != "" && $entered != "PAYCARD") {
     /*