| 1 |
<?php // $Id: qbwc.inc,v 1.7 2009/02/03 21:31:26 vauxia Exp $ |
<?php // $Id: qbwc.inc,v 1.8 2009/02/19 05:28:21 vauxia Exp $ |
| 2 |
|
|
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 11 |
*/ |
*/ |
| 12 |
function qbwc() { |
function qbwc() { |
| 13 |
global $base_url; |
global $base_url; |
| 14 |
$wsdl = $base_url .'/'. drupal_get_path('module', 'qbwc') .'/qbwc.wsdl'; |
|
| 15 |
$qbwc = new SoapServer($wsdl, array('uri' => variable_get('qbwc_url', ''))); |
if (!isset($_SERVER['HTTP_SOAPACTION'])) { |
| 16 |
$qbwc->setClass('qbwc'); |
// No callback function has been defined, so return nothing. |
| 17 |
$qbwc->handle(); |
echo ''; |
| 18 |
|
} |
| 19 |
|
else { |
| 20 |
|
// Pass the request to the SoapServer. |
| 21 |
|
$wsdl = dirname(__FILE__) .'/qbwc.wsdl'; |
| 22 |
|
$qbwc = new SoapServer($wsdl, array('uri' => variable_get('qbwc_url', ''))); |
| 23 |
|
$qbwc->setClass('qbwc'); |
| 24 |
|
$qbwc->handle(); |
| 25 |
|
return; |
| 26 |
|
} |
| 27 |
} |
} |
| 28 |
|
|
| 29 |
class qbwc { |
class qbwc { |
| 37 |
// We cannot get back the original Server SOAP object, but we can at least |
// We cannot get back the original Server SOAP object, but we can at least |
| 38 |
// load the right session getting our session variables back. |
// load the right session getting our session variables back. |
| 39 |
function _session($ticket) { |
function _session($ticket) { |
| 40 |
|
global $user; |
| 41 |
|
|
| 42 |
|
// The user has already been authenticated for some reason. |
| 43 |
|
if ($user->uid) return; |
| 44 |
|
|
| 45 |
if ($row = db_fetch_object(db_query("SELECT * FROM {qbwc} |
if ($row = db_fetch_object(db_query("SELECT * FROM {qbwc} |
| 46 |
WHERE ticket = '%s' AND timestamp_end >= %d", $ticket, time()))) { |
WHERE ticket = '%s' AND timestamp_end >= %d", $ticket, time()))) { |
| 47 |
|
|
| 48 |
$this->qbwc_id = $row->qbwc_id; |
$this->qbwc_id = $row->qbwc_id; |
| 49 |
$this->sid = $row->sid; |
$this->sid = $row->sid; |
| 50 |
|
|
| 51 |
// Pretend that cookies are enabled so we can get back our session |
// Remove any session that may have been started prior to this call. |
| 52 |
$_COOKIE[$row->sid] = TRUE; |
session_destroy(); |
| 53 |
return session_start(); |
|
| 54 |
|
// Pretend that cookies are enabled so we can get back our session. |
| 55 |
|
$_COOKIE[session_name()] = $row->sid; |
| 56 |
|
session_id($row->sid); |
| 57 |
|
|
| 58 |
|
// Re-run the session initiation phase of drupal_bootstrap. |
| 59 |
|
_drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); |
| 60 |
|
return TRUE; |
| 61 |
} |
} |
| 62 |
|
|
| 63 |
// Invalid session |
// Invalid session |
| 94 |
'timestamp_end' => time() + 1800, // Limit the session to 30 minutes. |
'timestamp_end' => time() + 1800, // Limit the session to 30 minutes. |
| 95 |
); |
); |
| 96 |
drupal_write_record('qbwc', $qbwc); |
drupal_write_record('qbwc', $qbwc); |
| 97 |
|
|
| 98 |
$this->qbwc_id = $qbwc->qbwc_id; |
$this->qbwc_id = $qbwc->qbwc_id; |
| 99 |
|
$this->sid = $qbwc->sid; |
| 100 |
|
|
| 101 |
// Initialize our session variable namespace and record the start time. |
// Initialize our session variable namespace and record the start time. |
| 102 |
// The timestamp will now be available via qbwc_get('time'). |
// The timestamp will now be available via qbwc_get('time'). |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
function closeConnection($params) { |
function closeConnection($params) { |
|
$ticket = $params->ticket; |
|
|
$this->_session($ticket); |
|
| 127 |
global $user; |
global $user; |
| 128 |
|
|
| 129 |
|
$this->_session($params->ticket); |
| 130 |
|
|
| 131 |
// Let modules know we are closing the session |
// Let modules know we are closing the session |
| 132 |
module_invoke_all('qbwc_close', $ticket); |
module_invoke_all('qbwc_close'); |
| 133 |
|
|
| 134 |
// Close the session and log it just like user_logout() sans drupal_goto. |
// Close the session and log it just like user_logout() sans drupal_goto. |
| 135 |
watchdog('user', t('Session closed for %name.', array('%name' => $user->name))); |
watchdog('user', t('Session closed for %name.', array('%name' => $user->name))); |
| 159 |
return 'done'; |
return 'done'; |
| 160 |
} |
} |
| 161 |
|
|
| 162 |
function getLastError($ticket) { |
function getLastError($params) { |
| 163 |
|
$this->_session($params->ticket); |
| 164 |
$errors = array(); |
$errors = array(); |
| 165 |
foreach (qbwc_error() as $error) { |
foreach (qbwc_error() as $error) { |
| 166 |
} |
} |
| 174 |
} |
} |
| 175 |
|
|
| 176 |
function sendRequestXML($params) { |
function sendRequestXML($params) { |
| 177 |
$ticket = $params->ticket; |
$this->_session($params->ticket); |
| 178 |
|
|
| 179 |
$hcp_response = $params->strHCPResponse; |
$hcp_response = $params->strHCPResponse; |
| 180 |
$company_file = $params->strCompanyFileName; |
$company_file = $params->strCompanyFileName; |
| 181 |
$country = $params->qbXMLCountry; |
$country = $params->qbXMLCountry; |
| 182 |
$major_version = $params->qbXMLMajorVers; |
$major_version = $params->qbXMLMajorVers; |
| 183 |
$minor_version = $params->qbXMLMinorVers; |
$minor_version = $params->qbXMLMinorVers; |
| 184 |
|
|
|
$this->_session($ticket); |
|
|
|
|
| 185 |
// Default: If the web service has no requests to send, use an empty string. |
// Default: If the web service has no requests to send, use an empty string. |
| 186 |
$ret = ''; |
$ret = ''; |
| 187 |
|
|
| 215 |
} |
} |
| 216 |
|
|
| 217 |
function receiveResponseXML($params) { |
function receiveResponseXML($params) { |
| 218 |
$ticket = $params->ticket; |
$this->_session($params->ticket); |
| 219 |
|
|
| 220 |
$response = DOMDocument::loadXML($params->response); |
$response = DOMDocument::loadXML($params->response); |
| 221 |
$hresult = $params->hresult; |
$hresult = $params->hresult; |
| 222 |
$message = $params->message; |
$message = $params->message; |
| 223 |
|
|
|
$this->_session($ticket); |
|
|
|
|
| 224 |
// Get the original list of requests and reset the queue. |
// Get the original list of requests and reset the queue. |
| 225 |
$requests = qbwc_request_queue(NULL, TRUE); |
$requests = qbwc_request_queue(NULL, TRUE); |
| 226 |
|
|
| 312 |
* session_regenerate(), so make sure we can find it next time. |
* session_regenerate(), so make sure we can find it next time. |
| 313 |
*/ |
*/ |
| 314 |
function __destruct() { |
function __destruct() { |
| 315 |
if ($this->sid && ($this->sid != session_id())) { |
if ($this->qbwc_id && ($this->sid != session_id())) { |
| 316 |
$qbwc = array('qbwc_id' => $this->qbwc_id, 'sid' => session_id()); |
$qbwc = array('qbwc_id' => $this->qbwc_id, 'sid' => session_id()); |
| 317 |
drupal_write_record('qbwc', $qbwc, 'qbwc_id'); |
drupal_write_record('qbwc', $qbwc, 'qbwc_id'); |
| 318 |
} |
} |