Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7312194
rating_tables.phtml
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
37 KB
Referenced Files
None
Subscribers
None
rating_tables.phtml
View Options
<?
include
(
"./global.inc"
);
page_open
(
array
(
"sess"
=>
"CDRTool_Session"
,
"auth"
=>
"CDRTool_Auth"
,
"perm"
=>
"CDRTool_Perm"
));
$perm
->
check
(
"rates"
);
$table_fname
=
array
(
"destinations"
=>
"destinations.csv"
,
"billing_customers"
=>
"customers.csv"
,
"billing_profiles"
=>
"profiles.csv"
,
"billing_rates"
=>
"rates.csv"
,
"billing_rates_history"
=>
"ratesHistory.csv"
,
"prepaid"
=>
"prepaid.csv"
,
"billing_enum_tlds"
=>
"enumtld.csv"
);
$PHP_SELF
=
$_SERVER
[
'PHP_SELF'
];
$REMOTE_ADDR
=
$_SERVER
[
'REMOTE_ADDR'
];
$web_elements
=
array
(
'table'
,
'export'
,
'action'
,
'subaction'
,
'confirmDelete'
,
'confirmCopy'
,
'next'
,
'id'
,
'search_text'
,
'ReloadRatingTables'
,
'account'
,
'balance'
,
'fromRate'
,
'toRate'
);
foreach
(
$web_elements
as
$_el
)
{
${$_el}
=
$_REQUEST
[
$_el
];
//printf ("<br>%s = %s",$_el,$_REQUEST[$_el]);
}
global
$CDRTool
;
$db
=
new
DB_CDRTool
;
$db
->
Halt_On_Error
=
"no"
;
$db1
=
new
DB_CDRTool
;
$db1
->
Halt_On_Error
=
"no"
;
// delimiter for exporting records
if
(
$CDRTool
[
'rating'
][
'delimiter'
])
{
$delimiter
=
$CDRTool
[
'rating'
][
'delimiter'
];
}
else
{
$delimiter
=
","
;
}
if
(
!
$export
)
{
$title
=
"Rating tables"
;
if
(
is_readable
(
"local/header.phtml"
))
{
include
(
"local/header.phtml"
);
}
else
{
include
(
"header.phtml"
);
}
$maxrowsperpage
=
15
;
}
else
{
if
(
$table_fname
[
$table
])
{
Header
(
"Content-type: text/plain"
);
Header
(
"Content-Disposition: inline; filename=
$table_fname[$table]
"
);
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"
);
$maxrowsperpage
=
1000000
;
}
else
{
exit
;
}
}
include
(
"rating_lib.phtml"
);
if
(
!
$export
)
{
$layout
=
new
pageLayoutLocal
();
$layout
->
showTopMenu
(
$title
);
}
$loginname
=
$auth
->
auth
[
"uname"
];
$RatingTables
=
new
RatingTables
();
$tables
=
$RatingTables
->
tables
;
if
(
!
$table
)
$table
=
"destinations"
;
$whereDomainFilter
=
" (1=1) "
;
if
(
$CDRTool
[
'filter'
][
'domain'
])
{
$Realms
=
explode
(
" "
,
$CDRTool
[
'filter'
][
'domain'
]);
if
(
$tables
[
$table
][
domainFilterColumn
])
{
$whereDomainFilter
=
$whereDomainFilter
.
" and "
.
$tables
[
$table
][
domainFilterColumn
]
.
" in ("
;
$rr
=
0
;
foreach
(
$Realms
as
$realm
)
{
if
(
$rr
)
$whereDomainFilter
=
$whereDomainFilter
.
","
;
$whereDomainFilter
=
$whereDomainFilter
.
"'"
.
addslashes
(
$realm
)
.
"'"
;
$insertDomainOption
[]
=
$realm
;
$rr
++
;
}
$whereDomainFilter
=
$whereDomainFilter
.
") "
;
}
if
(
$tables
[
$table
][
domainMatchColumn
])
{
$whereDomainFilter
=
$whereDomainFilter
.
" and ("
;
$rr
=
0
;
foreach
(
$Realms
as
$realm
)
{
if
(
$rr
)
$whereDomainFilter
=
$whereDomainFilter
.
" or "
;
$whereDomainFilter
=
$whereDomainFilter
.
" "
.
$tables
[
$table
][
domainMatchColumn
]
.
" like '%@"
.
addslashes
(
$realm
)
.
"'"
;
$rr
++
;
}
$whereDomainFilter
=
$whereDomainFilter
.
" ) "
;
}
}
$el_size
=
"20"
;
// Init table structure
$exceptions
=
$tables
[
$table
][
'exceptions'
];
if
(
!
is_array
(
$exceptions
))
$exceptions
=
array
();
$keys
=
$tables
[
$table
][
'keys'
];
if
(
!
is_array
(
$keys
))
$keys
=
array
();
$fields
=
$tables
[
$table
][
'fields'
];
if
(
!
is_array
(
$fields
))
$fields
=
array
();
$metadata
=
$db
->
metadata
(
$table
=
"
$table
"
);
$cc
=
count
(
$metadata
);
if
(
$tables
[
$table
][
'size'
])
$el_size
=
$tables
[
$table
][
'size'
];
// end init table structure
if
(
$action
==
"update"
&&
$table
)
{
$affected_rows
=
0
;
if
(
$subaction
==
"Update"
)
{
$query
=
"update
$table
set "
;
$k
=
1
;
while
(
$k
<
$cc
)
{
$Fname
=
$metadata
[
$k
][
"name"
];
$value
=
$_REQUEST
[
$Fname
];
//dprint("fname=$Fname, value=$value");
if
(
!
in_array
(
$Fname
,
$exceptions
)
)
{
if
(
$kkk
>
0
)
{
$comma
=
","
;
}
else
{
$comma
=
""
;
}
if
(
preg_match
(
"/^([\+\-\*\/])(.*)$/"
,
$value
,
$sign
))
{
$query
.=
$comma
.
$Fname
.
"= ROUND("
.
$Fname
.
" "
.
$sign
[
1
]
.
"'"
.
$sign
[
2
]
.
"')"
;
}
else
{
$query
.=
$comma
.
$Fname
.
"='"
.
$value
.
"'"
;
}
$kkk
++
;
}
$k
++
;
}
$log_entity
=
"id=
$id
"
;
$query
.=
" where id = '"
.
$id
.
"' and
$whereDomainFilter
"
;
dprint
(
$query
);
if
(
$table
==
"prepaid"
)
{
register_shutdown_function
(
"unLockTables"
,
$db
);
if
(
$db
->
query
(
"lock table prepaid write"
))
{
$query_q
=
sprintf
(
"select * from prepaid where account = '%s'"
,
addslashes
(
$account
));
dprint
(
$query_q
);
if
(
$db
->
query
(
$query_q
)
&&
$db
->
num_rows
())
{
$db
->
next_record
();
$old_balance
=
$db
->
f
(
'balance'
);
}
$db
->
query
(
"unlock tables"
);
}
}
if
(
$db
->
query
(
$query
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
{
if
(
$table
==
"prepaid"
)
{
list
(
$username
,
$domain
)
=
explode
(
"@"
,
$account
);
$value
=
$balance
-
$old_balance
;
if
(
floatval
(
$balance
)
!=
floatval
(
$old_balance
))
{
$query
=
sprintf
(
"insert into prepaid_history
(username,domain,action,number,value,balance,date)
values
('%s','%s','Set balance','Manual update by %s','%s','%s',NOW())"
,
addslashes
(
$username
),
addslashes
(
$domain
),
addslashes
(
$loginname
),
addslashes
(
$value
),
addslashes
(
$balance
)
);
dprint
(
$query
);
$db
->
query
(
$query
);
$log_query
=
sprintf
(
"insert into log
(date,login,ip,datasource,results,description)
values
(NOW(),'%s','%s','Rating tables','%d','Set prepaid balance of %s@%s to %s')"
,
addslashes
(
$loginname
),
addslashes
(
$REMOTE_ADDR
),
addslashes
(
$affected_rows
),
addslashes
(
$username
),
addslashes
(
$domain
),
addslashes
(
$balance
)
);
dprint
(
$log_query
);
$db
->
query
(
$log_query
);
}
if
(
!
reloadPrepaidAccounts
(
$account
))
{
// we failed to reload the prepaid account in real time so we mark the database for
// reload at a later time
if
(
!
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
)){
printf
(
"<font color=red>Database error: %s (%s)</font>"
,
$db
->
Error
,
$db
->
Errno
);
}
}
}
else
{
if
(
$table
!=
'prepaid_cards'
)
{
if
(
!
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
)){
printf
(
"<font color=red>Database error: %s (%s)</font>"
,
$db
->
Error
,
$db
->
Errno
);
}
}
}
}
}
else
{
printf
(
"<font color=red>Database error: %s (%s)</font>"
,
$db
->
Error
,
$db
->
Errno
);
}
}
elseif
(
$subaction
==
"Update selection"
)
{
$query
=
"update
$table
set "
;
$k
=
1
;
$kkk
=
0
;
while
(
$k
<
$cc
)
{
$Fname
=
$metadata
[
$k
][
"name"
];
$value
=
$_REQUEST
[
$Fname
];
if
(
strlen
(
$value
)
&&
!
in_array
(
$Fname
,
$exceptions
)
&&
!
in_array
(
$Fname
,
$keys
))
{
if
(
$kkk
>
0
)
{
$comma
=
","
;
}
else
{
$comma
=
""
;
}
if
(
$value
==
"NULL"
)
{
$value
=
""
;
}
if
(
preg_match
(
"/^([\+\-\*\/])(.*)$/"
,
$value
,
$sign
))
{
$query
.=
$comma
.
$Fname
.
"= ROUND("
.
$Fname
.
" "
.
$sign
[
1
]
.
"'"
.
$sign
[
2
]
.
"')"
;
}
else
{
$query
.=
$comma
.
$Fname
.
"='"
.
$value
.
"'"
;
}
$kkk
++
;
}
$k
++
;
}
if
(
$kkk
)
{
// reconstruct where clause to apply all changes to selection
// build where clause
// Search build for each field
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$f_name
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$f_name
];
if
(
preg_match
(
"/^([<|>]+)(.*)$/"
,
$value
,
$likes
))
{
$like
=
$likes
[
1
];
$likewhat
=
$likes
[
2
];
$quotes
=
""
;
}
else
{
$like
=
"like"
;
$likewhat
=
$value
;
$quotes
=
"'"
;
}
if
(
strlen
(
$value
))
{
$update_all_where
.=
" and
$Fname
$like
$quotes
"
.
$likewhat
.
"
$quotes
"
;
$t
++
;
}
}
$j
++
;
}
$endquery
=
$query
.
" where
$whereDomainFilter
"
.
$update_all_where
;
dprint
(
$endquery
);
if
(
$db
->
query
(
$endquery
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
{
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
);
}
}
else
{
printf
(
"<font color=red>Database error: %s</font>"
,
$db
->
Error
);
}
}
}
elseif
(
$subaction
==
"Delete selection"
)
{
if
(
$confirmDelete
)
{
$query
=
"delete from
$table
"
;
// reconstruct where clause to apply all changes to selection
// build where clause
// Search build for each field
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$f_name
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$f_name
];
if
(
preg_match
(
"/^([<|>]+)(.*)$/"
,
$value
,
$likes
))
{
$like
=
$likes
[
1
];
$likewhat
=
$likes
[
2
];
$quotes
=
""
;
}
else
{
$like
=
"like"
;
$likewhat
=
$value
;
$quotes
=
"'"
;
}
if
(
strlen
(
$value
))
{
$update_all_where
.=
" and
$Fname
$like
$quotes
"
.
$likewhat
.
"
$quotes
"
;
$t
++
;
}
}
$j
++
;
}
$endquery
=
$query
.
" where
$whereDomainFilter
"
.
$update_all_where
;
dprint
(
$endquery
);
if
(
$db
->
query
(
$endquery
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
{
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
);
}
}
else
{
printf
(
"<font color=red>Database error: %s</font>"
,
$db
->
Error
);
}
unset
(
$confirmDelete
);
}
else
{
print
"<p><font color=blue>"
;
print
"Please confirm the deletion by pressing the Delete button again. "
;
print
"</font>"
;
}
}
elseif
(
$subaction
==
"Copy rate"
&&
strlen
(
$fromRate
)
&&
strlen
(
$toRate
))
{
if
(
$confirmCopy
)
{
if
(
$toRate
==
'history'
)
{
$query
=
sprintf
(
"insert into billing_rates_history
(gateway,domain,subscriber,name,destination,durationRate,
trafficRate,application,connectCost,startDate,endDate)
select
billing_rates.gateway,
billing_rates.domain,
billing_rates.subscriber,
'%s',
billing_rates.destination,
billing_rates.durationRate,
billing_rates.trafficRate,
billing_rates.application,
billing_rates.connectCost,
NOW(),
NOW()
from billing_rates "
,
$fromRate
);
}
else
{
$query
=
sprintf
(
"insert into billing_rates
(gateway,domain,subscriber,name,destination,durationRate,
trafficRate,application,connectCost)
select
billing_rates.gateway,
billing_rates.domain,
billing_rates.subscriber,
'%s',
billing_rates.destination,
billing_rates.durationRate,
billing_rates.trafficRate,
billing_rates.application,
billing_rates.connectCost
from billing_rates "
,
$toRate
);
}
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$f_name
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$f_name
];
if
(
preg_match
(
"/^([<|>]+)(.*)$/"
,
$value
,
$likes
))
{
$like
=
$likes
[
1
];
$likewhat
=
$likes
[
2
];
$quotes
=
""
;
}
else
{
$like
=
"like"
;
$likewhat
=
$value
;
$quotes
=
"'"
;
}
if
(
strlen
(
$value
))
{
$update_all_where
.=
" and
$Fname
$like
$quotes
"
.
$likewhat
.
"
$quotes
"
;
$t
++
;
}
}
$j
++
;
}
$endquery
=
$query
.
" where
$whereDomainFilter
"
.
$update_all_where
;
dprint
(
$endquery
);
if
(
$db
->
query
(
$endquery
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
{
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
);
print
"
$affected_rows
rates copied. "
;
}
if
(
$toRate
==
'history'
)
{
// Switch to history
$table
=
'billing_rates_history'
;
// Init table structure
$exceptions
=
$tables
[
$table
][
'exceptions'
];
$keys
=
$tables
[
$table
][
'keys'
];
$fields
=
$tables
[
$table
][
'fields'
];
$metadata
=
$db
->
metadata
(
$table
=
"
$table
"
);
$cc
=
count
(
$metadata
);
if
(
$tables
[
$table
][
'size'
])
$el_size
=
$tables
[
$table
][
'size'
];
// end init table structure
}
unset
(
$confirmCopy
);
}
else
{
printf
(
"<font color=red>Database error: %s</font>"
,
$db
->
Error
);
}
$log_entity
=
"rate=
$toRate
"
;
}
else
{
print
"<p><font color=blue>"
;
print
"Please confirm the copy of rate
$fromRate
to
$toRate
. "
;
print
"</font>"
;
}
}
elseif
(
$subaction
==
"Insert"
)
{
//print "<h3>Insert</h3>";
if
(
is_array
(
$insertDomainOption
)
&&
!
in_array
(
$domain
,
$insertDomainOption
))
{
print
"<font color=red>
Error: Invalid domain
$domain
</font>
"
;
}
else
{
$query
=
"insert into
$table
( "
;
$k
=
1
;
$kkk
=
0
;
while
(
$k
<
$cc
)
{
$Fname
=
$metadata
[
$k
][
"name"
];
if
(
!
in_array
(
$Fname
,
$exceptions
)
)
{
if
(
$kkk
>
0
)
{
$comma
=
","
;
}
else
{
$comma
=
""
;
}
$query
.=
$comma
.
$Fname
;
$kkk
++
;
}
$k
++
;
}
$query
.=
") values ( "
;
$k
=
1
;
$kkk
=
0
;
while
(
$k
<
$cc
)
{
$Fname
=
$metadata
[
$k
][
"name"
];
$value
=
$_REQUEST
[
$Fname
];
if
(
!
in_array
(
$Fname
,
$exceptions
)
)
{
if
(
$kkk
>
0
)
{
$comma
=
","
;
}
else
{
$comma
=
""
;
}
$query
.=
$comma
.
"'"
.
$value
.
"'"
;
$kkk
++
;
}
$k
++
;
}
$query
.=
") "
;
$k
=
1
;
while
(
$k
<
$cc
)
{
$Fname
=
$metadata
[
$k
][
"name"
];
$value
=
$_REQUEST
[
$Fname
];
#print "var $Fname = ${$Fname} $keys<br>";
if
(
in_array
(
$Fname
,
$keys
)
)
{
if
(
$value
==
""
)
{
$Fname_print_insert
=
substr
(
$Fname
,
4
);
print
"
$Fname_print_insert
= ???? <br>"
;
$empty_insert
=
1
;
}
}
$k
++
;
}
dprint
(
$query
);
if
(
!
$empty_insert
)
{
dprint
(
$query
);
if
(
$db
->
query
(
$query
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
{
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
);
$db
->
query
(
"select LAST_INSERT_ID() as lid"
);
$db
->
next_record
();
$log_entity
=
sprintf
(
"id=%s"
,
$db
->
f
(
'lid'
));
}
}
else
{
printf
(
"<font color=red>Database error: %s</font>"
,
$db
->
Error
);
}
}
else
{
print
"<font color=red>
Error: The insert statement contains an empty key!
</font>
"
;
}
}
}
elseif
(
$subaction
==
"Delete"
)
{
if
(
$confirmDelete
)
{
$query
=
"delete from
$table
where id = '
$id
' and
$whereDomainFilter
"
;
dprint
(
$query
);
if
(
$db
->
query
(
$query
))
{
$affected_rows
=
$db
->
affected_rows
();
if
(
$affected_rows
)
$db
->
query
(
"update settings setting set var_value= '1' where var_name = 'reloadRating'"
);
$log_entity
=
sprintf
(
"id=%s"
,
$id
);
}
else
{
printf
(
"<font color=red>Database error: %s</font>"
,
$db
->
Error
);
}
unset
(
$confirmDelete
);
}
else
{
$idForDeletion
=
$id
;
print
"<p><font color=blue>"
;
print
"Please confirm the deletion by pressing the Delete button again. "
;
print
"</font>"
;
}
}
if
(
$affected_rows
&&
$table
!=
"prepaid"
)
{
$log_query
=
sprintf
(
"insert into log
(date,login,ip,datasource,results,description)
values (NOW(),'%s','%s','Rating','%d','%s in table %s %s')"
,
addslashes
(
$loginname
),
addslashes
(
$REMOTE_ADDR
),
addslashes
(
$affected_rows
),
addslashes
(
$subaction
),
addslashes
(
$table
),
addslashes
(
$log_entity
)
);
$db
->
query
(
$log_query
);
}
}
$query
=
"select count(*) as c from
$table
where
$whereDomainFilter
"
;
$t
=
0
;
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$f_name
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$f_name
];
#print "$Fname $size $t $nrsf $f_name ${$f_name}<br>";
if
(
preg_match
(
"/^([<|>]+)(.*)$/"
,
$value
,
$likes
))
{
$like
=
$likes
[
1
];
$likewhat
=
$likes
[
2
];
$quotes
=
""
;
}
else
{
$like
=
"like"
;
$likewhat
=
$value
;
$quotes
=
"'"
;
}
if
(
strlen
(
$value
))
{
$where
=
$where
.
" and
$Fname
$like
$quotes
"
.
$likewhat
.
"
$quotes
"
;
$t
++
;
}
}
$j
++
;
}
$query
.=
$where
;
dprint
(
$query
);
$db
->
query
(
$query
);
$db
->
next_record
();
$rows
=
$db
->
Record
[
0
];
if
(
!
$export
)
{
print
"
<center>
<p>
"
;
if
(
$rows
==
0
)
{
print
"No records found. "
;
}
else
{
print
"
$selectie
$rows
records found. "
;
}
global
$RatingEngine
;
if
(
$RatingEngine
[
"socketIP"
]
&&
$RatingEngine
[
"socketPort"
])
{
if
(
$ReloadRatingTables
)
{
reloadRatingEngineTables
();
}
else
{
$db
->
query
(
"select var_value from settings where var_name = 'reloadRating' and var_value='1'"
);
if
(
$db
->
num_rows
())
{
print
" | <a href=rating_tables.phtml?ReloadRatingTables=1&table=
$table
><font color=red>Reload rating tables</font></a>"
;
}
}
$engineAddress
=
$RatingEngine
[
"socketIP"
]
.
":"
.
$RatingEngine
[
"socketPort"
];
if
(
$RatingTables
->
checkRatingEngineConnection
())
{
print
" | <font color=green>Rating engine running at
$engineAddress
</font>"
;
}
else
{
print
" | <font color=red>Cannot connect to rating engine
$engineAddress
</font>"
;
}
}
print
" | <a href=doc/RATING.txt target=rating_help>Rating documentation</a>"
;
print
"
</center>
"
;
}
if
(
!
$next
)
{
$i
=
0
;
$next
=
0
;
}
else
{
$i
=
$next
;
}
$j
=
0
;
$z
=
0
;
if
(
$rows
>
$maxrowsperpage
)
{
$maxrows
=
$maxrowsperpage
+
$next
;
if
(
$maxrows
>
$rows
)
{
$maxrows
=
$rows
;
$prev_rows
=
$maxrows
;
}
}
else
{
$maxrows
=
$rows
;
}
if
(
!
$order
&&
$order_by
[
"
$table
"
])
{
$order
=
"order by "
.
$order_by
[
"
$table
"
]
.
" ASC "
;
}
$query
=
"select * from
$table
where (1=1)
$where
and
$whereDomainFilter
$order
limit
$i
,
$maxrowsperpage
"
;
dprint
(
$query
);
$db
->
query
(
$query
);
$num_fields
=
$db
->
num_fields
()
;
$k
=
0
;
if
(
!
$export
)
{
print
"
<table border=0 class=border align=center width=100%>
<tr bgcolor=lightgrey>
<td></td>
"
;
}
while
(
$k
<
$cc
)
{
$th
=
$metadata
[
$k
][
"name"
];
if
(
!
in_array
(
$th
,
$exceptions
)
)
{
if
(
$fields
[
$th
][
name
])
{
$th
=
$fields
[
$th
][
name
];
}
else
{
$th
=
ucfirst
(
$th
);
}
if
(
!
$export
)
{
print
"<td class=border><b>
$th
</b></td>"
;
}
else
{
if
(
$k
)
{
printf
(
"%s%s"
,
$delimiter
,
$th
);
}
else
{
print
"Ops"
;
}
}
$t_columns
++
;
}
$k
++
;
}
if
(
$export
)
{
print
"
\n
"
;
}
if
(
!
$export
)
{
print
"
<td class=border><b>Action</b></td>
</tr>"
;
$t_columns
=
$t_columns
+
2
;
// SEARCH FORM
print
"
<tr>
<td class=border colspan=
$t_columns
>
Use _ to match one character and % to match any. Use > or <
to find greater or smaller values.</td>
</tr>
"
;
// Search form
print
"
<form action=
$PHP_SELF
method=post>
<input type=hidden name=action value=Search>
<tr>
<td> </td>"
;
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$SEARCH_NAME
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$SEARCH_NAME
];
if
(
$value
!=
""
)
{
$selection_made
=
1
;
}
$maxlength
=
$size
;
if
(
$fields
[
$Fname
][
size
])
{
$field_size
=
$fields
[
$Fname
][
size
];
}
else
{
$field_size
=
$el_size
;
}
if
(
!
in_array
(
$Fname
,
$keys
)
)
{
if
(
$Fname
==
"domain"
&&
is_array
(
$insertDomainOption
))
{
print
"<td><select name=search_
$Fname
>"
;
$selected_domain
[
$value
]
=
"selected"
;
print
"<option>"
;
foreach
(
$insertDomainOption
as
$_option
)
{
print
"<option
$selected_domain[$_option]
>
$_option
"
;
}
print
"
</select>
</td>"
;
}
else
{
print
"<td><input type=text size=
$field_size
maxlength=
$maxlength
name=search_
$Fname
value=
\"
$value\
"
></
td
>
";
}
} else {
print "
<
td
></
td
>
";
}
}
$j
++;
}
print "
<
td
>
<
select
name
=
table
value
=
$table
>
";
$selected_table[$table]
="
selected
";
foreach (array_keys(
$tables
) as
$tb
) {
$sel_name
=
$tables[$tb]
[name];
print "
<
option
value
=
$tb
$selected_table
[
$tb
]
>
$sel_name
";
}
print "
</
select
>
<
input
type
=
submit
name
=
subaction
value
=
Search
>
</
form
>
<
form
action
=
$PHP_SELF
method
=
post
target
=
export
>
<
input
type
=
hidden
name
=
export
value
=
1
>
";
$j
=0;
while (
$j
<
$cc
) {
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (!in_array(
$Fname
,
$exceptions
)) {
$SEARCH_NAME
="
search_
".
$Fname
;
$value
=
$_REQUEST[$SEARCH_NAME]
;
print "
<
input
type
=
hidden
name
=
search_
$Fname
value
=
\
"
$value\
"
>
";
}
$j
++;
}
if (
$table
!=='prepaid_cards' ) {
print "
<
input
type
=
hidden
name
=
table
value
=
$table
>
<
input
type
=
submit
value
=
\
"Export
$table_fname[$table]
\"
>
"
;
}
print
"</td>
</tr>
</form>
"
;
print
"
<tr>
<td colspan=
$t_columns
><hr noshade size=2></td>
</tr>
"
;
if
(
$selection_made
)
{
// Update all form
print
"
<tr><td class=border colspan=
$t_columns
>
Use + or - to add/substract from curent values.
Use * or / to multiply/divide curent values.</td>
</tr>"
;
$j
=
0
;
print
"
<form action=
$PHP_SELF
method=post>
<input type=hidden name=action value=update>
<input type=hidden name=next value=
$next
>
<tr>
<td> </td>"
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
$fields
[
$Fname
][
size
])
{
$field_size
=
$fields
[
$Fname
][
size
];
}
else
{
$field_size
=
$el_size
;
}
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
if
(
!
in_array
(
$Fname
,
$keys
)
)
{
if
(
$Fname
==
"domain"
&&
is_array
(
$insertDomainOption
))
{
print
"<td><select name=
$Fname
>"
;
foreach
(
$insertDomainOption
as
$_option
)
{
print
"<option
$selected_domain[$_option]
>
$_option
"
;
}
print
"
</select>
</td>"
;
}
else
{
print
"<td><input type=text size=
$field_size
maxlength=
$size
name=
$Fname
></td>"
;
}
}
else
{
print
"<td></td>"
;
}
}
$j
++
;
}
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$SEARCH_NAME
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$SEARCH_NAME
];
print
"<input type=hidden name=search_
$Fname
value=
\"
$value\
"
>
";
}
$j
++;
}
if (
$subaction
=="
Delete
selection
" && !
$confirmDelete
) {
print "
<
td
bgcolor
=
lightgrey
>
";
print "
<
input
type
=
hidden
name
=
confirmDelete
value
=
1
>
";
print "
<
input
type
=
submit
name
=
subaction
value
=
\
"Delete selection
\"
>"
;
print
" (
$rows
records)"
;
}
else
{
if
(
$table
==
"billing_rates"
&&
strlen
(
$_REQUEST
[
'search_name'
]))
{
if
(
$subaction
==
"Copy rate"
&&
!
$confirmCopy
)
{
print
"<td bgcolor=lightgrey>"
;
print
"<input type=hidden name=confirmCopy value=1>"
;
}
else
{
print
"<td>"
;
print
"
<input type=submit name=subaction value=
\"
Update selection
\"
>
<input type=submit name=subaction value=
\"
Delete selection
\"
>
<br>"
;
}
print
"
<input type=submit name=subaction value=
\"
Copy rate
\"
>"
;
printf
(
" id %s to"
,
$_REQUEST
[
'search_name'
]);
$query
=
sprintf
(
"select distinct(name) as name
from billing_rates where
name like '%s'
order by name DESC
limit 1"
,
$_REQUEST
[
'search_name'
]);
dprint
(
$query
);
$db1
->
query
(
$query
);
$db1
->
next_record
();
$_rateName
=
$db1
->
f
(
'name'
);
if
(
preg_match
(
"/^(.*)_(\d+)$/"
,
$_rateName
,
$m
))
{
$_idx
=
$m
[
2
]
+
1
;
$newRateName
=
$m
[
1
]
.
"_"
.
$_idx
;
}
else
{
$newRateName
=
$_rateName
.
"_1"
;
}
printf
(
"<input type=hidden name=fromRate value=
\"
%s
\"
>"
,
$_REQUEST
[
'search_name'
]);
$selected_newtable
[
$toRate
]
=
'selected'
;
printf
(
"<select name=toRate>
<option value=
\"
%s
\"
%s>Rate id %s
<option value=history %s>Rate history table
</select>"
,
$newRateName
,
$selected_newtable
[
$newRateName
],
$newRateName
,
$selected_newtable
[
'history'
]
);
}
else
{
print
"<td>"
;
print
"
<input type=submit name=subaction value=
\"
Update selection
\"
>
<input type=submit name=subaction value=
\"
Delete selection
\"
>
<br>"
;
}
}
print
"
<td>
<input type=hidden name=table value=
$table
>
<input type=hidden name=search_text value=
\"
$search_text\
"
>
</
td
>
</
tr
>
</
form
>
";
} else {
// Insert form
$j
=0;
print "
<
form
action
=
$PHP_SELF
method
=
post
>
<
input
type
=
hidden
name
=
action
value
=
update
>
<
input
type
=
hidden
name
=
next
value
=
$next
>
<
tr
>
<
td
>&
nbsp
;
</
td
>
";
while (
$j
<
$cc
) {
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (
$fields[$Fname]
[size]) {
$field_size
=
$fields[$Fname]
[size];
} else {
$field_size
=
$el_size
;
}
if (!in_array(
$Fname
,
$exceptions
)) {
if (!in_array(
$Fname
,
$keys
) ) {
if (
$Fname
=="
domain
" && is_array(
$insertDomainOption
)) {
print "
<
td
><
select
name
=
$Fname
>
";
foreach (
$insertDomainOption
as
$_option
) {
print "
<
option
>
$_option
";
}
print "
</
select
>
</
td
>
";
} else {
print "
<
td
><
input
type
=
text
size
=
$field_size
maxlength
=
$size
name
=
$Fname
></
td
>
";
}
} else {
print "
<
td
></
td
>
";
}
}
$j
++;
}
$j
=0;
while (
$j
<
$cc
) {
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (!in_array(
$Fname
,
$exceptions
)) {
$SEARCH_NAME
="
search_
".
$Fname
;
$value
=
$_REQUEST[$SEARCH_NAME]
;
print "
<
input
type
=
hidden
name
=
search_
$Fname
value
=
\
"
$value\
"
>
";
}
$j
++;
}
print "
<
td
class
=
border
>
<
input
type
=
hidden
name
=
table
value
=
\
"
$table\
"
>
<
input
type
=
hidden
name
=
search_text
value
=
\
"
$search_text\
"
>
<
input
type
=
submit
name
=
subaction
value
=
Insert
>
</
td
>
</
tr
>
</
form
>
";
}
print "
<
tr
>
<
td
colspan
=
$t_columns
><
hr
noshade
size
=
2
></
td
>
</
tr
>
";
}
while (
$i
<
$maxrows
) {
$db->next_record
();
$id
=
$db->f
('id');
$status
=
$db->f
('status');
$found
=
$i
+1;
if (!
$export
) {
print "
<
form
action
=
$PHP_SELF
method
=
post
>
<
input
type
=
hidden
name
=
action
value
=
update
>
<
input
type
=
hidden
name
=
next
value
=
$next
>
<
input
type
=
hidden
name
=
id
value
=
$id
>
<
tr
>
<
td
>
$found
.
</
td
>
";
}
$j
=0;
while (
$j
<
$db->num_fields
()) {
$value
=
$db->Record
[
$j
];
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (
$fields[$Fname]
[size]) {
$field_size
=
$fields[$Fname]
[size];
} else {
$field_size
=
$el_size
;
}
if (
$fields[$Fname]
[readonly]=="
1
") {
$extra_form_els
="
disabled
=
true
";
} else {
$extra_form_els
="";
}
if (!in_array(
$Fname
,
$exceptions
)) {
if (!
$export
) {
if (!in_array(
$Fname
,
$keys
)) {
if (
$Fname
=="
domain
" && is_array(
$insertDomainOption
)) {
print "
<
td
><
select
name
=
$Fname
>
";
$selected_domain[$value]
="
selected
";
foreach (
$insertDomainOption
as
$_option
) {
print "
<
option
$selected_domain
[
$_option
]
>
$_option
";
}
print "
</
select
>
</
td
>
";
} else {
print "
<
td
><
input
type
=
text
bgcolor
=
grey
size
=
$field_size
maxlength
=
$size
name
=
$Fname
value
=
\
"
$value\
"
$extra_form_els
></
td
>
";
}
} else {
print "
<
td
>
$value
</
td
>
";
}
} else {
if (
$j
) {
printf ("
%
s
%
s
",
$delimiter
,
$value
);
} else {
print "
2
";
}
}
}
$j
++;
}
$j
=0;
while (
$j
<
$cc
) {
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (!in_array(
$Fname
,
$exceptions
)) {
$SEARCH_NAME
="
search_
".
$Fname
;
$value
=
$_REQUEST[$SEARCH_NAME]
;
if (!
$export
) {
print "
<
input
type
=
hidden
name
=
search_
$Fname
value
=
\
"
$value\
"
>
";
}
}
$j
++;
}
if (
$export
) {
print "
\n
";
}
if (!
$export
) {
if (
$subaction
=="
Delete
" &&
$idForDeletion
==
$id
&& !
$confirmDelete
) {
print "
<
td
class
=
border
bgcolor
=
lightgrey
>
";
print "
<
input
type
=
hidden
name
=
confirmDelete
value
=
1
>
";
print "
<
input
type
=
submit
name
=
subaction
value
=
Delete
>
";
} else {
print "
<
td
class
=
border
>
<
input
type
=
submit
name
=
subaction
value
=
Update
>
<
input
type
=
submit
name
=
subaction
value
=
Delete
>
";
}
print "
<
input
type
=
hidden
name
=
table
value
=
$table
>
<
input
type
=
hidden
name
=
next
value
=
$next
>
<
input
type
=
hidden
name
=
search_text
value
=
\
"
$search_text\
"
>
</
td
>
</
tr
>
</
form
>
";
}
$i
++;
}
if (!
$export
) {
print "
</
table
>
<
p
>
";
print "
<
center
>
<
table
border
=
0
>
<
tr
>
<
td
>
";
if (
$next
!= 0 ) {
$show_next
=
$maxrowsperpage
-
$next
;
if (
$show_next
<0) {
$mod_show_next
=
$show_next
-2*
$show_next
;
}
print "
<
form
method
=
post
>
<
input
type
=
hidden
name
=
maxrowsperpage
value
=
$maxrowsperpage
>
<
input
type
=
hidden
name
=
next
value
=
$mod_show_next
>
<
input
type
=
hidden
name
=
action
value
=
Search
>
<
input
type
=
hidden
name
=
table
value
=
$table
>
<
input
type
=
hidden
name
=
search_text
value
=
\
"
$search_text\
"
>
";
$j
=0;
while (
$j
<
$cc
) {
$Fname
=
$metadata[$j]
["
name
"];
$size
=
$metadata[$j]
["
len
"];
if (!in_array(
$Fname
,
$exceptions
)) {
$SEARCH_NAME
="
search_
".
$Fname
;
$value
=
$_REQUEST[$SEARCH_NAME]
;
print "
<
input
type
=
hidden
name
=
search_
$Fname
value
=
\
"
$value\
"
>
";
}
$j
++;
}
print "
<
input
type
=
submit
value
=
\
"Previous
\"
>
</form>
"
;
}
print
"</td>
<td>
"
;
if
(
$rows
>
$maxrowsperpage
&&
$rows
!=
$maxrows
)
{
$show_next
=
$maxrowsperpage
+
$next
;
print
"
<form method=post>
<input type=hidden name=maxrowsperpage value=
$maxrowsperpage
>
<input type=hidden name=next value=
$show_next
>
<input type=hidden name=table value=
$table
>
<input type=hidden name=action value=Search>
"
;
$j
=
0
;
while
(
$j
<
$cc
)
{
$Fname
=
$metadata
[
$j
][
"name"
];
$size
=
$metadata
[
$j
][
"len"
];
if
(
!
in_array
(
$Fname
,
$exceptions
))
{
$SEARCH_NAME
=
"search_"
.
$Fname
;
$value
=
$_REQUEST
[
$SEARCH_NAME
];
print
"<input type=hidden name=search_
$Fname
value=
\"
$value\
"
>
";
}
$j
++;
}
print "
<
input
type
=
hidden
name
=
search_text
value
=
\
"
$search_text\
"
>
<
input
type
=
submit
value
=
\
"Next
\"
>
</form>
"
;
}
print
"
</td>
</tr>
</table>"
;
print
"
</body>
</html>
"
;
}
page_close
();
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Feb 1, 5:21 AM (19 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3488740
Default Alt Text
rating_tables.phtml (37 KB)
Attached To
Mode
rCDRT CDRTool
Attached
Detach File
Event Timeline
Log In to Comment