[Added Update Gateway Adrian Georgescu **20081119132232] hunk ./library/ngnpro_client.php 234 - 'description' => 'Manage gateways used to call to the PSTN. Set the IP address and IP protocol. ', + 'description' => 'Manage gateways used to call to the PSTN. ', hunk ./library/ngnpro_client.php 394 + $this->ports['pstn_gateways']['description']= 'Manage gateways used to call to the PSTN. Click on the gateway to edit its rules. '; hunk ./library/ngnpro_client.php 8515 - hunk ./library/ngnpro_client.php 9021 + var $FieldsReadOnly=array( + 'reseller', + 'changeDate' + ); + + var $Fields=array( + 'name' => array('type'=>'string'), + 'carrier' => array('type'=>'string'), + 'transport' => array('type'=>'string'), + 'ip' => array('type'=>'string'), + 'port' => array('type'=>'integer') + ); hunk ./library/ngnpro_client.php 9034 + var $transports=array('udp','tcp','tls'); hunk ./library/ngnpro_client.php 9214 + $_carrier_url = $this->url.sprintf("&service=pstn_gateways@%s&carrier_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($carrier->name), + urlencode($carrier->reseller) + ); + + $name_link = $this->url.sprintf("&service=%s&name_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($gateway->name), + urlencode($gateway->reseller) + ); + hunk ./library/ngnpro_client.php 9236 - %s + %s hunk ./library/ngnpro_client.php 9251 + $name_link, hunk ./library/ngnpro_client.php 9296 - %s + %s hunk ./library/ngnpro_client.php 9307 + $name_link, hunk ./library/ngnpro_client.php 9398 - $this->showPagination($maxrows); + if ($this->rows == 1 && $this->version > 3) { + $this->showRecord($gateway); + } else { + $this->showPagination($maxrows); + } hunk ./library/ngnpro_client.php 9598 + + function showRecord($gateway) { + + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print " + + + + "; + print ""; + print "
"; + print "

Gateway

"; + print "
"; + print "

Rules

"; + print "
"; + + print ""; + + printf ("",$_SERVER['PHP_SELF']); + print ""; + + printf ("",$gateway->name); + + foreach (array_keys($this->Fields) as $item) { + if ($this->Fields[$item]['name']) { + $item_name=$this->Fields[$item]['name']; + } else { + $item_name=ucfirst($item); + } + + printf (" + + + ", + $item_name, + $item, + $gateway->$item + ); + } + + printf ("name); + printf ("reseller); + + $this->printFiltersToForm(); + $this->printHiddenFormElements(); + + print " +
Gateway%s
%s
+ "; + + print "
"; + + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + print ""; + + $j=0; + foreach ($gateway->rules as $_rule) { + $j++; + print ""; + print ""; + printf (" + + + + + + ", + $_rule->prefix, + $_rule->strip, + $_rule->prepend, + $_rule->min_length, + $_rule->max_length + ); + print ""; + } + + $j++; + print ""; + print ""; + + printf (" + + + + + + + + " + ); + + print "
RulePrefixStrip digitsPrependMin digitsMax digits
$j
"; + + print "
+ +
"; + + } + + function updateRecord () { + //print "

Updating gateway ..."; + + if (!$_REQUEST['name_filter'] || !$_REQUEST['reseller_filter']) return; + + if (!$gateway = $this->getRecord($name_filter)) { + return false; + } + + $new_rules=array(); + + $j=0; + while ($j < count($_REQUEST['rule_prefix'])) { + + $prefix = $_REQUEST['rule_prefix'][$j]; + $strip = $_REQUEST['rule_strip'][$j]; + $prepend = $_REQUEST['rule_prepend'][$j]; + $min_length = $_REQUEST['rule_min_length'][$j]; + $max_length = $_REQUEST['rule_max_length'][$j]; + + if (strlen($prefix) || + strlen($strip) || + strlen($prepend) || + strlen($min_length) || + strlen($max_length) + ) { + $new_rules[]=array( 'prefix' => $prefix, + 'strip' => intval($strip), + 'prepend' => $prepend, + 'min_length' => intval($min_length), + 'max_length' => intval($max_length) + ); + } + $j++; + } + + $gateway->rules=$new_rules; + + 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 ("Invalid transport '%s'",$gateway->transport); + return false; + } + + $function=array('commit' => array('name' => 'updateGateway', + 'parameters' => array($gateway), + 'logs' => array('success' => sprintf('Gateway %s has been updated',$name))) + ); + + $result = $this->SoapEngine->execute($function,$this->html); + + dprint_r($result) ; + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + + return false; + } else { + return true; + } + } + + function getRecord($name) { + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array('name' => $name); + + // 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 + $result = $this->SoapEngine->soapclient->getGateways($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } else { + if ($result->gateways[0]){ + return $result->gateways[0]; + } else { + return false; + } + } + }