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/productparcodefix.php
<?php

// get the config file
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');
//Availableparcode
require_once('../models/dao/AvailableparcodeDAO.class.php');
require_once('../models/dto/Availableparcode.class.php');
require_once('../models/mysql/AvailableparcodeMySqlDAO.class.php');
require_once('../models/mysql/ext/AvailableparcodeMySqlExtDAO.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();
//
$sizeColorStoreDetail = new Sizecolorstoredetail();
$sizeColorStoreDetailDAO = new SizecolorstoredetailMySqlDAO();
$sizeColorStoreDetailEX = new SizecolorstoredetailMySqlExtDAO();
//Availableparcode
$availableParcode = new Availableparcode();
$availableParcodeDAO = new AvailableparcodeMySqlDAO();
$availableParcodeEX = new AvailableparcodeMySqlExtDAO();

//check and use the condition that suite this action
if (empty($do)) {
    $count = 0;
    $allproduct = $productExt->getProductsCount();
    $repeatedParcodes = $productExt->queryAllrepateparcode($allproduct->productId);
    foreach ($repeatedParcodes as $parcode) {
        $productsWithSameParcode = $productDAO->queryByParcode($parcode->parcode);
        $i = 0;
        foreach ($productsWithSameParcode as $product) {
            if ($i > 0) {//to skip first product
                generateParcodeAndUpdateIt($product);
                $count++;
            }
            $i++;
        }
    }

    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'> number of serials changed : " . $count . " </span><br/>";
    print_r("</pre>");
}
##
//here the global templates


/* ===============================
  function in this CONTROLLER
  ================================ */

function generateParcodeAndUpdateIt($product) {
    global $productDAO;
    global $productExt;

    $randomString = generateParcode();
    $product->parcode = $randomString;
    $productExt->updatebarcode($product);
}

function generateParcode() {
    global $availableParcodeEX;
    $parcode = $availableParcodeEX->getAvailableParcodeValue();
    //check if this parcode already exists
    $data = checkbarcode2($parcode);
    if ($data != 2) {
        $parcode = generateParcode();
    }
    return $parcode;
}

function checkbarcode2($barcod) {
    global $productDAO;
    global $availableParcodeDAO;

    $parcodeResult = $availableParcodeDAO->queryByValue($barcod);
    if (isset($parcodeResult) && count($parcodeResult) > 0) {
        //if value in the table it is not repeated
        $flag = 2;
        return $flag;
    }


    //check if this parcode already exists in db
    $data = $productDAO->queryByParcode($barcod);
    $flag2;
    if (count($data) > 0) {//> 1 as now i check for barcode after in
        $flag2 = 1;
    } else {
        $flag2 = 2;
    }

    $flagToreturn = 1;
    if ($flag == 2 || $flag2 == 2) {
        $flagToreturn = 2;
    }


    return $flagToreturn;
}

?>