public function processRequestMessages()
 {
     $db = ZitDBAdapter::getDBAdapter();
     $query = "select \r\n\t\t\t      \trequest_data,\r\n\t\t\t\t\tagent_registered.callback_url,\r\n\t\t\t\t\tagent_registered.frozen,\r\n\t\t\t\t\trequest_id\r\n\t\t\t\t  from\r\n\t\t\t\t  \trequest\r\n\t\t\t\t  inner join\r\n\t\t\t\t  \tagent_registered on request.agent_id_responder = agent_registered.agent_id\r\n\t\t\t\t   where\r\n\t\t\t\t  \trequest.status_id in (1,2)\r\n\t\t\t\t  and\r\n\t\t\t\t  \tagent_registered.asleep = 0\r\n\t\t\t\t  and\r\n\t\t\t\t  \trequest.agent_mode_id = 1\r\n\t\t\t\t  and\r\n\t\t\t\t  \trequest.zone_id = " . $this->zoneId . "\r\n\t\t\t\t  and\r\n\t\t\t\t\tagent_registered.zone_id = " . $this->zoneId . "\r\n\t\t\t\t  and \r\n\t\t\t\t  \trequest.context_id = " . $this->contextId . "\r\n\t\t\t\t  and \r\n\t\t\t\t\tagent_registered.context_id = " . $this->contextId;
     $result = $db->fetchAll($query);
     foreach ($result as $row) {
         if ($row->frozen != 1) {
             $timestamp = Utility::createTimestamp();
             $msgId = Utility::createMessageId();
             $xml = XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->zoneName, $msgId, 0, $this->zoneVersion, $this->versionNamespace, $this->zoneName, $originalMsg = $row->request_data, $desc = null);
             $sendMessageResult = $this->sendMessage($xml, $row->callback_url, $this->zoneId, $this->contextId, $row->agent_id);
             echo 'here after';
             if (!$sendMessageResult['Error']) {
                 $data = array('status_id' => 2, 'msg_id' => $msgId);
                 $db->update('request', $data, 'request_id = ' . $row->request_id);
                 $processResponseResult = $this->processResponseMessage($sendMessageResult['Xml'], $this->zoneId, $this->contextId, $row->agent_id);
                 if (!$processResponseResult['Error']) {
                     if ($processResponseResult['ImmediateUpdate']) {
                         $data = array('status_id' => 3, 'msg_id' => $msgId);
                         $db->update('request', $data, 'request_id = ' . $row->request_id);
                     }
                     ZitLog::writeToLog($sendMessageResult['Xml'], $xml, $this->zoneId, $row->agent_id, 6);
                 }
                 //check for errors in response
             } else {
                 $data = array('status_id' => 4, 'msg_id' => $msgId);
                 $db->update('request', $data, 'request_id = ' . $row->request_id);
             }
             //errors in request
         }
         //make sure agent is not frozen
     }
     //loop through results
 }
Example #2
0
 public static function buildErrorMessage($categoryCode, $errorCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, $writeToLog = true)
 {
     $root = XmlHelper::buildSifAckMessage($msgId, $timestamp, $originalSourceId, $originalMsgId);
     $sifAck = $root->getElementsByTagName('SIF_Ack');
     $sifErrorNode = $root->createElement('SIF_Error');
     $sifCategoryNode = $root->createElement('SIF_Category');
     $text = $root->createTextNode($categoryCode);
     $sifCategoryNode->appendChild($text);
     $sifCodeNode = $root->createElement('SIF_Code');
     $text = $root->createTextNode($errorCode);
     $sifCodeNode->appendChild($text);
     $sifShortDescNode = $root->createElement('SIF_Desc');
     $text = $root->createTextNode($shortDesc);
     $sifShortDescNode->appendChild($text);
     $sifLongDescNode = $root->createElement('SIF_ExtendedDesc');
     $text = $root->createTextNode($longDesc);
     $sifLongDescNode->appendChild($text);
     $sifErrorNode->appendChild($sifCategoryNode);
     $sifErrorNode->appendChild($sifCodeNode);
     $sifErrorNode->appendChild($sifShortDescNode);
     $sifErrorNode->appendChild($sifLongDescNode);
     $sifAck->item(0)->appendChild($sifErrorNode);
     $xmlStr = $root->saveXML();
     if ($writeToLog) {
         $_SESSION['SIF_MESSAGE_TYPE'] = 1;
         ZitLog::writeToLog(REC_XML, $xmlStr);
     }
     $length = strlen($xmlStr);
     header('Content-Length: ' . $length);
     echo $xmlStr;
     session_destroy();
     exit;
 }