<?php
//require 'session.php';
require 'nusoap/nusoap.php';
require 'nusoap/class.wsdlcache.php';
$wsdl = 'http://192.168.20.119:8082/ws/live.php?wsdl';
//$wsdl = 'http://localhost:8082/ws/live.php?wsdl';
$client = new nusoap_client($wsdl, true);


$input_username=$_POST['username'];
$input_password=$_POST['password'];


$proxy = $client->getProxy();
if($input_username=='admin' AND $input_password=='admin'){
	$username='071027';
	$password='4kumth193uim1z';
	}
	else {
		$username=$input_username;
		$password=$input_password;
	}

echo $username."-".$password;	
$username = $input_username;
$password = $input_password;
$gettoken = $proxy->GetToken($username, $password);
$token=$gettoken;
//var_dump ($gettoken);
$sp="npsn='".$username."'";

$result=$proxy->GetRecord($gettoken,'satuan_pendidikan',$sp);
$id_sp=$result['result']['id_sp'];
$nm_lemb=$result['result']['nm_lemb'];
//echo "<br><br><br>".$id_sp['id_sp'];


if ($username =='' || ($password=='')){
	header('location:login.php?msg=1');
}
elseif (!ctype_alnum($gettoken)){
  header('location:login.php?msg=2');
  //echo "test";
}else {

session_start();
include "timeout.php";
$_SESSION['token']=$gettoken;
$_SESSION['username']=$username;
$_SESSION['password']=$password;

$_SESSION['id_sp']=$id_sp;
$_SESSION['nm_lemb']=$nm_lemb;

  $_SESSION['login'] = 1;
  timer();
  
  setcookie("username", $username, time()+3600);
  setcookie("password", $password, time()+3600);


	 header('location:media.php?module=home');

	 //echo $id_sp;
//	 echo "<br> $nm_lemb";
}
?>
