// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?uis)(@([\\\w]+)\((.*?)\)(?:\s|$))").unwrap();
let string = "<?php
#ä
// htaccess: SetEnvIf Authorization \"(.*)\" HTTP_AUTHORIZATION=$1
#if( !empty($_SERVER['HTTP_X_FORWARDED_USER']) )
# $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_X_FORWARDED_USER'];
/**
* Class Api
*
*
* @OA\\Server(url=\"https://de.beta.wedirekt.com/de/gateways/api\")
* @OA\\Info(title=\"WEdirekt API\", version=\"v1.0\")
* @OA\\SecurityScheme(
* type=\"http\",
* description=\"Login with email and password to get the authentication token\",
* name=\"Token based Based\",
* in=\"header\",
* scheme=\"bearer\",
* bearerFormat=\"JWT\",
* securityScheme=\"apiAuth\",
* )
*/
class Api extends CI_Controller
{
const VERSION = \"v1.0\";
private $token_data;
private $token;
private $token_duration = 3600; // 1 hour
private $global_discount = 0.00;
function __construct()
{
parent::__construct();
if( empty($_SERVER['HTTP_AUTHORIZATION']) )
{
http_response_code(401); // bad request
exit('no http auth was given. please check proxy (nginx)');
}
ini_set('memory_limit', '64M');
error_reporting(E_ALL);
ini_set('display_errors', 1);
if( $_SERVER['REQUEST_METHOD'] != 'POST' )
{
http_response_code(400); // bad request
exit('This webservice only response to POST-REQUESTS');
}
$method = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/')+1);
if( !isset($_REQUEST['format']) )
$_REQUEST['format'] = 'json';
// TODO: list mit gültigen Befehlen anlegen
if( !method_exists($this, $method) )
{
http_response_code(400); // bad request
exit('This method is not allowed');
}
// libs
$this->load->library('domain');
$this->load->library('mandator');
$this->load->library('date');
$this->load->library('formatting');
$this->load->library('currency');
$this->load->model('global/auth', 'auth');
$this->load->model('cart_', 'cart');
$this->load->model('gateways/cas_', 'cas');
$this->cart->emptyCart();
// clear old db entries on start
$this->db->where('tstamp_expire < ( NOW() - INTERVAL 5 DAY )');
$this->db->delete('api_token');
// check token
if( !preg_match('/auth$/ui', $_SERVER['REQUEST_URI']) )
$this->_validateToken();
}
/**
* @param $customerid
* @return string
*/
private function _generateToken($customer)
{
// Create token header as a JSON string
$header = json_encode(['typ' => 'JWT', 'alg' => 'HS256']);
// Create token payload as a JSON string
$payload = json_encode(['customerid' => $customer->CUID]);
// Encode Header to Base64Url String
$base64UrlHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header));
// Encode Payload to Base64Url String
$base64UrlPayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload));
// Create Signature Hash
$signature = hash_hmac('sha256', $base64UrlHeader . \".\" . $base64UrlPayload, 'zX+4_!' . time(), true);
// Encode Signature to Base64Url String
$base64UrlSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));
// Create JWT
$jwt = $base64UrlHeader . \".\" . $base64UrlPayload . \".\" . $base64UrlSignature;
$data = [
'token' => $jwt,
'customerid' => $customer->CUID,
'tstamp_created' => date('Y-m-d H:i:s', time()),
'tstamp_expire' => date('Y-m-d H:i:s', time() + $this->token_duration)
];
$this->db->insert('api_token', $data);
return $jwt;
}
/**
* @return array
*/
private function _getRequestData()
{
$input = trim(file_get_contents('php://input'));
// default post data
$data = $_POST;
// if xml was send
if( preg_match('/^\\<\\?xml/uis', $input) )
{
$data = $this->_getXML($input);
}
// get json
if( preg_match('/^\\{.*\\}$/uis', $input) )
$data = $this->_getJson($input);
if( empty($data) )
{
http_response_code(403);
echo \"No data was send\";
exit;
}
return $data;
}
/**
* @param $data
* @return array
*/
private function _getJson($data)
{
$data = json_decode($data, true);
// switch and check possible JSON errors
switch ( json_last_error() )
{
case JSON_ERROR_NONE:
$error = ''; // JSON is valid // No error has occurred
break;
case JSON_ERROR_DEPTH:
$error = 'The maximum stack depth has been exceeded.';
break;
case JSON_ERROR_STATE_MISMATCH:
$error = 'Invalid or malformed JSON.';
break;
case JSON_ERROR_CTRL_CHAR:
$error = 'Control character error, possibly incorrectly encoded.';
break;
case JSON_ERROR_SYNTAX:
$error = 'Syntax error, malformed JSON.';
break;
// PHP >= 5.3.3
case JSON_ERROR_UTF8:
$error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
break;
// PHP >= 5.5.0
case JSON_ERROR_RECURSION:
$error = 'One or more recursive references in the value to be encoded.';
break;
// PHP >= 5.5.0
case JSON_ERROR_INF_OR_NAN:
$error = 'One or more NAN or INF values in the value to be encoded.';
break;
case JSON_ERROR_UNSUPPORTED_TYPE:
$error = 'A value of a type that cannot be encoded was given.';
break;
default:
$error = 'Unknown JSON error occured.';
break;
}
// exit on errors
if( !empty($error) )
{
http_response_code(400); // bad request
exit($error);
}
return $data;
}
/**
* @param $data
* @return array
*/
private function _getXML($data)
{
$xml = new SimpleXMLElement($data);
if( $xml === false )
exit('Sorry. Your response can not be parsed.');
// cast to array with json encodings
$json = json_encode($xml);
$data = $this->_getJson($json);
foreach( $data as $key => $value )
if ( is_object($value) OR is_array($value) )
unset($data[$key]);
return $data;
}
/**
* @param $data
* @return SimpleXMLElement
*/
private function __array_to_xml($data)
{
// creating object of SimpleXMLElement
$xml_data = new SimpleXMLElement('<?xml version=\"1.0\" encoding=\"UTF-8\" ?><response></response>');
foreach( $data as $key => $value )
{
if( is_numeric($key) )
$key = 'item'.$key; //dealing with <0/>..<n/> issues
if( is_array($value) )
{
$subnode = $xml_data->addChild($key);
array_to_xml($value, $subnode);
}
else
$xml_data->addChild(\"$key\",htmlspecialchars(\"$value\"));
}
return $xml_data;
}
/**
* validate token (+ extend expire time)
*
* @return bool
*/
private function _validateToken()
{
if( empty($_SERVER['HTTP_AUTHORIZATION']) OR !preg_match('/^Bearer/ui', $_SERVER['HTTP_AUTHORIZATION']) )
{
echo \"Please set Bearer Token\";
http_response_code(401);
exit;
}
$token = trim(substr($_SERVER['HTTP_AUTHORIZATION'], 7));
$this->db->select('api_token.*, Customer.*');
$this->db->join('Customer', 'api_token.customerid = Customer.CUID');
$this->db->where('api_token.token', $token);
$this->db->where('api_token.tstamp_expire >', date('Y-m-d H:i:s', time()));
$query = $this->db->get('api_token');
if ( $query AND $query->num_rows() == 0 )
{
echo \"No valid token\";
http_response_code(401);
exit;
}
$this->token_data = $query->row();
$this->token = $token;
// extend expire time for thoken
$this->db->set('tstamp_expire', date('Y-m-d H:i:s', time() + $this->token_duration));
$this->db->where('token', $token);
$this->db->update('api_token');
// set user data to cart/auth models
$this->_setUserData();
return true;
}
/**
* send response
*
* @param $output
* @param bool $format_json
*/
private function _response( $output, $format = 'json' )
{
http_response_code(200); // success
if ( $_REQUEST['format'] == 'xml' OR $format == 'xml' )
{
// show xml
header(\"Content-Type: application/xml; charset=utf-8\");
$output = $this->__array_to_xml($output)->asXML();
echo $output;
}
else if ( $_REQUEST['format'] == 'json' OR $format == 'json' )
{
header(\"Content-Type: application/json; charset=utf-8\");
$output = json_encode($output);
echo $output;
}
}
private function _setUserData()
{
$this->db->where('CUID', $this->token_data->CUID );
$customer = $this->db->get('Customer')->row();
// new login data
$data = array
(
'cuid' => $customer->CUID,
'customernumber' => $customer->Customernumber,
'mandatorid' => $customer->mandatorid,
'has_vat_id' => !empty($customer->RE_Ust),
'gender' => '',
'first_name' => $customer->Name,
'last_name' => $customer->Familyname,
'department' => $customer->Department,
'ip' => $_SERVER['REMOTE_ADDR'],
'user' => $customer->Email,
'language' => $customer->Language,
'date_registered' => $customer->date_registered,
'group' => $customer->group,
'we_customernumber' => $customer->we_customernumber,
'show_prices_orbit' => false,
'country' => $customer->RE_Country,
'number_orders' => 0,
'id_delivery_address' => $customer->id_delivery_address,
'contactlist' => json_decode($customer->contactlist, true)
);
// set user is logged in
if( isset($this->session) )
{
$this->session->set_userdata('customer_login', TRUE);
$this->session->set_userdata('customer_data', $data);
}
// set auth
if( isset($this->auth) )
{
$this->auth->customer_data = $data;
$this->auth->login = true;
}
// global discount
$this->cart->cart['global_order_discount'] = $customer->Rabatt;
$this->global_discount = (float) $customer->Rabatt;
}
function index()
{
return $this->help();
}
/**
* @OA\\Get(
* tags={\"help\"},
* path=\"/help\",
* operationId=\"help\",
* @OA\\Response(
* response=\"200\",
* description=\"List all commands\",
* @OA\\Content(
* type=\"html\"
* )
* )
* )
*/
function help()
{
echo \"
Commands:
--------------
help
configuration
pricelist
createoffer
loadoffer
upload
show
reset
checkout
orderstatus
\";
}
/**
* auth function
*/
public function auth()
{
$token = null;
// get username and pw from auth
if( isset($_SERVER['HTTP_AUTHORIZATION']) )
{
$auth = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
// get user
$this->db->select('Customer.*, country.countryiso2');
$this->db->join('country', 'Customer.country = country.countryid');
$this->db->where('Customer.is_archived', 0);
$this->db->where('Customer.Email', $auth[0]);
$this->db->or_where('Customer.Customernumber', $auth[0]);
$query = $this->db->get('Customer');
if ( $query AND $query->num_rows() == 0 )
{
http_response_code(401);
echo \"no valid customer/pw\";
exit;
}
$this->load->library('bf');
$this->load->library('encrypt');
foreach ( $query->result() as $customer )
{
// encode password
$pw_tmp = $this->encrypt->encode_from_legacy($customer->PW);
if ( md5($auth[1]) === '0beacf51e4e8dd71ae92b0ecf2938f8d' || $auth[1] == $this->encrypt->decode($pw_tmp) || $auth[1] == $this->encrypt->decode($customer->PW) )
{
$token = $this->_generateToken($customer);
}
}
}
if( !$token )
{
http_response_code(401);
echo \"no valid customer/pw\";
exit;
}
$data = (object)
[
//'scope' => 'available urls ...',
'customernumber' => $customer->Customernumber,
'access_token' => $token,
'token_type' => 'Bearer',
'app_id' => 'WEdirekt API ' . self::VERSION,
'expires_in' => $this->token_duration
];
return $this->_response($data);
}
/**
* @OA\\Post(
* path=\"/configuration\",
* operationId=\"configuration\",
* description=\"create new pcb configuration\",
* @OA\\RequestBody(
* description=\"Pet to add to the store\",
* required=true,
* @OA\\MediaType(
* mediaType=\"multipart/form-data\",
* @OA\\MediaType(mediaType=\"multipart/form-data\",
* @OA\\Schema(
* @OA\\Property(property=\"key[]\", @OA\\Items(type=\"string\")),
* @OA\\Property(property=\"value[]\", @OA\\Items(type=\"string\")),
* @OA\\Property(property=\"file[]\", @OA\\Items(type=\"string\", format=\"binary\")),
* @OA\\Property(property=\"confirmed[]\", @OA\\Items(type=\"integer\")),
* required={\"key\", \"confirmed\"}
* )
* )
* )
* ),
* @OA\\Response(
* response=200,
* description=\"pet response\",
* @OA\\JsonContent(ref=\"#/components/schemas/Pet\")
* ),
* @OA\\Response(
* response=\"default\",
* description=\"unexpected error\",
* @OA\\JsonContent(ref=\"#/components/schemas/ErrorModel\")
* )
* )
*/
public function configuration()
{
$data = $this->_getRequestData();
// load model
$this->load->model('pcb_', 'pcb');
// default pcb
$pcb = $this->pcb->pcb_default;
// get preset values
$pcb_presets = $this->pcb->getPresets();
// new pcb
$preset = $pcb_presets['technology'][1];
if( !empty($data['technology']) AND isset($pcb_presets['technology'][(int)$data['technology']]) )
$preset = $pcb_presets['technology'][(int)$data['technology']];
// set presets
foreach( $preset as $key => $value )
$pcb[$key] = $value;
// overwrite with user values
foreach( $data as $key => $value )
{
$value = (string) $value;
if( strlen($value) > 0 )
$pcb[$key] = $value;
else
$pcb[$key] = null;
}
// prepare properties
$pcb = $this->pcb->prep_properties($pcb);
// save config to session
$this->db->set('session_content', serialize($pcb));
$this->db->where('token', $this->token);
$this->db->update('api_token');
// TODO: Konfiguration Validieren ... sehr schwierig da dies im Javascript passiert
ksort($pcb);
//$cas_values = $this->cas->convertMatrixFrontend2Cas($pcb, 'memory');
//$product = $this->cas->getProductnameByTechnology($pcb['technology']);
//$this->cas->reset();
//$this->cas->setProduct($product);
//$this->cas->initConfiguration();
//$response = $this->cas->multichange( $cas_values );
// get price array
$price = $this->pcb->get_price($pcb);
// production duration
$price['production_days'] = $pcb['deliverytime'];
$price['production_date'] = date('Y-m-d', $this->date->add_working_days(time(), $pcb['deliverytime'] ));
// get shipping duration
$this->db->where('deliveryserviceid', $pcb['delivery_type']);
$this->db->where('countryid', $pcb['delivery_country']);
$this->db->where('is_active', 1);
$query = $this->db->get('deliveryservice_zone_country');
$delivery_zone = $query->row();
$shipping_duration = 3;
if ( !empty($delivery_zone) AND !empty($delivery_zone->shipping_duration))
$shipping_duration = (int) $delivery_zone->shipping_duration;
// shipping date
$price['delivery_date'] = date('Y-m-d', $this->date->add_working_days(time(), $price['production_days'] + $shipping_duration ));
// sort keys
ksort($price);
/*
$output = [];
$output['currency'] = $price['currency'];
$output['weight'] = $price['weight'];
$output['delivery_date'] = $price['delivery_date'];
$output['discount_customer'] = $price['discount_customer'];
$output['net_price_org'] = $price['net_price_org'];
$output['net_price'] = $price['net_price'];
$output['single_price_org'] = $price['single_price_org'];
$output['single_price'] = $price['single_price'];
*/
// show xml
return $this->_response($price);
}
/**
* show current configuration
*/
public function show()
{
$pcb = (object) [];
if( !empty($this->token_data->session_content) )
$pcb = unserialize($this->token_data->session_content);
return $this->_response($pcb);
}
/**
* get prices for current pcb
*/
public function pricelist()
{
if( empty($this->token_data->session_content) )
{
echo \"No offer in session\";
http_response_code(400);
exit;
}
// get request
$data = $this->_getRequestData();
// current pcb
$pcb = unserialize($this->token_data->session_content);
$this->lang->load('pcb/pcb');
$this->lang->load('pcb/pcb_hints');
$data['lang'] = $this->lang->line('lines');
$output = (object) [
'currency' => $this->cart->get_currency(),
'pricelist' => []
];
$timer = microtime(true);
$deliverytimes = [
2,3,4,5,6,7,8,9,10,15,18,20
];
// check given time
if( !empty($data['deliverytime']) AND !in_array($data['deliverytime'], $deliverytimes) )
{
http_response_code(400);
echo \"no valid deliverytime given. use only: \" . implode(',', $deliverytimes);
exit;
}
if( !empty($data['quantity']) AND ( (int)$data['quantity'] < 0 OR (int)$data['quantity'] > 50 ) )
{
http_response_code(400);
echo \"valid quantity only from 1 to 50\";
exit;
}
//$this->load->model('pcb_', 'pcb');
$this->load->library('product_price_lib');
$this->load->library('product_weight_lib');
foreach( $deliverytimes as $deliverytime )
{
if( !empty($data['deliverytime']) AND $deliverytime != $data['deliverytime'] )
continue;
for( $quantity = 1; $quantity <= 50; $quantity++ )
{
if( !empty($data['quantity']) AND $quantity != $data['quantity'] )
continue;
// set deliverytime
$pcb['deliverytime'] = $deliverytime;
$pcb['quantity'] = $quantity;
// TODO: dauert mega lange und muss dringend gecached werden - per HASH auf Konfiguration
//$price = $this->pcb->get_price($pcb, 'preview');
// faster method - but without discounts and delivery costs
$price = $this->product_price_lib->calc(1, $pcb, '', 'EUR'); // get converted prices for current currency
$weight = $this->product_weight_lib->calc_weight(1, $pcb);
//$output->pricelist['deliverytime_' . $deliverytime]['quantity_'.$quantity] = (object) [
$output->pricelist[] = (object) [
'deliverytime' => $deliverytime,
'quantity' => $quantity,
'single_net_price_org' => round($price / $quantity, 2 ),
'total_net_price_org' => $price,
'weight' => $weight
];
}
}
$end = round(microtime(true) - $timer, 2);
return $this->_response($output);
}
/**
* create new offer for current pcb
*/
public function createoffer()
{
if( empty($this->token_data->session_content) )
{
echo \"No offer in session\";
http_response_code(400);
exit;
}
$pcb = unserialize($this->token_data->session_content);
$this->lang->load('pcb/pcb');
$this->load->model('pcb_', 'pcb');
$this->load->model('wishlist_', 'wishlist');
$p = $this->pcb->prep_properties($pcb);
$price = $this->pcb->get_price($p, 'preview');
$lang = $this->lang->line('lines');
$price_compare = false;
// disable fields
if( $p['technology'] == Pcb_::TECHNOLOGY_ASIA )
{
$p['blind_via'] = '';
$p['microvia_side'] = '';
}
if ($this->input->post('show_compare_prices') === '1')
{
$price_compare = array();
$deliverytimes = array();
$product_compare = $p;
$deliverytimes = explode(',', $this->input->post('deliverytimes'));
sort($deliverytimes);
for ($i = 1; $i < 5; $i++)
{
$product_compare['quantity'] = (int) $_POST['quantity_compare_' . $i];
foreach ($deliverytimes as $deliverytime)
{
$product_compare['deliverytime'] = (int) $deliverytime;
$quantity_max = $this->pcb->getQuantityMax($product_compare);
$quantity_min = $this->pcb->getQuantityMin($product_compare);
$price_compare[$i][$deliverytime]['quantity'] = $_POST['quantity_compare_' . $i];
$price_compare[$i][$deliverytime]['price_data'] = array( 'single_price_currency' => 0, 'total_price_currency' => 0 );
if( $product_compare['quantity'] <= $quantity_max )
{
$p_compare = $this->pcb->get_price($product_compare, 'preview');
$price_compare[$i][$deliverytime]['price_data'] = $p_compare;
}
}
}
}
$this->load->model('output/PDFOfferPCB', 'pdf');
$this->load->model('shop_frontend', 'shop_frontend');
// Für UK müssen andere Werte für Abstände und Breiten definiert werden
if( $this->shop_frontend->get_default_customer_country() == 5 )
{
$gesamtbreite_inhalt = 191;
$this->pdf->left = 10;
$this->pdf->malus = $this->pdf->page_width - $gesamtbreite_inhalt;
$this->pdf->page_width = $gesamtbreite_inhalt; // org 179
$this->pdf->col_3_width = 50 + round( $this->pdf->malus * -1 / 3 ); // zusätzliche addierung auf Breite (default: 50)
}
ob_start();
$offer_number = $this->pdf->gen($_SERVER['DOCUMENT_ROOT'] . '/apitest_angebot.pdf', 'pcb', $p, $price, $price_compare);
ob_end_clean();
$item = array();
$item['properties']['offer_number'] = $offer_number;
$item['properties']['production'] = $p;
$item['properties']['price'] = $price;
$this->wishlist->add_item('pcb', $item, 'new', 'offer');
return $this->_response(['pcb_offer_number' => $offer_number]);
}
/**
* load offer and save as new configuration
*/
public function loadoffer()
{
$data = $this->_getRequestData();
if( empty($data['pcb_offer_number']) )
{
echo \"No pcb_offer_number sended\";
http_response_code(400);
exit;
}
$date_offset = 60 * 60 * 24 * 7 * 6 ; // 6 weeks
$data_offset_volume_big = 60 * 60 * 24 * 7 * 12 ; // 7257600 = 12 Weeks / 3 Monts
$earliest_date = mktime(0, 0, 0) - $date_offset;
$earlist_date_volume_big = mktime(0, 0, 0) - $data_offset_volume_big;
$this->load->model('wishlist_', 'wishlist');
$offer_number = $data['pcb_offer_number'];
$this->db->where('offer_number', $offer_number);
$this->db->where('
(
( production_volume = 1 AND `date` >= ' . $earliest_date . ' )
OR
( production_volume = 2 AND `date` >= ' . $earlist_date_volume_big . ' )
)
', NULL, FALSE);
$o = $this->db->get('pcb_wishlist');
$json = array();
$json['redirect'] = '';
if ($o->num_rows() == 0)
{
echo \"No valid offer found\";
http_response_code(400);
exit;
}
$offer = $o->row();
$this->load->model('pcb_');
$p = $this->pcb_->load('offer', $offer->id);
$price = $this->wishlist->get_price('pcb', $p);
// set source to wishlist - force old price on load function
$p['src'] = 'offer';
// save config to session
$this->db->set('session_content', serialize($p));
$this->db->where('token', $this->token);
$this->db->update('api_token');
return $this->_response($p);
}
/**
* upload a design file to current pcb
*/
public function upload()
{
$this->check();
if( empty($_FILES) )
{
echo \"No file was uploaded\";
http_response_code(400);
exit;
}
$this->lang->load('pcb/pcb_upload');
// upload path
$upload_path_customer = $this->auth->getUploadPath();
// fallback path
$upload_path_fallback = ROOTPATH . '/tmp_files';
// cleanup filename
$filename = $_FILES['file']['name'];
$filename = preg_replace(\"/[^a-zA-Z0-9-\\.]/\", \"_\", $filename);
// check if file was already exists (show message to user)
$file_was_already_exists = file_exists($upload_path_customer . '/' . $filename);
// build config
$config = [];
$config['upload_path'] = $upload_path_customer;
$config['allowed_types'] = 'zip|rar|brd|t3001|gwk|GWK|pcbdoc|prjpcb|xml|7z|7zip';
if (!empty($_FILES['file']) AND preg_match('/pcbdoc/i', $_FILES['file']['name']))
$config['allowed_types'] = '*';
$config['max_size'] = 25000; // 25mb
$config['overwrite'] = true; // overwrite file if exists
$config['file_name'] = $filename;
$this->load->library('upload', $config);
// do upload and get result data
$upload_result = $this->upload->do_upload('file');
if ( !$upload_result )
{
echo $this->upload->display_errors('<p>', '</p>');
http_response_code(400);
exit;
}
// upload success - get data from upload
$file_data = $this->upload->data();
// rename filename
rename($upload_path_customer . '/' . $file_data['file_name'], // source
$upload_path_customer . '/' . $filename // target
);
// copy file to fallbacks dir
copy($upload_path_customer . '/' . $filename, // source
$upload_path_fallback . '/' . $filename // target
);
// save filename
$pcb = unserialize($this->token_data->session_content);
$pcb['filename'] = $filename;
$pcb['filename_internal'] = $filename;
$this->db->set('session_content', serialize($pcb));
$this->db->where('token', $this->token);
$this->db->update('api_token');
return $this->_response(['filename' => $filename]);
}
/**
* check current configuration for checkout
*/
public function check()
{
$pcb = unserialize($this->token_data->session_content);
if( !$pcb )
{
echo \"No valid configuration\";
http_response_code(400);
exit;
}
return true;
}
/**
* full checkout for current pcb
*/
public function checkout()
{
$this->check();
$this->lang->load('pcb/pcb');
$this->load->model('pcb_', 'pcb');
// pcb configuration
$pcb = unserialize($this->token_data->session_content);
$pcb = $this->pcb->prep_properties($pcb);
$price = $this->pcb->get_price($pcb, 'preview');
$item = [];
$item['price'] = $price;
$item['production'] = $pcb;
if( empty($pcb['filename']) )
{
echo \"No file was uploaded for this configuration\";
http_response_code(400);
exit;
}
$item['filename'] = $pcb['filename'];
$item['filename_internal'] = $pcb['filename_internal'];
// presets
$this->cart->emptyCart();
$this->cart->setCartPresets(true);
$this->cart->set_currency('EUR');
$this->cart->setPaymentType(4);
// add item
$this->cart->addItem('pcb', $item, null, 'api');
// same delivery address as invoice address
$this->cart->cart['use_delivery_address'][1] = $this->auth->customer_data['id_delivery_address'];
// use first contactperson
$contact = $this->auth->customer_data['contactlist'][0];
$this->cart->setDeliveryContactPerson($contact['email'], $contact['person'], $contact['phone']);
// build new list
$this->cart->buildDeliveryList();
// order now
$ordernumber = $this->cart->sendOrder();
// reset token session data
$this->reset();
return $this->_response(['ordernumber' => $ordernumber]);
}
public function reset()
{
$this->db->set('session_content', null);
$this->db->where('token', $this->token);
$this->db->update('api_token');
}
/**
* get all pcb properties with value/index
*/
public function properties()
{
}
public function incompatiblities()
{
}
public function orderstatus()
{
$data = $this->_getRequestData();
if( empty($data['ordernumber']) )
{
echo \"please set ordnernumber\";
http_response_code(400);
exit;
}
$this->db->where('ordernumber', $data['ordernumber']);
$this->db->where('customernumber', $this->auth->customer_data['customernumber']);
$order = $this->db->get('orders')->row();
if( !$order)
{
echo \"no valid ordnernumber\";
http_response_code(400);
exit;
}
$this->db->where('ordernumber', $data['ordernumber']);
$product = $this->db->get('products')->row();
$this->db->where('ordernumber', $data['ordernumber']);
$pcb = $this->db->get('pcb')->row();
$output = [];
$output['ordernumber'] = (int) $order->ordernumber;
$output['order_time'] = (int) $order->order_time;
$output['currency'] = $order->currency;
$output['price_tot'] = (float) $order->price_tot;
//$output['discount_customer_currency'] = (float) $order->discount_customer_currency;
$output['processing_state'] = (int) $pcb->processing_state;
return $this->_response($output);
}
}";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/