Commit eea2a96c authored by Ad Schellevis's avatar Ad Schellevis

(legacy) cleanups voucher.inc

parent e225795a
...@@ -276,7 +276,7 @@ function voucher_configure($sync = false) ...@@ -276,7 +276,7 @@ function voucher_configure($sync = false)
$ret = true; $ret = true;
if (!is_array($config['voucher'])) { if (!isset($config['voucher']) || !is_array($config['voucher'])) {
return $ret; return $ret;
} }
...@@ -427,25 +427,6 @@ function voucher_write_active_db($roll, $active) { ...@@ -427,25 +427,6 @@ function voucher_write_active_db($roll, $active) {
} }
} }
/* return how many vouchers are marked used on a roll */
function voucher_used_count($roll) {
global $g, $cpzone;
$bitstring = voucher_read_used_db($roll);
$max = strlen($bitstring) * 8;
$used = 0;
for ($i = 1; $i <= $max; $i++) {
// check if ticket already used or not.
$pos = $i >> 3; // divide by 8 -> octet
$mask = 1 << ($i % 8); // mask to test bit in octet
if (ord($bitstring[$pos]) & $mask)
$used++;
}
unset($bitstring);
return $used;
}
function voucher_read_used_db($roll) function voucher_read_used_db($roll)
{ {
global $cpzone; global $cpzone;
...@@ -464,13 +445,6 @@ function voucher_read_used_db($roll) ...@@ -464,13 +445,6 @@ function voucher_read_used_db($roll)
return base64_decode($vdb); return base64_decode($vdb);
} }
function voucher_unlink_db($roll)
{
global $cpzone;
@unlink("/var/db/voucher_{$cpzone}_used_{$roll}.db");
@unlink("/var/db/voucher_{$cpzone}_active_{$roll}.db");
}
/* we share the log with captiveportal for now */ /* we share the log with captiveportal for now */
function voucher_log($priority, $message) function voucher_log($priority, $message)
......
...@@ -37,6 +37,15 @@ require_once('filter.inc'); ...@@ -37,6 +37,15 @@ require_once('filter.inc');
require_once('captiveportal.inc'); require_once('captiveportal.inc');
require_once('voucher.inc'); require_once('voucher.inc');
function voucher_unlink_db($roll)
{
global $cpzone;
@unlink("/var/db/voucher_{$cpzone}_used_{$roll}.db");
@unlink("/var/db/voucher_{$cpzone}_active_{$roll}.db");
}
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_captiveportal_vouchers.php'); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_captiveportal_vouchers.php');
$cpzone = $_GET['zone']; $cpzone = $_GET['zone'];
......
...@@ -33,6 +33,27 @@ require_once("filter.inc"); ...@@ -33,6 +33,27 @@ require_once("filter.inc");
require_once("captiveportal.inc"); require_once("captiveportal.inc");
require_once("voucher.inc"); require_once("voucher.inc");
/* return how many vouchers are marked used on a roll */
function voucher_used_count($roll) {
global $g, $cpzone;
$bitstring = voucher_read_used_db($roll);
$max = strlen($bitstring) * 8;
$used = 0;
for ($i = 1; $i <= $max; $i++) {
// check if ticket already used or not.
$pos = $i >> 3; // divide by 8 -> octet
$mask = 1 << ($i % 8); // mask to test bit in octet
if (ord($bitstring[$pos]) & $mask)
$used++;
}
unset($bitstring);
return $used;
}
$cpzone = $_GET['zone']; $cpzone = $_GET['zone'];
if (isset($_POST['zone'])) { if (isset($_POST['zone'])) {
$cpzone = $_POST['zone']; $cpzone = $_POST['zone'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment