<?php
/**
 * Script called (Ajax) on login
 */
require_once("../../../../common/lib.php");
require_once("../../../../common/define.php");
    
$response = array("html" => "", "notices" => array(), "error" => "", "success" => "", "redirect" => "");
$company_id = isset($_SESSION['company']['id']) ? $_SESSION['company']['id'] : 0;
////////////////////////////////////////////////////////////////////////
$user = htmlentities($_POST['user'], ENT_COMPAT, "UTF-8");
$password = $_POST['pass'];
////////////////////////////////////
$login =  $saas->Normallogin($user, $password, $company_id);
////////////////////////////////////
// loginUser
// checked = 1
if ($login["success"]) {
   // print_r($login);
    $company = $login["company"];
    $token = $login["token"];
    $loginid = $login["id"];
    /////////////////////////////////// User
    $_SESSION['user']['id'] = $loginid;
    $_SESSION['user']['login'] = $login["login"];
    $_SESSION['user']['email'] = $login["email"];
    $_SESSION['user']['type'] = $login["type"];
    $_SESSION['user']['add_date'] = $login["add_date"];
    $_SESSION['user']['user_no'] = $login["user_no"];
    //////////////////////////////////////
    if($_SESSION['user']['type'] != "registered"){
         $response['redirect'] = DOCBASE.PMS_ADMIN_FOLDER;
    }
    echo json_encode($response);
}else{
    $response['error'] = $login["message"];
    ///$pms_texts['INCORRECT_LOGIN'];
    echo json_encode($response);
}

