[Added perform actions on selections in provisioning screens Adrian Georgescu **20070901095415] hunk ./provisioning.phtml 16 +set_time_limit(600); hunk ./provisioning.phtml 34 -$RECORDS->listRecords(); +if ($_REQUEST['action']=='PerformActions') { + $RECORDS->performActions(); +} else { + $RECORDS->listRecords(); +} hunk ./provisioning_logic.phtml 54 - // Use first defined service in global.inc hunk ./provisioning_logic.phtml 129 + var $selectionActive = false; + var $selectionKeys = array(); hunk ./provisioning_logic.phtml 135 - $this->filters['sortBy'] = trim($_REQUEST['sortBy']); - $this->filters['sortOrder'] = trim($_REQUEST['sortOrder']); + $this->sorting['sortBy'] = trim($_REQUEST['sortBy']); + $this->sorting['sortOrder'] = trim($_REQUEST['sortOrder']); hunk ./provisioning_logic.phtml 141 + foreach(array_keys($this->filters) as $_filter) { + if (strlen($this->filters[$_filter])) { + $this->selectionActive=true; + break; + } + } hunk ./provisioning_logic.phtml 160 - urlencode($this->filters['sortBy']), - urlencode($this->filters['sortOrder']) + urlencode($this->sorting['sortBy']), + urlencode($this->sorting['sortOrder']) hunk ./provisioning_logic.phtml 171 - print "Previous "; + $url_begin=$this->url."&next=0"; + + if ($mod_show_next/$this->maxrowsperpage >= 1) { + print "Begin "; + } + print "Previous"; hunk ./provisioning_logic.phtml 233 - + if ($_REQUEST['action'] != 'PerformActions') { + $this->showActionsForm(); + } hunk ./provisioning_logic.phtml 241 + function getRecordKeys() { + } + hunk ./provisioning_logic.phtml 274 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 283 - $selected_sortBy[$this->filters['sortBy']]='selected'; + $selected_sortBy[$this->sorting['sortBy']]='selected'; hunk ./provisioning_logic.phtml 293 - $selected_sortOrder[$this->filters['sortOrder']]='selected'; + $selected_sortOrder[$this->sorting['sortOrder']]='selected'; hunk ./provisioning_logic.phtml 328 - hunk ./provisioning_logic.phtml 332 + + + function showActionsForm() { + if (!$this->selectionActive) { + return; + } + + $class_name=get_class($this).'Actions'; + + if (class_exists($class_name)) { + $actions=new $class_name(&$this->SOAPEngine); + $actions->showActionsForm($this->filters,$this->sorting); + } + } + + function performActions() { + $this->showSeachForm(); + + $this->getRecordKeys(); + //print_r($this->selectionKeys); + + $class_name=get_class($this).'Actions'; + + if (class_exists($class_name)) { + $actions=new $class_name(&$this->SOAPEngine); + $actions->performActions(&$this->selectionKeys,$_REQUEST['sub_action'],$_REQUEST['sub_action_parameter']); + } + } hunk ./provisioning_logic.phtml 397 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'changeDate'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'DESC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; hunk ./provisioning_logic.phtml 400 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 628 + if ($this->selectionActive) return; + hunk ./provisioning_logic.phtml 937 + if ($this->selectionActive) return; + hunk ./provisioning_logic.phtml 1057 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'description'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'ASC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'description'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; hunk ./provisioning_logic.phtml 1060 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 1185 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 1312 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'name'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'ASC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; hunk ./provisioning_logic.phtml 1315 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 1430 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 1559 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'name'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'ASC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; hunk ./provisioning_logic.phtml 1562 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 1692 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 1920 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'prefix'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'ASC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'prefix'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; hunk ./provisioning_logic.phtml 1923 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 2056 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 2190 - var $sortElements=array('changeDate' =>'Change date', + var $sortElements=array('changeDate' => 'Change date', hunk ./provisioning_logic.phtml 2207 + function getRecordKeys() { + + if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) { + $this->filters['username'] = $m[1]; + $this->filters['domain'] = $m[2]; + } + + if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) { + $this->filters['domain'] = $this->allowedDomains[0]; + } + + // Filter + $filter=array('username' => $this->filters['username'], + 'domain' => $this->filters['domain'], + 'name' => $this->filters['fullname'] + ); + + // Range + $range=array('start' => 0, + 'count' => 1000 + ); + + // 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 + ); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + // Call function + $result = $this->SOAPEngine->soapclient->getAccounts($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } else { + foreach ($result->accounts as $account) { + $this->selectionKeys[]=$account->id->username.'@'.$account->id->domain; + } + + return true; + } + + return false; + + } + hunk ./provisioning_logic.phtml 2299 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'changeDate'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'DESC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; hunk ./provisioning_logic.phtml 2302 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 2515 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 2730 - if (!$this->filters['sortBy']) $this->filters['sortBy'] = 'aliasUsername'; - if (!$this->filters['sortOrder']) $this->filters['sortOrder'] = 'DESC'; + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'aliasUsername'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; hunk ./provisioning_logic.phtml 2733 - $orderBy = array('attribute' => $this->filters['sortBy'], - 'direction' => $this->filters['sortOrder'] + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] hunk ./provisioning_logic.phtml 2918 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 3182 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 3384 + if ($this->selectionActive) return; hunk ./provisioning_logic.phtml 3436 +} + +class Actions { + var $actions=array(); + + function Actions(&$SOAPEngine) { + $this->SOAPEngine = $SOAPEngine; + } + + function performActions($selectionKeys,$action,$sub_action_parameter) { + } + + function showActionsForm($filters,$sorting) { + if (!count($this->actions)) return; + + print " +

+ + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + foreach (array_keys($filters) as $_filter) { + printf ("\n", $_filter,$filters[$_filter]); + } + + foreach (array_keys($sorting) as $_sorting) { + printf ("\n", $_sorting,$sorting[$_sorting]); + } + + printf("",$this->SOAPEngine->service); + + foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) { + if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue; + printf ("\n",$element,$this->SOAPEngine->extraFormElements[$element]); + } + print " + + +
+ "; + + print " + + + "; + + print ""; + + + print " + + + + "; + print " +
+ "; + + } +} + +class SIPAccountsActions extends Actions { + var $actions=array('block' => 'Block SIP accounts', + 'deblock' => 'Deblock SIP accounts', + 'enable_pstn' => 'Enable access to PSTN for the SIP accounts', + 'disable_pstn' => 'Disable access to PSTN for the SIP accounts', + 'deblock_quota' => 'Deblock SIP accounts blocked by quota', + 'prepaid' => 'Make SIP accounts prepaid', + 'postpaid' => 'Make SIP accounts postpaid', + 'delete' => 'Delete SIP accounts', + 'setquota' => 'Set quota of SIP account to:' + ); + + function SIPAccountsActions(&$SOAPEngine) { + $this->Actions(&$SOAPEngine); + } + + function performActions($selectionKeys,$action,$sub_action_parameter) { + print "

    "; + foreach($selectionKeys as $key) { + flush(); + //printf ("
  1. Performing action=%s on key=%s",$action,$key); + list($username,$domain)=explode('@',$key); + + $account=array('username' => $username, + 'domain' => $domain + ); + + if ($action=='block') { + + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->addToGroup($account,'block'); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  2. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  3. SIP account %s has been blocked ",$key); + } + + } else if ($action=='deblock') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->removeFromGroup($account,'block'); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  4. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  5. SIP account %s has been de-blocked ",$key); + } + } else if ($action=='deblock_quota') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->removeFromGroup($account,'quota'); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  6. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  7. SIP account %s has been de-blocked ",$key); + } + } else if ($action=='enable_pstn') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->addToGroup($account,'free-pstn'); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  8. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  9. SIP account %s has access to the PSTN ",$key); + } + } else if ($action=='delete') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->deleteAccount($account); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  10. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  11. SIP account %s has been deleted ",$key); + } + } else if ($action=='disable_pstn') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->removeFromGroup($account,'free-pstn'); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  12. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  13. SIP account %s has been denied access to PSTN ",$key); + } + } else if ($action=='prepaid') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->getAccount($account); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  14. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + //print_r($result); + // Sanitize data types due to PHP bugs + + if (!is_array($result->properties)) $result->properties=array(); + if (!is_array($result->groups)) $result->groups=array(); + $result->quota=intval($result->quota); + + $result->prepaid=1; + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->updateAccount($result); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  15. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  16. SIP account %s has been set to prepaid ",$key); + } + } + } else if ($action=='postpaid') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->getAccount($account); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  17. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + //print_r($result); + // Sanitize data types due to PHP bugs + + if (!is_array($result->properties)) $result->properties=array(); + if (!is_array($result->groups)) $result->groups=array(); + $result->quota=intval($result->quota); + + $result->prepaid=0; + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->updateAccount($result); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  18. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  19. SIP account %s has been set to postpaid ",$key); + } + } + } else if ($action=='setquota') { + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->getAccount($account); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  20. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + //print_r($result); + // Sanitize data types due to PHP bugs + + if (!is_array($result->properties)) $result->properties=array(); + if (!is_array($result->groups)) $result->groups=array(); + $result->quota=intval($sub_action_parameter); + + $result->prepaid=0; + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->updateAccount($result); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("
  21. Error: %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + break; + } else { + printf ("
  22. SIP account %s has quota set to %s ",$key,$sub_action_parameter); + } + } + } + } + print "
"; + + } +