<?php
require_once ("varables.php");
$myJSON = array();
$myJSON['success'] = "0";
$myJSON['company']="وبکام";
$myJSON['cat']="0";
$myJSON['minBuy']= 0;
$myJSON['unit']="ریال";
$myJSON['extname']="";
$myJSON['extprice']="0";
$myJSON['holoo']="0";
$myJSON['canmanfi']="0";
$myJSON['tell']="";
$myJSON['showprice']="0";
$myJSON['moaref']="0";
$myJSON['benner']="0";
$myJSON['benner']="0";
$myJSON['mustRegister']="1";

if(isset($_POST["uzermane"]) && isset($_POST["wasport"]))
{
    $uzer = $_POST["uzermane"];
    $andid = $_POST["wasport"];
    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");

        if (strpos($uzer, 'android') !== false) {
            $q="SELECT id FROM tbl_androidid WHERE andid = '".$andid."'LIMIT 1";
            $res=@mysqli_query($connect,$q);
            $myid = 0;
            if($res){
                $myDate = jdate('Y/m/d');
                while($androw = @mysqli_fetch_assoc($res))
                    $myid = $androw['id'];
                if($myid == 0){
                    $q="INSERT INTO tbl_androidid (andid,date,firstdate) VALUES ('".$andid."','".$myDate."','".$myDate."')";
                    $res=@mysqli_query($connect,$q);
                }else{
                    $q="UPDATE tbl_androidid SET andid = '".$andid."' ,date ='".$myDate."' WHERE id = '".$myid."'";
                    $res=@mysqli_query($connect,$q);
                    if(!$res){
                        $myJSON['success']= @mysqli_error($connect);

                        echo json_encode($myJSON);
                        return;
                    }
                }
            }
        }
        $unitQ="SELECT * FROM " . $tbl_company . " LIMIT 1";
        $resQ=@mysqli_query($connect,$unitQ);
        if ($resQ) {
          $u = @mysqli_fetch_assoc($resQ);
              $myJSON['unit']= $u["p_Unit"];
              $myJSON['company']= $u["name"];
              $myJSON['cat']= $u["cat1"];
              $myJSON['minBuy']= $u["minBuy"];
              $myJSON['extname']= $u["extname"];
              $myJSON['extprice']= $u["extprice"];
              $myJSON['holoo']=$u["holoo"];
              $myJSON['canmanfi']=$u["canmanfi"];
              $myJSON['tell']=$u["tell"];
              $myJSON['showprice']=$u["showprice"];
              $myJSON['moaref']=$u["moaref"];
              $myJSON['benner']=$u["banner"];
              $myJSON['mustRegister']=$u["mustRegister"];
              $myJSON['success']= "200" ;
        }else{
            $myJSON['success']= "400" ;
        }
    }
    else{
        $myJSON['success']= "401" ;
    }
}
    echo json_encode($myJSON);
?>
