<?php 

  /*include "settings.php";
  $conn = sqlsrv_connect($serverName, $connectionInfo);

  if (!$conn)
  {
      die('Подключение к MSSQL не выполнено!');
  }
  $data = $_POST['data'];
  $data = stripslashes($data);
  $arraydata = (array)json_decode($data);*/
  
  include "settings.php";
  $db = new mysqli ($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
  $db->query("SET CHARSET SET utf8");
  $db->query("SET NAMES 'utf8'");
  if (mysqli_connect_errno()) {
    echo "Error connecting to DB";
    exit;
  }
  $db1 = new mysqli ($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);
  $db1->query("SET CHARSET SET utf8");
  $db1->query("SET NAMES 'utf8'");
  if (mysqli_connect_errno()) {
    echo "Error connecting to DB";
    exit;
  }
  $data = $_POST['data'];
  //$data = "{\"func\":\"ms_visits\",\"id\":1,\"lastSynch\":\"2012-06-26 13:05:00\"}";//DebugBreak();
  $data = stripslashes($data);
  $arraydata = (array)json_decode($data,true);
  
  /*if ($arraydata['func']=='check_login')
  {
    $login = $arraydata["login"];
    $password = $arraydata["password"];
    $i=0;

      $query = "SELECT [EmployeeNo], [EmployeeSotrudNo], [EmploeeCarsNo] FROM [work].[dbo].[Employee] WHERE [Login]='".$login."' AND [Password]='".$password."'";               //md5($password)
              
      $stmt = sqlsrv_query( $conn, $query );
      while( $objRow = sqlsrv_fetch_object( $stmt) )
      {
        $Model[$i] = array(
                      'id_temp'=>iconv("windows-1251", "UTF-8", $objRow->EmployeeNo),
                      'id'=>iconv("windows-1251", "UTF-8", $objRow->EmployeeSotrudNo),
                      'id_car'=>iconv("windows-1251", "UTF-8", $objRow->EmploeeCarsNo)
                      );
        $i++;
      }
 
    $str_file="logs.txt";
    $fp = fopen($str_file, "a"); 
    $test = fwrite($fp, date("Y-m-d H:i:s").' - '.$query);
    
    sqlsrv_free_stmt( $stmt);
    echo json_encode($Model);
  }*/
  
  if ($arraydata['func']=='check_login')
  {
    $login = $arraydata["login"];
    $password = $arraydata["password"];
    $i=0;

    $query = "SELECT id AS id_temp FROM ms_user WHERE login='".$login."' AND password='".md5($password)."'";
    if ($stmt = $db->prepare($query)){
      $stmt->execute();
      $stmt->bind_result($id);
      while($stmt->fetch()){
        $Model[$i]=
        array('id_temp'=>$id
        );
        $i++;
      } 
      $stmt->close();
      $db->close();
    }
    echo json_encode($Model);
  }

?>