diff --git a/library/NGNPro/Records/GatewayRules.php b/library/NGNPro/Records/GatewayRules.php index b9bfb6b..a8a117e 100644 --- a/library/NGNPro/Records/GatewayRules.php +++ b/library/NGNPro/Records/GatewayRules.php @@ -1,522 +1,570 @@ array('type'=>'integer','readonly' => true), - 'gateway_id' => array('type'=>'integer','name' => 'Gateway'), - 'prefix' => array('type'=>'string'), - 'strip' => array('type'=>'integer'), - 'prepend' => array('type'=>'string'), - 'minLength' => array('type'=>'integer'), - 'maxLength' => array('type'=>'integer') - ); + var $carriers = array(); + var $FieldsReadOnly = array( + 'reseller', + 'changeDate' + ); + + var $Fields = array( + 'id' => array('type'=>'integer','readonly' => true), + 'gateway_id' => array('type'=>'integer','name' => 'Gateway'), + 'prefix' => array('type'=>'string'), + 'strip' => array('type'=>'integer'), + 'prepend' => array('type'=>'string'), + 'minLength' => array('type'=>'integer'), + 'maxLength' => array('type'=>'integer') + ); public function __construct($SoapEngine) { $this->filters = array( 'id' => trim($_REQUEST['id_filter']), 'gateway_id' => trim($_REQUEST['gateway_id_filter']), 'carrier_id' => trim($_REQUEST['carrier_id_filter']), 'prefix' => trim($_REQUEST['prefix_filter']), ); - $this->sortElements=array( + $this->sortElements = array( 'changeDate' => 'Change date', 'gateway' => 'Gateway', 'carrier' => 'Carrier', 'prefix' => 'Prefix' ); parent::__construct($SoapEngine); } - function listRecords() { + function listRecords() + { $this->getCarriers(); $this->showSeachForm(); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter - $filter=array('id' => intval($this->filters['id']), - 'gateway_id' => intval($this->filters['gateway_id']), - 'carrier_id' => intval($this->filters['carrier_id']), - 'prefix' => $this->filters['prefix'], - 'customer' => intval($this->filters['customer']), - 'reseller' => intval($this->filters['reseller']) - ); + $filter = array( + 'id' => intval($this->filters['id']), + 'gateway_id' => intval($this->filters['gateway_id']), + 'carrier_id' => intval($this->filters['carrier_id']), + 'prefix' => $this->filters['prefix'], + 'customer' => intval($this->filters['customer']), + 'reseller' => intval($this->filters['reseller']) + ); // Range - $range=array('start' => intval($this->next), - 'count' => intval($this->maxrowsperpage) - ); + $range = array( + 'start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; - $orderBy = array('attribute' => $this->sorting['sortBy'], - 'direction' => $this->sorting['sortOrder'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); $this->log_action('getGatewayRules'); - $result = $this->SoapEngine->soapclient->getGatewayRules($Query); - - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - $log=sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); - syslog(LOG_NOTICE, $log); + $result = $this->SoapEngine->soapclient->getGatewayRules($Query); + + if ($this->checkLogSoapError($result, true)) { return false; } else { - $this->rows = $result->total; print " -
$this->rows records found
+
$this->rows records found

"; print " "; if (!$this->next) $this->next=0; - if ($this->rows > $this->maxrowsperpage) { + if ($this->rows > $this->maxrowsperpage) { $maxrows = $this->maxrowsperpage + $this->next; if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage; } else { - $maxrows=$this->rows; + $maxrows = $this->rows; } $i=0; if ($this->rows) { - while ($i < $maxrows) { - + while ($i < $maxrows) { if (!$result->gateway_rules[$i]) break; $gateway_rule = $result->gateway_rules[$i]; - $index=$this->next+$i+1; + $index = $this->next+$i+1; - $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($gateway_rule->id), - urlencode($gateway_rule->reseller) + $base_url_data = array( + 'service' => $this->SoapEngine->service, + 'id_filter' => $gateway_rule->id, + 'reseller_filter' => $gateway_rule->reseller ); - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['id_filter'] == $gateway_rule->id) { - $_delete_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - $_url = $this->url.sprintf("&service=%s&id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($gateway_rule->id), - urlencode($gateway_rule->reseller) + $delete_url_data = array_merge( + $base_url_data, + array( + 'action' => 'Delete', + ) ); - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($gateway_rule->reseller) + $customer_url_data = array( + 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), + 'customer_filter' => $gateway_rule->reseller ); - $_carrier_url = $this->url.sprintf("&service=pstn_carriers@%s&id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($gateway_rule->carrier_id), - urlencode($gateway_rule->reseller) + $carrier_url_data = array_merge( + $base_url_data, + array( + 'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine), + ) ); - $_gateway_url = $this->url.sprintf("&service=pstn_gateways@%s&id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($gateway_rule->gateway_id), - urlencode($gateway_rule->reseller) + $gateway_url_data = array_merge( + $base_url_data, + array( + 'service' => sprintf('pstn_gateways@%s', $this->SoapEngine->soapEngine), + ) ); - printf(" - - - - - - - - - - - - - - ", - $index, - $_customer_url, $gateway_rule->reseller, - $_url, $gateway_rule->id, - $_carrier_url, $gateway_rule->carrier,$gateway_rule->carrier_id, - $_gateway_url, $gateway_rule->gateway,$gateway_rule->gateway_id, - $gateway_rule->prefix, - $gateway_rule->strip, - $gateway_rule->prepend, - $gateway_rule->minLength, - $gateway_rule->maxLength, - $gateway_rule->changeDate, - $_delete_url, - $actionText + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['id_filter'] == $gateway_rule->id) { + $delete_url_data['confirm'] = 1; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + $_delete_url = $this->buildUrl($delete_url_data); + $_url = $this->buildUrl($base_url_data); + $_customer_url = $this->buildUrl($customer_url_data); + $_carrier_url = $this->buildUrl($carrier_url_data); + $_gateway_url = $this->buildUrl($gateway_url_data); + + printf( + " + + + + + + + + + + + + + + + ", + $index, + $_customer_url, + $gateway_rule->reseller, + $_url, + $gateway_rule->id, + $_carrier_url, + $gateway_rule->carrier, + $gateway_rule->carrier_id, + $_gateway_url, + $gateway_rule->gateway, + $gateway_rule->gateway_id, + $gateway_rule->prefix, + $gateway_rule->strip, + $gateway_rule->prepend, + $gateway_rule->minLength, + $gateway_rule->maxLength, + $gateway_rule->changeDate, + $_delete_url, + $actionText ); - printf(" - - "); + print ""; $i++; - } - } print "
Owner Rule Carrier Gateway Prefix Strip Prepend MinLength MaxLength Change date Actions
%s%s%s%s (%d)%s (%d)%s%s%s%s%s%s%s
%s%s%s%s (%d)%s (%d)%s%s%s%s%s%s%s
"; if ($this->rows == 1) { $this->showRecord($gateway_rule); } else { $this->showPagination($maxrows); } return true; } } - function showAddForm() { + function showAddForm() + { //if ($this->selectionActive) return; $this->getGateways(); if (!count($this->gateways)) { - print "

Create a gateway first"; + print "

Create a gateway first

"; return false; } - printf ("
",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - - "; - - print "
Gateway + +
+ Gateway +
"); - - printf ("
Prefix
"); - printf ("
Strip
"); - printf ("
Prepend
"); - printf ("
Min length
"); - printf ("
Max length
"); - + print <<< END + +
+
Prefix
+
Strip
+
+ Prepend +
+
+ Min length +
+
+ Max length +
+END; $this->printHiddenFormElements(); - print "
-
- "; + print <<< END + + +END; } - function addRecord($dictionary=array()) { + function addRecord($dictionary = array()) + { if ($dictionary['gateway_id']) { $gateway_id = $dictionary['gateway_id']; } else { $gateway_id = trim($_REQUEST['gateway_id']); } if ($dictionary['prefix']) { $prefix = $dictionary['prefix']; } else { $prefix = trim($_REQUEST['prefix']); } if ($dictionary['strip']) { $strip = $dictionary['strip']; } else { $strip = trim($_REQUEST['strip']); } if ($dictionary['prepend']) { $prepend = $dictionary['prepend']; } else { $prepend = trim($_REQUEST['prepend']); } if ($dictionary['minLength']) { $minLength = $dictionary['minLength']; } else { $minLength = trim($_REQUEST['minLength']); } if ($dictionary['maxLength']) { $maxLength = $dictionary['maxLength']; } else { $maxLength = trim($_REQUEST['maxLength']); } if (!strlen($gateway_id)) { - printf ("

Error: Missing gateway id"); + printf("

Error: Missing gateway id"); return false; } - $rule=array( - 'gateway_id' => intval($gateway_id), - 'prefix' => $prefix, - 'prepend' => $prepend, - 'strip' => intval($strip), - 'minLength' => intval($minLength), - 'maxLength' => intval($maxLength) - ); + $rule = array( + 'gateway_id' => intval($gateway_id), + 'prefix' => $prefix, + 'prepend' => $prepend, + 'strip' => intval($strip), + 'minLength' => intval($minLength), + 'maxLength' => intval($maxLength) + ); - $function=array('commit' => array('name' => 'addGatewayRule', - 'parameters' => array($rule), - 'logs' => array('success' => sprintf('Gateway rule has been added'))) - ); + $function = array( + 'commit' => array( + 'name' => 'addGatewayRule', + 'parameters' => array($rule), + 'logs' => array('success' => sprintf('Gateway rule has been added')) + ) + ); unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); + return $this->SoapEngine->execute($function, $this->html); } - function deleteRecord($dictionary=array()) { + function deleteRecord($dictionary = array()) + { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { - print "

Please press on Confirm to confirm the delete. "; + print "

Please press on Confirm to confirm the delete.

"; return true; } if ($dictionary['id']) { $id = $dictionary['id']; } else { $id = trim($this->filters['id']); } if (!strlen($id)) { print "

Error: missing rule id "; return false; } - $function=array('commit' => array('name' => 'deleteGatewayRule', - 'parameters' => array(intval($id)), - 'logs' => array('success' => sprintf('Gateway rule %d has been deleted',$id))) - ); + $function = array( + 'commit' => array( + 'name' => 'deleteGatewayRule', + 'parameters' => array(intval($id)), + 'logs' => array('success' => sprintf('Gateway rule %d has been deleted', $id)) + ) + ); unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); - + return $this->SoapEngine->execute($function, $this->html); } - function showSeachFormCustom() { - printf ("

Rule
",$this->filters['id']); - print " - + + ", + $this->filters['id'] + ); + print <<< END + "); - printf ("
Gateway
",$this->filters['gateway_id']); - printf ("
Prefix
",$this->filters['prefix']); + print ""; + printf( + " +
+ Gateway +
+ ", + $this->filters['gateway_id'] + ); + printf( + " +
+ Prefix +
+ ", + $this->filters['prefix'] + ); } - function showCustomerForm($name='customer_filter') { + function showCustomerForm($name = 'customer_filter') + { } - function showTextBeforeCustomerSelection() { + function showTextBeforeCustomerSelection() + { print "Owner"; } - function showRecord($rule) { - + function showRecord($rule) + { $this->getGateways(); print "

Rule

"; - printf ("
",$_SERVER['PHP_SELF']); + printf("", $_SERVER['PHP_SELF']); print ""; foreach (array_keys($this->Fields) as $item) { if ($this->Fields[$item]['name']) { - $item_name=$this->Fields[$item]['name']; + $item_name = $this->Fields[$item]['name']; } else { $item_name=ucfirst($item); } - printf ("
- - ", - $item_name + printf( + " +
+ + ", + $item_name ); if ($this->Fields[$item]['readonly']) { - printf ("
%s
", - $item, - $rule->$item, - $rule->$item + printf( + " +
+ + %s +
+ ", + $item, + $rule->$item, + $rule->$item ); } else { if ($item == 'gateway_id') { - printf ("
", $item); $selected_gateway[$rule->$item]='selected'; foreach (array_keys($this->gateways) as $_gateway) { - printf ("
"; - } else { - printf ("
", - $item, - $rule->$item + printf( + "
", + $item, + $rule->$item ); } } print "
"; } - printf ("",$rule->reseller); + printf("", $rule->reseller); $this->printFiltersToForm(); $this->printHiddenFormElements(); - print " -
+ print <<< END +
-
- "; - print ""; +
+ +END; } - function updateRecord () { + function updateRecord() + { //print "

Updating rule ..."; if (!$_REQUEST['id_form'] || !strlen($_REQUEST['reseller_filter'])) { return; } if (!$rule = $this->getRecord($_REQUEST['id_form'])) { return false; } foreach (array_keys($this->Fields) as $item) { - $var_name=$item.'_form'; + $var_name = $item.'_form'; if ($this->Fields[$item]['type'] == 'integer') { $rule->$item = intval($_REQUEST[$var_name]); } else { $rule->$item = trim($_REQUEST[$var_name]); } } - $function=array('commit' => array('name' => 'updateGatewayRule', + $function = array('commit' => array('name' => 'updateGatewayRule', 'parameters' => array($rule), - 'logs' => array('success' => sprintf('Rule %d has been updated',$_REQUEST['id_form']))) + 'logs' => array('success' => sprintf('Rule %d has been updated', $_REQUEST['id_form']))) ); - $result = $this->SoapEngine->execute($function,$this->html); + $result = $this->SoapEngine->execute($function, $this->html); + dprint_r($result); - dprint_r($result) ; - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - $log=sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); - syslog(LOG_NOTICE, $log); - return false; - } else { - return true; - } + return (bool)$result; } - function getRecord($id) { + function getRecord($id) + { // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); // Filter - $filter=array('id' => intval($id)); + $filter = array('id' => intval($id)); // Range - $range=array('start' => 0, + $range = array('start' => 0, 'count' => 1 ); // Order $this->sorting['sortBy'] = 'gateway'; $this->sorting['sortOrder'] = 'ASC'; $orderBy = array('attribute' => $this->sorting['sortBy'], 'direction' => $this->sorting['sortOrder'] ); // Compose query - $Query=array('filter' => $filter, + $Query = array('filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); // Call function - $this->log_action('getGatewayRules'); - $result = $this->SoapEngine->soapclient->getGatewayRules($Query); - - if ((new PEAR)->isError($result)) { - $error_msg = $result->getMessage(); - $error_fault= $result->getFault(); - $error_code = $result->getCode(); - $log=sprintf("SOAP request error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); - syslog(LOG_NOTICE, $log); + $this->log_action('getGatewayRules'); + $result = $this->SoapEngine->soapclient->getGatewayRules($Query); + + if ($this->checkLogSoapError($result, true)) { return false; } else { - if ($result->gateway_rules[0]){ + if ($result->gateway_rules[0]) { return $result->gateway_rules[0]; } else { return false; } } } } -