<?
if (isset($_POST['xyz'])) {
  ob_start();
  require "conn.php";
  $namapengguna = mysqli_real_escape_string($con, $_POST['user']);
  $katalaluan = mysqli_real_escape_string($con, $_POST['pass']);

  $result = mysqli_query($con, "SELECT * FROM ahli WHERE username='$namapengguna' AND password='$katalaluan'");

  $count = mysqli_num_rows($result);
  $rows = mysqli_fetch_array($result);

  if ($count == 1) {
    session_start();
    $_SESSION['aW1iZXN0cmEuY29tLm15'] = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
    $_SESSION['aidi']           = $rows['id'];
    $_SESSION['namapenuh']      = $rows['nama'];
    $_SESSION['email']          = $rows['email'];
    $_SESSION['pakej']          = $rows['pakej'];
    $_SESSION['username']       = $rows['username'];
    $_SESSION['telefon']        = $rows['telefon'];
    header("location:dashboard.php");
  }
  else {
    // echo mysqli_error($con);
    header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']); // cara baru !
  }
ob_end_flush();
}


if (isset($_POST['submit_merchant'])) {
  ob_start();
  require "conn.php";
  //echo "hai";
  $namapengguna = mysqli_real_escape_string($con, $_POST['user']);
  $katalaluan = mysqli_real_escape_string($con, $_POST['pass']);

  $result = mysqli_query($con, "SELECT * FROM merchant WHERE username='$namapengguna' AND password='$katalaluan'");

  $count = mysqli_num_rows($result);
  $rows = mysqli_fetch_array($result);

  if ($count == 1) {
    session_start();
    $_SESSION['aW1iZXN0cmEuY29tLm15'] = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
    $_SESSION['aidi']           = $rows['id'];
    $_SESSION['namapenuh']      = $rows['nama'];
    $_SESSION['roc']            = $rows['roc'];
    $_SESSION['email']          = $rows['email'];
    $_SESSION['carwash']        = $rows['carwash'];
    $_SESSION['polish']         = $rows['polish'];
    $_SESSION['repair']         = $rows['repair'];
    $_SESSION['accessories']    = $rows['accessories'];
    $_SESSION['insurance']      = $rows['insurance'];
    $_SESSION['username']       = $rows['username'];
    $_SESSION['telefon']        = $rows['telefon'];
    $_SESSION['role']           = "merchant";
    header("location:dashboard.php");
  }
  else {
   header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']); // cara baru !
  }
ob_end_flush();
}


if (isset($_POST['2pay'])) {
  ob_start();
  require "conn.php";
  $namapengguna = mysqli_real_escape_string($con, $_POST['user']);
  $katalaluan   = mysqli_real_escape_string($con, $_POST['pass']);
  $merchant     = $_POST['m'];

  $result = mysqli_query($con, "SELECT * FROM ahli WHERE username='$namapengguna' AND password='$katalaluan'");

  $count = mysqli_num_rows($result);
  $rows = mysqli_fetch_array($result);

  if ($count == 1) {
    session_start();
    $_SESSION['aW1iZXN0cmEuY29tLm15'] = md5(date("Y-m-d").":".$_SERVER['REMOTE_ADDR']);
    $_SESSION['aidi']           = $rows['id'];
    $_SESSION['namapenuh']      = $rows['nama'];
    $_SESSION['email']          = $rows['email'];
    $_SESSION['pakej']          = $rows['pakej'];
    $_SESSION['username']       = $rows['username'];
    $_SESSION['telefon']        = $rows['telefon'];
    $payee                      = $rows['id'];
    //$ids = $_SESSION['aidi'];
    //echo '<script>alert("'.$ids.'"); </script>';
    header("location:index.php?m=".$merchant."&p=".md5('redeem')."%".$payee);
  }
  else {
    // echo mysqli_error($con);
    header("location:".$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME']."?m=".$merchant); // cara baru !
  }
ob_end_flush();
}




?>