Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7232083
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
56 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/library/NGNPro/Records/GatewayRules.php b/library/NGNPro/Records/GatewayRules.php
index ff29a10..a2850be 100644
--- a/library/NGNPro/Records/GatewayRules.php
+++ b/library/NGNPro/Records/GatewayRules.php
@@ -1,572 +1,589 @@
<?php
class GatewayRules extends Records
{
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(
'changeDate' => 'Change date',
'gateway' => 'Gateway',
'carrier' => 'Carrier',
'prefix' => 'Prefix'
);
parent::__construct($SoapEngine);
}
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'])
);
// Range
$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']
);
// Compose query
$Query = array(
'filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
$this->log_action('getGatewayRules');
$result = $this->SoapEngine->soapclient->getGatewayRules($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
$this->rows = $result->total;
print "
<div class = \"alert alert-success\"><center>$this->rows records found</center></div>
<p>
<table class='table table-striped table-condensed' width=100%>
";
print "
<thead>
<tr>
<th></th>
<th>Owner</th>
<th>Rule</th>
<th>Carrier</th>
<th>Gateway</th>
<th>Prefix</th>
<th>Strip</th>
<th>Prepend</th>
<th>MinLength</th>
<th>MaxLength</th>
<th>Change date</th>
<th>Actions</th>
</tr>
</thead>
";
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows = $this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->gateway_rules[$i]) break;
$gateway_rule = $result->gateway_rules[$i];
$index = $this->next+$i+1;
$base_url_data = array(
'service' => $this->SoapEngine->service,
'id_filter' => $gateway_rule->id,
'reseller_filter' => $gateway_rule->reseller
);
$delete_url_data = array_merge(
$base_url_data,
array(
'action' => 'Delete',
)
);
$customer_url_data = array(
'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine),
'customer_filter' => $gateway_rule->reseller
);
$carrier_url_data = array_merge(
$base_url_data,
array(
'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine),
'id_filter' => $gateway_rule->carrier_id,
)
);
$gateway_url_data = array_merge(
$base_url_data,
array(
'service' => sprintf('pstn_gateways@%s', $this->SoapEngine->soapEngine),
'id_filter' => $gateway_rule->gateway_id,
)
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['id_filter'] == $gateway_rule->id) {
$delete_url_data['confirm'] = 1;
$actionText = "<font color=red>Confirm</font>";
} 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(
"
<tr>
<td valign=top>%s</td>
<td valign=top><a href=%s>%s</a></td>
<td valign=top><a href=%s>%s</a></td>
<td valign=top><a href=%s>%s</a> (%d)</td>
<td valign=top><a href=%s>%s (%d)</a></td>
<td valign=top>%s</td>
<td valign=top>%s</td>
<td valign=top>%s</td>
<td valign=top>%s</td>
<td valign=top>%s</td>
<td valign=top>%s</td>
<td valign=top><a class='btn-small btn-danger' href=%s>%s</a></td>
</tr>
",
$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
);
print "</tr>";
$i++;
}
}
print "</table>";
if ($this->rows == 1) {
$this->showRecord($gateway_rule);
} else {
$this->showPagination($maxrows);
}
return true;
}
}
function showAddForm()
{
//if ($this->selectionActive) return;
$this->getGateways();
if (!count($this->gateways)) {
print "<p>Create a gateway first</p>";
return false;
}
printf("<form class=form-inline method=post name=addform action=%s>", $_SERVER['PHP_SELF']);
print <<< END
<div class='well well-small'>
<input class='btn btn-warning' type=submit name=action value=Add>
<input type=hidden name=sortBy value=changeDate>
<div class='input-prepend'>
<span class='add-on'>Gateway</span>
<select class=span3 name=gateway_id>
END;
foreach (array_keys($this->gateways) as $_gateway) {
printf("<option value='%s'>%s", $_gateway, $this->gateways[$_gateway]);
}
print <<< END
</select>
</div>
<div class='input-prepend'><span class='add-on'>Prefix</span><input class=span1 type=text size=15 name=prefix></div>
<div class='input-prepend'><span class='add-on'>Strip</span><input class=span1 type=text size=5 name=strip></div>
<div class='input-prepend'>
<span class='add-on'>Prepend</span><input class=span1 type=text size=15 name=prepend>
</div>
<div class='input-prepend'>
<span class='add-on'>Min length</span><input class=span1 type=text size=5 name=minLength>
</div>
<div class='input-prepend'>
<span class='add-on'>Max length</span><input class=span1 type=text size=5 name=maxLength>
</div>
END;
$this->printHiddenFormElements();
print <<< END
</div>
</form>
END;
}
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("<p><font color=red>Error: Missing gateway id</font>");
return false;
}
$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'))
)
);
unset($this->filters);
return $this->SoapEngine->execute($function, $this->html);
}
function deleteRecord($dictionary = array())
{
if (!$dictionary['confirm'] && !$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete.</font></p>";
return true;
}
if ($dictionary['id']) {
$id = $dictionary['id'];
} else {
$id = trim($this->filters['id']);
}
if (!strlen($id)) {
print "<p><font color=red>Error: missing rule id </font>";
return false;
}
$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);
}
function showSeachFormCustom()
{
printf(
"
<div class='input-prepend'>
<span class='add-on'>Rule</span><input class=span2 type=text size=15 name=id_filter value='%s'>
</div>
",
$this->filters['id']
);
- print <<< END
- <select class=span2 name=carrier_id_filter>
- <option value=''>Carrier
-END;
- $selected_carrier[$this->filters['carrier_id']]='selected';
- foreach (array_keys($this->carriers) as $_carrier) {
- printf("<option value='%s' %s>%s", $_carrier, $selected_carrier[$_carrier], $this->carriers[$_carrier]);
+ if (count($this->carriers) > 250) {
+ printf(
+ "
+ <div class='input-prepend'>
+ <span class='add-on'>Carrier</span><input class=span2 type=text size=15 name=carrier_id_filter value='%s'>
+ </div>
+ ",
+ $this->filters['carrier_id']
+ );
+ } else {
+ print <<< END
+ <select class=span2 name=carrier_id_filter>
+ <option value=''>Carrier
+END;
+ $selected_carrier[$this->filters['carrier_id']] = 'selected';
+ foreach (array_keys($this->carriers) as $_carrier) {
+ printf(
+ "<option value='%s' %s>%s (%s)</option>",
+ $_carrier,
+ $selected_carrier[$_carrier],
+ $this->carriers[$_carrier],
+ $_carrier
+ );
+ }
+ print "</select>";
}
- print "</select>";
printf(
"
<div class='input-prepend'>
<span class='add-on'>Gateway</span><input class=span2 type=text size=15 name=gateway_id_filter value='%s'>
</div>
",
$this->filters['gateway_id']
);
printf(
"
<div class='input-prepend'>
<span class='add-on'>Prefix</span><input class=span1 type=text size=15 name=prefix_filter value='%s'>
</div>
",
$this->filters['prefix']
);
}
function showCustomerForm($name = 'customer_filter')
{
}
function showTextBeforeCustomerSelection()
{
print "Owner";
}
function showRecord($rule)
{
$this->getGateways();
print "<h3>Rule</h3>";
printf("<form class=form-horizontal method=post name=addform action=%s>", $_SERVER['PHP_SELF']);
print "<input type=hidden name=action value=Update>";
foreach (array_keys($this->Fields) as $item) {
if ($this->Fields[$item]['name']) {
$item_name = $this->Fields[$item]['name'];
} else {
$item_name=ucfirst($item);
}
printf(
"
<div class='control-group'>
<label class=control-label>%s</label>
",
$item_name
);
if ($this->Fields[$item]['readonly']) {
printf(
"
<div class=controls style='padding-top:5px'>
<input name=%s_form type=hidden value='%s'>
%s
</div>
",
$item,
$rule->$item,
$rule->$item
);
} else {
if ($item == 'gateway_id') {
printf("<div class=controls><select class=span2 name=%s_form>", $item);
$selected_gateway[$rule->$item]='selected';
foreach (array_keys($this->gateways) as $_gateway) {
printf(
"<option value='%s' %s>%s",
$_gateway,
$selected_gateway[$_gateway],
$this->gateways[$_gateway]
);
}
print "</select></div>";
} else {
printf(
"<div class=controls><input class=span2 name=%s_form size=30 type=text value='%s'></div>",
$item,
$rule->$item
);
}
}
print "
</div>";
}
printf("<input type=hidden name=reseller_filter value='%s'>", $rule->reseller);
$this->printFiltersToForm();
$this->printHiddenFormElements();
print <<< END
<div class="form-actions">
<input class='btn btn-warning' type=submit value=Update>
</div>
</form>
END;
}
function updateRecord()
{
//print "<p>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';
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',
'parameters' => array($rule),
'logs' => array('success' => sprintf('Rule %d has been updated', $_REQUEST['id_form'])))
);
$result = $this->SoapEngine->execute($function, $this->html);
dprint_r($result);
return (bool)$result;
}
function getRecord($id)
{
// Insert credetials
$this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth);
// Filter
$filter = array('id' => intval($id));
// Range
$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,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$this->log_action('getGatewayRules');
$result = $this->SoapEngine->soapclient->getGatewayRules($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
if ($result->gateway_rules[0]) {
return $result->gateway_rules[0];
} else {
return false;
}
}
}
}
diff --git a/library/NGNPro/Records/Gateways.php b/library/NGNPro/Records/Gateways.php
index 7641477..4092c8e 100644
--- a/library/NGNPro/Records/Gateways.php
+++ b/library/NGNPro/Records/Gateways.php
@@ -1,564 +1,580 @@
<?php
class Gateways extends Records
{
var $carriers = array();
var $FieldsReadOnly = array(
'reseller',
'changeDate'
);
var $Fields = array(
'id' => array('type'=>'integer',
'readonly' => true),
'name' => array('type'=>'string'),
'carrier_id' => array('type'=>'integer'),
'transport' => array('type'=>'string'),
'ip' => array('name'=>'IP or hostname',
'type'=>'string'),
'port' => array('type'=>'integer')
);
//var $transports = array('udp','tcp','tls');
var $transports = array('udp');
public function __construct($SoapEngine)
{
$this->filters = array(
'id' => trim($_REQUEST['id_filter']),
'name' => trim($_REQUEST['name_filter']),
'carrier_id' => trim($_REQUEST['carrier_id_filter'])
);
$this->sortElements = array(
'changeDate' => 'Change date',
'name' => 'Gateway',
'carrier_id' => 'Carrier',
'ip' => 'Address'
);
parent::__construct($SoapEngine);
}
function listRecords()
{
$this->getCarriers();
$this->showSeachForm();
// Insert credetials
$this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth);
// Filter
$filter = array(
'id' => intval($this->filters['id']),
'name' => $this->filters['name'],
'carrier_id'=> intval($this->filters['carrier_id']),
'customer' => intval($this->filters['customer']),
'reseller' => intval($this->filters['reseller'])
);
// Range
$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'] = 'DESC';
$orderBy = array(
'attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query = array(
'filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$this->log_action('getGateways');
$result = $this->SoapEngine->soapclient->getGateways($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
$this->rows = $result->total;
print <<< END
<div class="alert alert-success"><center>$this->rows records found</center></div>
<p>
<table class='table table-striped table-condensed' width=100%>
<thead>
<tr>
<th>Id</th>
<th>Owner</th>
<th>Gateway</th>
<th>Carrier</th>
<th>Name</th>
<th>Address</th>
<th>Rules</th>
<th>Change date</th>
<th>Actions</th>
</tr>
</thead>
END;
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows=$this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->gateways[$i]) break;
$gateway = $result->gateways[$i];
$index = $this->next + $i + 1;
$base_url_data = array(
'service' => $this->SoapEngine->service,
'id_filter' => $gateway->id,
);
$delete_url_data = array_merge(
$base_url_data,
array(
'action' => 'Delete',
)
);
$customer_url_data = array(
'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine),
'customer_filter' => $gateway->reseller
);
$carrier_url_data = array_merge(
$base_url_data,
array(
'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine),
'id_filter' => $gateway->carrier_id,
'reseller_filter' => $gateway->reseller,
)
);
$rules_url_data = array(
'service' => sprintf('gateway_rules@%s', $this->SoapEngine->soapEngine),
'gateway_id_filter' => $gateway->id,
'reseller_filter' => $gateway->reseller
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['id_filter'] == $gateway->id) {
$delete_url_data['confirm'] = 1;
$actionText = "<font color=red>Confirm</font>";
} 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);
$_rules_url = $this->buildUrl($rules_url_data);
printf(
"
<tr>
<td valign=top>%s</td>
<td valign=top><a href=%s>%s</a></td>
<td valign=top><a href=%s>%s</a></td>
<td valign=top><a href=%s>%s</a></td>
<td valign=top>%s</td>
<td valign=top>%s:%s:%s</td>
<td valign=top><a href=%s>Rules</a></td>
<td valign=top>%s</td>
<td valign=top><a class='btn-small btn-danger' href=%s>%s</a></td>
</tr>
",
$index,
$_customer_url,
$gateway->reseller,
$_url,
$gateway->id,
$_carrier_url,
$gateway->carrier,
$gateway->name,
$gateway->transport,
$gateway->ip,
$gateway->port,
$_rules_url,
$gateway->changeDate,
$_delete_url,
$actionText
);
printf("
</tr>
");
$i++;
}
}
print "</table>";
if ($this->rows == 1) {
$this->showRecord($gateway);
} else {
$this->showPagination($maxrows);
}
return true;
}
}
function showAddForm()
{
//if ($this->selectionActive) return;
$this->getCarriers();
if (!count($this->carriers)) {
print "<p>Create a carrier first";
return false;
}
printf("<form class='form-inline' method=post name=addform action=%s>", $_SERVER['PHP_SELF']);
print <<< END
<div class='well well-small'>
<input class='btn btn-warning' type=submit name=action value=Add>
Carrier
<select name=carrier_id>
END;
foreach (array_keys($this->carriers) as $_carrier) {
printf("<option value='%s'>%s", $_carrier, $this->carriers[$_carrier]);
}
print <<< END
</select>
<div class=input-prepend><span class="add-on">Name</span><input class=span2 type=text size=20 name=name></div>
<div class=input-prepend><span class="add-on">Transport</span>
<select class=span1 name=transport>
END;
foreach ($this->transports as $_transport) {
printf("<option value='%s'>%s", $_transport, $_transport);
}
print <<< END
</select>
</div>
<div class=input-prepend>
<span class="add-on">Address</span><input class=span2 type=text size=25 name=address>
</div>
END;
$this->printHiddenFormElements();
print "</div>
</form>
";
}
function addRecord($dictionary = array())
{
if ($dictionary['name']) {
$name = $dictionary['name'];
} else {
$name = trim($_REQUEST['name']);
}
if ($dictionary['carrier_id']) {
$carrier_id = $dictionary['carrier_id'];
} else {
$carrier_id = trim($_REQUEST['carrier_id']);
}
if ($dictionary['address']) {
$address = $dictionary['address'];
} else {
$address = trim($_REQUEST['address']);
}
if ($dictionary['transport']) {
$transport = $dictionary['transport'];
} else {
$transport = trim($_REQUEST['transport']);
}
if (!strlen($name) || !strlen($carrier_id) || !strlen($address)) {
printf("<p><font color=red>Error: Missing gateway name, carrier_id or address</font>");
return false;
}
$address_els = explode(':', $address);
if (count($address_els) == 1) {
$ip = $address_els[0];
$port ='5060';
} elseif (count($address_els) == 2) {
$ip = $address_els[0];
$port = $address_els[1];
}
if (!$port) $port = 5060;
if (!in_array($transport, $this->transports)) {
$transport=$this->transports[0];
}
$gateway = array(
'name' => $name,
'carrier_id' => intval($carrier_id),
'ip' => $ip,
'port' => intval($port),
'transport' => $transport
);
$function = array(
'commit' => array(
'name' => 'addGateway',
'parameters' => array($gateway),
'logs' => array('success' => sprintf('Gateway %s has been added', $name))
)
);
unset($this->filters);
return $this->SoapEngine->execute($function, $this->html);
}
function deleteRecord($dictionary = array())
{
if (!$dictionary['confirm'] && !$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return true;
}
if ($dictionary['id']) {
$id = $dictionary['id'];
} else {
$id = trim($this->filters['id']);
}
if (!strlen($id)) {
print "<p><font color=red>Error: missing gateway id.</font>";
return false;
}
$function = array(
'commit' => array(
'name' => 'deleteGateway',
'parameters' => array(intval($id)),
'logs' => array('success' => sprintf('Gateway %d has been deleted', $id))
)
);
unset($this->filters);
return $this->SoapEngine->execute($function, $this->html);
}
function showSeachFormCustom()
{
printf(
"
<div class=input-prepend>
<span class=\"add-on\">Gateway</span>
<input class=2 type=text size=10 name=id_filter value='%s'>
</div>
",
$this->filters['id']
);
- print "
- <select name=carrier_id_filter>
- <option value=''>Carrier";
-
- $selected_carrier[$this->filters['carrier_id']]='selected';
-
- foreach (array_keys($this->carriers) as $_carrier) {
- printf("<option value='%s' %s>%s", $_carrier, $selected_carrier[$_carrier], $this->carriers[$_carrier]);
+ if (count($this->carriers) > 250) {
+ printf(
+ "
+ <div class='input-prepend'>
+ <span class='add-on'>Carrier</span><input class=span2 type=text size=15 name=carrier_id_filter value='%s'>
+ </div>
+ ",
+ $this->filters['carrier_id']
+ );
+ } else {
+ print <<< END
+ <select class=span2 name=carrier_id_filter>
+ <option value=''>Carrier
+END;
+ $selected_carrier[$this->filters['carrier_id']] = 'selected';
+ foreach (array_keys($this->carriers) as $_carrier) {
+ printf(
+ "<option value='%s' %s>%s (%s)</option>",
+ $_carrier,
+ $selected_carrier[$_carrier],
+ $this->carriers[$_carrier],
+ $_carrier
+ );
+ }
+ print "</select>";
}
- print "</select>";
printf(
"
<div class=input-prepend>
<span class=\"add-on\">Name</span><input type=text size=20 name=name_filter value='%s'>
</div>
",
$this->filters['name']
);
}
function showCustomerForm($name = 'customer_filter')
{
}
function showTextBeforeCustomerSelection()
{
print "Owner";
}
function showRecord($gateway)
{
print "<h3>Gateway</h3>";
printf("<form class=form-horizontal method=post name=addform action=%s>", $_SERVER['PHP_SELF']);
print "<input type=hidden name=action value=Update>";
foreach (array_keys($this->Fields) as $item) {
if ($this->Fields[$item]['name']) {
$item_name=$this->Fields[$item]['name'];
} else {
$item_name = ucfirst($item);
}
printf(
"<div class=control-group><label class=control-label>%s</label>",
$item_name
);
if ($this->Fields[$item]['readonly']) {
printf(
"<div class=controls style='padding-top:5px'><input name=%s_form type=hidden value='%s'>%s</div>",
$item,
$gateway->$item,
$gateway->$item
);
} else {
if ($item == 'carrier_id') {
printf("<div class=controls><select class=span2 name=%s_form>", $item);
$selected_carrier[$gateway->$item]='selected';
foreach (array_keys($this->carriers) as $_carrier) {
printf(
"<option value='%s' %s>%s",
$_carrier,
$selected_carrier[$_carrier],
$this->carriers[$_carrier]
);
}
print "</select></div>";
} elseif ($item == 'transport') {
printf("<div class=controls><select class=span2 name=%s_form>", $item);
$selected_transport[$gateway->$item]='selected';
foreach ($this->transports as $_transport) {
printf("<option value='%s' %s>%s", $_transport, $selected_transport[$_transport], $_transport);
}
print "</select></div>";
} else {
printf(
"<div class=controls><input class=span2 name=%s_form size=30 type=text value='%s'></div>",
$item,
$gateway->$item
);
}
}
print "</div>";
}
printf("<input type=hidden name=id_filter value='%s'>", $gateway->id);
$this->printFiltersToForm();
$this->printHiddenFormElements();
print "
<div class=form-actions>
<input class='btn btn-warning' type=submit value=Update>
</div>
";
print "</form>";
}
function updateRecord()
{
//print "<p>Updating gateway ...";
if (!$_REQUEST['id_filter']) return;
if (!$gateway = $this->getRecord($_REQUEST['id_filter'])) {
return false;
}
foreach (array_keys($this->Fields) as $item) {
$var_name=$item.'_form';
if ($this->Fields[$item]['type'] == 'integer') {
$gateway->$item = intval($_REQUEST[$var_name]);
} else {
$gateway->$item = trim($_REQUEST[$var_name]);
}
}
if (!in_array($gateway->transport, $this->transports)) {
printf("<font color=red>Invalid transport '%s'</font>", $gateway->transport);
return false;
}
$function = array(
'commit' => array(
'name' => 'updateGateway',
'parameters' => array($gateway),
'logs' => array(
'success' => sprintf('Gateway %s has been updated', $_REQUEST['name_filter'])))
);
$result = $this->SoapEngine->execute($function, $this->html);
dprint_r($result);
return (bool)$result;
}
function getRecord($id)
{
// Insert credetials
$this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth);
// Filter
$filter = array('id' => intval($id));
// Range
$range = array(
'start' => 0,
'count' => 1
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array(
'attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query = array(
'filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$this->log_action('getGateways');
$result = $this->SoapEngine->soapclient->getGateways($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
if ($result->gateways[0]) {
return $result->gateways[0];
} else {
return false;
}
}
}
}
diff --git a/library/NGNPro/Records/Routes.php b/library/NGNPro/Records/Routes.php
index d5522c5d..8691089 100644
--- a/library/NGNPro/Records/Routes.php
+++ b/library/NGNPro/Records/Routes.php
@@ -1,528 +1,544 @@
<?php
class Routes extends Records
{
var $carriers = array();
var $Fields = array(
'id' => array(
'type'=>'integer',
'readonly' => true
),
'carrier_id' => array('type'=>'integer','name'=>'Carrier'),
'prefix' => array('type'=>'string'),
'originator' => array('type'=>'string'),
'priority' => array('type'=>'integer')
);
var $sortElements = array(
'prefix' => 'Prefix',
'priority' => 'Priority'
);
public function __construct($SoapEngine)
{
$this->filters = array(
'prefix' => trim($_REQUEST['prefix_filter']),
'priority' => trim($_REQUEST['priority_filter']),
'carrier_id'=> trim($_REQUEST['carrier_id_filter']),
'reseller' => trim($_REQUEST['reseller_filter']),
'id' => trim($_REQUEST['id_filter'])
);
parent::__construct($SoapEngine);
}
function listRecords()
{
$this->getCarriers();
$this->showSeachForm();
// Insert credetials
$this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth);
// Filter
$filter = array(
'prefix' => $this->filters['prefix'],
'carrier_id' => intval($this->filters['carrier_id']),
'reseller' => intval($this->filters['reseller']),
'id' => intval($this->filters['id'])
);
// Range
$range = array(
'start' => intval($this->next),
'count' => intval($this->maxrowsperpage)
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'prefix';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array(
'attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query = array(
'filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$this->log_action('getRoutes');
$result = $this->SoapEngine->soapclient->getRoutes($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
$this->rows = $result->total;
print <<< END
<div class="alert alert-success"><center>$this->rows records found</center></div>
<p>
<table class='table table-condensed table-striped'width=100%>
<thead>
<tr>
<th><b>Id</b></th>
<th><b>Owner</b></th>
<th><b>Route</b></th>
<th><b>Carrier</b></th>
<th><b>Gateways</b></th>
<th><b>Prefix</b></th>
<th><b>Originator</b></th>
<th><b>Priority</b></th>
<th><b>Change date</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
END;
if (!$this->next) $this->next=0;
if ($this->rows > $this->maxrowsperpage) {
$maxrows = $this->maxrowsperpage + $this->next;
if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage;
} else {
$maxrows = $this->rows;
}
$i=0;
if ($this->rows) {
while ($i < $maxrows) {
if (!$result->routes[$i]) break;
$route = $result->routes[$i];
$index = $this->next+$i+1;
$base_url_data = array(
'service' => $this->SoapEngine->service,
'id_filter' => $route->id,
);
$delete_url_data = array_merge(
$base_url_data,
array(
'action' => 'Delete',
)
);
$customer_url_data = array(
'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine),
'customer_filter' => $route->reseller
);
$carrier_url_data = array_merge(
$base_url_data,
array(
'service' => sprintf('pstn_carriers@%s', $this->SoapEngine->soapEngine),
'id_filter' => $route->carrier_id,
)
);
$gateway_url_data = array(
'service' => sprintf('pstn_gateways@%s', $this->SoapEngine->soapEngine),
'carrier_id_filter' => $route->carrier_id,
'reseller_filter' => $route->reseller
);
if ($_REQUEST['action'] == 'Delete' &&
$_REQUEST['id_filter'] == $route->id) {
$delete_url_data['confirm'] = 1;
$actionText = "<font color=red>Confirm</font>";
} 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(
"
<tr>
<td>%s</td>
<td><a href=%s>%s</a></td>
<td><a href=%s>%s</a></td>
<td><a href=%s>%s</a></td>
<td><a href=%s>Gateways</a></td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td><a class='btn-small btn-danger' href=%s>%s</a></td>
</tr>
",
$index,
$_customer_url,
$route->reseller,
$_url,
$route->id,
$_carrier_url,
$route->carrier,
$_gateway_url,
$route->prefix,
$route->originator,
$route->priority,
$route->changeDate,
$_delete_url,
$actionText
);
print "</tr>";
$i++;
}
}
print "</table>";
if ($this->rows == 1) {
$this->showRecord($route);
} else {
$this->showPagination($maxrows);
}
return true;
}
}
function showAddForm()
{
//if ($this->selectionActive) return;
if (!count($this->carriers)) {
print "<p>Create a carrier first";
return false;
}
printf(
"<form class=form-inline method=post name=addform action=%s><div class='well well-small'>",
$_SERVER['PHP_SELF']
);
print <<< END
<input class='btn btn-warning' type=submit name=action value=Add>
<div class='input-prepend'>
<span class='add-on'>Carrier</span>
<select class=span2 name=carrier_id>
END;
foreach (array_keys($this->carriers) as $_carrier) {
printf("<option value='%s'>%s", $_carrier, $this->carriers[$_carrier]);
}
print <<< END
</select>
</div>
<div class='input-prepend'><span class='add-on'>Prefix</span><input type=text size=20 name=prefix></div>
<div class='input-prepend'><span class='add-on'>Originator</span><input type=text size=20 name=originator></div>
<div class='input-prepend'><span class='add-on'>Priority</span><input type=text size=5 name=priority></div>
END;
$this->printHiddenFormElements();
print "</div>
</form>
";
}
function addRecord($dictionary = array())
{
if ($dictionary['prefix']) {
$prefix = $dictionary['prefix'];
} else {
$prefix = trim($_REQUEST['prefix']);
}
if ($dictionary['carrier_id']) {
$carrier_id = $dictionary['carrier_id'];
} else {
$carrier_id = trim($_REQUEST['carrier_id']);
}
if ($dictionary['originator']) {
$originator = $dictionary['originator'];
} else {
$originator = trim($_REQUEST['originator']);
}
if ($dictionary['priority']) {
$priority = $dictionary['priority'];
} else {
$priority = trim($_REQUEST['priority']);
}
if (!strlen($carrier_id)) {
printf("<p><font color=red>Error: Missing carrier id. </font>");
return false;
}
$route = array(
'prefix' => $prefix,
'originator' => $originator,
'carrier_id' => intval($carrier_id),
'priority' => intval($priority)
);
$routes = array($route);
$function = array(
'commit' => array(
'name' => 'addRoutes',
'parameters' => array($routes),
'logs' => array('success' => sprintf('Route %s has been added', $prefix))
)
);
unset($this->filters);
return $this->SoapEngine->execute($function, $this->html);
}
function deleteRecord($dictionary = array())
{
if (!$dictionary['confirm'] && !$_REQUEST['confirm']) {
print "<p><font color=red>Please press on Confirm to confirm the delete. </font>";
return true;
}
if ($dictionary['id']) {
$id = $dictionary['id'];
} else {
$id = trim($this->filters['id']);
}
if (!strlen($id)) {
print "<p><font color=red>Error: missing route id. </font>";
return false;
}
$route = array('id'=> intval($id));
$routes = array($route);
$function = array(
'commit' => array(
'name' => 'deleteRoutes',
'parameters' => array($routes),
'logs' => array('success' => sprintf('Route %s has been deleted', $id))
)
);
unset($this->filters);
return $this->SoapEngine->execute($function, $this->html);
}
function showSeachFormCustom()
{
-
printf(
"
<div class='input-prepend'>
<span class='add-on'>Route</span><input type=text size=10 name=id_filter value='%s'>
</div>
",
$this->filters['id']
);
- print <<< END
- <select name=carrier_id_filter>
- <option value=''>Carrier
-END;
- $selected_carrier[$this->filters['carrier_id']]='selected';
- foreach (array_keys($this->carriers) as $_carrier) {
- printf("<option value='%s' %s>%s", $_carrier, $selected_carrier[$_carrier], $this->carriers[$_carrier]);
+ if (count($this->carriers) > 250) {
+ printf(
+ "
+ <div class='input-prepend'>
+ <span class='add-on'>Carrier</span><input class=span2 type=text size=15 name=carrier_id_filter value='%s'>
+ </div>
+ ",
+ $this->filters['carrier_id']
+ );
+ } else {
+ print <<< END
+ <select class=span2 name=carrier_id_filter>
+ <option value=''>Carrier
+END;
+ $selected_carrier[$this->filters['carrier_id']] = 'selected';
+ foreach (array_keys($this->carriers) as $_carrier) {
+ printf(
+ "<option value='%s' %s>%s (%s)</option>",
+ $_carrier,
+ $selected_carrier[$_carrier],
+ $this->carriers[$_carrier],
+ $_carrier
+ );
+ }
+ print "</select>";
}
- print "</select>";
printf(
"
<div class='input-prepend'>
<span class='add-on'>Prefix</span><input type=text size=15 name=prefix_filter value='%s'>
</div>
",
$this->filters['prefix']
);
}
function showCustomerTextBox()
{
print "Owner";
$this->showResellerForm('reseller');
}
function showCustomerForm($name = 'customer_filter')
{
}
function showTextBeforeCustomerSelection()
{
print "Owner";
}
function getRecord($id)
{
// Insert credetials
$this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth);
// Filter
$filter = array('id' => intval($id));
// Range
$range = array(
'start' => 0,
'count' => 1
);
// Order
if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'prefix';
if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC';
$orderBy = array(
'attribute' => $this->sorting['sortBy'],
'direction' => $this->sorting['sortOrder']
);
// Compose query
$Query = array(
'filter' => $filter,
'orderBy' => $orderBy,
'range' => $range
);
// Call function
$this->log_action('getRoutes');
$result = $this->SoapEngine->soapclient->getRoutes($Query);
if ($this->checkLogSoapError($result, true)) {
return false;
} else {
if ($result->routes[0]) {
return $result->routes[0];
} else {
return false;
}
}
}
function showRecord($route)
{
print "<h3>Route</h3>";
printf("<form class = form-horizontal method=post name=addform action=%s>", $_SERVER['PHP_SELF']);
print "<input type=hidden name=action value=Update>";
foreach (array_keys($this->Fields) as $item) {
if ($this->Fields[$item]['name']) {
$item_name = $this->Fields[$item]['name'];
} else {
$item_name = ucfirst($item);
}
printf(
"
<div class=control-group>
<label class=control-label>%s</label>
",
$item_name
);
if ($this->Fields[$item]['readonly']) {
printf(
"<div class=controls style='padding-top:5px'><input name=%s_form type=hidden value='%s'>%s</div>",
$item,
$route->$item,
$route->$item
);
} else {
if ($item == 'carrier_id') {
printf("<div class=controls><select name=%s_form>", $item);
$selected_carrier[$route->$item] = 'selected';
foreach (array_keys($this->carriers) as $_carrier) {
printf(
"<option value='%s' %s>%s",
$_carrier,
$selected_carrier[$_carrier],
$this->carriers[$_carrier]
);
}
print "</select></div>";
} else {
printf(
"<div class=controls><input name=%s_form type=text value='%s'></div>",
$item,
$route->$item
);
}
}
print "</div>";
}
printf("<input type=hidden name=id_filter value='%s'>", $route->id);
$this->printFiltersToForm();
$this->printHiddenFormElements();
print "
<div class='form-actions'>
<input class='btn btn-warning' type=submit value=Update>
</div>
";
print "</form>";
}
function updateRecord()
{
//print "<p>Updating route ...";
if (!$_REQUEST['id_filter']) return;
if (!$route = $this->getRecord($_REQUEST['id_filter'])) {
return false;
}
foreach (array_keys($this->Fields) as $item) {
$var_name = $item.'_form';
if ($this->Fields[$item]['type'] == 'integer') {
$route->$item = intval($_REQUEST[$var_name]);
} else {
$route->$item = trim($_REQUEST[$var_name]);
}
}
$routes = array($route);
$function = array(
'commit' => array(
'name' => 'updateRoutes',
'parameters' => array($routes),
'logs' => array('success' => sprintf('Route %d has been updated', $_REQUEST['id_filter']))
)
);
return (bool)$this->SoapEngine->execute($function, $this->html);
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Dec 28, 8:46 AM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3453248
Default Alt Text
(56 KB)
Attached To
Mode
rCDRT CDRTool
Attached
Detach File
Event Timeline
Log In to Comment