| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/innoutstorage/webadmin/ |
Upload File : |
<?php
require_once('configure.php');
require_once('../inc/class.phpmailer.php');
//functions
if (!function_exists('validate_url')) {
function validate_url()
{
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')
=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$request_uri = $_SERVER['REQUEST_URI'];
//$currentUrl = $protocol . '://' . $host . $request_uri;
if (strpos($request_uri, ".php") !== FALSE){
$token = explode(".php", $request_uri);
//check unsafe url character, may add more here
if ( preg_match ( "/\/|\"|\'|>|</", urldecode($token[1]) ) ) {
header("Location: ".$protocol . '://' . $host . $script);
}
}else{
//for index page
if (strpos($request_uri, "?") !== FALSE){
$token = explode("?", $request_uri);
//check unsafe url character, may add more here
if ( preg_match ( "/\/|\"|\'|>|</", urldecode($token[1]) ) ) {
header("Location: ".$protocol . '://' . $host . $token[0]);
}
}
}
}
}
validate_url();
if (!function_exists('random_string')) {
function random_string($length = 8)
{
$chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789";
$random_string = substr(str_shuffle($chars), 0, $length);
return $random_string;
}
}
/*if (!function_exists('rsa_crypt')) {
function rsa_crypt($data, $encrypt_decrypt)
{
/*set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.8');
include('Net/SSH2.php');
include('Crypt/RSA.php');
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.8');
if (!class_exists('Crypt_RSA')) {
include('phpseclib0.3.8/Crypt/RSA.php');
}
if (!class_exists('Net_SSH2')) {
include('phpseclib0.3.8/Net/SSH2.php');
}
if ($encrypt_decrypt == 1) {
$rsa_encrypt = new Crypt_RSA();
$public_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNkpdN1VAtuqX/+X00auWqwle8 nreQCvI8oVHSQsZdGqWZIf2cBazZnSFDHpwjUSYfvxuhIjvYHRrUFVFhM+ocqSKl EtikvCebX3Z9H2UljvUfrg0oFjvsxwSQINUDWtGIbC7/tDsKhREjqglQFDI12PpS qykMXVmZoP9vcHLC7wIDAQAB
";
$rsa_encrypt->loadKey($public_key); // public key
if (!empty($data)) {
return base64_encode($rsa_encrypt->encrypt($data));
} else {
return;
}
}
if ($encrypt_decrypt == 2) {
$rsa_decrypt = new Crypt_RSA();
$private_key = "MIICXQIBAAKBgQDNkpdN1VAtuqX/+X00auWqwle8nreQCvI8oVHSQsZdGqWZIf2c BazZnSFDHpwjUSYfvxuhIjvYHRrUFVFhM+ocqSKlEtikvCebX3Z9H2UljvUfrg0o FjvsxwSQINUDWtGIbC7/tDsKhREjqglQFDI12PpSqykMXVmZoP9vcHLC7wIDAQAB AoGAU4jY8OjYfuyUnfK8vPsfPodgbaY1Q1QfYSHQhNdbkePNHO/iBW+M8JTYOlUK 75L/IfFfgdfOZ6BUEZBkFFKrM6XG4tlxTQ5bBIdGSJvTZtRQ42KnqLHJ1AO8UgLm 8niij5yl0CB8kg955tfXSAaW62Nz+E39gqDcMstThY4NuiECQQDsCn/5X4TPl1qS //IN+AUfDQRH/JSksQOXhzsOX84bKppC7rRy62CXq7YZWmV5Z+Foa8GsS8rTBL/Z IofGfs2RAkEA3vSNVpIuPa0S1jjPgrQ+9e6M7lEkZDlKPbkWmJOq5RHe+IdzVAfD kvCIVuYxDvtCbmP718VEGARbIFO2HRpIfwJBAMxLzjX1cYsHUhKXSlbCyxPz/Ted Kr5co2I8XmXzj/09Y2T5G9+3T9QWf7bz4Y4x1gu98FQDCZqYqr/xvhiUWbECQFdb Hl3DHNcRjwXccIHXuauGcjWWGVojkFEqyg2yHg1uuRxLhgZwnFJgaCsUOjiSfe7e wfhC1HFMk5/Q7NPuTmUCQQCCmw40SyyXw2Cx2feAYC9/1APcDLGYimqpegQKM0qh +qn8+2WMfvRQxwr3HM0Lu3mUd94cZwQqAobfVfPxgdqi
";
$rsa_decrypt->loadKey($private_key); // private key
if (!empty($data)) {
return $rsa_decrypt->decrypt(base64_decode($data));
} else {
return;
}
}
}
}*/
//crypt function changed to aes but function name not change
if (!function_exists('rsa_crypt')) {
function rsa_crypt($data, $encrypt_decrypt)
{
/*set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib0.3.8');
include('Net/SSH2.php');
include('Crypt/RSA.php');*/
set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib1.0.2');
if (!class_exists('Crypt_AES')) {
include_once('phpseclib1.0.2/Crypt/AES.php');
}
include_once('phpseclib1.0.2/Crypt/Random.php');
$rsa_crypt = new Crypt_AES();
$rsa_crypt->setKey('@b#5My5?!fk&EUzwr7qxBkkXAP!WB8h6Q$kmq5W#C5xjZ_3TMARu#GcH_VfV6gpbSKGZT#ZJ%6DRUKrMzM7Qw!=s=6zz#9uJzbB@+?dWNZ72BXZghukUR#Yv@Lc!4Vcm');
//$rsa_crypt->setIV(crypt_random_string($rsa_crypt->getBlockLength() >> 3));
$rsa_crypt->setIV('JaAK7vymB9jPbXCpfqc*ahLvp%8TDksxGekJTt32Qm$4r3Bzv#R-xANg7K?+PFEDv3ym_L@V6!n$2&s%3ztxT6HC@^esQ_HyX4#t4VH3=j@jqp6Xk2hz%5CM#hTUQ4-H');
if ($encrypt_decrypt == 1) {
if (!empty($data)) {
return base64_encode($rsa_crypt->encrypt($data));
} else {
return;
}
}
if ($encrypt_decrypt == 2) {
if (!empty($data)) {
return $rsa_crypt->decrypt(base64_decode($data));
} else {
return;
}
}
}
}
if (!function_exists('bind_pdo')) {
function bind_pdo($sql, $parameters = NULL, $action = NULL)
{
global $dbh;
if ($action == "insert" || $action == "update" || $action == "delete" || empty($action)) {
if (!($sth = $dbh->prepare($sql))) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
} else {
return true;
}
}
if ($action == "selectone") {
if (!($sth = $dbh->prepare($sql))) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetch(PDO::FETCH_ASSOC);
}
if ($action == "selectall") {
if (!($sth = $dbh->prepare($sql))) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
if (!$sth->execute($parameters)) {
debug_print_backtrace();
throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo()));
}
return $sth->fetchAll(PDO::FETCH_ASSOC);
}
if ($action == "dump") {
return dump_sql($sql, $parameters);
}
}
}
if (!function_exists('dump_sql')) {
function dump_sql($sql, $parameters)
{
$keys = array();
# build a regular expression for each parameter
foreach ($parameters as $key => $value) {
if (is_string($key)) {
$keys[] = '/:' . $key . '/';
} else {
$keys[] = '/[?]/';
}
}
foreach ($parameters as $key2 => $value) {
$parameters[$key2] = "'" . $value . "'";
}
$sql = preg_replace($keys, $parameters, $sql, 1, $count);
#trigger_error('replaced '.$count.' keys');
return $sql;
}
}
if (!function_exists('activity_log')) {
function activity_log($controller, $function, $input = array(), $data_before = array(), $data_after = array(), $step = 1)
{
$date = new DateTime();
$data = array(
'created_at' => $date->format('Y-m-d H:i:s'),
'login_id' => $_SESSION['cmsloginid'],
'controller' => $controller,
'function' => $function,
'input' => $input,
'data_before' => $data_before,
'data_after' => $data_after,
'step' => $step,
);
file_put_contents('./logs/activity/' . $date->format('Y-m-d') . '.log', json_encode($data)."\n*****\n", FILE_APPEND);
}
}
$sql = "SELECT * FROM sys_lang WHERE langstatus = '1' ORDER BY langsort ASC ";
$lang_array_info = bind_pdo($sql, NULL, "selectall");
foreach ($lang_array_info as $lang_info) {
$arraylangcode[$lang_info{'langcode'}] = $lang_info{'langname'};
}
function matched_option($data1, $data2, $type)
{
if ($data1 == $data2) {
if ($type == "checkbox" || $type == "radiobutton") {
return "checked";
} else if ($type == "select") {
return "selected";
} else {
}
}
}
if (!function_exists('startsWith')) {
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
}
if (!function_exists('check_upload_path')) {
function check_upload_path($img_file)
{
$session_path_str = "/uploader/" . $_SESSION['KCFINDER']['uploadURL'];
$session_path_long = strlen($session_path_str);
$path_error = 0;
foreach ($img_file as $key2 => $pathname) {
if ($key2 && $pathname) {
$submit_path_str = substr($pathname, 0, $session_path_long);
$submit_path_long = strlen($submit_path_str);
$file = str_replace('..', '', $pathname);
if ($session_path_long <> $submit_path_long || $session_path_str <> $submit_path_str || !startsWith($file, $session_path_str)) {
$path_error = 1;
}
}
}
}
}
if (!function_exists('get_site_info')) {
function get_site_info()
{
$sql = "SELECT * FROM site_info WHERE siteinfoid = ? ";
$parameters = array(1);
$site_info = bind_pdo($sql, $parameters, "selectone");
return $site_info;
}
}
$site_info = get_site_info();
if (!function_exists('clean_data')) {
function clean_data($data = array())
{
foreach ($data as $data_name => $data_value) {
if (is_array($data_value)) {
clean_data($data_value);
} else {
$_REQUEST[$data_name] = htmlspecialchars($data_value, ENT_QUOTES);
}
}
}
}
if (!function_exists('get_master_type_code')) {
function get_master_type_code($typeid, $code = NULL, $config_value=NULL)
{
$where_clause = "";
if(!empty($config_value)){
$where_clause = "and config_value = ".(int)$config_value;
}
if (!empty($code)) {
$sql = "select * from master_type_code where typeid = ? and code = ? and deleted = ? {$where_clause} order by sort ASC";
$parameters = array($typeid, $code, 0);
$master_type_code_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select * from master_type_code where typeid = ? and deleted = ? {$where_clause} order by sort ASC";
$parameters = array($typeid, 0);
$master_type_code_info = bind_pdo($sql, $parameters, "selectall");
}
return $master_type_code_info;
}
}
if (!function_exists('get_master_room')) {
function get_master_room($id = NULL, $location_id=NULL)
{
if (!empty($id)) {
$sql = "SELECT *,mroom.status as master_room_status, mroom.id as master_room_id, mroom.lastupdate as master_room_lastupdate FROM master_room mroom
INNER JOIN master_room_price price ON mroom.id = price.master_room_id
where mroom.deleted = 0 and price.deleted = 0 and mroom.id = ?
order by mroom.length ASC, mroom.width ASC, mroom.height ASC";
$parameters = array($id);
$master_room_info = bind_pdo($sql, $parameters, "selectone");
$master_room_info["id"] = ($master_room_info["master_room_id"]);
$master_room_info["length"] = ($master_room_info["length"]);
$master_room_info["width"] = ($master_room_info["width"]);
$master_room_info["height"] = ($master_room_info["height"]);
$master_room_info["display_size"] = ($master_room_info["display_size"]);
} else {
if(!empty($location_id)){
$sql2 = "and mroom.location_id = ?";
$parameters = array($location_id);
}else{
$sql2 = "";
$parameters = array();
}
$sql = "SELECT *, mroom.status as master_room_status, mroom.id as master_room_id, mroom.lastupdate as master_room_lastupdate FROM master_room mroom
INNER JOIN master_room_price price ON mroom.id = price.master_room_id
where mroom.deleted = 0 and price.deleted = 0 {$sql2}
order by mroom.length ASC, mroom.width ASC, mroom.height ASC";
$master_room_info = bind_pdo($sql, $parameters, "selectall");
foreach ($master_room_info as $key => $master_room) {
$master_room_info[$key]["id"] = ($master_room["master_room_id"]);
$master_room_info[$key]["length"] = ($master_room["length"]);
$master_room_info[$key]["width"] = ($master_room["width"]);
$master_room_info[$key]["height"] = ($master_room["height"]);
$master_room_info[$key]["display_size"] = ($master_room["display_size"]);
}
}
return $master_room_info;
}
}
if (!function_exists('get_room')) {
function get_room($room_id = NULL, $location_id=NULL)
{
if (!empty($room_id)) {
$sql = "select * from room where id = ? and deleted = ?";
$parameters = array($room_id, 0);
$room_info = bind_pdo($sql, $parameters, "selectone");
//2019-04-24 如租的倉是 "服裝倉",於所有合約/單上顯示倉的編號後加上 "(服裝倉)"
$master_room = get_master_room($room_info['master_room_id']);
if($master_room['type'] == 'CLOTH'){
$room_info['code'] .= "(服裝倉)";
}
} else {
if(!empty($location_id)){
$sql2 = "and location_id = ?";
$parameters = array(0, $location_id);
}else{
$sql2 = "";
$parameters = array(0);
}
$sql = "select * from room where deleted = ? {$sql2}";
$room_info = bind_pdo($sql, $parameters, "selectall");
}
return $room_info;
}
}
if (!function_exists('update_room_status')) {
function update_room_status($room_id = NULL)
{
if (!empty($room_id)) {
$sql = "update room set status = ?, lastupby = ?, lastupdate = ? where id = ?";
$parameters = $parameters = array("OPEN",$_SESSION['cmsloginid'], date('Y-m-d H:i:s'), $room_id);
$result = bind_pdo($sql, $parameters);
activity_log('basic_info.php', 'update_room_status', $input = array('sql' => $sql, 'parameters' => $parameters), $data_before = array(), $data_after = array(), $step = 1);
}
return $room_id;
}
}
if (!function_exists('get_room_by_code')) {
function get_room_by_code($room_code = NULL)
{
if (!empty($room_code)) {
$sql = "select * from room where code = ? and deleted = ?";
$parameters = array($room_code, 0);
$room_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select * from room where deleted = ?";
$parameters = array(0);
$room_info = bind_pdo($sql, $parameters, "selectall");
}
return $room_info;
}
}
if (!function_exists('get_customer_name')) {
function get_customer_name($firstname, $lastname)
{
if (preg_match('/^([a-zA-Z\s]+)$/', $lastname) && preg_match('/^([a-zA-Z\s]+)$/', $firstname)) {
$customer_name = $firstname . " " . $lastname;
} else {
$customer_name = $lastname . $firstname;
}
return $customer_name;
}
}
if (!function_exists('validateDate')) {
function validateDate($date, $format = 'Y-m-d H:i:s')
{
if(is_string($date)){
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}else{
return false;
}
}
}
if (!function_exists('get_location')) {
function get_location($location_id = NULL)
{
if (!empty($location_id)) {
$sql = "select *, location.code as location_code, location.id as location_id, location.name_tc as location_name_tc, branch.name_tc as branch_name_tc, company.name_tc as company_name_tc, location.code as location_code, branch.code as branch_code from location location INNER JOIN branch branch ON location.branch_id = branch.id INNER JOIN company company ON location.company_id = company.id where location.id = ? and location.deleted = ? order by location.sort ASC";
$parameters = array($location_id, 0);
$location_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select *, location.code as location_code, location.id as location_id, location.name_tc as location_name_tc, branch.name_tc as branch_name_tc, company.name_tc as company_name_tc, location.code as location_code, branch.code as branch_code from location location INNER JOIN branch branch ON location.branch_id = branch.id INNER JOIN company company ON location.company_id = company.id where location.deleted = ? order by location.sort ASC";
$parameters = array(0);
$location_info = bind_pdo($sql, $parameters, "selectall");
}
return $location_info;
}
}
if (!function_exists('get_customer')) {
function get_customer($customer_id = NULL)
{
$customer_info = array();
if (!empty($customer_id)) {
$sql = "select * from customer where id = ?";
$parameters = array($customer_id);
$customer_info = bind_pdo($sql, $parameters, "selectone");
if ($customer_info["typeid"] == "PERSONAL") {
$customer_info["customer_identity_id"] = $customer_info["hkid"];
} else {
$customer_info["customer_identity_id"] = $customer_info["hkbr"];
}
$customer_info["customer_name"] = get_customer_name(rsa_crypt($customer_info["firstname"], 2), rsa_crypt($customer_info["lastname"], 2));
} else {
$sql = "select * from customer";
$parameters = array();
$customer_info = bind_pdo($sql, $parameters, "selectall");
foreach ($customer_info as $key => $customer) {
if ($customer["typeid"] == "PERSONAL") {
$customer_info[$key]["customer_identity_id"] = $customer["hkid"];
} else {
$customer_info[$key]["customer_identity_id"] = $customer["hkbr"];
}
$customer_info[$key]["customer_name"] = get_customer_name(rsa_crypt($customer["firstname"], 2), rsa_crypt($customer["lastname"], 2));
}
}
return $customer_info;
}
}
if (!function_exists('get_customer2')) {
function get_customer2()
{
$customer_info = array();
$sql = "select id, code, firstname, lastname, tel from customer";
$parameters = array();
$customer_info = bind_pdo($sql, $parameters, "selectall");
foreach ($customer_info as $key => $customer) {
$customer_info[$key]["customer_name"] = get_customer_name(rsa_crypt($customer["firstname"], 2), rsa_crypt($customer["lastname"], 2));
$customer_info[$key]["tel"] = rsa_crypt($customer["tel"], 2);
}
return $customer_info;
}
}
if (!function_exists('get_customer_for_rent')) {
function get_customer_for_rent()
{
$sql = "select id, email, tel from customer where deleted = 0";
$parameters = array();
$customer_info = bind_pdo($sql, $parameters, "selectall");
return $customer_info;
}
}
if (!function_exists('get_order')) {
function get_order($order_id = NULL, $get_customer_name = true)
{
if (!empty($order_id)) {
$sql = "select * from `order` where id = ? and deleted = ? order by id DESC";
$parameters = array($order_id, 0);
// $order_info = bind_pdo($sql, $parameters, "selectone");
$order_info = bind_pdo($sql, $parameters, "selectone");
if ($order_info["customer_typeid"] == "PERSONAL") {
$order_info["customer_identity_id"] = $order_info["customer_hkid"];
} else {
$order_info["customer_identity_id"] = $order_info["customer_hkbr"];
}
if($get_customer_name){
//2019-04-24 於列印合約內的姓名後加入顯示Customer ID (不用顯示C字)
$customer = get_customer($order_info['customer_id']);
}
/* FIXME: customer info */
$customer_name = $customer['customer_name'];
$customer_code = str_replace('C', ' ', $customer['code']);
$customer_name = get_customer_name(rsa_crypt($order_info["customer_firstname"], 2), rsa_crypt($order_info["customer_lastname"], 2));
$order_info["clientID"] = $order_info['customer_id'];
$order_info["clientName"] = $customer_code;
// add col to $order_info
$order_info["customer_name"] = $customer_name;
$order_info["customer_code"] = $customer_code;
} else {
$sql = "select * from `order` where deleted = ? order by id DESC";
$parameters = array(0);
$order_info = bind_pdo($sql, $parameters, "selectall");
foreach($order_info as $key => $order){
if ($order["customer_typeid"] == "PERSONAL") {
$order_info[$key]["customer_identity_id"] = $order["customer_hkid"];
} else {
$order_info[$key]["customer_identity_id"] = $order["customer_hkbr"];
}
if($get_customer_name){
$customer_name = get_customer_name(rsa_crypt($order["customer_firstname"], 2), rsa_crypt($order["customer_lastname"], 2));
$order_info[$key]["customer_name"] = $customer_name;
}
}
}
return $order_info;
}
}
if (!function_exists('get_order_by_first_order_id_latest')) {
function get_order_by_first_order_id_latest($order_id, $get_customer_name = true)
{
if (!empty($order_id)) {
$sql = "select * from `order` where first_order_id = ? and deleted = ? and withdraw_date is not null order by id DESC";
$parameters = array($order_id, 0);
// $order_info = bind_pdo($sql, $parameters, "selectone");
$order_info = bind_pdo($sql, $parameters, "selectone");
if ($order_info["customer_typeid"] == "PERSONAL") {
$order_info["customer_identity_id"] = $order_info["customer_hkid"];
} else {
$order_info["customer_identity_id"] = $order_info["customer_hkbr"];
}
if($get_customer_name){
//2019-04-24 於列印合約內的姓名後加入顯示Customer ID (不用顯示C字)
$customer = get_customer($order_info['customer_id']);
}
/* FIXME: customer info */
$customer_name = $customer['customer_name'];
$customer_code = str_replace('C', ' ', $customer['code']);
$customer_name = get_customer_name(rsa_crypt($order_info["customer_firstname"], 2), rsa_crypt($order_info["customer_lastname"], 2));
$order_info["clientID"] = $order_info['customer_id'];
$order_info["clientName"] = $customer_code;
// add col to $order_info
$order_info["customer_name"] = $customer_name;
$order_info["customer_code"] = $customer_code;
} else {
return;
}
return $order_info;
}
}
if (!function_exists('get_order_floor_plan')) {
function get_order_floor_plan($order_id = NULL, $get_customer_name = true)
{
if (!empty($order_id)) {
// $sql = "select * from `order` where id = ? and deleted = ? and (status = ? or status = ?) order by id DESC";
$sql = "select `id`, `customer_id`, `code`, `startdate`, `enddate` from `order` where id = ? and deleted = ? and (status = ? or status = ?) order by id DESC";
$parameters = array($order_id, 0, "NEW", "REVISED");
$order_info = bind_pdo($sql, $parameters, "selectone");
}
return $order_info;
}
}
if (!function_exists('get_order_floor_plan_by_start_date')) {
function get_order_floor_plan_by_start_date($order_id = NULL, $get_customer_name = true)
{
if (!empty($order_id)) {
// $sql = "select * from `order` where id = ? and deleted = ? and (status = ? or status = ?) order by id DESC";
$sql = "select `id`, `customer_id`, `code`, `startdate`, `enddate` from `order` where id = ? and deleted = ? and (status = ? or status = ?) order by id DESC";
$parameters = array($order_id, 0, "NEW", "REVISED");
$order_info = bind_pdo($sql, $parameters, "selectone");
}
return $order_info;
}
}
if (!function_exists('get_order2')) {
function get_order2()
{
$sql = "select id, code from `order` where deleted = ? order by id DESC";
$parameters = array(0);
$order_info = bind_pdo($sql, $parameters, "selectall");
return $order_info;
}
}
if (!function_exists('get_order_discount')) {
function get_order_discount($order_id)
{
$order_discount_info = array();
if (!empty($order_id)) {
$sql = "select *, orddiscount.discount as order_discount_discount from `order_discount` orddiscount
INNER JOIN master_room_discount mrdiscount ON orddiscount.master_room_discount_id = mrdiscount.id
INNER JOIN master_type_code mtcode ON mrdiscount.payment_term = mtcode.code
where orddiscount.order_id = ? and orddiscount.deleted = ? ";
$parameters = array($order_id, 0);
$order_discount_info = bind_pdo($sql, $parameters, "selectall");
}
return $order_discount_info;
}
}
if (!function_exists('get_order_product')) {
function get_order_product($order_id)
{
$order_product_info = array();
if (!empty($order_id)) {
$sql = "select * from `order_product` where order_id = ? and deleted = ? ";
$parameters = array($order_id, 0);
$order_product_info = bind_pdo($sql, $parameters, "selectall");
}
return $order_product_info;
}
}
if (!function_exists('get_product')) {
function get_product($product_id = NULL)
{
if (!empty($product_id)) {
$sql = "select * from `product` where id = ? and deleted = ? ";
$parameters = array($product_id, 0);
$product_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select * from `product` where deleted = ? ";
$parameters = array(0);
$product_info = bind_pdo($sql, $parameters, "selectall");
}
return $product_info;
}
}
if (!function_exists('get_order_room')) {
function get_order_room($order_id)
{
$order_room_info = array();
if (!empty($order_id)) {
$sql = "select * from `order_room` where order_id = ? and deleted = ? ";
$parameters = array($order_id, 0);
$order_room_info = bind_pdo($sql, $parameters, "selectall");
}
return $order_room_info;
}
}
if (!function_exists('get_order_room_by_room_id')) {
function get_order_room_by_room_id($room_id)
{
$order_room_info = array();
if (!empty($room_id)) {
$sql = "select * from `order_room` where room_id = ? and deleted = ? order by createdate DESC limit 1";
$parameters = array($room_id, 0);
$order_room_info = bind_pdo($sql, $parameters, "selectone");
}
return $order_room_info;
}
}
if (!function_exists('get_all_order_room_by_room_id')) {
function get_all_order_room_by_room_id($room_id)
{
$order_room_info = array();
if (!empty($room_id)) {
$sql = "select * from `order_room` where room_id = ? and deleted = ? order by createdate DESC";
$parameters = array($room_id, 0);
$order_room_info = bind_pdo($sql, $parameters, "selectall");
}
return $order_room_info;
}
}
if (!function_exists('get_order_by_room_id')) {
function get_order_by_room_id($room_id)
{
$order_room_info = array();
if (!empty($room_id)) {
$sql = "select order_id from `order_room` where room_id = ?";
$parameters = array($room_id);
$order_room_info = bind_pdo($sql, $parameters, "selectall");
}
return $order_room_info;
}
}
if (!function_exists('customer_first_order')) {
function customer_first_order($customer_id = NULL)
{
$sql = "select * from customer cust INNER JOIN `order` ord ON cust.id = ord.customer_id where cust.deleted = 0 and ord.status != 'VOID' and ord.deleted = 0 and cust.id = ?";
$parameters = array($customer_id);
$customer_order = bind_pdo($sql, $parameters, "selectall");
return $customer_order;
}
}
if (!function_exists('insert_record')) {
function insert_record($table_name, $data, $dump_sql = NULL)
{
$result = "";
if (!empty($table_name) && !empty($data)) {
$sql = "insert into `" . $table_name . "` set ";
$parameters = array();
foreach ($data as $table_field => $value) {
$sql .= "`" . $table_field . "` = ?, ";
$parameters[] = $value;
}
$sql = substr_replace($sql, "", -2);
}
activity_log('insert_record', '', $input = array('sql' => $sql, 'parameters' => $parameters));
if (!empty($dump_sql)) {
$result = dump_sql($sql, $parameters);
} else {
$result = bind_pdo($sql, $parameters);
}
return $result;
}
}
if (!function_exists('update_record')) {
function update_record($table_name, $data, $where, $dump_sql = NULL)
{
$result = "";
if (!empty($table_name) && !empty($data)) {
$sql = "update `" . $table_name . "` set ";
$parameters = array();
foreach ($data as $table_field => $value) {
$sql .= "`" . $table_field . "` = ?, ";
$parameters[] = $value;
}
$sql = substr_replace($sql, "", -2);
$sql .= " where " . $where["sql"];
foreach ($where["parameters"] as $table_field => $value) {
$parameters[] = $value;
}
activity_log('update_record', '', $input = array('sql' => $sql, 'parameters' => $parameters));
if (!empty($dump_sql)) {
$result = dump_sql($sql, $parameters);
} else {
$result = bind_pdo($sql, $parameters);
}
}
return $result;
}
}
if (!function_exists('send_password_email')) {
function send_password_email($email, $name, $password, $langcode = "tc")
{
global $site_info;
$email_subject = "";
$email_body = '<html>
<head>
<META name=GENERATOR content="MSHTML 8.00.6001.19394">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="font-family:arial,helvetica,sans-serif!important;color:#000;background:#fff">
新密碼: ' . $password . '<br><br>
成功登入後請立刻重設密碼。<br><br><br><br>
' . $site_info{"companyname_" . $langcode} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
</body>
</html>';
$sender_email = $site_info["enquiryemail"];
$company_name = $site_info["companyname_" . $langcode];
//for customer
$x_mail = new PHPMailer();
$x_mail->CharSet = "UTF-8";
$x_mail->Sender = $sender_email;
$x_mail->AddReplyTo($sender_email, $company_name);
$x_mail->From = $sender_email;
$x_mail->FromName = $company_name;
//send to user not send to client
if(PRODUCTION == 1){
$x_mail->AddAddress($email, $name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}else{
$x_mail->AddAddress($sender_email, $company_name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}
$x_mail->WordWrap = 50;
$x_mail->IsHTML(true);
$x_mail->Subject = $email_subject;
$x_mail->Body = $email_body;
if ($x_mail->Send()) {
return true;
} else {
return false;
}
}
}
if (!function_exists('get_product')) {
function get_product($product_id = NULL)
{
if (!empty($product_id)) {
$sql = "select * from `product` where id = ? and deleted = ? ";
$parameters = array($product_id, 0);
$product_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select * from `product` where deleted = ? ";
$parameters = array(0);
$product_info = bind_pdo($sql, $parameters, "selectall");
}
return $product_info;
}
}
if (!function_exists('get_product_images')) {
function get_product_images($product_id)
{
$sql = "select * from `pro_image` where productid = ? and deleted = ? and status = ? order by sort ASC";
$parameters = array($product_id, 0, 1);
$product_image_info = bind_pdo($sql, $parameters, "selectall");
return $product_image_info;
}
}
if (!function_exists('get_deposit')) {
function get_deposit($deposit_id = NULL)
{
if (!empty($deposit_id)) {
if (is_numeric($deposit_id)) {
$sql = "select *,
deposit.id as deposit_id,
deposit.status as deposit_status,
deposit.code as deposit_code,
ord.code as order_code,
deposit.duedate as deposit_duedate,
deposit.docdate as deposit_docdate,
deposit.amount as deposit_amount,
deposit.balance as deposit_balance,
deposit.lastupdate as deposit_lastupdate,
deposit.lastupby as deposit_lastupby
from `deposit` deposit
INNER JOIN `order` ord ON deposit.order_id = ord.id
where deposit.id = ? and deposit.deleted = ? ";
$parameters = array($deposit_id, 0);
$deposit_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select *,
deposit.id as deposit_id,
deposit.status as deposit_status,
deposit.code as deposit_code,
ord.code as order_code,
deposit.duedate as deposit_duedate,
deposit.docdate as deposit_docdate,
deposit.amount as deposit_amount,
deposit.balance as deposit_balance,
deposit.lastupdate as deposit_lastupdate,
deposit.lastupby as deposit_lastupby
from `deposit` deposit
INNER JOIN `order` ord ON deposit.order_id = ord.id
where deposit.code = ? and deposit.deleted = ? ";
$parameters = array($deposit_id, 0);
$deposit_info = bind_pdo($sql, $parameters, "selectone");
}
} else {
$sql = "select *,
deposit.id as deposit_id,
deposit.status as deposit_status,
deposit.code as deposit_code,
ord.code as order_code,
deposit.duedate as deposit_duedate,
deposit.docdate as deposit_docdate,
deposit.amount as deposit_amount,
deposit.balance as deposit_balance,
deposit.lastupdate as deposit_lastupdate,
deposit.lastupby as deposit_lastupby
from `deposit` deposit
INNER JOIN `order` ord ON deposit.order_id = ord.id
where deposit.deleted = ? order by deposit.createdate DESC";
$parameters = array(0);
$deposit_info = bind_pdo($sql, $parameters, "selectall");
}
return $deposit_info;
}
}
if (!function_exists('get_deposit_by_order_id')) {
function get_deposit_by_order_id($order_id = NULL)
{
if (!empty($order_id)) {
if (is_numeric($order_id)) {
$sql = "select *,
deposit.id as deposit_id,
deposit.status as deposit_status,
deposit.code as deposit_code,
ord.code as order_code,
deposit.duedate as deposit_duedate,
deposit.docdate as deposit_docdate,
deposit.amount as deposit_amount,
deposit.balance as deposit_balance,
deposit.lastupdate as deposit_lastupdate,
deposit.lastupby as deposit_lastupby
from `deposit` deposit
INNER JOIN `order` ord ON deposit.order_id = ord.id
where deposit.order_id = ? and deposit.deleted = ?";
$parameters = array($order_id, 0);
$deposit_info = bind_pdo($sql, $parameters, "selectone");
}
}
return $deposit_info;
}
}
if (!function_exists('get_invoice')) {
function get_invoice($invoice_id = NULL)
{
if (!empty($invoice_id)) {
if (is_numeric($invoice_id)) {
/*$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
ord.code as order_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.remark as invoice_remark,
invoice.lastupdate as invoice_lastupdate,
invoice.lastupby as invoice_lastupby,
invoice.balance as invoice_balance
from `invoice` invoice
INNER JOIN `order` ord ON invoice.order_id = ord.id
where invoice.id = ? and invoice.deleted = ? ";*/
$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.lastupdate as invoice_lastupdate,
invoice.lastupby as invoice_lastupby,
invoice.amount as invoice_amount,
invoice.balance as invoice_balance
from `invoice` invoice
where invoice.id = ? and invoice.deleted = ? ";
$parameters = array($invoice_id, 0);
$invoice_info = bind_pdo($sql, $parameters, "selectone");
} else {
$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.lastupdate as invoice_lastupdate,
invoice.lastupby as invoice_lastupby,
invoice.amount as invoice_amount,
invoice.balance as invoice_balance
from `invoice` invoice
where invoice.code = ? and invoice.deleted = ? ";
$parameters = array($invoice_id, 0);
$invoice_info = bind_pdo($sql, $parameters, "selectone");
}
} else {
$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.lastupdate as invoice_lastupdate,
invoice.lastupby as invoice_lastupby,
invoice.amount as invoice_amount,
invoice.balance as invoice_balance
from `invoice` invoice
where invoice.deleted = ? order by invoice.createdate DESC";
$parameters = array(0);
$invoice_info = bind_pdo($sql, $parameters, "selectall");
}
return $invoice_info;
}
}
if (!function_exists('get_invoice_detail')) {
function get_invoice_detail($invoice_id)
{
$invoice_detail_info = "";
if (!empty($invoice_id)) {
$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.amount as invoice_amount,
invoice_dtl.amount as invoice_dtl_amount
from `invoice` invoice
INNER JOIN `invoice_dtl` invoice_dtl ON invoice_dtl.invoice_id = invoice.id
where invoice.id = ? and invoice.deleted = ? order by month ASC";
/*$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.amount as invoice_amount,
invoice_dtl.amount as invoice_dtl_amount,
ord.code as order_code
from `invoice` invoice
INNER JOIN `invoice_dtl` invoice_dtl ON invoice_dtl.invoice_id = invoice.id
INNER JOIN `order` ord ON invoice.order_id = ord.id
where invoice.id = ? and invoice.deleted = ? ";*/
$parameters = array($invoice_id, 0);
$invoice_detail_info = bind_pdo($sql, $parameters, "selectall");
}
return $invoice_detail_info;
}
}
/*if (!function_exists('get_payment')) {
function get_payment($customer_id, $payable_type, $payable_id)
{
$result = array();
if (!empty($customer_id) && !empty($payable_type) && !empty($payable_id)) {
$sql = "select * from payment where customer_id = ? and payable_type = ? and payable_id = ? and deleted = ?";
$parameters = array($customer_id, $payable_type, $payable_id, 0);
$result = bind_pdo($sql, $parameters, "selectall");
}
return $result;
}
}*/
if (!function_exists('get_payment_by_id')) {
function get_payment_by_id($payment_id)
{
$sql = "select * from payment where id = ?";
$parameters = array($payment_id);
$result = bind_pdo($sql, $parameters, "selectone");
return $result;
}
}
if (!function_exists('get_payment_dtl')) {
function get_payment_dtl($payment_id)
{
$sql = "select * from payment_dtl where payment_id = ?";
$parameters = array($payment_id);
$result = bind_pdo($sql, $parameters, "selectall");
return $result;
}
}
if (!function_exists('get_invoice_dtl_type')) {
function get_invoice_dtl_type($invoice_id, $type = NULL)
{
if (!empty($invoice_id)) {
if (!empty($type)) {
$sql = "select * from invoice_dtl where invoice_id = ? and type = ? order by month ASC";
$parameters = array($invoice_id, $type);
$result = bind_pdo($sql, $parameters, "selectall");
} else {
$sql = "select * from invoice_dtl where invoice_id = ? order by month ASC";
$parameters = array($invoice_id);
$result = bind_pdo($sql, $parameters, "selectall");
}
return $result;
}
}
}
if (!function_exists('count_room_status')) {
function count_room_status($status, $location_id=1)
{
if (!empty($status)) {
$all_room_info = get_room(null, $location_id);
$sql = "select * from room where status = ? and deleted = ? and location_id = ?";
$parameters = array($status, 0, $location_id);
$room_info = bind_pdo($sql, $parameters, "selectall");
$result["count_room_num"] = count($room_info);
$result["count_room_percentage"] = round(count($room_info) / count($all_room_info) * 100, 2) . "%";
return $result;
}
}
}
if (!function_exists('get_master_room_price')) {
function get_master_room_price($master_room_id)
{
if (!empty($master_room_id)) {
$sql = "select * from master_room_price where master_room_id = ? order by lastupdate DESC";
$parameters = array($master_room_id);
$result = bind_pdo($sql, $parameters, "selectone");
if ($result["effectivedate_from"] <= date("Y-m-d") && $result["effectivedate_to"] >= date("Y-m-d")) {
} else {
$result["discounted_price"] = $result["retail_price"];
}
return $result;
}
}
}
if (!function_exists('call_curl')) {
function call_curl($url, $postData, $post)
{
if (!empty($post)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
}
return $result;
}
}
if (!function_exists('overdue_email')) {
function overdue_email($order_id, $type_code, $invoice_id)
{
global $site_info;
$langcode = "en";
//$order_info = get_order($order_id);
if ($type_code == "DEPOSIT") {
$deposit_info = get_deposit($invoice_id);
$invoice_code = $deposit_info["deposit_code"];
$invoice_info = "";
$customer_info = get_customer($deposit_info["customer_id"]);
} else {
$invoice_info = get_invoice($invoice_id);
$invoice_code = $invoice_info["invoice_code"];
$deposit_info = "";
$customer_info = get_customer($invoice_info["customer_id"]);
}
if(empty($customer_info["email"])){
//echo "<script>alert('找不到客戶的電郵地址。'); history.back();</script>";
return "找不到客戶的電郵地址。";
}
$email_subject = "欠款提示";
$email_body = '<html>
<head>
<META name=GENERATOR content="MSHTML 8.00.6001.19394">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="font-family:arial,helvetica,sans-serif!important;color:#000;background:#fff">
<table style="border-collapse: collapse; width:715px;">
<tr>
<td style="width: 18%">Customer Name :</td>
<td style="width: 37%;">' . $customer_info["customer_name"] . '</td>
<td style="width: 18%;">Invoice Code :</td>
<td style="width: 37%;">'.$invoice_code.'</td>
</tr>
<tr>
<td>Customer Code :</td>
<td>' . $customer_info["code"] . '</td>
<td>Reminder Date :</td>
<td>' . date("Y-m-d") . '</td>
</tr>
</table>
<br>
<div>
Final Reminder<br><br>
<p>According to our records, your account is overdue at least 7 days. Please arrange your payment within 7 days after received this reminder;otherwise service will be suspended without further notice. Service reactivation will be subject to payment of service administration fee.</p>
<p>To avoid service suspension or termination and the service administraction fee of HK$200, please pay before the due data shown below.</p>
<p>For enquiry regarding this remainder, please call our 24 hours Hotline at 2580 2088. If you have already settled your account, please ignore this reminder.</p>
<p>Thank you for choosing IN N OUT Storage</p>
</div>
<br><br>
Invoice Detail<br>
<table style="border-collapse: collapse; width:715px;">';
$email_body .= '<tr>
<td style="width: 20%;">Invoice Code </td>
<td style="width: 40%;">Invoice Due Date </td>
<td style="width: 40%;">Amount Due </td>
</tr>';
if ($type_code == "DEPOSIT") {
$email_body .= '<tr>
<td>' . $deposit_info["deposit_code"] . '</td>
<td>' . $deposit_info["deposit_duedate"] . '</td>
<td>' . numberformat($deposit_info["deposit_balance"]) . '</td>
</tr>';
} else {
$email_body .= '<tr>
<td>' . $invoice_info["invoice_code"] . '</td>
<td>' . $invoice_info["invoice_duedate"] . '</td>
<td>HKD$' . numberformat($invoice_info["invoice_balance"]) . '</td>
</tr>';
}
$email_body .= '</table>
<br><br><br>
' . $site_info{"companyname_en"} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
<br><br><br><br>
<table style="border-collapse: collapse; width:715px;">
<tr>
<td style="width: 18%">客戶姓名 :</td>
<td style="width: 37%;">' . $customer_info["customer_name"] . '</td>
<td style="width: 18%;">賬單編號 :</td>
<td style="width: 37%;">'.$invoice_code.'</td>
</tr>
<tr>
<td>客戶編號 :</td>
<td>' . $customer_info["code"] . '</td>
<td>繳費通知書日期 :</td>
<td>' . date("Y-m-d") . '</td>
</tr>
</table>
<br>
<div>
最後繳費通知書<br><br>
<p>根據本公司記錄,閣下之賬單已逾期多於7天,請於收到此信七天內立即繳交欠款,否則服務會被終而不作另行通知,並於恢復服務時須繳付重新啟動服務行政費。</p>
<p>為避免因未繳清費用而暫停或終止服務,及須繳付重透啟動服務行政費港幣$200元正,請於最後繳款日期前繳付有關費用。</p>
<p>如有任何關於通知書之查詢,請致電24小時熱線2580 2088。若閣下已繳付所有欠款,請毋須理會此通知書。</p>
<p>多謝選用出入易迷你倉服務</p>
</div>
<br><br>
賬單項目<br>
<table style="border-collapse: collapse; width:715px;">';
$email_body .= '<tr>
<td style="width: 20%;">賬單編號</td>
<td style="width: 40%;">賬單到期日</td>
<td style="width: 40%;">未繳交金額</td>
</tr>';
if ($type_code == "DEPOSIT") {
$email_body .= '<tr>
<td>' . $deposit_info["deposit_code"] . '</td>
<td>' . $deposit_info["deposit_duedate"] . '</td>
<td>' . numberformat($deposit_info["deposit_balance"]) . '</td>
</tr>';
} else {
$email_body .= '<tr>
<td>' . $invoice_info["invoice_code"] . '</td>
<td>' . $invoice_info["invoice_duedate"] . '</td>
<td>HKD$' . numberformat($invoice_info["invoice_balance"]) . '</td>
</tr>';
}
$email_body .= '</table>
<br><br><br><br>
' . $site_info{"companyname_tc"} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
</body>
</html>';
/*var_dump($email_body);
exit;*/
$sender_email = $site_info["enquiryemail"];
$company_name = $site_info["companyname_" . $langcode];
//for customer
$x_mail = new PHPMailer();
$x_mail->CharSet = "UTF-8";
$x_mail->Sender = $sender_email;
$x_mail->AddReplyTo($sender_email, $company_name);
$x_mail->From = $sender_email;
$x_mail->FromName = $company_name;
//send to user not send to client
if(PRODUCTION == 1){
$x_mail->AddAddress(rsa_crypt($customer_info["email"], 2), $customer_info["customer_name"]);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}else{
$x_mail->AddAddress($sender_email, $company_name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}
/*$x_mail->AddAddress('kelvinchan@oneslution.com.hk', $company_name);
$x_mail->AddBCC('kelvin.onesolution@gmail.com', $company_name);*/
$x_mail->WordWrap = 50;
$x_mail->IsHTML(true);
$x_mail->Subject = $email_subject;
$x_mail->Body = $email_body;
if ($x_mail->Send()) {
return 1;
} else {
//var_dump($x_mail->ErrorInfo);
return 0;
}
}
}
if (!function_exists('invoice_email')) {
function invoice_email($type_code = "INVOICE", $id)
{
if (!empty($type_code) && !empty($id)) {
//only for invoice (rent) ?
global $site_info;
$langcode = "tc";
$invoice_info = get_invoice($id);
$invoice_dtl_info = get_invoice_detail($id);
$order_info = get_order($invoice_info["order_id"]);
$customer_info = get_customer($invoice_info["customer_id"]);
if(empty($customer_info["email"])){
echo "<script>alert('找不到客戶的電郵地址。'); history.back();</script>";
exit;
}
$email_subject = "IN N OUT STORAGE INVOICE 迷你倉發票";
$email_body = '<html>
<head>
<META name=GENERATOR content="MSHTML 8.00.6001.19394">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
table td{
padding: 5px;
}
</style>
</head>
<body style="font-family:arial,helvetica,sans-serif !important;color:#000;background:#fff">
<table style="border-collapse: collapse; width:715px;">
<tr>
<td style="width: 20%">Customer Name:</td>
<td style="width: 30%;">' . $customer_info["customer_name"] . '</td>
<td style="width: 20%;">Invoice Code:</td>
<td style="width: 30%;">' . $invoice_info["invoice_code"] . '</td>
</tr>
<tr>
<td>Customer Code:</td>
<td>' . $customer_info["code"] . '</td>
<td>Reminder Date:</td>
<td>' . date("Y-m-d") . '</td>
</tr>
</table>
<br><br>
<table style="border-collapse: collapse; width:715px;">';
$email_body .= '<tr>
<td colspan="4" style="text-align: left;">Invoice Detail</td>
</tr>';
$email_body .= '<tr>
<td style="width: 20%;">Type</td>
<td style="width: 30%;">Rent Date</td>
<td style="width: 20%;">Due Date</td>
<td style="width: 30%;">Amount</td>
</tr>';
foreach ($invoice_dtl_info as $dtl) {
if ($dtl["type"] == "RENT") {
$type_info = get_master_type_code("INVOICE_TYPE", "RENT");
$start_date = new DateTime($order_info["warehousing_date"]);
$start_date->modify('+' . ($dtl["month"] - 1) . ' month');
$end_date = new DateTime($order_info["warehousing_date"]);
if ($dtl["month"] == $order_info["rent_month"]) {
$end_date->modify('+' . $dtl["month"] . ' month - 1 day');
} else {
$end_date->modify('+' . $dtl["month"] . ' month');
}
$rent_date = $start_date->format('Y-m-d') . " - " . $end_date->format('Y-m-d');
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else if ($dtl["type"] == "ORDER_PRODUCT") {
$type_info = get_master_type_code("INVOICE_TYPE", "ORDER_PRODUCT");
$rent_date = "-";
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else if ($dtl["type"] == "PENALTY") {
$type_info = get_master_type_code("INVOICE_TYPE", "PENALTY");
$rent_date = "-";
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else {
}
$email_body .= '<tr>
<td>' . $type_info["name_en"] . '</td>
<td>' . $rent_date . '</td>
<td>' . $duedate . '</td>
<td>HKD$' . numberformat($amount) . '</td>
</tr>';
}
if ($invoice_info["balance"] != 0 && $invoice_info["balance"] < $invoice_info["amount"]) {
$email_body .= '<tr>
<td colspan="3">Paid:</td>
<td>HKD$' . numberformat($invoice_info["amount"] - $invoice_info["balance"]) . '</td>
</tr>';
}
$email_body .= '<tr>
<td colspan="3">Total Amount:</td>
<td>HKD$' . numberformat($invoice_info["balance"]) . '</td>
</tr>';
$email_body .= '</table><br><br>';
$email_body .= 'If you want to use PayPal to pay this invoice, please click <a href="' . $site_info["url"] . 'paypal/ReviewOrder.php?type=INVOICE&id=' . (int)$id . '">here</a> to process.';
$email_body .= '
<br><br>
' . $site_info{"companyname_en"} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
<br><br><br><br>
<table style="border-collapse: collapse; width:715px;">
<tr>
<td style="width: 20%">客戶姓名:</td>
<td style="width: 30%;">' . $customer_info["customer_name"] . '</td>
<td style="width: 20%;">發票編號:</td>
<td style="width: 30%;">' . $invoice_info["invoice_code"] . '</td>
</tr>
<tr>
<td>客戶編號:</td>
<td>' . $customer_info["code"] . '</td>
<td>通知書日期:</td>
<td>' . date("Y-m-d") . '</td>
</tr>
</table>
<br><br>
<table style="border-collapse: collapse; width:715px;">';
$email_body .= '<tr>
<td colspan="4" style="text-align: left;">發票項目</td>
</tr>';
$email_body .= '<tr>
<td style="width: 20%;">類別</td>
<td style="width: 30%;">租用日期</td>
<td style="width: 20%;">繳費日期</td>
<td style="width: 30%;">金額</td>
</tr>';
foreach ($invoice_dtl_info as $dtl) {
if ($dtl["type"] == "RENT") {
$type_info = get_master_type_code("INVOICE_TYPE", "RENT");
$start_date = new DateTime($order_info["warehousing_date"]);
$start_date->modify('+' . ($dtl["month"] - 1) . ' month');
$end_date = new DateTime($order_info["warehousing_date"]);
if ($dtl["month"] == $order_info["rent_month"]) {
$end_date->modify('+' . $dtl["month"] . ' month - 1 day');
} else {
$end_date->modify('+' . $dtl["month"] . ' month');
}
$rent_date = $start_date->format('Y-m-d') . " - " . $end_date->format('Y-m-d');
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else if ($dtl["type"] == "ORDER_PRODUCT") {
$type_info = get_master_type_code("INVOICE_TYPE", "ORDER_PRODUCT");
$rent_date = "-";
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else if ($dtl["type"] == "PENALTY") {
$type_info = get_master_type_code("INVOICE_TYPE", "PENALTY");
$rent_date = "-";
$duedate = $invoice_info["duedate"];
$amount = $dtl["amount"];
} else {
}
$email_body .= '<tr>
<td>' . $type_info["name_tc"] . '</td>
<td>' . $rent_date . '</td>
<td>' . $duedate . '</td>
<td>HKD$' . numberformat($amount) . '</td>
</tr>';
}
if ($invoice_info["balance"] != 0 && $invoice_info["balance"] < $invoice_info["amount"]) {
$email_body .= '<tr>
<td colspan="3">已支付金額:</td>
<td>HKD$' . numberformat($invoice_info["amount"] - $invoice_info["balance"]) . '</td>
</tr>';
}
$email_body .= '<tr>
<td colspan="3">總金額:</td>
<td>HKD$' . numberformat($invoice_info["balance"]) . '</td>
</tr>';
$email_body .= '</table><br><br>';
$email_body .= '如要使用PayPal網上付款,你可以按 <a href="' . $site_info["url"] . 'paypal/ReviewOrder.php?type=INVOICE&id=' . (int)$id . '"> 此 </a> 進入PayPal付款程序。';
$email_body .= '
<br><br>
' . $site_info{"companyname_tc"} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
</body>
</html>';
/*var_dump($email_body);
exit;*/
$sender_email = $site_info["enquiryemail"];
$company_name = $site_info["companyname_" . $langcode];
//for customer
$x_mail = new PHPMailer();
$x_mail->CharSet = "UTF-8";
$x_mail->Sender = $sender_email;
$x_mail->AddReplyTo($sender_email, $company_name);
$x_mail->From = $sender_email;
$x_mail->FromName = $company_name;
//send to user not send to client
if(PRODUCTION == 1){
$x_mail->AddAddress(rsa_crypt($customer_info["email"], 2), $customer_info["customer_name"]);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}else{
$x_mail->AddAddress($sender_email, $company_name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}
$x_mail->WordWrap = 50;
$x_mail->IsHTML(true);
$x_mail->Subject = $email_subject;
$x_mail->Body = $email_body;
if ($x_mail->Send()) {
//return 1;
echo "<script>alert('電郵已成功送出。'); history.back();</script>";
} else {
//return 0;
echo "<script>alert('電郵未能成功送出。'); history.back();</script>";
}
exit;
} else {
//error
}
}
}
if (!function_exists('contract_alert_email')) {
function contract_alert_email($order_id)
{
if(!empty($order_id)){
global $site_info;
$order_info = get_order($order_id);
$email_subject = "IN N OUT STORAGE CONTRACT ENDING REMARK 迷你倉合約完結提示";
$email_body = '<html>
<head>
<META name=GENERATOR content="MSHTML 8.00.6001.19394">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
table td{
padding: 5px;
}
</style>
</head>
<body style="font-family:arial,helvetica,sans-serif !important;color:#000;background:#fff">
<p>你的合約快將完結。</p>
<br>
<table style="border-collapse: collapse; width:715px;">
<tr>
<td style="width: 5%">合約編號:</td>
<td style="width: 30%;">' . $order_info["code"] . '</td>
</tr>
<tr>
<td style="width: 5%">租約期:</td>
<td style="width: 30%;">' . $order_info["startdate"] . ' 至 '.$order_info["enddate"].'</td>
</tr>
<tr>
<td style="width: 5%;">客戶編號:</td>
<td style="width: 30%;">' . $order_info["customer_code"] . '</td>
</tr>
<tr>
<td style="width: 5%;">姓氏:</td>
<td style="width: 30%;">' .rsa_crypt($order_info["customer_lastname"], 2) . '</td>
</tr>
<tr>
<td style="width: 5%;">名字:</td>
<td style="width: 30%;">' .rsa_crypt($order_info["customer_firstname"], 2) . '</td>
</tr>
</table>';
$email_body .= '<br><br>' . $site_info{"companyname_tc"} . '<br> <a href="' . $site_info{"url"} . '" target="_blank">' . $site_info{"url"} . '</a>
</body>
</html>';
/*echo ($email_body);
exit;*/
$sender_email = $site_info["enquiryemail"];
$company_name = $site_info["companyname_tc"];
$customer_name = get_customer_name(rsa_crypt($order_info["customer_firstname"], 2), rsa_crypt($order_info["customer_firstname"], 2));
//for customer
$x_mail = new PHPMailer();
$x_mail->CharSet = "UTF-8";
$x_mail->Sender = $sender_email;
$x_mail->AddReplyTo($sender_email, $company_name);
$x_mail->From = $sender_email;
$x_mail->FromName = $company_name;
//send to user not send to client
if(PRODUCTION == 1){
$x_mail->AddAddress(rsa_crypt($order_info["customer_email"], 2), $customer_name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}else{
$x_mail->AddAddress($sender_email, $company_name);
$x_mail->AddBCC("skycheng@onesolution.com.hk", $company_name);
}
$x_mail->WordWrap = 50;
$x_mail->IsHTML(true);
$x_mail->Subject = $email_subject;
$x_mail->Body = $email_body;
if ($x_mail->Send()) {
//return 1;
echo "<script>alert('電郵已成功送出。'); history.back();</script>";
} else {
//return 0;
echo "<script>alert('電郵未能成功送出。'); history.back();</script>";
}
exit;
}
}
}
if (!function_exists('get_master_room_discount')) {
function get_master_room_discount($discount_id)
{
$sql = "select * from master_room_discount where id = ?";
$parameters = array($discount_id);
$result = bind_pdo($sql, $parameters, "selectone");
return $result;
}
}
if (!function_exists('get_master_room_discount_by_mater_room_id')) {
function get_master_room_discount_by_mater_room_id($master_room_id, $date = NULL)
{
if (empty($date)) {
$sql = "select * from master_room_discount discount INNER JOIN master_type_code mtcode on discount.payment_term = mtcode.code where discount.master_room_id = ? order by CAST(mtcode.config_value AS DECIMAL(10,2)) DESC";
$parameters = array($master_room_id);
$result = bind_pdo($sql, $parameters, "selectall");
} else {
$sql = "select * from master_room_discount discount INNER JOIN master_type_code mtcode on discount.payment_term = mtcode.code where discount.master_room_id = ? and discount.status = ? and discount.deleted = ? and ? between discount.effectivedate_from and discount.effectivedate_to order by CAST(mtcode.config_value AS DECIMAL(10,2)) DESC";
$parameters = array($master_room_id, 1, 0, $date);
$result = bind_pdo($sql, $parameters, "selectall");
}
return $result;
}
}
if (!function_exists('numberformat')) {
function numberformat($data, $decial_place = 2, $thousand = ",")
{
return number_format($data, $decial_place, ".", $thousand);
}
}
if (!function_exists('get_order_invoice')) {
function get_order_invoice($order_id)
{
if (!empty($order_id)) {
$sql = "select *,
invoice.id as invoice_id,
invoice.status as invoice_status,
invoice.code as invoice_code,
invoice.docdate as invoice_docdate,
invoice.duedate as invoice_duedate,
invoice.lastupdate as invoice_lastupdate,
invoice.lastupby as invoice_lastupby,
invoice.amount as invoice_amount,
invoice.balance as invoice_balance
from `invoice` invoice
where invoice.deleted = ? and order_id = ? order by invoice.code DESC";
$parameters = array(0, $order_id);
$invoice_info = bind_pdo($sql, $parameters, "selectall");
return $invoice_info;
}
}
}
if (!function_exists('get_order_deposit')) {
function get_order_deposit($order_id)
{
if (!empty($order_id)) {
$sql = "select *,
deposit.id as deposit_id,
deposit.status as deposit_status,
deposit.code as deposit_code,
ord.code as order_code,
deposit.docdate as deposit_docdate,
deposit.duedate as deposit_duedate,
deposit.amount as deposit_amount,
deposit.balance as deposit_balance,
deposit.lastupdate as deposit_lastupdate,
deposit.lastupby as deposit_lastupby
from `deposit` deposit
INNER JOIN `order` ord ON deposit.order_id = ord.id
where deposit.deleted = ? and order_id = ? order by deposit.code DESC";
$parameters = array(0, $order_id);
$deposit_info = bind_pdo($sql, $parameters, "selectone");
return $deposit_info;
}
}
}
if (!function_exists('get_index_url_parameter')) {
function get_index_url_parameter()
{
$params = $_SERVER['QUERY_STRING'];
$get_index_url_parameter = $params;
return $get_index_url_parameter;
}
}
if (!function_exists('get_langcode')) {
function get_langcode()
{
if (strpos($_SERVER['REQUEST_URI'], "/en/") !== FALSE || strpos($_SERVER['REQUEST_URI'], "/tc/") !== FALSE){
$tokens = explode('/', $_SERVER['REQUEST_URI']);
$langcode = $tokens[sizeof($tokens) - 2];
if($langcode != "en" && $langcode != "tc"){
$langcode = "en";
}
return $langcode;
}else{
if(isset($_SESSION["langcode"]))
return $_SESSION["langcode"];
else
return "tc";
}
}
}
$langcode = get_langcode();
if (!empty($langcode)) {
$_SESSION["langcode"] = $langcode;
} else {
$_SESSION["langcode"] = "en";
$langcode = "en";
}
if (!function_exists('change_langcode_url')) {
function change_langcode_url()
{
$tokens = explode('/', $_SERVER['REQUEST_URI']);
$langcode_url = $tokens[sizeof($tokens) - 1];
return htmlspecialchars($langcode_url, ENT_QUOTES);
}
}
if (!function_exists('get_faq')) {
function get_faq($id = NULL)
{
if (empty($id)) {
$sql = "select * from faq where deleted = ? order by sort ASC";
$parameters = array(0);
$faq_info = bind_pdo($sql, $parameters, "selectall");
} else {
$sql = "select * from faq where deleted = ? and faq_id = ? order by sort ASC";
$parameters = array(0, $id);
$faq_info = bind_pdo($sql, $parameters, "selectone");
}
return $faq_info;
}
}
/*if (!function_exists('get_master_room_mapping')) {
function get_master_room_mapping($master_room_id = NULL)
{
$master_room_mapping_info[2] = array(
"display_size" => "3' x 3' x 8'",
"map_to_master_room_id" => array(2, 3),
);
$master_room_mapping_info[4] = array(
"display_size" => "3' x 5' x 8'",
"map_to_master_room_id" => array(4, 5),
);
$master_room_mapping_info[1] = array(
"display_size" => "3' x 4' x 8'",
"map_to_master_room_id" => array(1, 7),
);
$master_room_mapping_info[9] = array(
"display_size" => "4' x 4.5' x 8'",
"map_to_master_room_id" => array(9),
);
$master_room_mapping_info[11] = array(
"display_size" => "4' x 6' x 8'",
"map_to_master_room_id" => array(11, 12),
);
if (empty($master_room_id)) {
return $master_room_mapping_info;
} else {
if ($master_room_id == 2 || $master_room_id == 4 || $master_room_id == 1 || $master_room_id == 9 || $master_room_id == 11)
return $master_room_mapping_info[$master_room_id];
}
}
}*/
if (!function_exists('get_master_room_by_display_size')) {
function get_master_room_by_display_size($display_size = NULL)
{
if(empty($display_size)){
$sql = "select * from master_room where is_onlinesales = ? and deleted = ? group by display_size order by location_id ASC, id ASC";
$parameters = array(1, 0);
return bind_pdo($sql, $parameters, "selectall");
}else{
$sql = "select * from master_room where is_onlinesales = ? and deleted = ? and display_size = ? order by location_id ASC, id ASC";
$parameters = array(1, 0, $display_size);
return bind_pdo($sql, $parameters, "selectall");
}
}
}
if (!function_exists('get_master_room_info_web')) {
function get_master_room_info_web()
{
$master_room_info = array();
//$all_master_room_info = get_master_room();
$i = 0;
$available_master_room = array();
$display_size_info = get_master_room_by_display_size();
foreach ($display_size_info as $key => $master_room) {
$find_available_room = false;
//need to find same display size master room
$sql = "select master_room.* from master_room
INNER JOIN master_room_price ON master_room_price.master_room_id = master_room.id
INNER JOIN location ON location.id = master_room.location_id
where display_size = ? and master_room.status = ? and master_room.deleted = ? and location.deleted = ? order by master_room.location_id ASC, retail_price ASC";
$parameters = array($master_room["display_size"], 1, 0, 0);
$result = bind_pdo($sql, $parameters, "selectall");
if (!empty($result)) {
$available_master_room[] = $result[0];
//foreach ($result as $row) {
//$available_master_room[] = $row;
/*if (!$find_available_room) {
//check if this master room available
$sql = "select * from room where master_room_id = ? and (status = ? or (status = ? and session_id = ? and online_hold_time >= ?)) and deleted = ? order by location_id ASC, FIELD(status, 'OPEN_FOR_INTERNAL', 'OPEN')";
$parameters = array($row["id"], "OPEN", "OPEN_FOR_INTERNAL", session_id(), date("Y-m-d H:i:s"), 0);
$available_room_info = bind_pdo($sql, $parameters, "selectone");
if(!empty($available_room_info)){
$find_available_room = true;
$available_master_room[] = $row;
break;
}
}*/
//}
}
}
foreach ($available_master_room as $master_room) {
//$master_room_info[$i]["size"] = $master_room["length"] . "' x " . $master_room["width"] . "' x " . $master_room["height"] . "'";
$room_info = get_master_room_price($master_room["id"]);
$master_room_info[$i]["size"] = $master_room["display_size"];
$master_room_info[$i]["LWH"] = $master_room["length"] . $master_room["width"] . $master_room["height"] . "'";
$master_room_info[$i]["master_room_id"] = $master_room["id"];
$master_room_info[$i]["retail_price"] = $room_info["retail_price"];
$today = date("Y-m-d");
$master_room_info[$i]["lowest_price"] = $room_info["retail_price"];
if(!empty($room_info["effectivedate_from"]) && !empty($room_info["effectivedate_to"]) && $room_info["effectivedate_from"] != "0000-00-00" && $room_info["effectivedate_to"] != "0000-00-00"){
if ($today >= $room_info["effectivedate_from"] && $today <= $room_info["effectivedate_to"]) {
$master_room_info[$i]["lowest_price"] = $room_info["discounted_price"];
}
}
$master_room_discount_info = get_master_room_discount_by_mater_room_id($master_room["id"], date("Y-m-d"));
if (!empty($master_room_discount_info)) {
$pass_prepaid_discount = false;
foreach ($master_room_discount_info as $discount_info) {
if($discount_info["show_frontend"] == 1){
if ($discount_info["payment_term"] != "SPECIFIC_SIZE") {
if (!$pass_prepaid_discount) {
$master_room_info[$i]["lowest_price"] = $master_room_info[$i]["lowest_price"] * (100 - $discount_info["discount"]) / 100;
$pass_prepaid_discount = true;
}
if ($discount_info["is_final_discount"] == 1) {
break;
}
} else {
$master_room_info[$i]["lowest_price"] = $master_room_info[$i]["lowest_price"] * (100 - $discount_info["discount"]) / 100;
}
}
}
}
$i++;
}
return $master_room_info;
}
}
if (!function_exists('get_master_room_by_display_size2')) {
function get_master_room_by_display_size2($display_size = NULL, $location_id = NULL){
$sql2 = '';
if(!empty($location_id)){
$sql2 = ' and location_id IN '.$location_id;
}
if(empty($display_size)){
//$sql = "select * from master_room where is_onlinesales = ? and deleted = ? $sql2 group by display_size order by location_id ASC, id ASC";
$sql = "select *, (length*width*height) as lwh from master_room where is_onlinesales = ? and deleted = ? $sql2 group by display_size order by lwh ASC";
$parameters = array(1, 0);
return bind_pdo($sql, $parameters, "selectall");
}else{
//$sql = "select * from master_room where is_onlinesales = ? and deleted = ? and display_size = ? $sql2 order by location_id ASC, id ASC";
$sql = "select *, (length*width*height) as lwh from master_room where is_onlinesales = ? and deleted = ? and display_size = ? $sql2 order by lwh ASC";
$parameters = array(1, 0, $display_size);
return bind_pdo($sql, $parameters, "selectall");
}
}
}
if (!function_exists('get_master_room_info_web2')) {
function get_master_room_info_web2($location_id = NULL)
{
$master_room_info = array();
//$all_master_room_info = get_master_room();
$i = 0;
$available_master_room = array();
$display_size_info = get_master_room_by_display_size2(null, $location_id);
foreach ($display_size_info as $key => $master_room) {
$find_available_room = false;
if($location_id == '(1,2,3,4)'){
$order_by = 'DESC';
}else{
$order_by = 'ASC';
}
//need to find same display size master room
$sql = "select master_room.* from master_room
INNER JOIN master_room_price ON master_room_price.master_room_id = master_room.id
INNER JOIN location ON location.id = master_room.location_id
where display_size = ? and master_room.status = ? and master_room.deleted = ? and location.deleted = ? and location.id IN $location_id order by retail_price $order_by";
$parameters = array($master_room["display_size"], 1, 0, 0);
$result = bind_pdo($sql, $parameters, "selectall");
if (!empty($result)) {
$available_master_room[] = $result[0];
//foreach ($result as $row) {
//$available_master_room[] = $row;
/*if (!$find_available_room) {
//check if this master room available
$sql = "select * from room where master_room_id = ? and (status = ? or (status = ? and session_id = ? and online_hold_time >= ?)) and deleted = ? order by location_id ASC, FIELD(status, 'OPEN_FOR_INTERNAL', 'OPEN')";
$parameters = array($row["id"], "OPEN", "OPEN_FOR_INTERNAL", session_id(), date("Y-m-d H:i:s"), 0);
$available_room_info = bind_pdo($sql, $parameters, "selectone");
if(!empty($available_room_info)){
$find_available_room = true;
$available_master_room[] = $row;
break;
}
}*/
//}
}
}
foreach ($available_master_room as $master_room) {
//$master_room_info[$i]["size"] = $master_room["length"] . "' x " . $master_room["width"] . "' x " . $master_room["height"] . "'";
$room_info = get_master_room_price($master_room["id"]);
$display_size = $master_room["display_size"];
if($master_room["height"] > 4){
$explode_display_size = explode('x', $master_room["display_size"]);
if(!empty($explode_display_size)){
$display_size = trim($explode_display_size[0]) .' x '.trim($explode_display_size[1]);
}
}
$master_room_info[$i]["size"] = $display_size;
$master_room_info[$i]["LWH"] = $master_room["length"] . $master_room["width"] . $master_room["height"] . "'";
$master_room_info[$i]["master_room_id"] = $master_room["id"];
$master_room_info[$i]["retail_price"] = $room_info["retail_price"];
$today = date("Y-m-d");
$master_room_info[$i]["lowest_price"] = $room_info["retail_price"];
if(!empty($room_info["effectivedate_from"]) && !empty($room_info["effectivedate_to"]) && $room_info["effectivedate_from"] != "0000-00-00" && $room_info["effectivedate_to"] != "0000-00-00"){
if ($today >= $room_info["effectivedate_from"] && $today <= $room_info["effectivedate_to"]) {
$master_room_info[$i]["lowest_price"] = $room_info["discounted_price"];
}
}
$master_room_discount_info = get_master_room_discount_by_mater_room_id($master_room["id"], date("Y-m-d"));
if (!empty($master_room_discount_info)) {
$pass_prepaid_discount = false;
foreach ($master_room_discount_info as $discount_info) {
if($discount_info["show_frontend"] == 1){
if ($discount_info["payment_term"] != "SPECIFIC_SIZE") {
if (!$pass_prepaid_discount) {
$master_room_info[$i]["lowest_price"] = $master_room_info[$i]["lowest_price"] * (100 - $discount_info["discount"]) / 100;
$pass_prepaid_discount = true;
}
if ($discount_info["is_final_discount"] == 1) {
break;
}
} else {
$master_room_info[$i]["lowest_price"] = $master_room_info[$i]["lowest_price"] * (100 - $discount_info["discount"]) / 100;
}
}
}
}
$i++;
}
return $master_room_info;
}
}
if (!function_exists('check_and_update_reserved_room')) {
function check_and_update_reserved_room()
{
$sql = "select * from room where deleted = ? and status = ?";
$parameters = array(0, "RESERVED");
$reserved_room_info = bind_pdo($sql, $parameters, "selectall");
foreach ($reserved_room_info as $reserved_room) {
if (date("Y-m-d H:i:s") > $reserved_room["reservedate_to"]) {
//auto change this room status to open
$sql = "update room set status = ?, lastupby = ?, lastupdate = ? where id = ?";
$parameters = array("OPEN",$_SESSION['cmsloginid'], date('Y-m-d H:i:s'), $reserved_room["id"]);
$result = bind_pdo($sql, $parameters);
activity_log('basic_info.php', 'check_and_update_reserved_room', $input = array('sql' => $sql, 'parameters' => $parameters), $data_before = array(), $data_after = array(), $step = 1);
}
}
}
}
//for front end
if (!function_exists('check_available_room')) {
function check_available_room($master_room_id)
{
$reserve_room = false;
unset($_SESSION["available_master_room_id"]);
if (!empty($master_room_id) && (int)($master_room_id) > 0) {
check_and_update_reserved_room();
//$master_room_id = (int)$_POST["master_room_id"];
//check which floor user has valid contract, not do
$this_master_room_info = get_master_room($master_room_id);
/*$available_master_master_room_info = get_master_room_by_display_size($this_master_room_info["display_size"]);*/
//need to find same display size master room
$sql = "select master_room.* from master_room
INNER JOIN master_room_price ON master_room_price.master_room_id = master_room.id
where display_size = ? and master_room.status = ? and master_room.deleted = ? order by master_room.location_id ASC, retail_price ASC";
$parameters = array($this_master_room_info["display_size"], 1, 0);
$available_master_master_room_info = bind_pdo($sql, $parameters, "selectall");
if (empty($available_master_master_room_info)) {
$available_master_master_room_id = array($master_room_id);
}else{
foreach($available_master_master_room_info as $available_master_room_info){
$available_master_master_room_id[] = $available_master_room_info["id"];
}
}
foreach ($available_master_master_room_id as $this_master_room_id) {
$master_room_info = get_master_room($this_master_room_id);
$remain_room = $master_room_info["remain_room"];
$sql = "select * from room where master_room_id = ? and (status = ? or (status = ? and session_id = ? and online_hold_time >= ?)) and deleted = ? order by location_id ASC, FIELD(status, 'OPEN_FOR_INTERNAL', 'OPEN')";
$parameters = array($this_master_room_id, "OPEN", "OPEN_FOR_INTERNAL", session_id(), date("Y-m-d H:i:s"), 0);
$available_room_info = bind_pdo($sql, $parameters, "selectall");
if (!empty($available_room_info)) {
if (count($available_room_info) > $remain_room && count($available_room_info) >= 1) {
//allow to reserve this room size
$reserve_room = true;
$_SESSION["available_master_room_id"] = $available_room_info[0]["id"];
break;
} else {
//not allow to reserve
}
}
}
if (!$reserve_room) {
//echo "Not available to rent this kind of size.";
}
} else {
//echo "Not available to rent this kind of size.";
}
return $reserve_room;
}
}
if (!function_exists('check_new_customer_new_order_by_email_phone')) {
function check_new_customer_new_order_by_email_phone($email, $phone)
{
$order_exist = false;
$new_customer = true;
$customer_id = "";
$all_customer_info = get_customer_for_rent();
foreach ($all_customer_info as $customer) {
if($customer["deleted"] == 1)
continue;
if (rsa_crypt($customer["email"], 2) == $email && rsa_crypt($customer["tel"], 2) == $phone ) {
$new_customer = false;
$customer_id = $customer["id"];
}
}
if (!empty($customer_id) && !$new_customer) {
$sql = "select id from `order` where customer_id = ? and deleted = ? and status != ?";
$parameters = array($customer_id, 0, "VOID");
$order_info = bind_pdo($sql, $parameters, "selectone");
if (!empty($order_info)) {
$order_exist = true;
}
}
return array("customer_id" => $customer_id, "new_customer" => $new_customer, "order_exist" => $order_exist);
}
}
if (!function_exists('update_master_room_total_number')) {
function update_master_room_total_number($enable = 0)
{
if($enable){
$sql = "select COUNT(*) as master_room_num, master_room_id from room where deleted = ? group by master_room_id";
$parameters = array(0);
$room_info = bind_pdo($sql, $parameters, "selectall");
$sql = "update master_room set total_room = ? ";
$parameters = array(0);
bind_pdo($sql, $parameters);
foreach($room_info as $room){
$sql = "update master_room set total_room = ? where id = ?";
$parameters = array($room["master_room_num"], $room["master_room_id"]);
bind_pdo($sql, $parameters);
}
}
}
}
if (!function_exists('update_room_online_hold')) {
function update_room_online_hold()
{
$sql = "update room set status = ?, session_id = ?, online_hold_time = ?, lastupby = ?, lastupdate = ? where status = ? and (? > online_hold_time or online_hold_time = '' or online_hold_time IS NULL)";
$parameters = array("OPEN" ,"", "", $_SESSION['cmsloginid'], date("Y-m-d H:i:s"), "OPEN_FOR_INTERNAL", date("Y-m-d H:i:s"));
bind_pdo($sql, $parameters);
activity_log('basic_info.php', 'update_room_online_hold', $input = array('sql' => $sql, 'parameters' => $parameters), $data_before = array(), $data_after = array(), $step = 1);
}
}
update_room_online_hold();
if(!function_exists('sorting_by_price')){
function sorting_by_price($a, $b)
{
if ($a["lowest_price"] == $b["lowest_price"]) {
return 0;
}
return ($a["lowest_price"] < $b["lowest_price"]) ? -1 : 1;
}
}
if(!function_exists('sorting_by_LWH')){
function sorting_by_LWH($a, $b)
{
if ($a["LWH"] == $b["LWH"]) {
return 0;
}
return ($a["LWH"] < $b["LWH"]) ? -1 : 1;
}
}
if (!function_exists('_log')) {
function _log($page, $log_id, $log_sql, $log_para)
{
$data = array(
"page" => $page,
"log_id" => $log_id,
"log_sql" => $log_sql,
"log_para" => json_encode($log_para),
"log_query" => dump_sql($log_sql, $log_para),
"createdate" => date("Y-m-d H:i:s"),
);
insert_record("log", $data);
}
}
if (!function_exists('debug_log')) {
function debug_log($code, $data)
{
$date = new DateTime();
$date->modify("-1 month");
$sql = "delete from debug_log where createdate <= ?";
$parameters = array($date->format("Y-m-d"));
bind_pdo($sql, $parameters);
$sql = "insert into debug_log (code, log_data, createdate) value (?,?,?)";
$parameters = array($code, json_encode($data), date("Y-m-d H:i:s"));
bind_pdo($sql, $parameters);
}
}
if (!function_exists('dump_sql')) {
function dump_sql($sql, $parameters)
{
$keys = array();
# build a regular expression for each parameter
foreach ($parameters as $key => $value) {
if (is_string($key)) {
$keys[] = '/:' . $key . '/';
} else {
$keys[] = '/[?]/';
}
}
foreach ($parameters as $key2 => $value) {
$parameters[$key2] = "'" . $value . "'";
}
$sql = preg_replace($keys, $parameters, $sql, 1, $count);
#trigger_error('replaced '.$count.' keys');
return $sql;
}
}
if (!function_exists('check_if_f12_has_this_size')) {
function check_if_f12_has_this_size($master_room_id)
{
$master_room_info = get_master_room($master_room_id);
$sql = "select * from master_room where ( (length = ? and width = ?) or (length = ? and width = ?)) and height = ? and type = ? and location_id = ?";
$parameters = array($master_room_info["length"], $master_room_info["width"],$master_room_info["width"], $master_room_info["length"], $master_room_info["height"], $master_room_info["type"], 1);
$result = bind_pdo($sql, $parameters, "selectone");
if(!empty($result)){
return $result;
}else{
return false;
}
}
}
if (!function_exists('last_day_of_month')) {
function last_day_of_month($year, $month)
{
}
}
if (!function_exists('get_master_room_discount')) {
function get_master_room_discount($discount_id)
{
$sql = "select * from master_room_discount where id = ?";
$parameters = array($discount_id);
$result = bind_pdo($sql, $parameters, "selectone");
return $result;
}
}
if (!function_exists('is_admin')) {
function is_admin()
{
if($_SESSION["cmsrole"] == "super_admin" || $_SESSION["cmsrole"] == "admin"){
return true;
}else{
return false;
}
}
}
if (!function_exists('same_size_master_room')) {
function same_size_master_room($master_room_id)
{
$sql = "select id from master_room where display_size = (select display_size from master_room where id = ?) and deleted = ?";
$parameters = array($master_room_id, 0);
$result = bind_pdo($sql, $parameters, "selectall");
/*$temp = array();
if(!empty($result)){
foreach ($result as $row){
$temp[] = $row["id"];
}
}
return $temp;*/
return $result;
}
}
if (!function_exists('get_rent_date_from_to')) {
function get_rent_date_from_to($start_date, $month_num)
{
$date = new DateTime($start_date);
$year = $date->format("Y");
$month = $date->format("m");
$day = $date->format("d");
$month_num-=1;
if ($month + ($month_num) > 12 && $month + ($month_num) <= 24) {
$this_year = $year + 1;
$this_month = $month + ($month_num) - 12;
} else if ($month + ($month_num) > 24 && $month + ($month_num) <= 36) {
$this_year = $year + 2;
$this_month = $month + ($month_num) - 24;
} else if ($month + ($month_num) > 36) {
$this_year = $year + 3;
$this_month = $month + ($month_num) - 36;
} else {
$this_year = $year;
$this_month = $month + $month_num;
}
/*if ($date->format("m-d") >= "01-29" && $date->format("m-d") <= "01-31" && $month_num == 1) {
//special case, first month
$total_days_of_month = cal_days_in_month(CAL_GREGORIAN, 2, $year);
$start = $year . "-" . $date->format("m-d");
$end = $year . "-" . "02-" . $total_days_of_month;
$mode = 1;
} else if ($date->format("m-d") >= "01-29" && $date->format("m-d") <= "01-31" && $month_num > 1 && $month_num < $rent_month) {
//special case, middle month, start from March
$total_days_of_month = cal_days_in_month(CAL_GREGORIAN, $this_month, $this_year);
$start = $this_year . "-" . str_pad($this_month, 1, "0", STR_PAD_LEFT) . "-01";
$end = $this_year . "-" . str_pad($this_month, 1, "0", STR_PAD_LEFT) . "-" . $total_days_of_month;
$mode = 2;
} else if ($date->format("m-d") >= "01-29" && $date->format("m-d") <= "01-31" && $month_num == $rent_month) {
//special case, last month
$start = $this_year . "-" . str_pad($this_month, 1, "0", STR_PAD_LEFT) . "-01";
$end = $this_year . "-" . str_pad($this_month, 1, "0", STR_PAD_LEFT) . "-" . str_pad($day - 1, 1, "0", STR_PAD_LEFT);
$mode = 3;
} else {
//normal case
$start = $this_year . "-" . str_pad($this_month-1, 1, "0", STR_PAD_LEFT) . "-" . str_pad($day, 1, "0", STR_PAD_LEFT);
$end = $this_year . "-" . str_pad($this_month, 1, "0", STR_PAD_LEFT) . "-" . str_pad($day - 1, 1, "0", STR_PAD_LEFT);
$mode = 4;
}*/
if ($date->format("d") == "1") {
$total_days_of_month = cal_days_in_month(CAL_GREGORIAN, $this_month, $this_year);
$start = $this_year . "-" . str_pad($this_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year . "-" . str_pad($this_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($total_days_of_month, 2, "0", STR_PAD_LEFT);
$mode = 6;
}else if ($date->format("d") >= "29") {
//special case
if ($this_month == 12) {
$start = $this_year . "-" . "12-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year + 1 . "-" . "01-" . str_pad($day - 1, 2, "0", STR_PAD_LEFT);
$mode = 1;
} else if ($this_month == 1) {
$total_days_of_month = cal_days_in_month(CAL_GREGORIAN, 2, $this_year);
$start = $this_year . "-" . "01-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year . "-" . "02-" . str_pad($total_days_of_month - 1, 2, "0", STR_PAD_LEFT);
$mode = 1;
} else if ($this_month == 2) {
$total_days_of_month = cal_days_in_month(CAL_GREGORIAN, 2, $this_year);
$start = $this_year . "-" . "02-" . ($total_days_of_month);
$end = $this_year . "-" . "03-" . str_pad($day - 1, 2, "0", STR_PAD_LEFT);
$mode = 2;
} else {
$start = $this_year . "-" . str_pad($this_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year . "-" . str_pad($this_month + 1, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day - 1, 2, "0", STR_PAD_LEFT);
$mode = 3;
}
} else {
//normal case
if ($this_month == 12) {
$start = $this_year . "-" . "12-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year + 1 . "-" . "01-" . str_pad($day - 1, 2, "0", STR_PAD_LEFT);
$mode = 4;
} else {
$start = $this_year . "-" . str_pad($this_month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day, 2, "0", STR_PAD_LEFT);
$end = $this_year . "-" . str_pad($this_month + 1, 2, "0", STR_PAD_LEFT) . "-" . str_pad($day - 1, 2, "0", STR_PAD_LEFT);
$mode = 5;
}
}
return array("start" => $start, "end" => $end, "mode" => $mode);
}
}
if (!function_exists('check_combine_room')) {
function check_combine_room($room_key)
{
$sql = "select * from combine_room where deleted = ? and room1_code = ?";
$parameters = array(0, $room_key);
$result = bind_pdo($sql, $parameters, "selectone");
if(!empty($result)){
return $result["room1_code"]." ".$result["room2_code"];
}else{
return $room_key;
}
}
}
clean_data($_REQUEST);