/** * Test Controller Class * Index Action - "http://SERVER/Test" * This useful for testing the NGP * * @package ApplicationController * @subpackage CronController */ public function indexAction() { $reply = Application_Model_General::getSettings('test-response', 'true'); $params = $this->getRequest()->getParams(); // error_log(print_R($params, 1)); switch (strtolower($reply)) { case 'rand': case 'random': $ack = $this->randResponse(); break; case 'true': $ack = 'true'; break; case 'ack00': default: $ack = 'Ack00'; break; } $arr = array('reqId' => $params['reqId'], 'status' => $ack, 'desc' => 'run on ' . $reply); switch ($params['method']) { case "execute_transfer": $arr['more']['connect_time'] = time(); break; case "inquire_number": case "inquire_number_response": $arr['more']['current_operator'] = 'PR'; break; } $response = json_encode($arr); $this->view->response = $response; }
public function init() { $this->setMethod('GET'); $this->setAction(''); $this->addElement('text', 'request_id', array('label' => 'Request Id')); $this->addElement('text', 'phone', array('label' => 'Phone', 'required' => true, 'validators' => array('Alnum', array('regex', false, '/^[a-z]/i'), 'int'), 'filters' => array('StringTrim'))); $msgTypeOptions = array('label' => 'Stage', 'required' => true, 'multioptions' => array('All' => 'All', 'Check' => 'Check', 'Request' => 'Request', 'Execute' => 'Execute', 'Publish' => 'Publish')); $this->addElement('select', 'stage', $msgTypeOptions); $this->addElement('text', 'date', array('label' => 'Date (YYYY-MM-DD)', 'required' => true)); $this->addElement('text', 'time', array('label' => 'Time (HH:MM:SS)', 'required' => true, 'invalidMessage' => 'Invalid date specified.', 'filters' => array('StringTrim'))); $providers = Application_Model_General::getProviderArray(); $currentProvider = Application_Model_General::getSettings('InternalProvider'); if (($key = array_search($currentProvider, $providers)) !== FALSE) { unset($providers[$key]); } array_unshift($providers, 'None', $currentProvider); $toOptions = array('label' => 'From provider', 'multioptions' => array_combine($providers, $providers)); $this->addElement('select', 'from', $toOptions); $toOptions['label'] = 'To provider'; $this->addElement('select', 'to', $toOptions); $statusOptions = array('label' => 'Status', 'multioptions' => array(-1 => "All", 1 => "Active", 0 => "Inactive")); $this->addElement('select', 'status', $statusOptions); // Add the submit button $this->addElement('submit', 'submit', array('ignore' => true, 'label' => 'Search', 'class' => 'request-search-button')); }
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; }
public function init() { // Set the method for the display form to POST $this->setMethod('POST'); $this->setAction(Application_Model_General::getBaseUrl() . "/monitor/send/"); $this->setAttrib('class', 'request-form'); $msgTypeOptions = array('label' => 'Message', 'required' => true, 'multioptions' => array('Check' => 'Check', 'Request' => 'Request', 'Update' => 'Update', 'Cancel' => 'Cancel', 'Inquire_number' => 'Inquire_number', 'Return' => 'Return')); $this->addElement('select', 'MSG_TYPE', $msgTypeOptions); $numberOptions = array('label' => 'Phone number', 'required' => true, 'validators' => array('Int', array('StringLength', FALSE, array(10, 10))), 'value' => ''); $this->addElement('text', 'NUMBER', $numberOptions); $d = new Zend_Date(null, null, Application_Model_General::getLocale(null, false)); $dateOptions = array('label' => 'Port Time', 'id' => 'datetimepicker', 'required' => true, 'value' => $d->toString('YYYY-MM-dd HH:mm:ss', Application_Model_General::getLocale(null, false))); $this->addElement('text', 'porttime', $dateOptions); $providers = Application_Model_General::getProviderArray(); $currentProvider = Application_Model_General::getSettings('InternalProvider'); if (($key = array_search($currentProvider, $providers)) !== FALSE) { unset($providers[$key]); } $toOptions = array('label' => 'To', 'multioptions' => array_combine($providers, $providers)); $this->addElement('select', 'TO', $toOptions); $dateTimeLabelOptions = array('label' => 'Date and Time', 'required' => true, 'value' => date('y/m/d:h/i/s'), 'disabled' => 'true'); $this->addElement('text', 'Date and Time', $dateTimeLabelOptions); $submitOptions = array('ignore' => true, 'label' => 'Send'); $this->addElement('submit', 'submit', $submitOptions); }
/** * sendMessage method defined by NP wsdl * called by external providers to send transaction messages to internal * the call to internal will be forward by forking * * @param Array $params * @return array "NP_ACK" or string */ public function sendMessage($params) { Application_Model_General::virtualSleep(); $reqModel = new Application_Model_Request($params); //prepares data for sending internal the message $ack = $reqModel->Execute(); // log all received calls if request log enabled if (Application_Model_General::getSettings('EnableRequestLog')) { Application_Model_General::logRequestResponse($params, $ack, $reqModel->getRequest()->getHeaderField('REQUEST_ID'), '[Input] '); } if ($ack === FALSE || strpos(strtolower($ack), "ack") === FALSE) { $ack = "Ack00"; } return array('NP_ACK' => array('ACK_CODE' => $ack, 'ACK_DATE' => Application_Model_General::getDateTimeIso())); }
/** * 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 }
/** * Cron Controller Class * Index Action - "http://SERVER/Cron" * calls the modle to select the requests to Transfer and * opens process for each one of the requests * * @package ApplicationController * @subpackage CronController */ public function indexAction() { $disabled_output = $this->getRequest()->getParam('no-output'); $forceAll = $this->getRequest()->getParam('force-all'); if (!isset($disabled_output) || !$disabled_output) { $this->view->output_enabled = true; } else { $this->view->output_enabled = false; } // we make 3 process at different iteraion // we order the check publish before publish for scenario of force all (all on one time) // we don't use else in case we force all $this->view->transfer = array(); $this->view->publish_check = array(); $this->view->publish = array(); $minute = date('i'); if ($minute % 2 === 0 || $forceAll) { //first execute $this->view->transfer = Application_Model_Cron::makeChangeProvider(); } $publish_verification_iteration = Application_Model_General::getSettings('publish-verification-iteration', 20); $hour = date('G'); // 24-hour format of an hour without leading zeros $dayofweek = date('w'); // Numeric representation of the day of the week, 0 (for Sunday) through 6 (for Saturday) $working_days = (bool) ($dayofweek >= 0 && $dayofweek <= 4 && $hour >= 8 && $hour < 23); $friday = (bool) ($dayofweek == 5 && $hour >= 8 && $hour < 15); if ($minute % $publish_verification_iteration == 0 && ($working_days || $friday) || $forceAll) { // verify all requests return publish $this->view->publish_check = Application_Model_Cron::checkPublishResponseFromProviders(); } if ($minute % 2 === 1 || $forceAll) { // publish $this->view->publish = Application_Model_Cron::publishChangeProvider(); } }
/** * Adds Hardcoded Values to Missing Fields for SOAP Request * * @param array $params * */ private function AddParamsToInternalReq(&$params) { // $params['FORK'] = 1; $params['FROM_PROVIDER'] = Application_Model_General::getSettings('InternalProvider'); //requests from internal - Transfer to internal if (isset($params['MSG_TYPE'])) { $params['PROCESS_TYPE'] = Application_Model_General::getProcessType($params['MSG_TYPE']); } if (isset($params['msg_type'])) { $params['PROCESS_TYPE'] = Application_Model_General::getProcessType($params['msg_type']); } $params['VERSION_NO'] = Application_Model_General::getSettings("VersionNo"); $params['RETRY_NO'] = 1; $params['RETRY_DATE'] = Application_Model_General::getDateTimeIso(); $params['NETWORK_TYPE'] = Application_Model_General::getSettings("NetworkType"); if (isset($params['more'])) { foreach ($params['more'] as $key => $value) { $params[strtoupper($key)] = $value; } } // backward compatibility if (!isset($params['NUMBER_TYPE'])) { $params['NUMBER_TYPE'] = Application_Model_General::getSettings("NumberType"); } if (isset($params['number_type'])) { $params['NUMBER_TYPE'] = $params['number_type']; } }
protected function checkDirection() { if ($this->getHeaderField("TO") != Application_Model_General::getSettings('InternalProvider')) { return FALSE; } return TRUE; }
/** * convert Xml data to associative array * * @param simple_xml $xmlObject simple xml object * * @return array converted data from hierarchical xml to flat array */ public function convertArray($xmlObject) { $ret = array(); $networkTypeConfig = Application_Model_General::getSettings("NetworkType"); if ($networkTypeConfig === "M") { $networkType = "mobile"; $ret['NETWORK_TYPE'] = (string) $networkTypeConfig; } else { $networkType = "fixed"; $ret['NETWORK_TYPE'] = (string) $networkTypeConfig; } if (!empty($xmlObject->{$networkType}->mobileNumberIdentified) && $xmlObject->{$networkType}->mobileNumberIdentified !== NULL) { $ret['IDENTIFICATION_VALUE'] = (string) $xmlObject->{$networkType}->mobileNumberIdentified->identificationValue; $ret['IDENTIFICATION_VALUE_2ND'] = (string) $xmlObject->{$networkType}->mobileNumberIdentified->identificationValue2nd; $ret['IDENTIFICATION_VALUE_3RD'] = (string) $xmlObject->{$networkType}->mobileNumberIdentified->identificationValue3rd; $ret['NUMBER_TYPE'] = (string) $xmlObject->{$networkType}->mobileNumberIdentified->numberType; $ret['PHONE_NUMBER'] = (string) $xmlObject->{$networkType}->mobileNumberIdentified->number; } else { $ret['NUMBER_TYPE'] = (string) $xmlObject->{$networkType}->mobileNumberUnidentified->numberType; $ret['PHONE_NUMBER'] = (string) $xmlObject->{$networkType}->mobileNumberUnidentified->number; } return $ret; }
public function createXml() { $xml = parent::createXml(); $msgType = $this->getHeaderField('MSG_TYPE'); $networkType = Application_Model_General::getSettings("NetworkType"); $xml->{$msgType}->donor = $this->getBodyField('DONOR'); $xml->{$msgType}->connectDateTime = Application_Model_General::getDateTimeIso($this->getBodyField('CONNECT_TIME')); $xml->{$msgType}->publishType = $this->getBodyField('PUBLISH_TYPE'); $xml->{$msgType}->disconnectDateTime = Application_Model_General::getDateTimeIso($this->getBodyField('DISCONNECT_TIME')); if ($networkType === "M") { $xml->{$msgType}->mobile; $xml->{$msgType}->mobile->numberType = "I"; $xml->{$msgType}->mobile->number = $this->getBodyField("NUMBER"); } else { $xml->{$msgType}->fixed->fixedNumberSingle; } return $xml; }
/** * 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; }
/** * method to create xml from the request * * @return SimpleXml xml object */ public function createXml() { $xml = parent::createXml(); $msgType = $this->getHeaderField('MSG_TYPE'); $numberType = $this->getBodyField('NUMBER_TYPE'); $xml->{$msgType}->number = $this->getBodyField('NUMBER'); if (Application_Model_General::getSettings("NetworkType") === "M") { $xml->{$msgType}->mobile; $xml->{$msgType}->mobile->networkType = "M"; $xml->{$msgType}->mobile->numberType = $numberType; } else { $xml->{$msgType}->fixed->networkType = "M"; $xml->{$msgType}->fixed->numberType = $numberType; } return $xml; }
public function executeAction() { $params = $this->getRequest()->getParams(); if (isset($params['from_provider']) && $params['from_provider'] == Application_Model_General::getSettings('InternalProvider')) { $params['FROM_PROVIDER'] = $params['from_provider']; $params['PROCESS_TYPE'] = 'PORT'; $params['MSG_TYPE'] = 'Execute'; $params['NUMBER'] = $params['phone_number']; $params['MANUAL'] = 1; $params['REQUEST_ID'] = $params['request_id']; unset($params['phone_number']); unset($params['from_provider']); unset($params['to_provider']); $url = '/provider/internal'; } else { if (isset($params['from_provider']) && $params['to_provider'] == Application_Model_General::getSettings('InternalProvider')) { if (isset($params['TO_PROVIDER'])) { $params['TO'] = $params['TO_PROVIDER']; } else { if (isset($params['to_provider'])) { $params['TO'] = $params['to_provider']; } } $url = '/cron/transfer'; } else { die("something got wrong"); } } unset($params['controller']); unset($params['action']); unset($params['module']); $success = Application_Model_General::forkProcess($url, $params, true); if ($success) { $params['success'] = 1; $params['message'] = 'Execute sent'; } else { $params['success'] = 0; $params['message'] = 'Execute failed'; } $this->_redirect(Application_Model_General::getBaseUrl() . '/monitor/?' . http_build_query($params)); }
/** * Get Provider RPC URL via "TO" field * * @return string URL */ protected function getRecipientUrl() { $providers = Application_Model_General::getSettings('provider'); $key = $this->request->getHeaderField("TO"); if (isset($providers[$key])) { return $providers[$key]; } return FALSE; }
/** * sends automatic response to transaction messages sent to internal. * * @param bool $status * * @todo refactoring to bridge classes */ public function CreateMethodResponse($status) { //update DB ack! //SEND RESPONSE TO PROVIDER $response = array('REQUEST_ID' => $this->params['REQUEST_ID'], 'PROCESS_TYPE' => $this->params['PROCESS_TYPE'], 'MSG_TYPE' => $this->params['MSG_TYPE'] . "_response", 'REQUEST_TRX_NO' => $this->params['TRX_NO'], 'FROM' => $this->params['TO'], 'TO' => $this->params['FROM'], 'REQUEST_RETRY_DATE' => $this->params['RETRY_DATE'], 'RETRY_DATE' => Application_Model_General::getDateTimeIso(), 'RETRY_NO' => isset($this->params['RETRY_NO']) ? $this->params['RETRY_NO'] : 1, 'VERSION_NO' => Application_Model_General::getSettings("VersionNo"), 'NETWORK_TYPE' => Application_Model_General::getSettings('NetworkType'), 'NUMBER_TYPE' => isset($this->params['NUMBER_TYPE']) ? $this->params['NUMBER_TYPE'] : Application_Model_General::getSettings("NumberType")); $phone_number = array("PHONE_NUMBER" => $this->params['PHONE_NUMBER']); Application_Model_General::writeToLog(array_merge($response, $phone_number)); //check $status if (($status->status == "Ack00" || $status->status == "true") && !isset($status->resultCode) || $status->status == NULL && $status->resultCode == "Ack00") { $response['APPROVAL_IND'] = "Y"; } elseif ($status->status == "Gen07") { $response['APPROVAL_IND'] = "N"; $response['REJECT_REASON_CODE'] = "Gen07"; } else { $response['APPROVAL_IND'] = "N"; $response['REJECT_REASON_CODE'] = $status->status; } if ($this->params['MSG_TYPE'] == "Execute") { $time = isset($status->DISCONNECT_TIME) ? $status->DISCONNECT_TIME : null; $response['DISCONNECT_TIME'] = Application_Model_General::getDateTimeIso($time); } if ($response['MSG_TYPE'] == "Inquire_number_response") { $response['CURRENT_OPERATOR'] = isset($status->current_operator) ? $status->current_operator : $status->more->current_operator; } if (isset($status->resultCode) && !empty($status->resultCode)) { $response['REJECT_REASON_CODE'] = $status->resultCode; } $reqModel = new Application_Model_Request($response); $reqModel->ExecuteFromInternal(FALSE); // ExecuteResponse(); }
public function createXml() { $xml = parent::createXml(); $msgType = $this->getHeaderField('MSG_TYPE'); $networkType = Application_Model_General::getSettings("NetworkType"); $numberType = $this->getBodyField('NUMBER_TYPE'); $requestId = $this->getHeaderField('REQUEST_ID'); $requestRecord = Application_Model_General::getFieldFromRequests(array('flags', 'transfer_time'), $requestId, 'request_id'); $flags = json_decode($requestRecord['flags'], true); if (empty($numberType)) { $numberType = isset($flags['number_type']) ? $flags['number_type'] : Application_Model_General::getSettings("NumberType"); } $number = $this->getBodyField('NUMBER'); $portTime = Application_Model_General::getDateTimeIso($requestRecord['transfer_time']); $process_type = $this->getHeaderField('PROCESS_TYPE'); if ($process_type == "PORT") { $path =& $xml->{$msgType}->updateRequestType; $path->updateType = "REQUEST"; $path->portingDateTime = $portTime; } else { if ($process_type == "CANCEL") { $path =& $xml->{$msgType}->updateCancelTypeType; $path->updateType = "CANCEL"; $path->portingDateTime = $portTime; } else { if ($process_type == "UPDATE") { $path =& $xml->{$msgType}->updateUpdateTypeType; $path->updateType = "UPDATE"; $path->portingDateTime = $portTime; } } } if ($networkType === "M") { $networkType = "mobile"; } else { $networkType = "fixed"; } $path->{$networkType}; $path->{$networkType}->networkType = "M"; if ($numberType === "I") { $path->{$networkType}->mobileNumberIdentified; $path->{$networkType}->mobileNumberIdentified->numberType = $numberType; $path->{$networkType}->mobileNumberIdentified->identificationValue = isset($flags['identification_value']) ? $flags['identification_value'] : 'default'; $path->{$networkType}->mobileNumberIdentified->identificationValue2nd = 'default'; $path->{$networkType}->mobileNumberIdentified->identificationValue3rd = 'default'; $path->{$networkType}->mobileNumberIdentified->number = $number; } else { $path->{$networkType}->mobileNumberUnidentified; $path->{$networkType}->mobileNumberUnidentified->numberType = $numberType; $path->{$networkType}->mobileNumberUnidentified->number = $number; } return $xml; }
public function revertPublish($request) { $internalProvider = Application_Model_General::getSettings('InternalProvider'); // check if this not the internal provider publish //TODO oc666: check if necessary if (substr($request['request_id'], 2, 2) != $internalProvider) { $where[] = "request_id = " . $resultFetch['request_id'] . ""; $where[] = "trx_no NOT LIKE '" . $internalProvider . "%'"; $req_tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $res = $req_tbl->update(array('last_transaction' => 'Publish_response'), $where); return $res; } $publish_response_providers = array(); if ($publish_response_providers) { //problem! - send providers again $ret = array(); foreach ($publish_response_providers as $provider) { $request['provider'] = $provider; Application_Model_General::forkProcess("/cron/cancelpublish", $request); $ret[] = $request; } return $ret; } else { //no problem - update publish_response $req_tbl = new Application_Model_DbTable_Requests(Np_Db::master()); $req_tbl->update(array('last_transaction' => 'Publish_response', 'status' => 0), 'id=' . $request['id']); //send to internal! } return TRUE; }
/** * retrieve all providers not respond to publish * * @param string $request_id the request id that need to be checked * @param string $from the source provider * @param string $to the destination provider * * @return array of all providers without publish response */ public static function getProvidersRequestWithoutPublishResponse($request_id, $from, $to) { $publish_response_providers = self::getProvidersRequestWithPublishResponse($request_id); $providerArray = array_keys(Application_Model_General::getSettings('provider', array())); //remove publish response, source & destination provider $problem_providers = array_diff($providerArray, array_merge($publish_response_providers, array($from, $to))); return $problem_providers; }