public function renewItemViaSIP($patronId, $itemId, $useAlternateSIP = false) { global $configArray; global $user; //renew the item via SIP 2 $mysip = new sip2(); $mysip->hostname = $configArray['SIP2']['host']; if ($useAlternateSIP) { $mysip->port = $configArray['SIP2']['alternate_port']; } else { $mysip->port = $configArray['SIP2']['port']; } $hold_result['itemId'] = $itemId; $hold_result['title'] = $itemId; $hold_result['result'] = false; if ($mysip->connect()) { //send selfcheck status message $in = $mysip->msgSCStatus(); $msg_result = $mysip->get_message($in); // Make sure the response is 98 as expected if (preg_match("/^98/", $msg_result)) { $result = $mysip->parseACSStatusResponse($msg_result); // Use result to populate SIP2 setings $mysip->AO = $result['variable']['AO'][0]; /* set AO to value returned */ $mysip->AN = $result['variable']['AN'][0]; /* set AN to value returned */ $mysip->patron = $user->cat_username; $mysip->patronpwd = $user->cat_password; $in = $mysip->msgRenew($itemId, '', '', '', 'N', 'N', 'Y'); //print_r($in . '<br/>'); $msg_result = $mysip->get_message($in); //print_r($msg_result); if (preg_match("/^30/", $msg_result)) { $result = $mysip->parseRenewResponse($msg_result); $hold_result['title'] = $result['variable']['AJ'][0]; //print_r($result); $hold_result['result'] = $result['fixed']['Ok'] == 1; $hold_result['message'] = $result['variable']['AF'][0]; //If the renew fails, check to see if we need to override the SIP port $alternatePortSet = false; if (isset($configArray['SIP2']['alternate_port']) && strlen($configArray['SIP2']['alternate_port']) > 0 && $configArray['SIP2']['alternate_port'] != $configArray['SIP2']['port']) { $alternatePortSet = true; } if ($alternatePortSet && $hold_result['result'] == false && $useAlternateSIP == false) { //Can override the SIP port if there are sufficient copies on the shelf to cover any holds //Get the id for the item $searchObject = SearchObjectFactory::initSearchObject(); $record = $searchObject->getRecordByBarcode($itemId); if ($record) { //Get holdings summary $statusSummary = $this->getStatusSummary($record['id'], $record, $mysip); //If # of available copies >= waitlist change sip port and renew if ($statusSummary['availableCopies'] >= $statusSummary['holdQueueLength']) { $hold_result = $this->renewItemViaSIP($patronId, $itemId, true); } } } } } } else { $hold_result['message'] = "Could not connect to circulation server, please try again later."; } return $hold_result; }