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

//the global file operation
include("../public/impOpreation.php");

//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
include_once("../public/config.php");
include_once("dailyentryfun.php");
include("../library/uploadImages.php");

//here the db files that include in the file
include("../public/include_dao.php");

//Breadcrumb
require_once("../library/breadcrumb.php");

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

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

  Controller Name :- assetsCTRL

  OPERTATION in Controller

  1-display add form
  2- add in Assets tble
  3-display sucess or error
  4-display show form
  5-delete from Assets tbl
  6-edit in Assets data

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

//here the global templates
$smarty->display("header.html");

//here goes the instances and general variables
//Client
$client = new Client();
$clientDAO = new ClientMySqlDAO();
$clientExt = new ClientMySqlExtDAO();

//Clientdebtchange
$clientDeptChange = new Clientdebtchange();
$clientDeptChangeDAO = new ClientdebtchangeMySqlDAO();
$clientDeptChangeExt = new ClientdebtchangeMySqlExtDAO();

$today = date("Y-m-d");

//Store
$store = new Store();
$storeDAO = new StoreMySqlDAO();
$storeEX = new StoreMySqlExtDAO();


//Dailyentry
$dailyEntry = new Dailyentry();
$dailyEntryDAO = new DailyentryMySqlDAO();
$dailyEntryEX = new DailyentryMySqlExtDAO();

//Dailyentrycreditor دائن
$dailyEntryCreditor = new Dailyentrycreditor();
$dailyEntryCreditorDAO = new DailyentrycreditorMySqlDAO();
$dailyEntryCreditorEX = new DailyentrycreditorMySqlExtDAO();

//Dailyentrydebtor مدين
$dailyEntryDebtor = new Dailyentrydebtor();
$dailyEntryDebtorDAO = new DailyentrydebtorMySqlDAO();
$dailyEntryDebtorEX = new DailyentrydebtorMySqlExtDAO();

//check and use the condition that suite this action
if (empty($do)) {
    //here the permission check
    include_once("../public/authentication.php");

    $smarty->display("upload_data/upload.html");
} elseif ($do == 'add') {






    try {
        //# upload excel file and store it in folder
        if (isset($_FILES['client_excel'])) {
            $file_name = $_FILES['client_excel']['name'];
            $file_temp = $_FILES['client_excel']['tmp_name'];
            move_uploaded_file($file_temp, "../upload/uploaded_excelfiles/" . $file_name . "");

            $start = 0;
            $increment = 10;
            $end = 9;
            $file_name_full = "../upload/uploaded_excelfiles/" . $file_name . "";

            $url = $file_name_full;
            // $file_name = $_FILES['client_excel']['name'];
            // $file_name_full = "../upload/uploaded_excelfiles/".$file_name."";
        } else {
            $start = (int) $_GET['start'];
            $increment = (int) $_GET['increment'];
            $end = (int) $_GET['end'];
            $url = $_GET['url'];

            //$url = "../upload/uploaded_excelfiles/client_view.csv";
            // $url = $url;
        }
        //#load file from folder to read it.


        $file = file($url);

        $i = $start;


        if (!empty($file)) {


            $count_arr = count($file);

            foreach ($file as $key => $f) {


                if ($key >= $start && $key <= $end) {
                    $clientData = explode(";", $f);

                    //    print_r('<br> $key = '.$key. ' $clientData '.$clientData[0].'<br>');


                    $clientData[0] = trim($clientData[0], '"');
                    $clientData[1] = trim($clientData[1], '"');

                    $clientData[0] = iconv('UTF-8', 'Windows-1252', $clientData[0]);
                    $clientData[1] = iconv('UTF-8', 'Windows-1252', $clientData[1]);

                    print_r('<br>' . $clientData[0] . ' = done <br>');

                    //# call function add of client to insert clients from excel file.

                    add($clientData);
                    $i++;
                }
            }
            if ($start + 1 < $count_arr) {
                $start = $end + 1;
                $end = $end + 10;
                $increment = 10;
                header("refresh:5;url=http://localhost/ERP/controllers/upload_data.php?do=add&start=" . $start . "&end=" . $end . "&increment=" . $increment . "&url=" . $url . "");
                return;
            } else {
                $smarty->display("upload_data/upload.html");
            }
        }
    } catch (Exception $e) {
        header("location:?do=error");
    }
}

// add in client tbl
function add($clientData) {
    global $clientDAO;
    global $client;
    global $clientDeptChange;
    global $clientDeptChangeDAO;
    global $today;
    global $storeDAO;

//Dailyentry
    global $dailyEntry;

//Dailyentrycreditor دائن
    global $dailyEntryCreditor;

//Dailyentrydebtor مدين
    global $dailyEntryDebtor;

    $clientname = $clientData[0];
    $clientaddress = 'default';
    $clientphone = 123;
    $clientmobile = 'default';
    $clientdebt = $clientData[1];
    $clientdebt = round($clientdebt, 2);
    $clientdetails = 'default';
    $clientareaid = 2;
    $clientcode = 'default';
    $store_all = 1;


    $checkName = $clientDAO->queryByClientname($clientname);

    if (!empty($checkName)) {
        return -1;
    } else {
        $checknumber = filter_var($clientdebt, FILTER_VALIDATE_INT);
        /* if (!$checknumber) {

          return -2;
          } else { */
//insert into client
        $client->clientcode = $clientcode;
        $client->clientaddress = $clientaddress;
        $client->clientdate = $today;
        $client->clientdebt = $clientdebt;
        $client->clientdetails = $clientdetails;
        $client->clientmobile = $clientmobile;
        $client->clientname = $clientname;
        $client->clientphone = $clientphone;
        $client->conditions = 0;
        $client->userid = $_SESSION['userid'];
        $client->clientareaid = $clientareaid;
        $client->dailyentryid = 0;

        if (isset($store_all) && $store_all == 1) {
            $client->clientStoreIds = '-10'; //all stores
        } else {
            $client->clientStoreIds = '';
            $stores = $storeDAO->queryAll();
            foreach ($stores as $data) {
                $selectStore = $_POST["store" . $data->storeId];
                if (isset($selectStore) && $selectStore == 1) {
                    $client->clientStoreIds .= $data->storeId . ',';
                }
            }
            $client->clientStoreIds = rtrim($client->clientStoreIds, ",");
        }

        $clientid = $clientDAO->insert($client);
//}
    }
    if (!empty($clientid)) {
//insert into clientdeptchange
        $clientDeptChange->clientdebtchangeafter = $clientdebt;
        $clientDeptChange->clientdebtchangeamount = $clientdebt;
        $clientDeptChange->clientdebtchangebefore = 0;
        $clientDeptChange->clientdebtchangedate = $today;
        $clientDeptChange->clientdebtchangemodelid = $clientid;
        $clientDeptChange->clientdebtchangetype = 0;
        $clientDeptChange->clientid = $clientid;
        $clientDeptChange->comment = "";
        $clientDeptChange->processname = "إضافة عميل جديد";
        $clientDeptChange->tablename = "clientController.php";
        $clientDeptChange->userid = $clientareaid;
        $clientDeptChange->clientareaid = $_SESSION['userid'];
        $clientDeptChange->dailyentryid = 0;
        $clientDeptChangeDAO->insert($clientDeptChange);
    }
    $clientTypeForTree = 0;
    if ($clientTypeForTree == 0)
        $parent = 58;
    elseif ($clientTypeForTree == 1)
        $parent = 60;
    $treeId = addTreeElement($clientname, $parent, 3, 0, 1, '', 0, 0);


    $dailyEntry->dDateTime = date('Y-m-d H:i:s');
    $dailyEntry->entryComment = 'تم اضافة عميل ' . $clientname;

    $dailyEntryDebtor->value = $clientdebt;
    $dailyEntryDebtor->accountstreeid = $treeId;

    $dailyEntryCreditor->value = $clientdebt;
    $dailyEntryCreditor->accountstreeid = 121;

    $dailyEntryDebtorArray = array();
    $dailyEntryCreditorArray = array();
    array_push($dailyEntryDebtorArray, $dailyEntryDebtor);
    array_push($dailyEntryCreditorArray, $dailyEntryCreditor);

    $returnedData = insertEntery($dailyEntry, $dailyEntryDebtorArray, $dailyEntryCreditorArray);
    $did = $returnedData[1];

    $rowData = $clientDAO->load($clientid);
    $client->clientcode = $rowData->clientcode;
    $client->clientaddress = $rowData->clientaddress;
    $client->clientdate = $rowData->clientdate;
    $client->clientdebt = $rowData->clientdebt;
    $client->clientdetails = $rowData->clientdetails;
    $client->clientmobile = $rowData->clientmobile;
    $client->clientname = $rowData->clientname;
    $client->clientphone = $rowData->clientphone;
    $client->conditions = $rowData->conditions;
    $client->userid = $rowData->userid;
    $client->clientareaid = $rowData->clientareaid;
    $client->clientStoreIds = $rowData->clientStoreIds;
    $client->dailyentryid = $did;

    $clientDAO->update($client);
}

//here the global templates
$smarty->assign("customValidation", 1);
$smarty->display("footer.html");
?>