<?php
include("SOAP/Client.php");

class mantisconnect{
	function __construct($url,$user,$password)
	{
		$this->soapclient =  new SOAP_Client($url."?wsdl",true);
		$this->soapoptions = array('namespace' => 'http://futureware.biz/mantisconnect', 'trace' => 0);

		$this->username    = $user;
		$this->password    = $password;
		$this->error_code  = 0; // error message
		$this->error_msg   = ""; // error message
	}

	function docall($function,$params)
	{
		$ret = $this->soapclient->call($function,$params, $this->soapoptions);

		if (PEAR::isError($ret))
		{
			$this->error_code =  $ret->getCode(); 
			$this->error_msg  =  $ret->getMessage();
			return null;
		}
		$this->error_code  = 0; // error message
		$this->error_msg   = ""; // error message
		return $ret;	
	}

	function mc_enum_priorities()
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password
        	);
		return $this->docall(__FUNCTION__,$params);
	}

	function mc_enum_reproducibilities()
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password
        	);
		return $this->docall(__FUNCTION__,$params);
	}

	function mc_enum_severities()
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password
        	);
		return $this->docall(__FUNCTION__,$params);
	}

	function mc_project_get_categories($id)
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password,
		    'project_id' => $id
        	);
		return $this->docall(__FUNCTION__,$params);
	}

	function mc_issue_get($id)
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password,
		    'issue_id' => $id
        	);
		return $this->docall(__FUNCTION__,$params);
	}

	function mc_issue_add($issue)
	{
 		$params = array(
                'username' => $this->username, 
                'password' => $this->password,
		    'issue' => $issue
        	);
		return $this->docall(__FUNCTION__,$params);
	}

}


/**** helper classes ****/

class mc_issue{
	function __construct()
	{
	$this->id= 0;
      $this->view_state   = null;
	$this->last_updated = null;
	$this->project      = null;
	$this->category     = null;
    	$this->priority     = null;
      $this->severity     = null;
      $this->status=null;
      $this->reporter=null;

    	$this->summary=null;
	$this->version=null;
      $this->build=null;
      $this->platform=null;
      $this->os=null;
      $this->os_build=null;
      $this->reproducibility=null;

    $this->date_submitted=null;
    $this->sponsorship_total=null;
    $this->handler=null;
    $this->projection=null;

    $this->eta=null;

    $this->resolution=null;

    $this->fixed_in_version=null;
    $this->description=null;
    $this->steps_to_reproduce=null;
    $this->additional_information=null;
    $this->attachments = array();
    $this->relationships = array();
    $this->notes = array();
    $this->custom_fields = array();
}

}

class mc_enum
{
function __construct($id, $name=null)
{
	if($id != null)
	{
		$this->id = $id;
	}
	if($name != null)
	{
		$this->name = $name;
	}
}
}
