[Moved Carriers to seperate file Tijmen de Mes **20240212155920 Ignore-this: 25a9b1db45522a033392ded42304bf0d7d61db335fe2192d20b3aa81d235b20f4f79347651c16232 ] addfile ./library/NGNPro/Records/Carriers.php hunk ./library/NGNPro/Records/Carriers.php 1 + array('type'=>'integer', + 'readonly' => true), + 'name' => array('type'=>'string') + ); + + var $sortElements=array( + 'changeDate' => 'Change date', + 'name' => 'Carrier' + ); + + public function __construct($SoapEngine) + { + $this->filters = array( + 'id' => trim($_REQUEST['id_filter']), + 'name' => trim($_REQUEST['name_filter']) + ); + parent::__construct($SoapEngine); + } + + function showCustomerTextBox () { + print "Reseller"; + print ""; + $this->showResellerForm('reseller'); + print ""; + } + + function listRecords() { + + $this->showSeachForm(); + + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array( + 'id' => intval($this->filters['id']), + 'name' => $this->filters['name'], + '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('getCarriers'); + $result = $this->SoapEngine->soapclient->getCarriers($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); + return false; + } else { + + $this->rows = $result->total; + + print " +
$this->rows records found
+

+ + "; + + print " + + + + + + + + + + + + "; + + 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->carriers[$i]) break; + + $carrier = $result->carriers[$i]; + + $index=$this->next+$i+1; + + $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($carrier->id) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['id_filter'] == $carrier->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($carrier->id), + urlencode($carrier->reseller) + ); + + $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", + urlencode($this->SoapEngine->customer_engine), + urlencode($carrier->reseller) + ); + + $_gateway_url = $this->url.sprintf("&service=pstn_gateways@%s&carrier_id_filter=%d&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($carrier->id), + urlencode($carrier->reseller) + ); + + printf(" + + + + + + + + + ", + $index, + $_customer_url, + $carrier->reseller, + $_url, + $carrier->id, + $carrier->name, + $_gateway_url, + $carrier->changeDate, + $_delete_url, + $actionText + ); + + printf(" + + "); + $i++; + + } + + } + + print "
IdOwnerCarrierNameGatewaysChange dateActions
%s%s%s%sGateways%s%s
"; + + if ($this->rows == 1) { + $this->showRecord($carrier); + } else { + $this->showPagination($maxrows); + } + + return true; + } + } + + function showAddForm() { + //if ($this->selectionActive) return; + printf ("

",$_SERVER['PHP_SELF']); + print " +
+ "; + + print " + + "; + print "
"; + $this->showCustomerTextBox(); + + printf ("
Name
"); + + $this->printHiddenFormElements(); + + print "
+ + "; + } + + function addRecord($dictionary=array()) { + + if ($dictionary['name']) { + $name=$dictionary['name']; + } else { + $name = trim($_REQUEST['name']); + } + + list($customer,$reseller)=$this->customerFromLogin($dictionary); + + $structure=array('name' => $name, + 'reseller' => intval($reseller) + ); + + + if (!strlen($name)) { + printf ("

Error: Missing name. "); + return false; + } + + $function=array('commit' => array('name' => 'addCarrier', + 'parameters' => array($structure), + 'logs' => array('success' => sprintf('Carrier %s has been added',$name))) + ); + + return $this->SoapEngine->execute($function,$this->html); + } + + function deleteRecord($dictionary=array()) { + if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { + 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 carrier id "; + return false; + } + + $function=array('commit' => array('name' => 'deleteCarrier', + 'parameters' => array(intval($id)), + 'logs' => array('success' => sprintf('Carrier %d has been deleted',$id))) + ); + + unset($this->filters); + return $this->SoapEngine->execute($function,$this->html); + } + + function showSeachFormCustom() { + printf ("

Carrier
",$this->filters['id']); + printf ("
Name
",$this->filters['name']); + } + + 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'] = '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('getCarriers'); + $result = $this->SoapEngine->soapclient->getCarriers($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); + return false; + } else { + if ($result->carriers[0]){ + return $result->carriers[0]; + } else { + return false; + } + } + } + + function showRecord($carrier) { + + print "

Carrier

"; + + + printf ("
",$_SERVER['PHP_SELF']); + print ""; + + 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 + ); + + if ($this->Fields[$item]['readonly']) { + printf ("
%s
", + $item, + $carrier->$item, + $carrier->$item + ); + } else { + printf ("
", + $item, + $carrier->$item + ); + } + print " +
"; + } + + printf ("",$carier->id); + + $this->printFiltersToForm(); + $this->printHiddenFormElements(); + + print " +
+ +
+ "; + print "
"; + + } + + function updateRecord () { + //print "

Updating carrier ..."; + + if (!$_REQUEST['id_filter']) return; + + if (!$carrier = $this->getRecord($_REQUEST['id_filter'])) { + return false; + } + + foreach (array_keys($this->Fields) as $item) { + $var_name=$item.'_form'; + if ($this->Fields[$item]['type'] == 'integer') { + $carrier->$item = intval($_REQUEST[$var_name]); + } else { + $carrier->$item = trim($_REQUEST[$var_name]); + } + } + + $function=array('commit' => array('name' => 'updateCarrier', + 'parameters' => array($carrier), + 'logs' => array('success' => sprintf('Carrier %d has been updated',$_REQUEST['id_filter']))) + ); + + $result = $this->SoapEngine->execute($function,$this->html); + + 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; + } + } +} + hunk ./library/ngnpro_client.php 3296 -class Carriers extends Records -{ - var $carriers=array(); - - var $Fields=array( - 'id' => array('type'=>'integer', - 'readonly' => true), - 'name' => array('type'=>'string') - ); - - var $sortElements=array( - 'changeDate' => 'Change date', - 'name' => 'Carrier' - ); - - public function __construct($SoapEngine) - { - $this->filters = array( - 'id' => trim($_REQUEST['id_filter']), - 'name' => trim($_REQUEST['name_filter']) - ); - parent::__construct($SoapEngine); - } - - function showCustomerTextBox () { - print "Reseller"; - print ""; - $this->showResellerForm('reseller'); - print "

"; - } - - function listRecords() { - - $this->showSeachForm(); - - // Insert credetials - $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); - - // Filter - $filter=array( - 'id' => intval($this->filters['id']), - 'name' => $this->filters['name'], - '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('getCarriers'); - $result = $this->SoapEngine->soapclient->getCarriers($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); - return false; - } else { - - $this->rows = $result->total; - - print " -
$this->rows records found
-

- - "; - - print " - - - - - - - - - - - - "; - - 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->carriers[$i]) break; - - $carrier = $result->carriers[$i]; - - $index=$this->next+$i+1; - - $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($carrier->id) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['id_filter'] == $carrier->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($carrier->id), - urlencode($carrier->reseller) - ); - - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($carrier->reseller) - ); - - $_gateway_url = $this->url.sprintf("&service=pstn_gateways@%s&carrier_id_filter=%d&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($carrier->id), - urlencode($carrier->reseller) - ); - - printf(" - - - - - - - - - ", - $index, - $_customer_url, - $carrier->reseller, - $_url, - $carrier->id, - $carrier->name, - $_gateway_url, - $carrier->changeDate, - $_delete_url, - $actionText - ); - - printf(" - - "); - $i++; - - } - - } - - print "
IdOwnerCarrierNameGatewaysChange dateActions
%s%s%s%sGateways%s%s
"; - - if ($this->rows == 1) { - $this->showRecord($carrier); - } else { - $this->showPagination($maxrows); - } - - return true; - } - } - - function showAddForm() { - //if ($this->selectionActive) return; - printf ("

",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - "; - print "
"; - $this->showCustomerTextBox(); - - printf ("
Name
"); - - $this->printHiddenFormElements(); - - print "
- - "; - } - - function addRecord($dictionary=array()) { - - if ($dictionary['name']) { - $name=$dictionary['name']; - } else { - $name = trim($_REQUEST['name']); - } - - list($customer,$reseller)=$this->customerFromLogin($dictionary); - - $structure=array('name' => $name, - 'reseller' => intval($reseller) - ); - - - if (!strlen($name)) { - printf ("

Error: Missing name. "); - return false; - } - - $function=array('commit' => array('name' => 'addCarrier', - 'parameters' => array($structure), - 'logs' => array('success' => sprintf('Carrier %s has been added',$name))) - ); - - return $this->SoapEngine->execute($function,$this->html); - } - - function deleteRecord($dictionary=array()) { - if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { - 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 carrier id "; - return false; - } - - $function=array('commit' => array('name' => 'deleteCarrier', - 'parameters' => array(intval($id)), - 'logs' => array('success' => sprintf('Carrier %d has been deleted',$id))) - ); - - unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); - } - - function showSeachFormCustom() { - printf ("

Carrier
",$this->filters['id']); - printf ("
Name
",$this->filters['name']); - } - - 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'] = '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('getCarriers'); - $result = $this->SoapEngine->soapclient->getCarriers($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); - return false; - } else { - if ($result->carriers[0]){ - return $result->carriers[0]; - } else { - return false; - } - } - } - - function showRecord($carrier) { - - print "

Carrier

"; - - - printf ("
",$_SERVER['PHP_SELF']); - print ""; - - 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 - ); - - if ($this->Fields[$item]['readonly']) { - printf ("
%s
", - $item, - $carrier->$item, - $carrier->$item - ); - } else { - printf ("
", - $item, - $carrier->$item - ); - } - print " -
"; - } - - printf ("",$carier->id); - - $this->printFiltersToForm(); - $this->printHiddenFormElements(); - - print " -
- -
- "; - print "
"; - - } - - function updateRecord () { - //print "

Updating carrier ..."; - - if (!$_REQUEST['id_filter']) return; - - if (!$carrier = $this->getRecord($_REQUEST['id_filter'])) { - return false; - } - - foreach (array_keys($this->Fields) as $item) { - $var_name=$item.'_form'; - if ($this->Fields[$item]['type'] == 'integer') { - $carrier->$item = intval($_REQUEST[$var_name]); - } else { - $carrier->$item = trim($_REQUEST[$var_name]); - } - } - - $function=array('commit' => array('name' => 'updateCarrier', - 'parameters' => array($carrier), - 'logs' => array('success' => sprintf('Carrier %d has been updated',$_REQUEST['id_filter']))) - ); - - $result = $this->SoapEngine->execute($function,$this->html); - - 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; - } - } -} +require_once 'NGNPro/Records/Carriers.php';