예제 #1
0
파일: index.php 프로젝트: Ratler/phpipam
 *
 */
# include funtions
require dirname(__FILE__) . '/../../functions/functions.php';
// functions and objects from phpipam
require dirname(__FILE__) . '/controllers/Common.php';
// common methods
require dirname(__FILE__) . '/controllers/Responses.php';
// exception, header and response handling
# settings
$enable_authentication = true;
# database object
$Database = new Database_PDO();
$Tools = new Tools($Database);
# exceptions/result object
$Response = new Responses();
# get phpipam settings
$settings = $Tools->fetch_object("settings", "id", 1);
# set empty controller for options
if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
    if (!isset($_GET['controller']) || $_GET['controller'] == "") {
        $_GET['controller'] = "Tools";
    }
}
/* wrap in a try-catch block to catch exceptions */
try {
    /* Validate application ---------- */
    // verify that API is enabled on server
    if ($settings->api != 1) {
        $Response->throw_exception(503, "API server disabled");
    }
예제 #2
0
 /**
  * Adds an expert response to a question. This action has the effect of generating an email to the person asking
  * the questions as well as setting the question state to read + responded for this expert
  *
  * @param $questionId
  * @param $expertUserName
  * @param $responseText
  *
  * @return \Responses
  */
 public function addResponse($questionId, $expertUserName, $responseText)
 {
     $response = new \Responses();
     $response->setQuestionId($questionId);
     $response->setExpert($expertUserName);
     $response->setResponse($responseText);
     $response->save();
     return $response;
 }
예제 #3
0
 public function getApiResponses($workorder_id, $section_id)
 {
     return Responses::where('workorder_id', $workorder_id)->where('section_id', $section_id)->get();
 }
예제 #4
0
// functions and objects from phpipam
require dirname(__FILE__) . '/controllers/Common.php';
// common methods
require dirname(__FILE__) . '/controllers/Responses.php';
// exception, header and response handling
# settings
$enable_authentication = true;
$time_response = true;
// adds [time] to response
$lock_file = "";
// (optional) file to write lock to
# database object
$Database = new Database_PDO();
$Tools = new Tools($Database);
# exceptions/result object
$Response = new Responses();
# get phpipam settings
if (SETTINGS === null) {
    $settings = $Tools->fetch_object("settings", "id", 1);
}
# set empty controller for options
if ($_SERVER['REQUEST_METHOD'] == "OPTIONS") {
    if (!isset($_GET['controller']) || $_GET['controller'] == "") {
        $_GET['controller'] = "Tools";
    }
}
/* wrap in a try-catch block to catch exceptions */
try {
    // start measuring
    $start = microtime(true);
    /* Validate application ---------- */
예제 #5
0
 /**
  * Exists with exception
  *
  * @access public
  * @param mixed $content
  * @return void
  */
 public function throw_exception($content)
 {
     // include Exceptions class for API
     include_once dirname(__FILE__) . '../../../api/v2/controllers/Responses.php';
     // initialize exceptions
     $Exceptions = new Responses();
     // throw error
     $Exceptions->throw_exception(500, $content);
 }
예제 #6
0
 private function getFirstMessage($agent)
 {
     /*
     	NOTE:  CHRISTOPHER WHITELEY
     	Within this section we have allowed the alteration of how SIF Ack messages are needed.
     	If $sif_response, $sif_request, and $sif_event are set to a value of 2 then your system
     	will work according to SIF Specifications.  If you do not want to send a SIF_Ack message
     	for any of the three message types below you can change the value to 3.
     This functionality was done per request of a paid support member.
     */
     $sif_response = 2;
     $sif_request = 2;
     $sif_event = 2;
     $sif_ack = 2;
     $empty = null;
     $zero = 0;
     $id = $zero;
     $db = Zend_Registry::get('my_db');
     #		$mysql =   ''
     #				.' ('
     #				.' Select response_id v, 1 t '
     #				.' from ' .DBConvertor::convertCase('response').' where status_id in (1,2) '
     #				.' and agent_id_requester = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID']
     #				.') '
     #				.' union all '
     #				.' ('
     #				.' Select request_id v, 2 t '
     #				.' from ' .DBConvertor::convertCase('request').' where status_id in (1,2) '
     #				.' and agent_id_responder = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID']
     #				.') '
     #				.' union all '
     #				.' ('
     #				.'Select event_id v, 3 t '
     #				.' from ' .DBConvertor::convertCase('event').' where status_id in (1,2) '
     #				.' and agent_id_rec = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID']
     #				.')'
     #				.' ORDER BY t, v LIMIT 1';
     $oracle = 'Select v, t from ( Select response_id v, 1 t ' . ' from ' . DBConvertor::convertCase('response') . ' where status_id in (1,2) ' . ' and agent_id_requester = ' . $agent->agentId . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ' union all ' . 'Select request_id v, 2 t ' . 'from ' . DBConvertor::convertCase('request') . ' where status_id in (1,2) ' . '   and agent_id_responder = ' . $agent->agentId . '   and context_id = ' . $_SESSION['CONTEXT_ID'] . '   and zone_id = ' . $_SESSION['ZONE_ID'] . ' union all ' . 'Select event_id v, 3 t ' . ' from ' . DBConvertor::convertCase('event') . ' where status_id in (1,2) ' . ' and agent_id_rec = ' . $agent->agentId . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ') ORDER BY t, v';
     $mysql = 'select id, msg_type, data ' . ' from ' . DBConvertor::convertCase('messagequeue') . ' where agt_id_out = ' . $agent->agentId . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and status_id in (1,2) ' . ' order by status_id desc, msg_type asc, insert_timestamp asc' . ' Limit 1';
     switch (DB_TYPE) {
         case 'mysql':
             $sql = $mysql;
             break;
         case 'oci8':
             $sql = $oracle;
             $db->setLobAsString(true);
             break;
     }
     try {
         $stmt = $db->query($sql);
         $result = $stmt->fetchAll();
     } catch (Zend_Exception $e) {
         ZitLog::writeToErrorLog("[SystemControl]", "Errors:{$e->getTraceAsString}() \n \n {$sql}", "Try|Catch block", $_SESSION['ZONE_ID']);
         GeneralError::systemError($xml);
     }
     switch (DB_TYPE) {
         case 'mysql':
             $id = isset($result[0]->id) ? $result[0]->id : $zero;
             #				$msgType = isset($result[0]->msg_type) ? $result[0]->msg_type : $zero;
             $msgType = 4;
             $XMLData = isset($result[0]->data) ? $result[0]->data : $zero;
             break;
         case 'oci8':
             $id = isset($result[0]->V) ? $result[0]->V : $zero;
             $msgType = isset($result[0]->T) ? $result[0]->T : $zero;
             break;
     }
     //		ZitLog::writeToErrorLog("[SystemControl]", "id: $id --> msgType: $msgType\n\n", "Record Found?", $_SESSION['ZONE_ID']);
     if ($id != $zero) {
         switch ($msgType) {
             case 1:
                 /*****
                 			ORACLE ONLY
                 			$SIF_ACK is used to set the status of the message read. The SIF Standard states that you should 
                 			set this value to 2 so that the item can be requested again if an error happens. Setting the item
                 			to a 3 will allow you not to send a SIF_Ack Message.
                 			*****/
                 $response = new Responses($db);
                 $where = "response_id = {$id}";
                 $result2 = $response->fetchAll($where);
                 foreach ($result2 as $row) {
                     switch (DB_TYPE) {
                         case 'mysql':
                             $status_id = $row->status_id;
                             $responseData = $row->response_data;
                             break;
                         case 'oci8':
                             $status_id = $row->STATUS_ID;
                             $responseData = $row->RESPONSE_DATA;
                             break;
                     }
                 }
                 $dom = new DomDocument();
                 $dom->loadXML($responseData);
                 $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0);
                 $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue;
                 $data = array(DBConvertor::convertCase('status_id') => $sif_response, DBConvertor::convertCase('msg_id') => $msgId);
                 $n = $response->update($data, 'response_id = ' . $id);
                 return $responseData;
                 break;
             case 2:
                 /*****
                 			ORACLE ONLY
                 			$SIF_ACK is used to set the status of the message read. The SIF Standard states that you should 
                 			set this value to 2 so that the item can be requested again if an error happens. Setting the item
                 			to a 3 will allow you not to send a SIF_Ack Message.
                 			*****/
                 $request = new Requests($db);
                 $where = "request_id = {$id}";
                 $result = $request->fetchAll($where);
                 foreach ($result as $row) {
                     switch (DB_TYPE) {
                         case 'mysql':
                             $status_id = $row->status_id;
                             $requestData = $row->request_data;
                             break;
                         case 'oci8':
                             $status_id = $row->STATUS_ID;
                             $messageDataXML = $row->REQUEST_DATA;
                             //	$requestData = $messageDataXML->read($messageDataXML->size());
                             $requestData = $messageDataXML;
                             break;
                     }
                 }
                 $dom = new DomDocument();
                 $dom->loadXML($requestData);
                 $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0);
                 $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue;
                 $data = array(DBConvertor::convertCase('status_id') => $sif_request, DBConvertor::convertCase('msg_id') => $msgId);
                 $n = $request->update($data, 'request_id = ' . $id);
                 return $requestData;
                 break;
             case 3:
                 /*****
                 			ORACLE ONLY
                 			$SIF_ACK is used to set the status of the message read. The SIF Standard states that you should 
                 			set this value to 2 so that the item can be requested again if an error happens. Setting the item
                 			to a 3 will allow you not to send a SIF_Ack Message.
                 			*****/
                 $event = new Events($db);
                 $where = "event_id = {$id}";
                 $result = $event->fetchAll($where);
                 foreach ($result as $row) {
                     switch (DB_TYPE) {
                         case 'mysql':
                             $status_id = $row->status_id;
                             $eventData = $row->event_data;
                             break;
                         case 'oci8':
                             $status_id = $row->STATUS_ID;
                             $eventData = $row->EVENT_DATA;
                             break;
                     }
                 }
                 $dom = new DomDocument();
                 $dom->loadXML($eventData);
                 $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0);
                 $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue;
                 $data = array(DBConvertor::convertCase('status_id') => $sif_event, DBConvertor::convertCase('msg_id') => $msgId);
                 $n = $event->update($data, 'event_id = ' . $id);
                 return $eventData;
                 break;
             case 4:
                 $message = new MessageQueues($db);
                 /*****
                 			$SIF_ACK is used to set the status of the message read. The SIF Standard states that you should 
                 			set this value to 2 so that the item can be requested again if an error happens. Setting the item
                 			to a 3 will allow you not to send a SIF_Ack Message.
                 			*****/
                 $data = array(DBConvertor::convertCase('status_id') => $sif_ack);
                 $n = $message->update($data, 'id = ' . $id);
                 return $XMLData;
                 break;
         }
     } else {
         return null;
     }
 }