<?
if (count(get_included_files()) ==1) die("<h4>You don't have right permission to access this file directly.</h4>");

  require "conn2.php";

  try {
      $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      // set the PDO error mode to exception
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      // prepare sql and bind parameters
      $stmt = $conn->prepare("INSERT INTO ahli (nama, kp, telefon, email, tarikh, penaja, username, password, pakej)
      VALUES (:nama, :kp, :telefon, :email, :tarikh, :penaja, :username, :password, :pakej)");

      $stmt->bindParam(':nama', $nama);
      $stmt->bindParam(':kp', $mykad);
      $stmt->bindParam(':telefon', $telefon);
      $stmt->bindParam(':email', $email);
      $stmt->bindParam(':tarikh', $tarikh);
      $stmt->bindParam(':penaja', $penaja);
	  $stmt->bindParam(':username', $usrnm);
      $stmt->bindParam(':password', $pswd);
      $stmt->bindParam(':pakej', $pakejName);


      $stmt->execute();
      
        if ($_SESSION['username'] != "admin")  { 
              // Get profile $penaja
                $info = telUser($penaja);
                list($tel, $uname, $sms) = explode("|", $info);
                echo '<script>alert('.$directSponsor.');</script>';
              // Production Bonus
                $lastid = $conn->lastInsertId();
                $test   = mysqli_query($con, "INSERT INTO cwallet (tarikh, keterangan, rujukan, masuk, userid)
                                            VALUES ('".$tarikh."', 'Bonus Sponsor: RM".$directSponsor." [".$pakejName."] for ".$uname."', '".$usrnm."', '".$directSponsor."', '".$penaja."')");
                include "_sms_bonus_sponsor.php";
                      
        }       


      // prepare db 1000
/*
      $stmt->bindParam(':rujukan', 'Startup DB');
      $stmt->bindParam(':masuk', 1000);
      $stmt->bindParam(':userid', $lastid);
      $stmt = $conn->prepare("INSERT INTO db (tarikh, keterangan, rujukan, masuk, userid)
      VALUES (:tarikh, :keterangan, :rujukan, :masuk, :userid)");
 */
      $_SESSION['flash_message'] = "Registration successful!";
      echo "<div class=\"alert alert-success\"><strong>Congratulations!</strong> You have successfully signed up new members.</div>";
      // echo "Welcome email has been sent to ".$email;
      //echo "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />\n";
      }
  catch(PDOException $e)
      {
      echo "Error: " . $e->getMessage();
      }
  $conn = null;
?>
