HEX
Server: Apache
System: Linux server1.royalgt4.com 4.18.0-553.89.1.lve.el8.x86_64 #1 SMP Wed Dec 10 13:58:50 UTC 2025 x86_64
User: mostafedeg (1125)
PHP: 5.6.40
Disabled: mail,passthru,parse_ini_file,show_source,eval,assert,pcntl_exec,dl,putenv,proc_open,popen
Upload Files
File: /home/mostafedeg/public_html/erp/controllers/setProductPriceLastMean.php
<?php

include_once("../public/config.php");
include("../public/include_dao.php");
//Product
require_once('../models/dao/ProductDAO.class.php');
require_once('../models/dto/Product.class.php');
require_once('../models/mysql/ProductMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductMySqlExtDAO.class.php');

//get the do the action
$do = $_GET['do'];

/* ======================

  Controller Name :- productController

  OPERTATION in Controller


  ======================== */

//here the global templates
//$smarty->display("header.html");
//here goes the instances and general variables
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productExt = new ProductMySqlExtDAO();

//$started_at = microtime(true);
//check and use the condition that suite this action
if (empty($do)) {
    //here the permssion check
    $count = 0;
    $start = 0;
    $limit = 30;
    $end = $start + $limit;
    $all_products_count = $productExt->getProductsCount();
    for ($i = $limit; $i <= $all_products_count->productId; $i+=$limit) {
        $allproduct = $productExt->queryAllOrderedLimitedSimple($start, $limit);
        $update_sql = '';
        foreach ($allproduct as $value) {
            $value->lastbuyprice = $value->productBuyPrice;
            $value->lastbuyprice_withDiscount = $value->productBuyPrice;
            $value->meanbuyprice = $value->productBuyPrice;
            $value->meanbuyprice_withDiscount = $value->productBuyPrice;
            $update_sql .= "UPDATE product SET lastbuyprice = $value->productBuyPrice,meanbuyprice= $value->productBuyPrice WHERE productId = $value->productId;";
            $count++;
        }
        if ($update_sql != "") {
            $conn = mysqli_connect(ConnectionProperty::getHost(), ConnectionProperty::getUser(), ConnectionProperty::getPassword(), ConnectionProperty::getDatabase()) or die('unable to connect to db');
            $res = mysqli_multi_query($conn, $update_sql); //mysqli_query for one query , mysqli_multi_query for multi query
            mysqli_close($con);
        }
        //
        $start += $limit;
        $end += $limit;
    }
//    echo 'Cool, that only took ' . (microtime(true) - $started_at) . ' seconds!';


    echo "<span style='color:green'> DONE. </span><br/>";
    print_r("<pre>");
    echo "<div style='border:1px solid green;margin-right:60%'><span style='color:green'> no of queries products fixed : " . $count . " </span><br/>";
    print_r("</pre>");
}
?>