<?php header('Content-Type: text/html; charset=utf-8');?>
<?php 


if(count(get_included_files()) ==1) exit("Direct access not permitted.");?>
<?php 
class DatabaseFunctions{
private $db_name;
     


private $connectionss;
 
    function __construct($db){
        $this -> db_name = 'shirazsa_prctest';

        
 
       
        $this -> connectionss = OdbcSimulator::getConnection(); 
        
   }
    
    //Get All Tables
    
	function getConnection(){
		return $this -> connectionss;
	}
	
    function convertinput($data){return iconv("Windows-1256", "UTF-8", $data);}
    function convertdate($data){
		     $mdate = new DateTime($data);
                    return $mdate -> format("Ymd");
					}
					
	
	
	         
    function getPrcWithVer($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "pic_path" => $this -> convertinput(OdbcSimulator::odbc_result($result, "pic_path")),
                    "cod" => $this -> convertinput(OdbcSimulator::odbc_result($result, "cod")),
                    "nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "nam")),
                    "price" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price")),
                    "price1" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price1")),
                    "price2" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price2")),
                    "price3" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price3")),
                    "price4" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price4")),
                    "price5" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price5")),
                    "box" => $this -> convertinput(OdbcSimulator::odbc_result($result, "box")),
                    "numb" => $this -> convertinput(OdbcSimulator::odbc_result($result, "numb")),
                    "ver" => $this -> convertinput(OdbcSimulator::odbc_result($result, "ver")),
                    "unit" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unit")),
                    "unit2" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unit2")),
                    "stut" => $this -> convertinput(OdbcSimulator::odbc_result($result, "stut")),
                    "unam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unam")),
                    "pic" => $this -> convertinput(OdbcSimulator::odbc_result($result, "pic")),
                    "kalagroup_nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "kalagroup_nam"))
                );

                  array_push($resro, $temp);  
              }

        }
 
             array_push($resarr, array("getprcwithver" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }

	
	
    function getPrcWithCode($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "pic_path" => $this -> convertinput(OdbcSimulator::odbc_result($result, "pic_path")),
                    "cod" => $this -> convertinput(OdbcSimulator::odbc_result($result, "cod")),
                    "nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "nam")),
                    "price" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price")),
                    "price1" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price1")),
                    "price2" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price2")),
                    "price3" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price3")),
                    "price4" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price4")),
                    "price5" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price5")),
                    "box" => $this -> convertinput(OdbcSimulator::odbc_result($result, "box")),
                    "numb" => $this -> convertinput(OdbcSimulator::odbc_result($result, "numb")),
                    "ver" => $this -> convertinput(OdbcSimulator::odbc_result($result, "ver")),
                    "unit" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unit")),
                    "unit2" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unit2")),
                    "stut" => $this -> convertinput(OdbcSimulator::odbc_result($result, "stut")),
                    "unam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "unam")),
                    "pic" => $this -> convertinput(OdbcSimulator::odbc_result($result, "pic")),
                    "kalagroup_nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "kalagroup_nam"))
                );

                  array_push($resro, $temp);  
              }

            
        }
 
             array_push($resarr, array("getprcwithcod" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }
	
	
	function getCodeCast($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "id" => $this -> convertinput(OdbcSimulator::odbc_result($result, "id"))
                );

                  array_push($resro, $temp);  
              }

            
        }
 
             array_push($resarr, array("getcod_cast" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }
	
	 function getPayment($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "id" => $this -> convertinput(OdbcSimulator::odbc_result($result, "id")),
                    "store_nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "store_nam")),
                    "id_payment" => $this -> convertinput(OdbcSimulator::odbc_result($result, "id_payment")),
                    "store_icon" => $this -> convertinput(OdbcSimulator::odbc_result($result, "store_icon"))
                );

                  array_push($resro, $temp);  
              }

            
        }
 
             array_push($resarr, array("getpayment" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }
	
	
	function getFactorValidation($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "factoridz" => $this -> convertinput(OdbcSimulator::odbc_result($result, "factorid")),
                    "countkala" => $this -> convertinput(OdbcSimulator::odbc_result($result, "countkala")),
                    "sumnumb" => $this -> convertinput(OdbcSimulator::odbc_result($result, "sumnumb")),
                    "sumprice" => $this -> convertinput(OdbcSimulator::odbc_result($result, "sumprice"))
                );

                  array_push($resro, $temp);  
              }

            
        }
 
             array_push($resarr, array("factorvalidation" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }	
	function deleteFactor($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        return true;
        
     }
	
		
	
	function getSetting($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "gfs1" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs1")),
                    "gfs2" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs2")),
                    "gfs3" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs3")),
                    "gfs4" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs4")),
                    "gfs5" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs5")),
                    "gfs6" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs6")),
                    "gfs7" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs7")),
                    "gfs8" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs8")),
                    "gfs9" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs9")),
                    "gfs10" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs10")),
                    "gfs11" => $this -> convertinput(OdbcSimulator::odbc_result($result, "gfs11"))
                );

                  array_push($resro, $temp);  
              }

            
        }
 
             array_push($resarr, array("setting2" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }
	
	
		 
    function getdata($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = false;
		$rs2= 'resualt = False';
        if($result){

	      while($row = OdbcSimulator::odbc_fetch_array($result) ) {


		     $rs2= 'resualt = True';
          }
                 

        }
 
             array_push($resarr,$rs2);
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
			
       
        
     } 
	
     function addUser($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
                
                $temp = array(
                    
                    "mag" => $this -> convertinput(OdbcSimulator::odbc_result($result, "msg"))
                );

                  array_push($resro, $temp);  
              }

            
        }

 
             array_push($resarr, array("newcast" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }

    function addfactors($partnumber, $cod_cast, $tasvieh, $day_numb, $numb, $usernam, $price, $factorid, $cod_kala, $yad ,$us,$pas,$ucid){ 
        

           
           
         $result = OdbcSimulator::odbc_exec($this->getConnection(), "EXEC insert_newsalsefactor_sp  @partnumber = '$partnumber', @cod_cast = '$cod_cast', @tasvieh = '$tasvieh', @day_numb = '$day_numb', @numb = '$numb', @usernam = '$usernam', @price = '$price', @factorid = '$factorid', @cod_kala = '$cod_kala', @yad = '$yad', @ucid = '$ucid'");
           
         if(!$result){
              die("Failed To Fetch addfactors");
         }        
 
           
           return true;
        

  
    }
	
	
	
		
	         
    function getnewfactors($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){
			
                $temp = array(
                    
                    "cod_cast" => $this -> convertinput(OdbcSimulator::odbc_result($result, "cod_cast")),
                    "tasvieh" => $this -> convertinput(OdbcSimulator::odbc_result($result, "tasvieh")),
                    "day_numb" => $this -> convertinput(OdbcSimulator::odbc_result($result, "day_numb")),
                    "cod_kala" => $this -> convertinput(OdbcSimulator::odbc_result($result, "cod_kala")),
                    "numb" => $this -> convertinput(OdbcSimulator::odbc_result($result, "numb")),
                    "price" => $this -> convertinput(OdbcSimulator::odbc_result($result, "price")),
                    "usernam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "usernam")),
                    "factorid" => $this -> convertinput(OdbcSimulator::odbc_result($result, "factorid")),
                    "part" => $this -> convertinput(OdbcSimulator::odbc_result($result, "part")),
                    "yad" => $this -> convertinput(OdbcSimulator::odbc_result($result, "yad")),
                    "rowi" => $this -> convertinput(OdbcSimulator::odbc_result($result, "rowi"))
                );

                  array_push($resro, $temp);  
              }

        }
 
             array_push($resarr, array("newfactors" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }

			
	         
    function getnewcasts($que){
 
        $result = OdbcSimulator::odbc_exec($this->getConnection(), $que);
        $resarr = array(); 
        $resro = array();  
        if($result){

            while (OdbcSimulator::odbc_fetch_row($result)){

                $temp = array(
                    
                    "nam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "nam")),
                    "adr" => $this -> convertinput(OdbcSimulator::odbc_result($result, "adr")),
					"tel" => $this -> convertinput(OdbcSimulator::odbc_result($result, "tel")),
                    "usernam" => $this -> convertinput(OdbcSimulator::odbc_result($result, "usernam")),
                    "pass" => $this -> convertinput(OdbcSimulator::odbc_result($result, "pass")),
                    "dat" => $this -> convertinput(OdbcSimulator::odbc_result($result, "dat")),
                    "rowi" => $this -> convertinput(OdbcSimulator::odbc_result($result, "rowi"))
                );

                  array_push($resro, $temp);  
              }

        }
 
             array_push($resarr, array("newcasts" => $resro));
             return json_encode($resarr, JSON_UNESCAPED_UNICODE);
        
     }

		
	function chkuseval($uone, $utwo){

 
        $completeList=  array();
        $counter = 0;
        
        $result = OdbcSimulator::odbc_exec($this->getConnection(), "EXEC chkuseval @uname = $uone , @upass = $utwo");
        if(!$result){
              die("Failed To Fetch chkuseval");
         }else{
            
             while (OdbcSimulator::odbc_fetch_row($result)){
                
                $bowl = array(
                    
                    "uid" => $this -> convertinput(OdbcSimulator::odbc_result($result, "ucid"))
                );
                
                  array_push($completeList, $bowl["uid"]);  
              }
            
        }
 
        return $completeList;
            
        
    }     
	 
}
?>