Esempio n. 1
0
 /**
  * overridden from np_method , updates requests table row by 
  * request_id  and last transaction msg_type
  * 
  * 
  * @return int number of affected rows
  */
 public function saveToDB()
 {
     $updateArray = array('last_transaction' => $this->getHeaderField("MSG_TYPE"));
     $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
     $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
     return $tbl->update($updateArray, $whereArray);
 }
Esempio n. 2
0
 public function PostValidate()
 {
     $this->setAck($this->validateParams($this->getHeaders()));
     //first step is GEN
     if (!$this->checkDirection()) {
         return "Gen04";
     }
     //HOW TO CHECK Gen05
     //		if (!$this->ValidateDB()) {
     //			return "Gen07";
     //		}
     if (($timer_ack = Np_Timers::validate($this)) !== TRUE) {
         return $timer_ack;
     }
     $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
     $updateArray = array('last_transaction' => $this->getHeaderField("MSG_TYPE"));
     // if we received success return_response and we are not the initiator we need to publish it after (so leave it with status on)
     if ($this->getHeaderField("TO") == Application_Model_General::getSettings('InternalProvider')) {
         $updateArray['status'] = 0;
     } else {
         $updateArray['status'] = 1;
     }
     $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
     if (!$tbl->update($updateArray, $whereArray)) {
         return false;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * extended function from parent Np_Method
  * checks if db object exists and last transaction is Cancel
  * 
  * @return bool 
  */
 public function saveToDB()
 {
     if ($this->checkApprove() === TRUE) {
         $updateArray = array('status' => 0, 'last_transaction' => $this->getHeaderField("MSG_TYPE"));
         $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         return $tbl->update($updateArray, $whereArray);
     }
     return FALSE;
 }
Esempio n. 4
0
 public function saveToDB()
 {
     if ($this->getHeaderField("TRX_NO")) {
         //this is a request from provider!
         //save a new row in Requests DB
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         $data = array('status' => 1, 'request_id' => $this->getHeaderField("REQUEST_ID"), 'phone_number' => $this->getBodyField("NUMBER"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'last_transaction' => $this->getHeaderField("MSG_TYPE"));
         return $tbl->insert($data);
     }
     //else //this request is from cron! internal is sending to all providers
     //don't save in Requests DB
 }
Esempio n. 5
0
 /**
  * overridden function from parent Np_Method
  * 
  * inserts row to requests table
  * 
  * @return bool 
  */
 public function saveToDB()
 {
     //INSERT into Requests
     if ($this->getHeaderField("TO") == Application_Model_General::getSettings('InternalProvider')) {
         // if the check received from external provider create request
         // request id already exists
         //else - it's from internal - already INSERT into Requests
         $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("FROM"), 'to_provider' => $this->getHeaderField("TO"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER"));
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         return $tbl->insert($data);
     }
 }
Esempio n. 6
0
 protected function checkApprove()
 {
     // reset request id if check response not succeed
     if (!parent::checkApprove()) {
         $updateArray = array('status' => 0);
         $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         $tbl->update($updateArray, $whereArray);
         return false;
     }
     return true;
 }
Esempio n. 7
0
 public function saveToDB()
 {
     //		if ($this->checkApprove() === FALSE) {
     //			return FALSE;
     //		}
     //        $transfer_time = $this->getBodyField("PORT_TIME");
     $msg_type = $this->getHeaderField("MSG_TYPE");
     $updateArray = array('status' => 1, 'last_transaction' => $msg_type);
     $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
     $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
     $ret = $tbl->update($updateArray, $whereArray);
     return $ret;
 }
Esempio n. 8
0
 /**
  * overridden from parent
  * 
  * update status,last_transaction and transfer_time in requests table by 
  * request_id
  * 
  * @return bool
  */
 public function saveToDB()
 {
     if ($this->checkApprove() === FALSE) {
         return FALSE;
     }
     $trxno = $this->getBodyField("REQUEST_TRX_NO");
     $msg_type = $this->getHeaderField("MSG_TYPE");
     $updateArray = array('status' => 1, 'last_transaction' => $msg_type, 'transfer_time' => application_model_general::getTrxPortTime($trxno));
     $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
     $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
     $ret = $tbl->update($updateArray, $whereArray);
     return $ret;
 }
Esempio n. 9
0
 /**
  * overridden from parent Np_Method
  * updates status and last transaction in requests table 
  * where request_id 
  * 
  * 
  * @return bool 
  */
 public function saveToDB()
 {
     if ($this->getHeaderField("FROM") == Application_Model_General::getSettings('InternalProvider')) {
         try {
             //send request response from internal to provider - update DB
             $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
             $updateArray = array('status' => 0, 'last_transaction' => $this->getHeaderField("MSG_TYPE"));
             $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
             return $tbl->update($updateArray, $whereArray);
         } catch (Exception $e) {
             error_log("Error on update record in requests table: " . $e->getMessage());
         }
     }
     //else //cron will take care of it. save only in transaction
 }
Esempio n. 10
0
 public function saveToDB()
 {
     if (parent::saveToDB()) {
         //this is a request from provider!
         //save a new row in Requests DB
         $flags = new stdClass();
         $flags->inquire = $this->getBodyField("CURRENT_OPERATOR");
         $data = array('last_transaction' => $this->getHeaderField("MSG_TYPE"), 'status' => 0, 'flags' => json_encode($flags));
         $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         $ret = $tbl->update($data, $whereArray);
         return $ret;
     }
     return false;
     //else //this request is from cron! internal is sending to all providers
     //don't save in Requests DB
 }
Esempio n. 11
0
 public function updateGoodPublish($reqId, $provider)
 {
     $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
     $where[] = "request_id ='" . $reqId . "' AND from_provider='" . $provider . "'";
     $res = $tbl->update(array('last_transaction' => 'Publish_response'), $where);
     return $res;
 }
Esempio n. 12
0
 public function saveRow($row)
 {
     $id = $row['id'];
     unset($row['id']);
     $table = $row['table'];
     unset($row['table']);
     // date fields empty should be set to null, else they will set to 00-00-00 00:00:00
     $date_fields_array = array('transfer_time', 'disconnect_time', 'connect_time');
     foreach ($date_fields_array as $field) {
         if (empty($row[$field])) {
             $row[$field] = null;
         }
     }
     $table_class = 'Application_Model_DbTable_' . ucfirst($table);
     if (class_exists($table_class)) {
         $table_object = new $table_class(Np_Db::master());
         $ret = $table_object->update($row, array('id = ' . $id));
         if (!$ret) {
             print "Nothing update...";
         }
         sleep(1.5);
     }
 }
Esempio n. 13
0
 /**
  * method triggered after internal response to NPG
  * 
  * @param object $internalResponseObject
  */
 public function postInternalRequest($internalResponseObject)
 {
     if ($this->getHeaderField("TO") == Application_Model_General::getSettings('InternalProvider')) {
         if (isset($internalResponseObject->connect_time)) {
             $connect_time = $internalResponseObject->connect_time;
         } else {
             $connect_time = time();
         }
         $updateArray = array('connect_time' => Application_Model_General::getDateTimeInSqlFormat($connect_time));
         $whereArray = array('request_id =?' => $this->getHeaderField("REQUEST_ID"));
         $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
         return $tbl->update($updateArray, $whereArray);
     }
     return true;
 }
Esempio n. 14
0
 /**
  *
  * @return String transfer date of autocheck if it's autocheck else false
  */
 protected function isAutoCheck()
 {
     $tbl = new Application_Model_DbTable_Requests(Np_Db::slave());
     $select = $tbl->select()->where('request_id=?', $this->params['REQUEST_ID'])->order('id DESC');
     $result = $select->query()->fetchObject();
     if ($result && $result->auto_check) {
         return Application_Model_General::getDateTimeInTimeStamp($result->transfer_time);
     }
     return false;
 }
Esempio n. 15
0
 /**
  * overridden function from parent Np_Method
  * 
  * inserts row to requests table
  * 
  * @return bool 
  */
 public function saveToDB()
 {
     if ($this->ValidateDB() === FALSE) {
         return FALSE;
     }
     if ($this->getHeaderField("FROM") != Application_Model_General::getSettings('InternalProvider')) {
         // if the check received from external provider create request
         // request id already exists
         //else - it's from internal - already INSERT into Requests
         try {
             $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER"));
             $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
             return $tbl->insert($data);
         } catch (Exception $e) {
             error_log("Error on create record in transactions table: " . $e->getMessage());
         }
     }
 }
Esempio n. 16
0
 /**
  * saveTransactionDB saves data to Transactions table in db
  * @return bool db Success or Failure 
  */
 protected function saveTransactionsDB($TRX = FALSE)
 {
     $tbl = new Application_Model_DbTable_Transactions(Np_Db::master());
     if ($TRX != FALSE) {
         $trxNo = $TRX;
     } else {
         $trxNo = $this->request->getHeaderField("TRX_NO");
     }
     $msgType = $this->request->getHeaderField("MSG_TYPE");
     $portTime = $this->request->getBodyField('PORT_TIME');
     $rejectReasonCode = $this->request->getRejectReasonCode();
     $reqId = $this->request->getHeaderField('REQUEST_ID');
     if ($trxNo) {
         $data = array('trx_no' => $trxNo, 'request_id' => $reqId, 'message_type' => $msgType, 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO"));
         if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") {
             // do nothing
         } else {
             $data['reject_reason_code'] = $rejectReasonCode;
         }
         if ($msgType == "Update" || $msgType == "Request") {
             $data['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime);
         }
         if ($msgType == "Publish") {
             $data['donor'] = Application_Model_General::getDonorByReqId($reqId);
         }
         $res = $tbl->insert($data);
         return $res;
     } else {
         //this request if from internal - have to add trx_no
         //save to Transactions table trx_no  has to be consisten to id of the table
         $adapter = $tbl->getAdapter();
         $adapter->beginTransaction();
         try {
             $temp_trx_no = Application_Model_General::createRandKey(14);
             if (isset($this->data['request_id'])) {
                 $reqId = $this->data['request_id'];
             }
             $row_insert = array('trx_no' => $temp_trx_no, 'request_id' => $reqId, 'message_type' => $this->request->getHeaderField("MSG_TYPE"), 'ack_code' => $this->request->getAck(), 'target' => $this->request->getHeaderField("TO"));
             if (!$rejectReasonCode || $rejectReasonCode === NULL || $rejectReasonCode == "") {
                 // do nothing
             } else {
                 $row_insert['reject_reason_code'] = $rejectReasonCode;
             }
             if ($msgType == "Update" || $msgType == "Request" || $msgType == "Check" && Application_Model_General::isAutoCheck($reqId)) {
                 $row_insert['requested_transfer_time'] = Application_Model_General::getDateTimeInSqlFormat($portTime);
             }
             if ($msgType == "Publish") {
                 $row_insert['donor'] = Application_Model_General::getDonorByReqId($reqId);
             }
             $_id = $tbl->insert($row_insert);
             $id = substr("00000000000" . $_id, -12, 12);
             $trx_no = Application_Model_General::getSettings('InternalProvider') . $id;
             $ret = $tbl->update(array('trx_no' => $trx_no), "id = " . $_id);
             $this->request->setTrxNo($trx_no);
             $adapter->commit();
             return true;
         } catch (Exception $e) {
             error_log("Error on create record in transactions table: " . $e->getMessage());
             $adapter->rollBack();
             return false;
         }
     }
 }
Esempio n. 17
0
 /**
  * overridden from parent
  * 
  * inserts row to database
  * 
  * @return type 
  */
 public function saveToDB()
 {
     //this is a request from provider!
     //save a new row in Requests DB
     if ($this->getHeaderField("FROM") != Application_Model_General::getSettings('InternalProvider')) {
         try {
             $flags = new stdClass();
             $flags->publish_type = $this->getBodyField("PUBLISH_TYPE");
             $tbl = new Application_Model_DbTable_Requests(Np_Db::master());
             $data = array('request_id' => $this->getHeaderField("REQUEST_ID"), 'from_provider' => $this->getHeaderField("TO"), 'to_provider' => $this->getHeaderField("FROM"), 'status' => 1, 'last_transaction' => $this->getHeaderField("MSG_TYPE"), 'phone_number' => $this->getBodyField("NUMBER"), 'disconnect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("DISCONNECT_TIME")), 'connect_time' => Application_Model_General::getDateTimeInSqlFormat($this->getBodyField("CONNECT_TIME")), 'transfer_time' => Application_Model_General::getDateTimeInSqlFormat(), 'flags' => json_encode($flags));
             return $tbl->insert($data);
         } catch (Exception $e) {
             error_log("Error on create record in transactions table: " . $e->getMessage());
         }
     }
     return TRUE;
 }
Esempio n. 18
0
 /**
  * retrieve all providers respond to publish
  * 
  * @param string $request_id the request id that need to be checked
  * 
  * @return array of providers
  */
 public static function getProvidersRequestWithPublishResponse($request_id)
 {
     $db = Np_Db::slave();
     $select = $db->select();
     $internalProvider = Application_Model_General::getSettings('InternalProvider');
     $select->from('Transactions');
     //, array('provider' => new Zend_Db_Expr('SUBSTR(trx_no,1,2)') ,'request_id')); //THERE IS NO FROM FIELD!!
     $select->where('request_id = ?', $request_id)->where('message_type = ?', 'Publish_response')->where('target = ?', $internalProvider)->where('reject_reason_code is NULL');
     $result = $db->query($select);
     $rows = $result->fetchAll();
     $publish_response_providers = array();
     foreach ($rows as $row) {
         $publish_response_providers[] = substr($row['trx_no'], 0, 2);
     }
     return $publish_response_providers;
 }