PHP Code:
function _connect() {
if (is_null($this->_conn)) {
$this->_soap = @new soapclient($this->_config['helpdesk_soap_url'] . '?wsdl',true);
if ($err = $this->_soap->getError()) {
array_push($this->_error, $err);
return false;
}
$this->_conn = $this->_soap->getProxy();
if ($err = $this->_soap->getError()) {
array_push($this->_error, $err);
return false;
}
}
return $this->_conn;
}
function _name_value_pair_to_simple_array($aValuePair){
$aSimpleArray=array();
while(list($sName,$aValue) = each($aValuePair)){
$aSimpleArray[$aValue['name']] = $aValue['value'];
}
return $aSimpleArray;
}
function getError() {
if (count($this->_error)) {
return $this->_error;
}
return false;
}
function _login() {
if (is_null($this->_sess)) {
$params = array(
'user_name' => $this->_config['helpdesk_soap_user'],
'password' => $this->_config['helpdesk_soap_pass'],
'version' => '.01'
);
if ($result = $this->_request('login',array($params, $this->_config['helpdesk_soap_portal']))) {
$this->_sess = $result['id'];
} else {
return false;
}
}
return $this->_sess;
}
function _request($sAction, $aParams){
if ($this->_connect()) {
$aResult = $this->_conn->call($sAction, $aParams);
// check for errors
if ($err = $this->_soap->getError()) {
array_push($this->_error, $err);
return false;
}
switch ($sAction) {
case 'get_entry_list':
$aMyResult = array();
if (is_array($aResult['entry_list'])) {
foreach ($aResult['entry_list'] as $iKey => $aArray) {
$aMyResult[$iKey] = $this->_name_value_pair_to_simple_array($aArray['name_value_list']);
}
}
return $aMyResult;
break;
case 'get_relationships':
return $aResult['ids'];
break;
default:
break;
}
return $aResult;
}
return false;
}
function set_contact($helpdesk_info=null, $contact_id=null) {
if (!is_null($this->_login()) && !is_null($helpdesk_info)) {
$set_fields_params = array();
if (!is_null($contact_id)) $set_fields_params[] = array('name' => 'id', 'value' => $contact_id);
$set_fields_params[] = array('name' => 'email1', 'value' => $helpdesk_info['email1']);
$set_fields_params[] = array('name' => 'last_name', 'value' => $helpdesk_info['last_name']);
$set_fields_params[] = array('name' => 'first_name', 'value' => $helpdesk_info['first_name']);
$set_fields_params[] = array('name' => 'salutation', 'value' => $helpdesk_info['salutation']);
$set_fields_params[] = array('name' => 'description', 'value' => $helpdesk_info['description']);
$set_fields_params[] = array('name' => 'phone_work', 'value' => $helpdesk_info['phone_work']);
// $set_fields_params[] = array('name' => 'date_entered', 'value' => date('Y-m-d H:i:s', $helpdesk_info['date_entered']));
// $set_fields_params[] = array('name' => 'date_modified', 'value' => date('Y-m-d H:i:s', $helpdesk_info['date_modified']));
$set_fields_params[] = array('name' => 'portal_name', 'value' => $helpdesk_info['portal_name']);
$set_fields_params[] = array('name' => 'portal_active', 'value' => 1);
$params = array(
'session' => $this->_sess,
'module_name' => 'Contacts',
'name_value_list' => $set_fields_params
);
if ($result = $this->_request('set_entry',$params)) {
return $result['id'];
}
}
return false;
}
function get_contacts($where='', $maxnum=10, $offset=0, $orderby=' contacts.last_name ASC') {
if (!is_null($this->_login())) {
$params = array(
$this->_sess,
'Contacts',
$where,
$orderby,
$offset,
array(
'id',
'first_name',
'last_name',
'salutation',
'account_name',
'account_id',
'email1',
'phone_work',
'portal_name',
'date_entered',
'date_modified'
),
$maxnum,
false
);
if ($result = $this->_request('get_entry_list',$params)) {
if ($maxnum == 1) {
return $result[0];
} else {
return $result;
}
}
}
return false;
}
function get_cases($where='', $maxnum=10, $offset=0, $orderby=' cases.date_modified DESC') {
if (!is_null($this->_login())) {
$params = array(
$this->_sess,
'Cases',
$where,
$orderby,
$offset,
array(
'id',
'case_number',
'name',
'status',
'date_modified'
),
$maxnum,
false
);
$result = $this->_request('get_entry_list',$params);
return $result;
}
}
Bookmarks