[Fixed customer properties update Adrian Georgescu **20080421124615 Added page and functions for generating prepaid batches Display access number for anonymous reject ] addfile ./prepaid_cards.phtml hunk ./prepaid_cards.phtml 1 + "CDRTool_Session", + "auth" => "CDRTool_Auth", + "perm" => "CDRTool_Perm") + ); + +$loginname=$auth->auth["uname"]; + +$perm->check("provisioning"); + +$title="Prepaid card generator"; + +$action = $_REQUEST['action']; +$batch = $_REQUEST['batch']; +$confirm = $_REQUEST['confirm']; + +if ($action != "export") { + if (is_readable("local/header.phtml")) { + include("local/header.phtml"); + } else { + include("header.phtml"); + } + $layout = new pageLayoutLocal(); + $layout->showTopMenu($title); +} else { + Header("Content-type: text/plain"); + Header("Content-Disposition: inline; filename=$batch.txt"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 + header("Pragma: no-cache"); +} + +include("prepaid_lib.phtml"); + +$PrepaidCards = new PrepaidCards(); + +if ($action == "generate") { + $PrepaidCards->generate(); + $PrepaidCards->showGenerateForm(); + $PrepaidCards->showBatches(); +} elseif ($action == "delete") { + $PrepaidCards->showGenerateForm(); + $PrepaidCards->deleteBatch($batch,$confirm); + $PrepaidCards->showBatches(); +} elseif ($action == "export") { + $PrepaidCards->export($batch); +} else { + $PrepaidCards->showGenerateForm(); + $PrepaidCards->showBatches(); +} + +if ($action != "export") { + print " + + + "; +} +page_close(); +?> addfile ./prepaid_lib.phtml hunk ./prepaid_lib.phtml 1 +loginname = $auth->auth["uname"]; + $this->db = new DB_CDRTool; + $this->db1 = new DB_CDRTool; + } + + function showGenerateForm() { + + $this->PHP_SELF = $_SERVER['PHP_SELF']; + + print "

Prepaid card generator

"; + + print "
PHP_SELF method=post> + "; + print " + + + + + + + + + + + + + + + + + + + + + +
Batch name
Begins with
Number of digits + +
Number of cards
Value:
+
+
+ "; + } + + function generate() { + $start = $_REQUEST['start']; + $nr_cards = $_REQUEST['nr_cards']; + $digits = $_REQUEST['digits']; + $batch = $_REQUEST['batch']; + $value = $_REQUEST['value']; + + if (!$digits) { + print "

Error: No digits specified!"; + return 0; + } + + $card_len=$digits; + + if (!$nr_cards) $nr_cards = 10; + if (!$value) $value = 10; + + $alf=array("0","1","2","3","4","5","6","7","8","9"); + + print "

"; + printf ("Request generation of %d cards or %d digits in value of %s",$nr_cards,$card_len,$value); + + $now = date("Y-m-d_H:i:s"); + + if (!$batch) { + $batch_name=$now."-cards_".$nr_cards."-value_".$value; + } else { + $batch_name=$now."-".$batch."-cards_".$nr_cards."-value_".$value; + } + + $generated = 0; + $failed = 0; + $j = 0; + $random_len = $card_len-strlen($start); + $initial_len = strlen($start); + + + while ($generated < $nr_cards) { + $j++; + + if ($j > 5 * $nr_cards) { + print "Error: could not generate $nr_cards unique random cards"; + break; + } + + $card=$start; + $i=0; + + while($i < $random_len) { + srand((double)microtime()*1000000); + if ($i==0) { + $randval = rand(1,9); + } else { + $randval = rand(0,9); + } + $card=$card.$alf[$randval]; + $i++; + } + + $query=sprintf("insert into prepaid_cards + (number,value,date_batch,batch) + values ('%s','%s',NOW(),'%s')", + + addslashes($card), + addslashes($value), + addslashes($batch_name) + ); + + dprint($query); + + if ($this->db->query($query) && $this->db->affected_rows()) { + $generated++; + } else { + $failed++; + } + } + + if ($generated) { + print "

Generated $generated cards"; + + $log_query=sprintf("insert into log + (date,login,ip,datasource,results,description) + values + (NOW(),'%s','%s','Prepaid generator','%d','Batch %s created')", + addslashes($this->loginname), + addslashes($_SERVER['REMOTE_ADDR']), + addslashes($generated), + addslashes($batch_name) + ); + + dprint($log_query); + $this->db->query($log_query); + } + } + + function export($batch) { + + if (!$batch) return false; + + $available = $_REQUEST['available']; + + $query = sprintf("select * from prepaid_cards where batch = '%s'",addslashes($batch)); + + if ($available == "yes") { + $query .= " and value > 0"; + $query .= " order by id ASC "; + + } elseif ($available == "no") { + $query .= " and value = 0"; + $query .= " order by date_active DESC "; + } + + dprint($query); + + print "Id,Number,Batch,Value\n"; + + $this->db->query($query); + + $rows= $this->db->num_rows(); + + while ($this->db->next_record()) { + $i++; + $id = $this->db->f('id'); + $batch = $this->db->f('batch'); + $number = $this->db->f('number'); + $value = $this->db->f('value'); + $date_active = $this->db->f('date_active'); + + print "$id,$number,$batch,$value\n"; + } + + $log_query=sprintf("insert into log + (date,login,ip,datasource,results,description) + values + (NOW(),'%s','%s','Prepaid generator','%d','Batch %s exported')", + addslashes($this->loginname), + addslashes($_SERVER['REMOTE_ADDR']), + addslashes($rows), + addslashes($batch) + ); + + dprint($log_query); + $this->db->query($log_query); + + } + + function deleteBatch($batch, $confirm) { + + if (!$batch) return false; + + if (!$confirm) { + $batch_enc=urlencode($batch); + print " +

+ PHP_SELF?batch=$batch_enc&action=delete&confirm=1>Confirm deletion of batch $batch +

+ "; + return; + } + + $query=sprintf("delete from prepaid_cards where batch = '%s'",addslashes($batch)); + $this->db->query($query); + + if ($this->db->affected_rows()) { + $log_query=sprintf("insert into log + (date,login,ip,datasource,results,description) + values + (NOW(),'%s','%s','Prepaid generator','%d','Batch %s deleted')", + addslashes($this->loginname), + addslashes($_SERVER['REMOTE_ADDR']), + addslashes($this->db->affected_rows()), + addslashes($batch) + ); + + dprint($log_query); + $this->db->query($log_query); + return true; + + } + + return false; + } + + function blockBatch($batch) { + + if (!$batch) return false; + + $query=sprintf("update prepaid_cards set blocked = '1' where batch = '%s'",addslashes($batch)); + $this->db->query($query); + } + + function deblockBatch($batch) { + + if (!$batch) return false; + + $query=sprintf("update prepaid_cards set blocked = '0' where batch = '%s'",addslashes($batch)); + $this->db->query($query); + } + + function showBatches () { + + $query="select count(*) as c,batch,date_batch + from prepaid_cards + group by batch + order by date_batch DESC"; + dprint($query); + + $this->db->query($query); + print ""; + + print " + + + + + + + "; + + while ($this->db->next_record()) { + $date=$this->db->f('date_batch'); + $c=$this->db->f('c'); + $batch=$this->db->f('batch'); + $batch_enc=urlencode($batch); + + $query=sprintf("select count(*) as c from prepaid_cards + where batch = '%s' and value = '0'",addslashes($batch)); + dprint($query); + + $this->db1->query($query); + $this->db1->next_record(); + $used=$this->db1->f('c'); + + $query=sprintf("select count(*) as c from prepaid_cards + where batch = '%s' and value <> '0'",addslashes($batch)); + dprint($query); + + $this->db1->query($query); + $this->db1->next_record(); + + $unused=$this->db1->f('c'); + + print " + + + + + + + + + + "; + } + + print "
CardsDateBatchDownloadActions
$c$date$batchPHP_SELF?batch=$batch_enc&action=export target=_new>All cardsPHP_SELF?batch=$batch_enc&action=export&available=yes target=_new>Available cards ($unused)PHP_SELF?batch=$batch_enc&action=export&available=no target=_new>Used cards ($used)PHP_SELF?batch=$batch_enc&action=delete>Delete
"; + + } +} + +?> hunk ./provisioning/ngnpro_client_lib.phtml 8269 - $customer->properties=$properties; + if (is_array($properties)) { + $customer->properties=$properties; + } else { + $customer->properties=array(); + } hunk ./provisioning/ngnpro_client_lib.phtml 8277 + // update properties + hunk ./provisioning/ngnpro_client_lib.phtml 8288 + // update property hunk ./provisioning/ngnpro_client_lib.phtml 8293 - } - - if ($customer->id != $customer->reseller && $this->allProperties[$item]['resellerMayManageForChildAccounts']) { - $customer->properties[$_key]->permission='reseller'; - $customer->properties[$_key]->value=trim($_REQUEST[$var_name]); + } else if ($this->login_credentials['login_type'] == 'reseller' && $this->allProperties[$item]['resellerMayManageForChildAccounts']) { + if ($customer->id != $customer->reseller) { + $customer->properties[$_key]->value=trim($_REQUEST[$var_name]); + } hunk ./provisioning/ngnpro_client_lib.phtml 8305 - $customer->properties[$_key]->permission='customer'; hunk ./provisioning/ngnpro_client_lib.phtml 8308 + hunk ./provisioning/ngnpro_client_lib.phtml 8314 - $var_value = ''; - $_permission = 'customer'; + // add new property + + unset($var_value); + unset($_permission); hunk ./provisioning/ngnpro_client_lib.phtml 8320 - if ($this->login_credentials['login_type'] == 'admin') { - $var_value = trim($_REQUEST[$var_name]); - $_permission = 'admin'; - } + $_permission = 'admin'; hunk ./provisioning/ngnpro_client_lib.phtml 8322 - if ($customer->id != $customer->reseller && $this->allProperties[$item]['resellerMayManageForChildAccounts']) { + if ($this->login_credentials['login_type'] == 'admin') { hunk ./provisioning/ngnpro_client_lib.phtml 8324 - $_permission = 'reseller'; + } else if ($this->login_credentials['login_type'] == 'reseller' && $this->allProperties[$item]['resellerMayManageForChildAccounts']) { + if ($customer->id != $customer->reseller) { + $var_value = trim($_REQUEST[$var_name]); + } hunk ./provisioning/ngnpro_client_lib.phtml 8331 + $_permission = 'reseller'; + hunk ./provisioning/ngnpro_client_lib.phtml 8335 - $_permission = 'reseller'; hunk ./provisioning/ngnpro_client_lib.phtml 8337 + $_permission = 'customer'; hunk ./provisioning/ngnpro_client_lib.phtml 8339 - $_permission = 'customer'; + hunk ./provisioning/ngnpro_client_lib.phtml 8344 - 'value' => $var_value, - 'category' => $this->allProperties[$item]['category'], - 'permission' => $_permission - ); + 'value' => $var_value, + 'category' => $this->allProperties[$item]['category'], + 'permission' => $_permission + ); hunk ./provisioning/ngnpro_client_lib.phtml 8406 + + // roll back local changes hunk ./provisioning/ngnpro_client_lib.phtml 8410 + $function=array('commit' => array('name' => 'updateAccount', + 'parameters' => array($customer_old), + 'logs' => array('success' => sprintf('Customer id %s has been rolled back',$customer->id)) + ) + ); + + $this->SoapEngine->execute($function,$this->html); + hunk ./provisioning/ngnpro_client_lib.phtml 8521 - $properties=array(); - hunk ./provisioning/ngnpro_client_lib.phtml 8525 - $customer->properties=$properties; + if (is_array($properties)) { + $customer->properties=$properties; + } else { + $customer->properties=array(); + } hunk ./provisioning/sip_settings_lib.phtml 9 - of SIP accounts retrieved from NGN-Pro server + of SIP accounts retrieved from NGNPro hunk ./provisioning/sip_settings_lib.phtml 25 - // this variables can be overwritten per soap engine (in ngnpro_soap_engines.inc) - // and in reseller properties + // these variables can be overwritten per soap engine + // and subsequently by reseller properties + // (in ngnpro_soap_engines.inc) hunk ./provisioning/sip_settings_lib.phtml 40 - var $voicemail_access_number = "*70"; hunk ./provisioning/sip_settings_lib.phtml 41 + var $enable_thor = false; + var $sip_accounts_lite = false; // show basic settings by default, and advanced if property advanced is set to 1 + + // access numbers + + var $voicemail_access_number = "*70"; hunk ./provisioning/sip_settings_lib.phtml 51 - - var $change_privacy_access_number = "*67"; - var $check_privacy_access_number = "*68"; + var $change_privacy_access_number = "*67"; + var $check_privacy_access_number = "*68"; hunk ./provisioning/sip_settings_lib.phtml 54 - var $enable_thor = false; - var $sip_accounts_lite = false; // show basic settings by default, and advanced if property advanced is set to 1 hunk ./provisioning/sip_settings_lib.phtml 97 + hunk ./provisioning/sip_settings_lib.phtml 105 - var $emergencyRegions = array(); - var $timeoutDefault = 35; + hunk ./provisioning/sip_settings_lib.phtml 121 - var $exportFilename = "export.txt"; - var $presenceRules=array(); - var $enums=array(); - var $barringPrefixes=array(); - var $presenceWatchers=array(); - var $SipUaAImagesPath="status/images"; + var $emergencyRegions = array(); + var $FNOA_timeoutDefault = 35; + var $exportFilename = "export.txt"; + var $presenceRules = array(); + var $enums = array(); + var $barringPrefixes = array(); + var $presenceWatchers = array(); + var $SipUaAImagesPath = "status/images"; hunk ./provisioning/sip_settings_lib.phtml 636 - $this->timeout=intval($this->timeoutDefault); + $this->timeout=intval($this->FNOA_timeoutDefault); hunk ./provisioning/sip_settings_lib.phtml 1529 - Presence agent (RFC3903) with XCAP policy (RFC4825) + Presence agent