<?php

/******************************************************************

	Sample INDEXU Integration codes
	This file should be in 3rd party script

******************************************************************/


include "nusoap.php";

/******************************************************************/

$indexu_username = "dody";
$indexu_password = "dody";
$indexu_soap_key = "aabbcc";
$indexu_soap_url = "http://localhost/indexu/dev/upload/soap/server.php";

IndexuLogin($indexu_username, $indexu_password); 


/******************************************************************/
/* DO NOT CHANGE THE CODES BELOW                                  */
/******************************************************************/

function IndexuLogin($username, $password) {
	/*
		1. TestAuth
		2. GetUrl 
		3. Set indexu cookie
	*/

	global $indexu_soap_key, $indexu_soap_url;	
	
	// TestAuth
	
  $parameters = array('api_key'  => $indexu_soap_key,
                      'username' => $username,
                      'password' => $password);
  $soapclient = new soapclient($indexu_soap_url);
  $auth = $soapclient->call('TestAuth',$parameters);
	
	if ($auth==0) {

		// GetUrl 

	  $parameters = array('api_key' => $indexu_soap_key);
  	$soapclient = new soapclient($indexu_soap_url);
  	$url = $soapclient->call('GetUrl',$parameters);
		
		// set indexu cookie
		
		$arr = parse_url($url);
		$domain = $arr['host'];
		$path   = $arr['path'];
		$expire = time()+(3600*24*30); 
		
    setcookie("COOKIE_USER_AUTHENTICATED", //string name
              "1",                         //string value
              $expire,                     //int expire
              "$path",                     //string path
              "$domain",                   //string domain
              0                            //int secure
    );

    setcookie("COOKIE_USERNAME", //string name
              "$username",       //string value
               $expire,           //int expire
               "$path",           //string path
               "$domain",         //string domain
               0                  //int secure
    );

    setcookie("COOKIE_PASSWORD", //string name
              "$password",       //string value
              $expire,           //int expire
              "$path",           //string path
              "$domain",         //string domain
              0                  //int secure
    );		
	}
}

?>