<?php

//the global file operation
session_start();
ob_start();
//global varable
global $showoutside;

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

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

//MStageproperity
require_once('../models/dao/MStageproperityDAO.class.php');
require_once('../models/dto/MStageproperity.class.php');
require_once('../models/mysql/MStageproperityMySqlDAO.class.php');
require_once('../models/mysql/ext/MStageproperityMySqlExtDAO.class.php');




//MProducthistory
require_once('../models/dao/MProducthistoryDAO.class.php');
require_once('../models/dto/MProducthistory.class.php');
require_once('../models/mysql/MProducthistoryMySqlDAO.class.php');
require_once('../models/mysql/ext/MProducthistoryMySqlExtDAO.class.php');

//MInitialmaintenance
require_once('../models/dao/MInitialmaintenanceDAO.class.php');
require_once('../models/dto/MInitialmaintenance.class.php');
require_once('../models/mysql/MInitialmaintenanceMySqlDAO.class.php');
require_once('../models/mysql/ext/MInitialmaintenanceMySqlExtDAO.class.php');
//MInitialmaintenancedetail
require_once('../models/dao/MInitialmaintenancedetailDAO.class.php');
require_once('../models/dto/MInitialmaintenancedetail.class.php');
require_once('../models/mysql/MInitialmaintenancedetailMySqlDAO.class.php');
require_once('../models/mysql/ext/MInitialmaintenancedetailMySqlExtDAO.class.php');

//MExternalmaintenance
require_once('../models/dao/MExternalmaintenanceDAO.class.php');
require_once('../models/dto/MExternalmaintenance.class.php');
require_once('../models/mysql/MExternalmaintenanceMySqlDAO.class.php');
require_once('../models/mysql/ext/MExternalmaintenanceMySqlExtDAO.class.php');

//MInsurance
require_once('../models/dao/MInsuranceDAO.class.php');
require_once('../models/dto/MInsurance.class.php');
require_once('../models/mysql/MInsuranceMySqlDAO.class.php');
require_once('../models/mysql/ext/MInsuranceMySqlExtDAO.class.php');



//MComreceipt
require_once('../models/dao/MComreceiptDAO.class.php');
require_once('../models/dto/MComreceipt.class.php');
require_once('../models/mysql/MComreceiptMySqlDAO.class.php');
require_once('../models/mysql/ext/MComreceiptMySqlExtDAO.class.php');
//MComreceiptdetail
require_once('../models/dao/MComreceiptdetailDAO.class.php');
require_once('../models/dto/MComreceiptdetail.class.php');
require_once('../models/mysql/MComreceiptdetailMySqlDAO.class.php');
require_once('../models/mysql/ext/MComreceiptdetailMySqlExtDAO.class.php');
//Client
require_once('../models/dao/ClientDAO.class.php');
require_once('../models/dto/Client.class.php');
require_once('../models/mysql/ClientMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientMySqlExtDAO.class.php');
//Clientdebtchange
require_once('../models/dao/ClientdebtchangeDAO.class.php');
require_once('../models/dto/Clientdebtchange.class.php');
require_once('../models/mysql/ClientdebtchangeMySqlDAO.class.php');
require_once('../models/mysql/ext/ClientdebtchangeMySqlExtDAO.class.php');


//MCheck
require_once('../models/dao/MCheckDAO.class.php');
require_once('../models/dto/MCheck.class.php');
require_once('../models/mysql/MCheckMySqlDAO.class.php');
require_once('../models/mysql/ext/MCheckMySqlExtDAO.class.php');


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

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

  Controller Name :- productController

  OPERTATION in Controller

  1- display add form, add supplier cat and supplier with ajax
  2- add in supplier tbl
  2.1- insert into supplier unit tbl
  2.2- insert into storedetail tbl
  2.3- insert new row into storereport tbl
  3- display show and tempdelete
  4- edit supplier
  5- update supplier
  5.1- update supplier tbl with supplierid
  5.2- delete supplier units associated to this supplier from productunit tbl, then insert it again

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

//here goes the instances and general variables
$mStageProperityDAO = new MStageproperityMySqlDAO();



$MProductHistory = new MProducthistory();
$MProductHistoryDAO = new MProducthistoryMySqlDAO();

$MInitialNaintenance = new MInitialmaintenance();
$MInitialNaintenanceDAO = new MInitialmaintenanceMySqlDAO();
$MInitialMaintenanceDetail = new MInitialmaintenancedetail();
$MInitialMaintenanceDetailDAO = new MInitialmaintenancedetailMySqlDAO();
$MInitialMaintenanceDetailEX = new MInitialmaintenancedetailMySqlExtDAO();


$MExternalMaintenance = new MExternalmaintenance();
$MExternalMaintenanceDAO = new MExternalmaintenanceMySqlDAO();
$MExternalMaintenanceEX = new MExternalmaintenanceMySqlExtDAO();

$MInsurance = new MInsurance();
$MInsuranceDAO = new MInsuranceMySqlDAO();
$MInsuranceEX = new MInsuranceMySqlExtDAO();

$MComreceipt = new MComreceipt();
$MComreceiptDAO = new MComreceiptMySqlDAO();
$MComreceiptEX = new MComreceiptMySqlExtDAO();

$MComreceiptdetailEX = new MComreceiptdetailMySqlExtDAO();

$Client = new Client();
$ClientDAO = new ClientMySqlDAO();
$ClientEx = new ClientMySqlExtDAO();

$myClientdebtchange = new Clientdebtchange();
$myClientdebtchangeRecord = new ClientdebtchangeMySqlDAO();

$mCheckDAO = new MCheckMySqlDAO();

//check and use the condition that suite this action
if (empty($do)) {

} elseif ($do == "fillMyList") {
     try
      { 
    //$StageProperityIDsArray='';
         fillMyList();
       /* foreach($mStageProperity as $myMStageProperity)
        {
        $StageProperityIDsArray.=$myMStageProperity->stageProperityId.',';
        }
        $smarty->assign("StageProperityIDsArray", $StageProperityIDsArray);
        $smarty->assign("mStageProperity", $mStageProperity);
        $smarty->display("checkReportView/StageProperity.html");*/
     }
      catch(Exception $e)
      {
      header("location:?do=error");
      } 
}



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

function fillMyList() {
    global $MComreceiptEX;
    global $MComreceiptdetailEX;
    global $ClientEx;

    $row_array = array();

    $arr = array();

    $name = $_GET['term']; //It could be product name or category name
    $limit = intval($_GET['page_limit']);
    /* $storeid=$_REQUEST["storeid"];
      $hiddenpricetype=$_REQUEST["hiddenpricetype"]; */
    $using = $_REQUEST["using"];

    /*     * *************************************************** */
    if ($using == 1) {
        //using Recit Serial
        $data = $MComreceiptEX->getserialnumber2($name);
    }

    if ($using == 2) {
        //using Product Serial
        $data = $MComreceiptdetailEX->getserialnumber2($name);
    }

    if ($using == 3) {
        //using ourSerial
        $data = $MComreceiptdetailEX->getserialnumber3($name);
    }

    if ($using == 4) {
        //using ClientId
        //with client name
        $data = $ClientEx->getClients1($name);
    }

    if ($using == 5) {
        //using ClientId
        //with client tel
        $data = $ClientEx->getClients2($name);
    }
    /*     * ************************************************** */

    if (count($data) > 0) {

        foreach ($data as $mydata) {
            $arr['id'] = $mydata->value;
            $arr['text'] = $mydata->label;

            array_push($row_array, $arr);
        }
    }

    /* print_r('<pre>');
      print_r($row_array);
      print_r('</pre>'); */

    echo json_encode($row_array);
}

/* function fetch_recursive($parentid, $categories)
  {
  global $myProductcatEx;
  //print($parentid."<br>");
  $catData = $myProductcatEx->getCategoryAndParentByCatId($parentid);
  //print_r($catData);
  if(count($catData) > 0)
  {
  $categories .= $catData->productCatName.'/';
  $newParentId = $catData->productCatParent;

  //if($newParentId != 0 && isset($newParentId))
  {
  //$newParentName = $catData->parentName;
  //$categories .= $newParentName.'/';
  return fetch_recursive($newParentId, $categories);
  }
  }
  $categories = substr($categories, 0, strlen($categories) - 1);
  return $categories;
  } */
?>