<?php require_once('../Connections/conn_ama.php'); 

  include("../../../../../../functions/functions.php");  

  // *** Validate request to login to this site.
  if (!isset($_SESSION)) {
    session_start();
  }

  $loginFormAction = $_SERVER['PHP_SELF'];
  if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  }

  if (isset($_POST['theopener'])) {

    $loginUsername=$_POST['theopener'];
    $password=$_POST['thepasser'];
    $MM_fldUserAuthorization = "";
    $MM_redirectLoginSuccess = "3323123";
    $MM_redirectLoginFailed = "ioiyu";
    $MM_redirecttoReferrer = false;

    //echo $loginUsername; 
    //echo $password;

    //login sql call
    $LoginRS__query=sprintf("CALL get_passer(%s, %s)",
      GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
    
    $LoginRS = mysqli_query($conn_ama, $LoginRS__query) or die(mysqli_error($conn_ama));
    $row_rslogin =  mysqli_fetch_assoc($LoginRS);
    $loginFoundUser = mysqli_num_rows($LoginRS);

    //mysqli_free_result($LoginRS);  
    //mysqli_next_result($conn_ama); 

    if ($loginFoundUser) {
      $loginStrGroup = "";
      
    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
      //declare session variables and assign them
      $_SESSION['MM_Username'] = $loginUsername;
      $_SESSION['MM_Firstname'] = $row_rslogin['fname'];
      $_SESSION['MM_Fullname'] = $row_rslogin['thename'];
      $_SESSION['MM_Rolename'] = $row_rslogin['rolename'];
      $_SESSION['MM_UserGroup'] = $loginStrGroup;


      if (isset($_SESSION['PrevUrl']) && false) {
        $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
      }
    echo "datasent";
    }
    else {
      echo "notset";
    }

    mysqli_next_result($conn_ama);  
    mysqli_close($conn_ama);

  }
?>

