query("set names utf8"); } catch(PDOException $e) { throw new Exception('Could not connect to database'); } $value) { $dirty[$key] = $value; if(!is_object($value) && !is_array($value)) $this->$key = sanitize($value); } $this->dirty = $dirty; } function unsanitize() { $dirty = $this->dirty; unset($this->dirty); foreach($this as $key => $value) $this->$key = $dirty[$key]; } function setArray($data) { for($i = 0; $i < count($data); $i++) if($i%2 == 0) $this->$data[$i] = $data[$i + 1]; } function setPost($fields, $prefix = "") { foreach($fields as $field => $name) { $field_name = $prefix == "" ? $name : $prefix . "_$name"; if (isset($_POST[$field_name])) { if (is_numeric($field)) $this->$name = trim($_POST[$field_name]); else $this->$field = trim($_POST[$field_name]); } else $this->$name = ""; } } function setQuery($row) { foreach($this as $key => $value) if(isset($row["$key"])) $this->$key = $row["$key"]; } function load($id) { } /** @return boolean */ function isValid() { return true; } } name_en; return $this->name_pl; } function getInfo() { if(isEN()) return $this->info_en; return $this->info_pl; } /** * @param $payment_means PaymentMeans */ function addPaymentMeans($payment_means) { $this->payment_means_array[] = $payment_means; } function isForeign() { return preg_match("/F/", $this->flag); } } class PaymentMeans extends Sepuku { /* @var $id int */ var $id; /* @var $code string */ var $code; /* @var $name_pl string */ var $name_pl; /* @var $info_pl string */ var $info_pl; /* @var $name_en string */ var $name_en; /* @var $info_en string */ var $info_en; /* @var $flag string */ var $flag; /* @var $item_id int */ var $item_id; function getName() { if(isEN()) return $this->name_en; return $this->name_pl; } function getInfo() { if(isEN()) return $this->info_en; return $this->info_pl; } } class ForeignDeliveryCostEntry extends Sepuku { /* @var $id int */ var $id; /* @var $country_id int */ var $country_id; /* @var $weight float */ var $weight; /* @var $net_price float */ var $net_price; function getNetPrice() { return round($this->net_price * (1 + get_numeric_parameter("GLS_OIL") / 100) + get_numeric_parameter("GLS_VIATOLL"), 2); } function getGrossPrice() { return net2Gross($this->getNetPrice()); } } class GroupType extends Sepuku { /* @var $id int */ var $id; /* @var $name string */ var $name; } class Country extends Sepuku { /* @var $id int */ var $id; /* @var $code string */ var $code; /* @var $name string */ var $name; /* @var $info string */ var $info; /* @var $days string */ var $days; } class ConsentType extends Sepuku { /* @var $id int */ var $id; /* @var $code string */ var $code; /* @var $short_text string */ var $short_text; /* @var $full_text string */ var $full_text; /* @var $is_mandatory string */ var $is_mandatory; /* @var $is_active string */ var $is_active; /* @var $seq int */ var $seq; } class ConsentEvent extends Sepuku { /* @var $id int */ var $id; /* @var $code string */ var $code; /* @var $name string */ var $name; } class Dictionary extends Sepuku { /** @var $delivery_option_array DeliveryOption[] */ var $delivery_option_array; /** @var $payment_means_array PaymentMeans[] */ var $payment_means_array; /** @var $groupTypes GroupType[] */ var $groupTypes; /** @var $countries Country[] */ var $countries; /** @var $prices Price[] */ var $prices; /** @var $consentTypes ConsentType[] */ var $consentTypes; /** @var $consentEvents ConsentEvent[] */ var $consentEvents; function Dictionary($days = 0) { global $pdo; $this->delivery_option_array = array(); $st = $pdo->query("select * from delivery_option order by seq"); while($row = $st->fetch()) { $delivery_option = new DeliveryOption(); $delivery_option->setQuery($row); $this->delivery_option_array[] = $delivery_option; } $this->payment_means_array = array(); $st = $pdo->query("select * from payment_means order by seq"); while($row = $st->fetch()) { $payment_means = new PaymentMeans(); $payment_means->setQuery($row); if($payment_means->code == "PRE") { if($days == 0) $this->payment_means_array[] = $payment_means; } elseif($payment_means->code == "TRAN") { if($days > 0) { $payment_means->name_pl = str_replace("%DAYS%", $days, $payment_means->name_pl); $payment_means->name_en = str_replace("%DAYS%", $days, $payment_means->name_en); $this->payment_means_array[] = $payment_means; } } else $this->payment_means_array[] = $payment_means; } $st = $pdo->query("select * from delivery_payment_relation"); while($row = $st->fetch()) { $delivery_option = $this->getDeliveryOption($row["delivery_option_id"]); $payment_means = $this->getPaymentMeans($row["payment_means_id"]); if(is_object($delivery_option) && is_object($payment_means)) $delivery_option->addPaymentMeans($payment_means); } $this->groupTypes = array(); $st = $pdo->query("select * from group_type"); while($row = $st->fetch()) { $entry = new GroupType(); $entry->setQuery($row); $this->groupTypes[] = $entry; } $this->countries = array(); if(isPL()) $st = $pdo->query("select id, code, name_pl name, info_pl info, days from country"); else $st = $pdo->query("select id, code, name_en name, info_en info, days from country"); while($row = $st->fetch()) { $entry = new Country(); $entry->setQuery($row); $this->countries[] = $entry; } $this->prices = array(); $st = $pdo->query("select id, name, comment, is_default from price order by name"); while($row = $st->fetch()) { $entry = new Price(); $entry->setQuery($row); $this->prices[] = $entry; } $this->consentTypes = array(); $st = $pdo->query("select * from consent_type where is_active = 'Y' order by seq"); while($row = $st->fetch()) { $entry = new ConsentType(); $entry->setQuery($row); $this->consentTypes[] = $entry; } $this->consentEvents = array(); $st = $pdo->query("select * from consent_event"); while($row = $st->fetch()) { $entry = new ConsentEvent(); $entry->setQuery($row); $this->consentEvents[] = $entry; } } /** * @param $code string * @return ConsentType */ function getConsentTypeByCode($code) { foreach($this->consentTypes as $consentType) { if($consentType->code == $code) return $consentType; } return null; } /** * @param $code string * @return ConsentEvent */ function getConsentEventByCode($code) { foreach($this->consentEvents as $consentEvent) { if($consentEvent->code == $code) return $consentEvent; } return null; } /** * @param $country_code string * @return ForeignDeliveryCostEntry[] */ function getForeignDeliveryCostArray($country_code) { global $pdo; $foreign_cost_array = array(); $st = $pdo->prepare("select * from delivery_cost_foreign where country_code = :country_code order by weight"); $st->bindValue(":country_code", $country_code); $st->execute(); while($row = $st->fetch()) { $entry = new ForeignDeliveryCostEntry(); $entry->setQuery($row); $foreign_cost_array[] = $entry; } return $foreign_cost_array; } /** * @param $id int * @return Country */ function getCountryById($id) { foreach($this->countries as $country) { if($country->id == $id) return $country; } return null; } /** * @param $code string * @return Country */ function getCountryByCode($code) { foreach($this->countries as $country) { if($country->code == $code) return $country; } return null; } /** * @param $id int * @return DeliveryOption */ function getDeliveryOption($id) { foreach($this->delivery_option_array as $delivery_option) if($delivery_option->id == $id) return $delivery_option; return null; } /** * @param $code string * @param $foreign bool * @return DeliveryOption */ function getDeliveryOptionByCode($code, $foreign) { foreach($this->delivery_option_array as $delivery_option) if($delivery_option->code == $code && preg_match("/" . ($foreign ? "F" : "D") . "/", $delivery_option->flag)) return $delivery_option; return null; } /** * @param $foreign bool * @return DeliveryOption[] */ function getDeliveryOptionArray($foreign) { $result = array(); foreach($this->delivery_option_array as $delivery_option) if(preg_match("/" . ($foreign ? "F" : "D") . "/", $delivery_option->flag)) $result[] = $delivery_option; return $result; } /** * @param $id int * @return PaymentMeans */ function getPaymentMeans($id) { foreach($this->payment_means_array as $payment_means) if($payment_means->id == $id) return $payment_means; return null; } /** * @param $code string * @param $foreign bool * @return PaymentMeans */ function getPaymentMeansByCode($code, $foreign) { foreach($this->payment_means_array as $payment_means) if($payment_means->code == $code && preg_match("/" . ($foreign ? "F" : "D") . "/", $payment_means->flag)) return $payment_means; return null; } /** * @param $foreign bool * @return PaymentMeans[] */ function getPaymentMeansArray($foreign) { $result = array(); foreach($this->payment_means_array as $payment_means) if(preg_match("/" . ($foreign ? "F" : "D") . "/", $payment_means->flag)) $result[] = $payment_means; return $result; } /** * @param $delivery_option_id int * @param $payment_means_id int * @return bool */ function isDeliveryPaymentAllowed($delivery_option_id, $payment_means_id) { $delivery_option = $this->getDeliveryOption($delivery_option_id); if(is_object($delivery_option)) foreach($delivery_option->payment_means_array as $payment_means) if($payment_means->id == $payment_means_id) return true; return false; } /** * @param $delivery_option_id int * @return array[] */ function getDeliveryCostArray($delivery_option_id) { global $pdo; $st = $pdo->prepare("select * from delivery_cost where delivery_option_id = :delivery_option_id " . "order by net_threshold"); $st->bindValue(":delivery_option_id", $delivery_option_id); $st->execute(); $result = array(); while($row = $st->fetch()) $result[] = $row; return $result; } /** * @param $payment_means_id int * @return array[] */ function getPaymentMeansCost($payment_means_id) { global $pdo; $st = $pdo->prepare("select * from payment_means_cost where payment_means_id = :payment_means_id"); $st->bindValue(":payment_means_id", $payment_means_id); $st->execute(); if($row = $st->fetch()) return $row; return null; } /** * @param $typeId int * @return string */ function getGroupType($typeId) { foreach($this->groupTypes as $row) { if($typeId == $row->id) return $row->name; } return null; } /** * @param $id int * @return Price */ function getPrice($id) { foreach($this->prices as $price) if($price->id == $id) return $price; return null; } /** * @param $name string * @return Price */ function getPriceByName($name) { foreach($this->prices as $price) if($price->name == $name) return $price; return null; } /** @return Price */ function getDefaultPrice() { foreach($this->prices as $price) if($price->is_default == "Y") return $price; return null; } /** @return Price[] */ function getPrices() { return $this->prices; } }