<?php

  include "nusoap.php";

/*
  $parameters = array('api_key'=>'aabbcc',
                      'username'=>'hore3dd34gssvds',
                      'password'=>'123f',
                      'email'=>'hore2@yes.com');
  $soapclient = new soapclient('http://localhost/indexu/dev/upload/soap/server.php');
  $t = $soapclient->call('AddNewUser',$parameters);
  print_r($t);
*/

 
/* 
  $parameters = array('api_key'=>'aabbcc',
                      'username'=>'hore3dd34gssvds',
                      'new_password'=>'dody');
  $soapclient = new soapclient('http://localhost/indexu/dev/upload/soap/server.php');
  $t = $soapclient->call('SetPassword',$parameters);
  print_r($t);
*/

/*
  $parameters = array('api_key'=>'aabbcc');
  $soapclient = new soapclient('http://localhost/indexu/dev/upload/soap/server.php');
  $t = $soapclient->call('GetPath',$parameters);
  print_r($t);
*/

/*
  $parameters = array('api_key'=>'aabbcc',
                      'username'=>'admin',
                      'password'=>'admin');
  $soapclient = new soapclient('http://localhost/indexu/dev/upload/soap/server.php');
  $t = $soapclient->call('TestAuth',$parameters);
  print_r($t);
*/

$info = array(
	'category_id' => '43',
	'title'       => "testing's soap22",
	'url'         => "http://www.tes234.com"
);

  $parameters = array('api_key'=>'aabbcc',
                      'link_data'=>$info);
  $soapclient = new soapclient('http://localhost/indexu/dev/upload/soap/server.php');
  $t = $soapclient->call('AddNewLink',$parameters);
  print_r($t);





//Login();
//Logout();

function Login() {
	/*
		1. TestAuth
		2. GetUrl 
		3. Set indexu cookie
	*/
	
	$username = "dody";
	$password = "dody";
	$key      = "aabbcc";
	$soap_url = "http://localhost/indexu/dev/upload/soap/server.php";
	
	// TestAuth
	
  $parameters = array('api_key'  => $key,
                      'username' => $username,
                      'password' => $password);
  $soapclient = new soapclient($soap_url);
  $auth = $soapclient->call('TestAuth',$parameters);
	
	if ($auth==0) {

		// GetUrl 

	  $parameters = array('api_key' => $key);
  	$soapclient = new soapclient($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
    );
		
		
		header("Location: cookie.php");
	}
}


function Logout() {
	
	$username = "dody";
	$password = "dody";
	$key      = "aabbcc";
	$soap_url = "http://localhost/indexu/dev/upload/soap/server.php";
	
  // GetUrl 

  $parameters = array('api_key' => $key);
 	$soapclient = new soapclient($soap_url);
 	$url = $soapclient->call('GetUrl',$parameters);

		
	$arr = parse_url($url);
	$domain = $arr['host'];
	$path   = $arr['path'];
	$expire = time()-3600; 
		
  setcookie("COOKIE_USER_AUTHENTICATED", //string name
            "",                         //string value
            $expire,                     //int expire
            "$path",                     //string path
            "$domain",                   //string domain
            0                            //int secure
  );

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

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

		
	header("Location: cookie.php");	
}

?>