Пример #1
0
function orders_condition_check()
{
    $query = "SELECT * FROM SHEK_orders WHERE status > 0 AND status < 4";
    $connection = MySQLConnection::get_connection();
    $query_obj = $connection->query($query);
    if ($query_obj->num_rows == 0) {
        return;
    }
    $final_result = array();
    while ($result = $query_obj->fetch_assoc()) {
        array_push($final_result, new Order($result));
    }
    foreach ($final_result as $order) {
        $separeted_conditions_array = $order->get_separated_conditions();
        foreach ($separeted_conditions_array as $condition) {
            $from_obj = date_create($condition[2]);
            $from = date_format($from_obj, "Y/m/d H:i:s");
            $to_obj = date_create($condition[3]);
            $to = date_format($to_obj, "Y/m/d H:i:s");
            $now = date("Y/m/d H:i:s");
            if ($to <= $now) {
                $condition[5] = 4;
                $order->change_progress($condition[4]);
            } elseif ($from <= $now) {
                $condition[5] = 2;
            }
        }
        $order->change_conditions_array($separeted_conditions_array);
        $order->change_conditions();
    }
}
Пример #2
0
/**
 * This function return order with order id and user object.If any error occurs returns -1;
 * @param $id:int
 * @param $user_id:WP_USER
 * @returns int|NULL|array
 */
function get_order($id, $user_id)
{
    $connection = MySQLConnection::get_connection();
    $query = "SELECT * FROM SHEK_orders WHERE id = ? AND owner_id = ?";
    if ($prepare = $connection->prepare($query)) {
        $prepare->bind_param("ii", $ID, $ownerId);
        $ID = $id;
        $ownerId = $user_id;
        if ($prepare->execute()) {
            $get_result = $prepare->get_result();
            return $get_result->fetch_assoc();
        } else {
            return -1;
        }
    } else {
        return -1;
    }
}
Пример #3
0
 /**
  * This method adds current ticket to the database;
  * @return bool|int
  */
 public function create()
 {
     $query = "INSERT INTO SHEK_tickets(applicant_id,related_ticket,related_order,status,create_date,title,content,";
     $query .= "attachments,other,tracking_code,department) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
     $connection = MySQLConnection::get_connection();
     if ($prepare = $connection->prepare($query)) {
         $prepare->bind_param("iiiissssssi", $apId, $relatedTicket, $relatedOrder, $Status, $crDate, $Title, $Content, $attch, $Other, $trCode, $department);
         $apId = $this->applicant_id;
         $relatedTicket = $this->related_ticket;
         $relatedOrder = $this->related_order;
         $Status = $this->status;
         $crDate = date("Y/m/d H:i:s");
         $Title = $this->title;
         $Content = $this->content;
         $attch = $this->attachments;
         $Other = $this->other;
         $trCode = $this->tracking_code;
         $department = $this->department;
         if ($prepare->execute()) {
             $this->id = $connection->insert_id;
             return true;
         }
         return false;
     }
     return -1;
 }
Пример #4
0
<?php

defined("MYSQLCLASS") || define("MYSQLCLASS", true);
require_once '../__Classes/class.MySQL.php';
defined("FAKE") || define("FAKE", true);
require_once "../common/fake_handler.php";
defined("USERGETTER") || define("USERGETTER", true);
require_once "../common/get_user.php";
defined("COMMONC") || define("COMMONC", true);
require_once "../common/users_common.php";
if (get_user_from_cookie()) {
    header("Location: ../dashboard");
    exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $connection = MySQLConnection::get_connection();
    $query = $connection->query("SELECT ID FROM wp_users WHERE user_email = '" . $_POST['email'] . "'");
    if (is_null($id = $query->fetch_array())) {
        echo "0";
        exit;
    } else {
        if ($meta = portal_get_user_meta($id[0], "forget-password")) {
            $meta_array = explode("|", $meta);
            $date_create = date_create($meta_array[count($meta_array) - 1]);
            $date = date_format($date_create, "Y/m/d H:i:s");
            $new_date = date("Y/m/d H:i:s", strtotime("-7 days"));
            if ($new_date < $date) {
                echo "شما به تازگی پسورد خود را بازیابی کرده اید.امکان بازیابی دوباره ی رمز عبور پیش از یک هفته وجود ندارد";
                exit;
            }
        }
Пример #5
0
/**
 * @param string $discount_code
 * @return bool|array
 */
function get_discount_percent($discount_code)
{
    $query = "SELECT percent FROM SHEK_discounts WHERE code = ? ";
    $connection = MySQLConnection::get_connection();
    if ($prepare = $connection->prepare($query)) {
        $prepare->bind_param("s", $discountCode);
        $discountCode = $discount_code;
        if ($prepare->execute()) {
            $get_result = $prepare->get_result();
            return is_null($result = $get_result->fetch_array()) ? false : val_($result[0]);
        }
        return false;
    }
    return -1;
}
Пример #6
0
 /**
  * This method adds invoice to the database if not exists.If exists, update that;
  * @return bool|int
  */
 public function create()
 {
     $query = "INSERT INTO Shek_invoices(owner_id,order_id,price,discount,create_date,expire_date,settlement_date,";
     $query .= "status,installment_number) VALUES(?,?,?,?,?,?,?,?,?)";
     $connection = MySQLConnection::get_connection();
     if ($check_prepare = $connection->prepare("SELECT id FROM Shek_invoices WHERE owner_id = ? AND order_id = ? AND installment_number = ?")) {
         $check_prepare->bind_param("iii", $owner_Id, $order_Id, $instNum);
         $owner_Id = $this->owner_id;
         $order_Id = $this->order_id;
         $instNum = $this->installment_number;
         if ($check_prepare->execute()) {
             $check_get_result = $check_prepare->get_result();
             if (!is_null($check_get_result->fetch_array())) {
                 $this->update();
                 exit;
             }
         } else {
             return false;
         }
     }
     if ($prepare = $connection->prepare($query)) {
         $prepare->bind_param("iiidsssii", $ownerId, $orderId, $Price, $Discount, $CreateDate, $exDate, $setDate, $Status, $instNumber);
         $ownerId = $this->related_user();
         $orderId = $this->related_order();
         $Price = $this->get_price();
         $Discount = $this->get_discount_percent();
         $CreateDate = $this->get_create_date();
         $exDate = $this->get_expire_date();
         $setDate = $this->get_settlement_date();
         $Status = $this->status;
         $instNumber = $this->installment_number;
         if ($prepare->execute()) {
             $this->id = $connection->insert_id;
             return true;
         }
         return -1;
     }
     return -1;
 }
Пример #7
0
 /**
  * This method adds new order to the database If that does not added before;
  * @return bool|int
  */
 public function create()
 {
     $query = " INSERT INTO SHEK_orders(owner_id,title,description,status,progress,installments,price,paid,discount,";
     $query .= "create_date,delivery_date,settlement_date,expire_date,conditions)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
     $connection = MySQLConnection::get_connection();
     // checking if this is a duplicate order
     if ($check_prepare = $connection->prepare("SELECT id FROM SHEK_orders WHERE owner_id = ? AND title = ?")) {
         $check_prepare->bind_param("is", $ID, $checkTitle);
         $ID = $this->owner_id;
         $checkTitle = $this->title;
         if ($check_prepare->execute()) {
             $check_get_result = $check_prepare->get_result();
             if (!is_null($check_get_result->fetch_array())) {
                 return "-1";
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
     if ($prepare = $connection->prepare($query)) {
         $prepare->bind_param("issiisiidsssss", $ownerId, $Title, $Description, $Status, $Progress, $Installments, $Price, $Paid, $Discount, $createDate, $deliveryDate, $settlementDate, $expireDate, $Conditions);
         $ownerId = $this->owner_id;
         $Title = $this->title;
         $Description = $this->description;
         $Status = $this->status;
         $Progress = $this->progress;
         $Installments = $this->installments;
         $Price = $this->price;
         $Paid = $this->paid;
         $Discount = $this->discount;
         $createDate = date("Y/m/d H:i:s");
         $deliveryDate = $this->delivery_date;
         $settlementDate = $this->settlement_date;
         $expireDate = $this->expire_date;
         $Conditions = $this->conditions;
         if ($prepare->execute()) {
             $this->id = $connection->insert_id;
             $this->add_invoices();
             return true;
         }
         return -1;
     }
     return -1;
 }
Пример #8
0
/**
 * @param int $user_id
 * @param string $new_email
 * @return bool
 */
function update_user_email($user_id, $new_email)
{
    $query = "UPDATE wp_users SET user_email = ? WHERE ID = ?";
    $connection = MySQLConnection::get_connection();
    if ($prepare = $connection->prepare($query)) {
        $prepare->bind_param("si", $newEmail, $id);
        $newEmail = $new_email;
        $id = $user_id;
        if ($prepare->execute()) {
            if (portal_get_user_meta($user_id, "change-email") !== false) {
                portal_concat_user_meta($user_id, "change-email", date("Y/m/d H:i:s") . "|");
            } else {
                portal_add_user_meta($user_id, "change-email", date("Y/m/d H:i:s") . "|");
            }
            return true;
        }
    }
    return false;
}
Пример #9
0
/**
 *  returns an array of Invoice objects;
 * @param int $limit
 * @return array|void
 */
function get_invoices($limit = 1000)
{
    defined("INVOICECLASS") || define("INVOICECLASS", true);
    require_once "../__Classes/class.Invoice.php";
    $query = "SELECT * FROM Shek_invoices ORDER BY create_date DESC LIMIT " . strval($limit);
    $connection = MySQLConnection::get_connection();
    $query_object = $connection->query($query);
    if ($query_object->num_rows < 1) {
        return;
    }
    $final_result = array();
    while ($result = $query_object->fetch_assoc()) {
        array_push($final_result, new Invoice($result));
    }
    return $final_result;
}
Пример #10
0
/**
 * This function adds meta_value to the end of existing value of that meta_key ;
 * @param $user_id:int
 * @param $meta_key:string
 * @param $meta_value:string
 * @return bool|int
 */
function portal_concat_user_meta($user_id, $meta_key, $meta_value)
{
    $query = "UPDATE wp_usermeta SET meta_value = CONCAT(meta_value,?) WHERE {$user_id} = ? AND meta_key = ?";
    $connection = MySQLConnection::get_connection();
    if ($prepare = $connection->prepare($query)) {
        $prepare->bind_param("sis", $metaValue, $userId, $metaKey);
        $metaValue = $meta_value;
        $userId = $user_id;
        $metaKey = $meta_key;
        if ($prepare->execute()) {
            return true;
        }
        return false;
    }
    return -1;
}