Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • smradius/smradius
  • centiva-shail/smradius
  • nkukard/smradius
3 results
Show changes
Showing
with 1181 additions and 722 deletions
<?php
# Admin Client Attributes functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,7 +24,7 @@ function addAdminClientAttribute($params) {
# Perform query
$res = DBDo("
INSERT INTO
client_attributes (ClientID,Name,Operator,Value,Disabled)
@TP@client_attributes (ClientID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['ClientID'],
......@@ -30,7 +46,7 @@ function addAdminClientAttribute($params) {
function removeAdminClientAttribute($params) {
# Perform query
$res = DBDo("DELETE FROM client_attributes WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@client_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -44,7 +60,7 @@ function removeAdminClientAttribute($params) {
function updateAdminClientAttribute($params) {
# Perform query
$res = DBDo("UPDATE client_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@client_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
......@@ -64,7 +80,7 @@ function updateAdminClientAttribute($params) {
function getAdminClientAttribute($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM client_attributes WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@client_attributes WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -90,11 +106,11 @@ function getAdminClientAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'client_attributes.ID',
'Name' => 'client_attributes.Name',
'Operator' => 'client_attributes.Operator',
'Value' => 'client_attributes.Value',
'Disabled' => 'client_attributes.Disabled'
'ID' => '@TP@client_attributes.ID',
'Name' => '@TP@client_attributes.Name',
'Operator' => '@TP@client_attributes.Operator',
'Value' => '@TP@client_attributes.Value',
'Disabled' => '@TP@client_attributes.Disabled'
);
# Perform query
......@@ -102,7 +118,7 @@ function getAdminClientAttributes($params) {
SELECT
ID, Name, Operator, Value, Disabled
FROM
client_attributes
@TP@client_attributes
WHERE
ClientID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
......
<?php
# Admin Client Realms functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -7,7 +23,7 @@ include_once("include/db.php");
function addAdminClientRealm($params) {
# Perform query
$res = DBDo("INSERT INTO clients_to_realms (ClientID,RealmID) VALUES (?,?)",array($params[0]['ClientID'],$params[0]['RealmID']));
$res = DBDo("INSERT INTO @TP@clients_to_realms (ClientID,RealmID) VALUES (?,?)",array($params[0]['ClientID'],$params[0]['RealmID']));
# Return result
if ($res !== TRUE) {
......@@ -21,7 +37,7 @@ function addAdminClientRealm($params) {
function removeAdminClientRealm($params) {
# Perform query
$res = DBDo("DELETE FROM clients_to_realms WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -36,19 +52,19 @@ function getAdminClientRealms($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'clients_to_realms.ID',
'Name' => 'realms.Name'
'ID' => '@TP@clients_to_realms.ID',
'Name' => '@TP@realms.Name'
);
# Perform query
$res = DBSelectSearch("
SELECT
clients_to_realms.ID, realms.Name
@TP@clients_to_realms.ID, @TP@realms.Name
FROM
clients_to_realms, realms
@TP@clients_to_realms, @TP@realms
WHERE
clients_to_realms.RealmID = realms.ID
AND clients_to_realms.ClientID = ".DBQuote($params[0])."
@TP@clients_to_realms.RealmID = @TP@realms.ID
AND @TP@clients_to_realms.ClientID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......@@ -63,7 +79,7 @@ function getAdminClientRealms($params) {
$item = array();
$item['ID'] = $row->id;
$item['Name'] = $row->name;
$item['Name'] = htmlspecialchars($row->name);
# Push this row onto array
array_push($resultArray,$item);
......
<?php
# Admin Clients functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,13 +24,13 @@ function getAdminClients($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'clients.ID',
'Name' => 'clients.Name',
'AccessList' => 'clients.AccessList'
'ID' => '@TP@clients.ID',
'Name' => '@TP@clients.Name',
'AccessList' => '@TP@clients.AccessList'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, AccessList FROM clients",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Name, AccessList FROM @TP@clients",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -43,7 +59,7 @@ function getAdminClients($params) {
function getAdminClient($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, AccessList FROM clients WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, AccessList FROM @TP@clients WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -69,16 +85,16 @@ function removeAdminClient($params) {
DBBegin();
# Perform query
$res = DBDo("DELETE FROM client_attributes WHERE ClientID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@client_attributes WHERE ClientID = ?",array($params[0]));
# Remove client from realms
if ($res !== FALSE) {
$res = DBDo("DELETE FROM clients_to_realms WHERE ClientID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ClientID = ?",array($params[0]));
}
# Perform next query if successful
if ($res !== FALSE) {
$res = DBDo("DELETE FROM clients WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@clients WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -96,7 +112,7 @@ function removeAdminClient($params) {
function createAdminClient($params) {
# Perform query
$res = DBDo("INSERT INTO clients (Name,AccessList) VALUES (?,?)",array($params[0]['Name'],$params[0]['AccessList']));
$res = DBDo("INSERT INTO @TP@clients (Name,AccessList) VALUES (?,?)",array($params[0]['Name'],$params[0]['AccessList']));
# Return result
if ($res !== TRUE) {
......@@ -110,7 +126,7 @@ function createAdminClient($params) {
function updateAdminClient($params) {
# Perform query
$res = DBDo("UPDATE clients SET Name = ?, AccessList = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@clients SET Name = ?, AccessList = ? WHERE ID = ?",
array($params[0]['Name'],$params[0]['AccessList'],$params[0]['ID']));
# Return result
......
<?php
# Admin Group Attributes functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
include_once("include/util.php");
# Add group attribute
function addAdminGroupAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
$res = DBDo("
INSERT INTO
group_attributes (GroupID,Name,Operator,Value,Disabled)
@TP@group_attributes (GroupID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['GroupID'],
$params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'])
$disabled)
);
# Return result
......@@ -28,7 +51,7 @@ function addAdminGroupAttribute($params) {
# Remove group attribute
function removeAdminGroupAttribute($params) {
$res = DBDo("DELETE FROM group_attributes WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@group_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -41,11 +64,17 @@ function removeAdminGroupAttribute($params) {
# Edit group attribute
function updateAdminGroupAttribute($params) {
$res = DBDo("UPDATE group_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
$res = DBDo("UPDATE @TP@group_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'],
$disabled,
$params[0]['ID'])
);
......@@ -60,7 +89,7 @@ function updateAdminGroupAttribute($params) {
# Return specific attribute row
function getAdminGroupAttribute($params) {
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM group_attributes WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@group_attributes WHERE ID = ?",array($params[0]));
if (!is_object($res)) {
return $res;
}
......@@ -83,11 +112,11 @@ function getAdminGroupAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'group_attributes.ID',
'Name' => 'group_attributes.Name',
'Operator' => 'group_attributes.Operator',
'Value' => 'group_attributes.Value',
'Disabled' => 'group_attributes.Disabled'
'ID' => '@TP@group_attributes.ID',
'Name' => '@TP@group_attributes.Name',
'Operator' => '@TP@group_attributes.Operator',
'Value' => '@TP@group_attributes.Value',
'Disabled' => '@TP@group_attributes.Disabled'
);
# Fetch attributes
......@@ -95,7 +124,7 @@ function getAdminGroupAttributes($params) {
SELECT
ID, Name, Operator, Value, Disabled
FROM
group_attributes
@TP@group_attributes
WHERE
GroupID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
......
<?php
# Admin Group Members functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
# Remove group member
function removeAdminGroupMember($params) {
$res = DBDo("DELETE FROM users_to_groups WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -20,21 +36,21 @@ function getAdminGroupMembers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users_to_groups.ID',
'Username' => 'group_attributes.Username',
'Disabled' => 'group_attributes.Disabled'
'ID' => '@TP@users_to_groups.ID',
'Username' => '@TP@group_attributes.Username',
'Disabled' => '@TP@group_attributes.Disabled'
);
# Fetch members
$res = DBSelectSearch("
SELECT
users_to_groups.ID, users.Username, users.Disabled
@TP@users_to_groups.ID, @TP@users.Username, @TP@users.Disabled
FROM
users_to_groups, users
@TP@users_to_groups, @TP@users
WHERE
users.ID = users_to_groups.UserID
@TP@users.ID = @TP@users_to_groups.UserID
AND
users_to_groups.GroupID = ".DBQuote($params[0])."
@TP@users_to_groups.GroupID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......
<?php
# Admin Groups functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,15 +24,15 @@ function getAdminGroups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'groups.ID',
'Name' => 'groups.Name',
'Priority' => 'groups.Priority',
'Disabled' => 'groups.Disabled',
'Comment' => 'groups.Comment'
'ID' => '@TP@groups.ID',
'Name' => '@TP@groups.Name',
'Priority' => '@TP@groups.Priority',
'Disabled' => '@TP@groups.Disabled',
'Comment' => '@TP@groups.Comment'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, Priority, Disabled, Comment FROM groups",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Name, Priority, Disabled, Comment FROM @TP@groups",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -47,7 +63,7 @@ function getAdminGroups($params) {
function getAdminGroup($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Priority, Disabled, Comment FROM groups WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Priority, Disabled, Comment FROM @TP@groups WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -75,16 +91,16 @@ function removeAdminGroup($params) {
DBBegin();
# Unlink users from group
$res = DBDo("DELETE FROM users_to_groups WHERE GroupID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE GroupID = ?",array($params[0]));
# Delete group attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM group_attributes WHERE GroupID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@group_attributes WHERE GroupID = ?",array($params[0]));
}
# Delete group
if ($res !== FALSE) {
$res = DBDo("DELETE FROM groups WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@groups WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -102,7 +118,7 @@ function removeAdminGroup($params) {
function createAdminGroup($params) {
# Perform query
$res = DBDo("INSERT INTO groups (Name) VALUES (?)",array($params[0]['Name']));
$res = DBDo("INSERT INTO @TP@groups (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if ($res !== TRUE) {
......@@ -116,7 +132,7 @@ function createAdminGroup($params) {
function updateAdminGroup($params) {
# Perform query
$res = DBDo("UPDATE groups SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@groups SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# Return result
if ($res !== TRUE) {
......
<?php
# Admin Realm Attributes functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,7 +24,7 @@ function addAdminRealmAttribute($params) {
# Perform query
$res = DBDo("
INSERT INTO
realm_attributes (RealmID,Name,Operator,Value,Disabled)
@TP@realm_attributes (RealmID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['RealmID'],
......@@ -30,7 +46,7 @@ function addAdminRealmAttribute($params) {
function removeAdminRealmAttribute($params) {
# Perform query
$res = DBDo("DELETE FROM realm_attributes WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@realm_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -44,7 +60,7 @@ function removeAdminRealmAttribute($params) {
function updateAdminRealmAttribute($params) {
# Perform query
$res = DBDo("UPDATE realm_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@realm_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
......@@ -64,7 +80,7 @@ function updateAdminRealmAttribute($params) {
function getAdminRealmAttribute($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM realm_attributes WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@realm_attributes WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -90,11 +106,11 @@ function getAdminRealmAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'realm_attributes.ID',
'Name' => 'realm_attributes.Name',
'Operator' => 'realm_attributes.Operator',
'Value' => 'realm_attributes.Value',
'Disabled' => 'realm_attributes.Disabled'
'ID' => '@TP@realm_attributes.ID',
'Name' => '@TP@realm_attributes.Name',
'Operator' => '@TP@realm_attributes.Operator',
'Value' => '@TP@realm_attributes.Value',
'Disabled' => '@TP@realm_attributes.Disabled'
);
# Perform query
......@@ -102,7 +118,7 @@ function getAdminRealmAttributes($params) {
SELECT
ID, Name, Operator, Value, Disabled
FROM
realm_attributes
@TP@realm_attributes
WHERE
RealmID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
......
<?php
# Admin Realm Members functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
# Remove realm member
function removeAdminRealmMember($params) {
$res = DBDo("DELETE FROM clients_to_realms WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@clients_to_realms WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -20,20 +36,20 @@ function getAdminRealmMembers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'clients_to_realms.ID',
'Name' => 'realm_attributes.Name'
'ID' => '@TP@clients_to_realms.ID',
'Name' => '@TP@realm_attributes.Name'
);
# Fetch members
$res = DBSelectSearch("
SELECT
clients_to_realms.ID, clients.Name
@TP@clients_to_realms.ID, @TP@clients.Name
FROM
clients_to_realms, clients
@TP@clients_to_realms, @TP@clients
WHERE
clients.ID = clients_to_realms.ClientID
@TP@clients.ID = @TP@clients_to_realms.ClientID
AND
clients_to_realms.RealmID = ".DBQuote($params[0])."
@TP@clients_to_realms.RealmID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......
<?php
# Admin Realms functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,13 +24,13 @@ function getAdminRealms($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'realms.ID',
'Name' => 'realms.Name',
'Disabled' => 'realms.Disabled'
'ID' => '@TP@realms.ID',
'Name' => '@TP@realms.Name',
'Disabled' => '@TP@realms.Disabled'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name, Disabled FROM realms",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Name, Disabled FROM @TP@realms",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -43,7 +59,7 @@ function getAdminRealms($params) {
function getAdminRealm($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Disabled FROM realms WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Disabled FROM @TP@realms WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -69,11 +85,11 @@ function removeAdminRealm($params) {
DBBegin();
# Perform query
$res = DBDo("DELETE FROM realm_attributes WHERE RealmID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@realm_attributes WHERE RealmID = ?",array($params[0]));
# Perform next query if successful
if ($res !== FALSE) {
$res = DBDo("DELETE FROM realms WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@realms WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -91,7 +107,7 @@ function removeAdminRealm($params) {
function createAdminRealm($params) {
# Perform query
$res = DBDo("INSERT INTO realms (Name) VALUES (?)",array($params[0]['Name']));
$res = DBDo("INSERT INTO @TP@realms (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if ($res !== TRUE) {
......@@ -105,7 +121,7 @@ function createAdminRealm($params) {
function updateAdminRealm($params) {
# Perform query
$res = DBDo("UPDATE realms SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@realms SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# Return result
if ($res !== TRUE) {
......
<?php
# Admin User Attributes functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
include_once("include/util.php");
# Add user attribute
function addAdminUserAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
# Perform query
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value,Disabled)
@TP@user_attributes (UserID,Name,Operator,Value,Disabled)
VALUES
(?,?,?,?,?)",
array( $params[0]['UserID'],
$params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'])
$disabled)
);
# Return result
......@@ -30,7 +53,7 @@ function addAdminUserAttribute($params) {
function removeAdminUserAttribute($params) {
# Perform query
$res = DBDo("DELETE FROM user_attributes WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -43,12 +66,18 @@ function removeAdminUserAttribute($params) {
# Edit attribute
function updateAdminUserAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
# Perform query
$res = DBDo("UPDATE user_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@user_attributes SET Name = ?, Operator = ?, Value = ?, Disabled = ? WHERE ID = ?",
array($params[0]['Name'],
$params[0]['Operator'],
$params[0]['Value'],
$params[0]['Disabled'],
$disabled,
$params[0]['ID'])
);
......@@ -64,7 +93,7 @@ function updateAdminUserAttribute($params) {
function getAdminUserAttribute($params) {
# Perform query
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM user_attributes WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name, Operator, Value, Disabled FROM @TP@user_attributes WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -90,11 +119,11 @@ function getAdminUserAttributes($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'user_attributes.ID',
'Name' => 'user_attributes.Name',
'Operator' => 'user_attributes.Operator',
'Value' => 'user_attributes.Value',
'Disabled' => 'user_attributes.Disabled'
'ID' => '@TP@user_attributes.ID',
'Name' => '@TP@user_attributes.Name',
'Operator' => '@TP@user_attributes.Operator',
'Value' => '@TP@user_attributes.Value',
'Disabled' => '@TP@user_attributes.Disabled'
);
# Perform query
......@@ -102,7 +131,7 @@ function getAdminUserAttributes($params) {
SELECT
ID, Name, Operator, Value, Disabled
FROM
user_attributes
@TP@user_attributes
WHERE
UserID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
......
<?php
# Admin User Groups functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -7,7 +23,7 @@ include_once("include/db.php");
function addAdminUserGroup($params) {
# Perform query
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['UserID'],$params[0]['GroupID']));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['UserID'],$params[0]['GroupID']));
# Return result
if ($res !== TRUE) {
......@@ -21,7 +37,7 @@ function addAdminUserGroup($params) {
function removeAdminUserGroup($params) {
# Perform query
$res = DBDo("DELETE FROM users_to_groups WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -36,19 +52,19 @@ function getAdminUserGroups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users_to_groups.ID',
'Name' => 'groups.Name'
'ID' => '@TP@users_to_groups.ID',
'Name' => '@TP@groups.Name'
);
# Perform query
$res = DBSelectSearch("
SELECT
users_to_groups.ID, groups.Name
@TP@users_to_groups.ID, @TP@groups.Name
FROM
users_to_groups, groups
@TP@users_to_groups, @TP@groups
WHERE
users_to_groups.GroupID = groups.ID
AND users_to_groups.UserID = ".DBQuote($params[0])."
@TP@users_to_groups.GroupID = @TP@groups.ID
AND @TP@users_to_groups.UserID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......
<?php
# Admin User Logs functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -6,14 +22,18 @@ include_once("include/db.php");
# Return user logs summary
function getAdminUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect("
SELECT
user_attributes.Name,
user_attributes.Value
@TP@group_attributes.Name,
@TP@group_attributes.Value
FROM
user_attributes
@TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE
user_attributes.UserID = ?",
@TP@group_attributes.GroupID = @TP@groups.ID
AND @TP@groups.ID = @TP@users_to_groups.GroupID
AND @TP@users_to_groups.UserID = ?",
array($params[0]['ID'])
);
......@@ -22,10 +42,7 @@ function getAdminUserLogsSummary($params) {
return $res;
}
# Array of results
$resultArray = array();
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$trafficCap = -1;
$uptimeCap = -1;
while ($row = $res->fetchObject()) {
......@@ -37,31 +54,65 @@ function getAdminUserLogsSummary($params) {
}
}
# Add cap type / amount to result
# Get user attributes
$res = DBSelect("
SELECT
Name,
Value
FROM
@TP@user_attributes
WHERE
UserID = ?",
array($params[0]['ID'])
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
while ($row = $res->fetchObject()) {
if ($row->name == 'SMRadius-Capping-Traffic-Limit') {
$trafficCap = (int)$row->value;
}
if ($row->name == 'SMRadius-Capping-Uptime-Limit') {
$uptimeCap = (int)$row->value;
}
}
# Add caps to result
$resultArray = array();
$resultArray['trafficCap'] = $trafficCap;
$resultArray['uptimeCap'] = $uptimeCap;
# Dates we want to use to search search
$dateFrom = new DateTime($params[0]['From']);
$dateTo = new DateTime($params[0]['To']);
$periodKey = new DateTime($params[0]['PeriodKey']."-01");
# Return if error
if (!is_object($periodKey)) {
return $periodKey;
}
# Fetch user uptime and traffic summary
$res = DBSelect("
SELECT
topups_summary.Balance,
topups.Type,
topups.Value
@TP@topups_summary.Balance,
@TP@topups.ID,
@TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM
topups_summary,
topups
@TP@topups_summary,
@TP@topups
WHERE
topups_summary.TopupID = topups.ID
AND topups.UserID = ?
AND topups_summary.PeriodKey = ?
AND topups.Depleted = 0
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?
AND @TP@topups_summary.PeriodKey = ?
AND @TP@topups_summary.Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m'))
@TP@topups.Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
# Return if error
......@@ -74,26 +125,30 @@ function getAdminUserLogsSummary($params) {
$i = 0;
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->balance;
$topups[$i]['OriginalLimit'] = $row->value;
$topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['Limit'] = $row->value;
$i++;
}
# Fetch user uptime and traffic topups
$periodKeyEnd = new DateTime($periodKey->format('Y-m-d'));
$periodKeyEnd->modify("+1 month");
$res = DBSelect("
SELECT
Value, Type
ID, Value, Type, ValidTo
FROM
topups
@TP@topups
WHERE
topups.UserID = ?
AND topups.ValidFrom = ?
AND topups.ValidTo >= ?
AND topups.Depleted = 0
UserID = ?
AND ValidFrom = ?
AND ValidTo >= ?
AND Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d'))
Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
);
# Return if error
......@@ -104,6 +159,8 @@ function getAdminUserLogsSummary($params) {
# Store normal topups
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$i++;
......@@ -111,18 +168,18 @@ function getAdminUserLogsSummary($params) {
$res = DBSelect("
SELECT
accounting.AcctSessionTime,
accounting.AcctInputOctets,
accounting.AcctInputGigawords,
accounting.AcctOutputOctets,
accounting.AcctOutputGigawords
SUM(@TP@accounting.AcctSessionTime) / 60 AS TotalSessionTime,
SUM(@TP@accounting.AcctInputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctInputGigawords) * 4096 +
SUM(@TP@accounting.AcctOutputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctOutputGigawords) * 4096 AS TotalTraffic
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.ID = ?
AND EventTimestamp >= ?
AND accounting.Username = users.Username",
array($params[0]['ID'],$dateFrom->format('Y-m-d'))
@TP@users.ID = ?
AND @TP@accounting.PeriodKey = ?
AND @TP@accounting.Username = @TP@users.Username",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
if (!is_object($res)) {
......@@ -130,169 +187,178 @@ function getAdminUserLogsSummary($params) {
}
# Set total traffic and uptime used
$totalTraffic = 0;
$totalUptime = 0;
while ($row = $res->fetchObject()) {
$row = $res->fetchObject();
# Traffic in
$inputDataItem = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$inputDataItem += ($row->acctinputoctets / 1024) / 1024;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096);
}
$totalTraffic += $inputDataItem;
# Traffic out
$outputDataItem = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$outputDataItem += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$outputDataItem += ($row->acctoutputgigawords * 4096);
}
$totalTraffic += $outputDataItem;
# Uptime
$sessionTimeItem = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$sessionTimeItem += $row->acctsessiontime;
}
$totalUptime += $sessionTimeItem;
# Round up
$totalUptime = ceil($totalUptime / 60);
# Add usage to our return array
$resultArray['trafficUsage'] = 0;
$resultArray['uptimeUsage'] = 0;
if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$resultArray['trafficUsage'] += $row->totaltraffic;
}
if (isset($row->totalsessiontime) && $row->totalsessiontime > 0) {
$resultArray['uptimeUsage'] += $row->totalsessiontime;
}
# Set excess traffic usage
# Excess usage
$excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) {
$excessTraffic += $totalTraffic - $trafficCap;
if ($trafficCap == -1) {
$excessTraffic = $resultArray['trafficUsage'];
} else {
$excessTraffic += $totalTraffic;
$excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
}
# Set excess uptime usage
$excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) {
$excessUptime += $totalUptime - $uptimeCap;
if ($uptimeCap == -1) {
$excessUptime = $resultArray['uptimeUsage'];
} else {
$excessUptime += $totalUptime;
$excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
}
$currentTrafficTopup = array();
$topupTrafficRemaining = 0;
# Loop through traffic topups and check for current topup, total topups not being used
if (is_string($trafficCap) || $trafficCap != 0) {
$i = 0;
# User is using traffic from topups
if ($excessTraffic > 0) {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
if ($excessTraffic <= 0) {
$topupTrafficRemaining += $topupItem['Limit'];
next($topupItem);
} elseif ($excessTraffic >= $topupItem['Limit']) {
$excessTraffic -= $topupItem['Limit'];
} else {
if (isset($topupItem['OriginalLimit'])) {
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentTrafficTopup['Cap'] = $topupItem['Limit'];
}
$currentTrafficTopup['Used'] = $excessTraffic;
$excessTraffic -= $topupItem['Limit'];
}
}
}
# User has not used traffic topups yet
} else {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
if ($i == 0) {
if (isset($topupItem['OriginalLimit'])) {
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentTrafficTopup['Cap'] = $topupItem['Limit'];
}
$i = 1;
$currentTrafficTopup['Used'] = 0;
} else {
$topupTrafficRemaining += $topupItem['Limit'];
}
}
# Loop through topups and add to return array
$resultArray['trafficTopups'] = 0;
$resultArray['uptimeTopups'] = 0;
$resultArray['TotalTrafficTopups'] = 0;
$resultArray['TotalUptimeTopups'] = 0;
# Traffic and uptime topups
$resultArray['AllTrafficTopups'] = array();
$resultArray['AllUptimeTopups'] = array();
$t = 0; $u = 0;
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
# Topup not currently in use
if ($excessTraffic <= 0) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Subtract this topup from excessTraffic usage
$excessTraffic -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
}
}
}
$currentUptimeTopup = array();
$topupUptimeRemaining = 0;
# Loop through uptime topups and check for current topup, total topups not being used
if (is_string($uptimeCap) || $uptimeCap != 0) {
$i = 0;
# User is using uptime from topups
if ($excessUptime > 0) {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 2) {
if ($excessUptime <= 0) {
$topupUptimeRemaining += $topupItem['Limit'];
next($topupItem);
} elseif ($excessUptime >= $topupItem['Limit']) {
$excessUptime -= $topupItem['Limit'];
} else {
if (isset($topupItem['OriginalLimit'])) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit'];
}
$currentUptimeTopup['Used'] = $excessUptime;
$excessUptime -= $topupItem['Limit'];
}
}
}
# User has not used uptime topups yet
} else {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 2) {
if ($i == 0) {
if (isset($topupItem['OriginalLimit'])) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit'];
}
$i = 1;
$currentUptimeTopup['Used'] = 0;
} else {
$topupUptimeRemaining += $topupItem['Limit'];
}
}
if ($topupItem['Type'] == 2) {
# Topup not currently in use
if ($excessUptime <= 0) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Subtract this topup from excessUptime usage
$excessUptime -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
}
}
}
# Traffic..
$resultArray['trafficCurrentTopupUsed'] = -1;
$resultArray['trafficCurrentTopupCap'] = -1;
if (count($currentTrafficTopup) > 0) {
$resultArray['trafficCurrentTopupUsed'] = $currentTrafficTopup['Used'];
$resultArray['trafficCurrentTopupCap'] = (int)$currentTrafficTopup['Cap'];
}
$resultArray['trafficTopupRemaining'] = $topupTrafficRemaining;
# Uptime..
$resultArray['uptimeCurrentTopupUsed'] = -1;
$resultArray['uptimeCurrentTopupCap'] = -1;
if (count($currentUptimeTopup) > 0) {
$resultArray['uptimeCurrentTopupUsed'] = $currentUptimeTopup['Used'];
$resultArray['uptimeCurrentTopupCap'] = (int)$currentUptimeTopup['Cap'];
}
$resultArray['uptimeTopupRemaining'] = $topupUptimeRemaining;
# Return results
return array($resultArray, 1);
}
......@@ -302,45 +368,45 @@ function getAdminUserLogs($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'accounting.ID',
'EventTimestamp' => 'accounting.EventTimestamp',
'AcctStatusType' => 'accounting.AcctStatusType',
'ServiceType' => 'accounting.ServiceType',
'FramedProtocol' => 'accounting.FramedProtocol',
'NASPortType' => 'accounting.NASPortType',
'NASPortID' => 'accounting.NASPortID',
'CallingStationID' => 'accounting.CallingStationID',
'CalledStationID' => 'accounting.CalledStationID',
'AcctSessionID' => 'accounting.AcctSessionID',
'FramedIPAddress' => 'accounting.FramedIPAddress',
'ID' => '@TP@accounting.ID',
'EventTimestamp' => '@TP@accounting.EventTimestamp',
'AcctStatusType' => '@TP@accounting.AcctStatusType',
'ServiceType' => '@TP@accounting.ServiceType',
'FramedProtocol' => '@TP@accounting.FramedProtocol',
'NASPortType' => '@TP@accounting.NASPortType',
'NASPortID' => '@TP@accounting.NASPortID',
'CallingStationID' => '@TP@accounting.CallingStationID',
'CalledStationID' => '@TP@accounting.CalledStationID',
'AcctSessionID' => '@TP@accounting.AcctSessionID',
'FramedIPAddress' => '@TP@accounting.FramedIPAddress',
);
# Perform query
$res = DBSelectSearch("
SELECT
accounting.ID,
accounting.EventTimestamp,
accounting.AcctStatusType,
accounting.ServiceType,
accounting.FramedProtocol,
accounting.NASPortType,
accounting.NASPortID,
accounting.CallingStationID,
accounting.CalledStationID,
accounting.AcctSessionID,
accounting.FramedIPAddress,
accounting.AcctInputOctets,
accounting.AcctInputGigawords,
accounting.AcctOutputOctets,
accounting.AcctOutputGigawords,
accounting.AcctTerminateCause,
accounting.AcctSessionTime
@TP@accounting.ID,
@TP@accounting.EventTimestamp,
@TP@accounting.AcctStatusType,
@TP@accounting.ServiceType,
@TP@accounting.FramedProtocol,
@TP@accounting.NASPortType,
@TP@accounting.NASPortID,
@TP@accounting.CallingStationID,
@TP@accounting.CalledStationID,
@TP@accounting.AcctSessionID,
@TP@accounting.FramedIPAddress,
@TP@accounting.AcctInputOctets / 1024 / 1024 +
@TP@accounting.AcctInputGigawords * 4096 AS AcctInput,
@TP@accounting.AcctOutputOctets / 1024 / 1024 +
@TP@accounting.AcctOutputGigawords * 4096 AS AcctOutput,
@TP@accounting.AcctTerminateCause,
@TP@accounting.AcctSessionTime / 60 AS AcctSessionTime
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.Username = accounting.Username
@TP@users.Username = @TP@accounting.Username
AND
users.ID = ".DBQuote($params[0])."
@TP@users.ID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......@@ -354,38 +420,27 @@ function getAdminUserLogs($params) {
while ($row = $sth->fetchObject()) {
# Input
$acctInputMbyte = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
$acctInput = 0;
if (isset($row->acctinput) && $row->acctinput > 0) {
$acctInput += $row->acctinput;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$acctInputMbyte += ($row->acctinputgigawords * 4096);
}
# Output
$acctOutputMbyte = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
$acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
$acctOutput += $row->acctoutput;
}
# Uptime
$acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += ($row->acctsessiontime / 60);
$acctSessionTime += $row->acctsessiontime;
}
ceil($acctSessionTime);
# Build array for this row
$item = array();
$item['ID'] = $row->id;
# Convert to ISO format
# Convert to ISO format
$date = new DateTime($row->eventtimestamp);
$value = $date->format("Y-m-d H:i:s");
$item['EventTimestamp'] = $value;
......@@ -398,10 +453,10 @@ function getAdminUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte;
$item['AcctOutputMbyte'] = $acctOutputMbyte;
$item['AcctSessionTime'] = $acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype);
$item['AcctInput'] = $acctInput;
$item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# Push this row onto main array
array_push($resultArray,$item);
......
<?php
# Admin User Topups functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -10,7 +26,7 @@ function createAdminUserTopup($params) {
$timestamp = date('Y-m-d H:i:s');
# Perform query
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
$res = DBDo("INSERT INTO @TP@topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo'])
);
......@@ -27,7 +43,7 @@ function createAdminUserTopup($params) {
function updateAdminUserTopup($params) {
# Perform query
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -46,8 +62,16 @@ function updateAdminUserTopup($params) {
# Delete user topup
function removeAdminUserTopup($params) {
# Perform query
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
# Delete topup summary
$res = DBDo("DELETE FROM @TP@topups_summary WHERE TopupID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
return $res;
}
# Delete topup
$res = DBDo("DELETE FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -61,7 +85,7 @@ function removeAdminUserTopup($params) {
function getAdminUserTopup($params) {
# Perform query
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -93,11 +117,11 @@ function getAdminUserTopups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'topups.ID',
'Type' => 'topups.Type',
'Value' => 'topups.Value',
'ValidFrom' => 'topups.ValidFrom',
'ValidTo' => 'topups.ValidTo'
'ID' => '@TP@topups.ID',
'Type' => '@TP@topups.Type',
'Value' => '@TP@topups.Value',
'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => '@TP@topups.ValidTo'
);
# Perform query
......@@ -105,7 +129,7 @@ function getAdminUserTopups($params) {
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......
<?php
# Admin Users functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,13 +24,13 @@ function getAdminUsers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users.ID',
'Username' => 'users.Username',
'Disabled' => 'users.Disabled',
'ID' => '@TP@users.ID',
'Username' => '@TP@users.Username',
'Disabled' => '@TP@users.Disabled',
);
# Perform query
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM users",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Username, Disabled FROM @TP@users",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -45,7 +61,7 @@ function getAdminUsers($params) {
function getAdminUser($params) {
# Perform query
$res = DBSelect("SELECT ID, Username, Disabled FROM users WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Username, Disabled FROM @TP@users WHERE ID = ?",array($params[0]));
# Return error if failed
if (!is_object($res)) {
......@@ -71,16 +87,16 @@ function removeAdminUser($params) {
DBBegin();
# Delete user information, if any
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_userdata WHERE UserID = ?",array($params[0]));
# Delete user attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE UserID = ?",array($params[0]));
}
# Remove user from groups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE UserID = ?",array($params[0]));
}
# Get list of topups and delete summaries
......@@ -88,12 +104,12 @@ function removeAdminUser($params) {
$topupList = array();
$res = DBSelect("
SELECT
topups_summary.TopupID
@TP@topups_summary.TopupID
FROM
topups_summary, topups
@TP@topups_summary, @TP@topups
WHERE
topups_summary.TopupID = topups.ID
AND topups.UserID = ?",
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?",
array($params[0])
);
......@@ -112,7 +128,7 @@ function removeAdminUser($params) {
if ($res !== FALSE) {
$res = DBDo("
DELETE FROM
topups_summary
@TP@topups_summary
WHERE
TopupID = ?",
array($id)
......@@ -124,12 +140,12 @@ function removeAdminUser($params) {
# Remove topups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM topups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@topups WHERE UserID = ?",array($params[0]));
}
# Delete user
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -146,7 +162,7 @@ function removeAdminUser($params) {
function createAdminUser($params) {
# Perform query
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($params[0]['Username'],$params[0]['Disabled']));
# Return result
if ($res !== TRUE) {
......@@ -160,7 +176,7 @@ function createAdminUser($params) {
function updateAdminUser($params) {
# Perform query
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
# Return result
if ($res !== TRUE) {
......
<?php
# WiSP Location Members functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -6,7 +22,7 @@ include_once("include/db.php");
function removeWiSPLocationMember($params) {
# Perform query
$res = DBDo("UPDATE wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = NULL WHERE UserID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -21,20 +37,20 @@ function getWiSPLocationMembers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'users.ID',
'Username' => 'users.Username'
'ID' => '@TP@users.ID',
'Username' => '@TP@users.Username'
);
# Perform query
$res = DBSelectSearch("
SELECT
users.ID, users.Username
@TP@users.ID, @TP@users.Username
FROM
wisp_userdata, users
@TP@wisp_userdata, @TP@users
WHERE
wisp_userdata.LocationID = ".DBQuote($params[0])."
@TP@wisp_userdata.LocationID = ".DBQuote($params[0])."
AND
users.ID = wisp_userdata.UserID
@TP@users.ID = @TP@wisp_userdata.UserID
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......
<?php
# WiSP Locations functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,12 +24,12 @@ function getWiSPLocations($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'wisp_locations.ID',
'Name' => 'wisp_locations.Name'
'ID' => '@TP@wisp_locations.ID',
'Name' => '@TP@wisp_locations.Name'
);
# Perform query
$res = DBSelectSearch("SELECT ID, Name FROM wisp_locations",$params[1],$filtersorts,$filtersorts);
$res = DBSelectSearch("SELECT ID, Name FROM @TP@wisp_locations",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data
......@@ -43,7 +59,7 @@ function getWiSPLocations($params) {
function getWiSPLocation($params) {
# Perform query
$res = DBSelect("SELECT ID, Name FROM wisp_locations WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Name FROM @TP@wisp_locations WHERE ID = ?",array($params[0]));
# Return if error or nothing to return
if (!is_object($res)) {
......@@ -68,11 +84,11 @@ function removeWiSPLocation($params) {
DBBegin();
# Unlink users from this location
$res = DBDo("UPDATE wisp_userdata SET LocationID = NULL WHERE LocationID = ?",array($params[0]));
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = NULL WHERE LocationID = ?",array($params[0]));
# Delete location
if ($res !== FALSE) {
$res = DBDo("DELETE FROM wisp_locations WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_locations WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -90,7 +106,7 @@ function removeWiSPLocation($params) {
function createWiSPLocation($params) {
# Perform query
$res = DBDo("INSERT INTO wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
$res = DBDo("INSERT INTO @TP@wisp_locations (Name) VALUES (?)",array($params[0]['Name']));
# Return result
if ($res !== TRUE) {
......@@ -104,7 +120,7 @@ function createWiSPLocation($params) {
function updateWiSPLocation($params) {
# Perform query
$res = DBDo("UPDATE wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
$res = DBDo("UPDATE @TP@wisp_locations SET Name = ? WHERE ID = ?",array($params[0]['Name'],$params[0]['ID']));
# Return result
if ($res !== TRUE) {
......
<?php
# WiSP User Logs functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -6,14 +22,18 @@ include_once("include/db.php");
# Return user logs summary
function getWiSPUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect("
SELECT
user_attributes.Name,
user_attributes.Value
@TP@group_attributes.Name,
@TP@group_attributes.Value
FROM
user_attributes
@TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE
user_attributes.UserID = ?",
@TP@group_attributes.GroupID = @TP@groups.ID
AND @TP@groups.ID = @TP@users_to_groups.GroupID
AND @TP@users_to_groups.UserID = ?",
array($params[0]['ID'])
);
......@@ -22,10 +42,7 @@ function getWiSPUserLogsSummary($params) {
return $res;
}
# Array of results
$resultArray = array();
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$trafficCap = -1;
$uptimeCap = -1;
while ($row = $res->fetchObject()) {
......@@ -37,31 +54,65 @@ function getWiSPUserLogsSummary($params) {
}
}
# Add cap type / amount to result
# Get user attributes
$res = DBSelect("
SELECT
Name,
Value
FROM
@TP@user_attributes
WHERE
UserID = ?",
array($params[0]['ID'])
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
while ($row = $res->fetchObject()) {
if ($row->name == 'SMRadius-Capping-Traffic-Limit') {
$trafficCap = (int)$row->value;
}
if ($row->name == 'SMRadius-Capping-Uptime-Limit') {
$uptimeCap = (int)$row->value;
}
}
# Add caps to result
$resultArray = array();
$resultArray['trafficCap'] = $trafficCap;
$resultArray['uptimeCap'] = $uptimeCap;
# Dates we want to use to search search
$dateFrom = new DateTime($params[0]['From']);
$dateTo = new DateTime($params[0]['To']);
$periodKey = new DateTime($params[0]['PeriodKey']."-01");
# Return if error
if (!is_object($periodKey)) {
return $periodKey;
}
# Fetch user uptime and traffic summary
$res = DBSelect("
SELECT
topups_summary.Balance,
topups.Type,
topups.Value
@TP@topups_summary.Balance,
@TP@topups.ID,
@TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM
topups_summary,
topups
@TP@topups_summary,
@TP@topups
WHERE
topups_summary.TopupID = topups.ID
AND topups.UserID = ?
AND topups_summary.PeriodKey = ?
AND topups.Depleted = 0
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?
AND @TP@topups_summary.PeriodKey = ?
AND @TP@topups_summary.Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m'))
@TP@topups.Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
# Return if error
......@@ -74,26 +125,30 @@ function getWiSPUserLogsSummary($params) {
$i = 0;
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->balance;
$topups[$i]['OriginalLimit'] = $row->value;
$topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['Limit'] = $row->value;
$i++;
}
# Fetch user uptime and traffic topups
$periodKeyEnd = new DateTime($periodKey->format('Y-m-d'));
$periodKeyEnd->modify("+1 month");
$res = DBSelect("
SELECT
Value, Type
ID, Value, Type, ValidTo
FROM
topups
@TP@topups
WHERE
topups.UserID = ?
AND topups.ValidFrom = ?
AND topups.ValidTo >= ?
AND topups.Depleted = 0
UserID = ?
AND ValidFrom = ?
AND ValidTo >= ?
AND Depleted = 0
ORDER BY
topups.Timestamp",
array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d'))
Timestamp ASC",
array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
);
# Return if error
......@@ -104,6 +159,8 @@ function getWiSPUserLogsSummary($params) {
# Store normal topups
while ($row = $res->fetchObject()) {
$topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$i++;
......@@ -111,18 +168,18 @@ function getWiSPUserLogsSummary($params) {
$res = DBSelect("
SELECT
accounting.AcctSessionTime,
accounting.AcctInputOctets,
accounting.AcctInputGigawords,
accounting.AcctOutputOctets,
accounting.AcctOutputGigawords
SUM(@TP@accounting.AcctSessionTime) / 60 AS TotalSessionTime,
SUM(@TP@accounting.AcctInputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctInputGigawords) * 4096 +
SUM(@TP@accounting.AcctOutputOctets) / 1024 / 1024 +
SUM(@TP@accounting.AcctOutputGigawords) * 4096 AS TotalTraffic
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.ID = ?
AND EventTimestamp >= ?
AND accounting.Username = users.Username",
array($params[0]['ID'],$dateFrom->format('Y-m-d'))
@TP@users.ID = ?
AND @TP@accounting.PeriodKey = ?
AND @TP@accounting.Username = @TP@users.Username",
array($params[0]['ID'],$periodKey->format('Y-m'))
);
if (!is_object($res)) {
......@@ -130,169 +187,178 @@ function getWiSPUserLogsSummary($params) {
}
# Set total traffic and uptime used
$totalTraffic = 0;
$totalUptime = 0;
while ($row = $res->fetchObject()) {
$row = $res->fetchObject();
# Traffic in
$inputDataItem = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$inputDataItem += ($row->acctinputoctets / 1024) / 1024;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096);
}
$totalTraffic += $inputDataItem;
# Traffic out
$outputDataItem = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$outputDataItem += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$outputDataItem += ($row->acctoutputgigawords * 4096);
}
$totalTraffic += $outputDataItem;
# Uptime
$sessionTimeItem = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$sessionTimeItem += $row->acctsessiontime;
}
$totalUptime += $sessionTimeItem;
# Round up
$totalUptime = ceil($totalUptime / 60);
# Add usage to our return array
$resultArray['trafficUsage'] = 0;
$resultArray['uptimeUsage'] = 0;
if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$resultArray['trafficUsage'] += $row->totaltraffic;
}
if (isset($row->totalsessiontime) && $row->totalsessiontime > 0) {
$resultArray['uptimeUsage'] += $row->totalsessiontime;
}
# Set excess traffic usage
# Excess usage
$excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) {
$excessTraffic += $totalTraffic - $trafficCap;
if ($trafficCap == -1) {
$excessTraffic = $resultArray['trafficUsage'];
} else {
$excessTraffic += $totalTraffic;
$excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
}
# Set excess uptime usage
$excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) {
$excessUptime += $totalUptime - $uptimeCap;
if ($uptimeCap == -1) {
$excessUptime = $resultArray['uptimeUsage'];
} else {
$excessUptime += $totalUptime;
$excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
}
$currentTrafficTopup = array();
$topupTrafficRemaining = 0;
# Loop through traffic topups and check for current topup, total topups not being used
if (is_string($trafficCap) || $trafficCap != 0) {
$i = 0;
# User is using traffic from topups
if ($excessTraffic > 0) {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
if ($excessTraffic <= 0) {
$topupTrafficRemaining += $topupItem['Limit'];
next($topupItem);
} elseif ($excessTraffic >= $topupItem['Limit']) {
$excessTraffic -= $topupItem['Limit'];
} else {
if (isset($topupItem['OriginalLimit'])) {
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentTrafficTopup['Cap'] = $topupItem['Limit'];
}
$currentTrafficTopup['Used'] = $excessTraffic;
$excessTraffic -= $topupItem['Limit'];
}
}
}
# User has not used traffic topups yet
} else {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
if ($i == 0) {
if (isset($topupItem['OriginalLimit'])) {
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentTrafficTopup['Cap'] = $topupItem['Limit'];
}
$i = 1;
$currentTrafficTopup['Used'] = 0;
} else {
$topupTrafficRemaining += $topupItem['Limit'];
}
}
# Loop through topups and add to return array
$resultArray['trafficTopups'] = 0;
$resultArray['uptimeTopups'] = 0;
$resultArray['TotalTrafficTopups'] = 0;
$resultArray['TotalUptimeTopups'] = 0;
# Traffic and uptime topups
$resultArray['AllTrafficTopups'] = array();
$resultArray['AllUptimeTopups'] = array();
$t = 0; $u = 0;
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 1) {
# Topup not currently in use
if ($excessTraffic <= 0) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
# Set total available topups
$resultArray['trafficTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessTraffic = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllTrafficTopups'][$t] = array();
$resultArray['AllTrafficTopups'][$t]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
$resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$t++;
$resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# Subtract this topup from excessTraffic usage
$excessTraffic -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
}
}
}
$currentUptimeTopup = array();
$topupUptimeRemaining = 0;
# Loop through uptime topups and check for current topup, total topups not being used
if (is_string($uptimeCap) || $uptimeCap != 0) {
$i = 0;
# User is using uptime from topups
if ($excessUptime > 0) {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 2) {
if ($excessUptime <= 0) {
$topupUptimeRemaining += $topupItem['Limit'];
next($topupItem);
} elseif ($excessUptime >= $topupItem['Limit']) {
$excessUptime -= $topupItem['Limit'];
} else {
if (isset($topupItem['OriginalLimit'])) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit'];
}
$currentUptimeTopup['Used'] = $excessUptime;
$excessUptime -= $topupItem['Limit'];
}
}
}
# User has not used uptime topups yet
} else {
foreach ($topups as $topupItem) {
if ($topupItem['Type'] == 2) {
if ($i == 0) {
if (isset($topupItem['OriginalLimit'])) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit'];
}
$i = 1;
$currentUptimeTopup['Used'] = 0;
} else {
$topupUptimeRemaining += $topupItem['Limit'];
}
}
if ($topupItem['Type'] == 2) {
# Topup not currently in use
if ($excessUptime <= 0) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Topup currently in use
} elseif (!isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['Limit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
} elseif (isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['CurrentLimit']) {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
# Set total available topups
$resultArray['uptimeTopups'] += $topupItem['CurrentLimit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# If we hit this topup then all the rest of them are available
$excessUptime = 0;
# Topup has been used up
} else {
# Add stats to topup array
$resultArray['AllUptimeTopups'][$u] = array();
$resultArray['AllUptimeTopups'][$u]['Used'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
$u++;
$resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
$resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
# Subtract this topup from excessUptime usage
$excessUptime -= isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
}
}
}
# Traffic..
$resultArray['trafficCurrentTopupUsed'] = -1;
$resultArray['trafficCurrentTopupCap'] = -1;
if (count($currentTrafficTopup) > 0) {
$resultArray['trafficCurrentTopupUsed'] = $currentTrafficTopup['Used'];
$resultArray['trafficCurrentTopupCap'] = (int)$currentTrafficTopup['Cap'];
}
$resultArray['trafficTopupRemaining'] = $topupTrafficRemaining;
# Uptime..
$resultArray['uptimeCurrentTopupUsed'] = -1;
$resultArray['uptimeCurrentTopupCap'] = -1;
if (count($currentUptimeTopup) > 0) {
$resultArray['uptimeCurrentTopupUsed'] = $currentUptimeTopup['Used'];
$resultArray['uptimeCurrentTopupCap'] = (int)$currentUptimeTopup['Cap'];
}
$resultArray['uptimeTopupRemaining'] = $topupUptimeRemaining;
# Return results
return array($resultArray, 1);
}
......@@ -302,45 +368,45 @@ function getWiSPUserLogs($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'accounting.ID',
'EventTimestamp' => 'accounting.EventTimestamp',
'AcctStatusType' => 'accounting.AcctStatusType',
'ServiceType' => 'accounting.ServiceType',
'FramedProtocol' => 'accounting.FramedProtocol',
'NASPortType' => 'accounting.NASPortType',
'NASPortID' => 'accounting.NASPortID',
'CallingStationID' => 'accounting.CallingStationID',
'CalledStationID' => 'accounting.CalledStationID',
'AcctSessionID' => 'accounting.AcctSessionID',
'FramedIPAddress' => 'accounting.FramedIPAddress',
'ID' => '@TP@accounting.ID',
'EventTimestamp' => '@TP@accounting.EventTimestamp',
'AcctStatusType' => '@TP@accounting.AcctStatusType',
'ServiceType' => '@TP@accounting.ServiceType',
'FramedProtocol' => '@TP@accounting.FramedProtocol',
'NASPortType' => '@TP@accounting.NASPortType',
'NASPortID' => '@TP@accounting.NASPortID',
'CallingStationID' => '@TP@accounting.CallingStationID',
'CalledStationID' => '@TP@accounting.CalledStationID',
'AcctSessionID' => '@TP@accounting.AcctSessionID',
'FramedIPAddress' => '@TP@accounting.FramedIPAddress',
);
# Perform query
$res = DBSelectSearch("
SELECT
accounting.ID,
accounting.EventTimestamp,
accounting.AcctStatusType,
accounting.ServiceType,
accounting.FramedProtocol,
accounting.NASPortType,
accounting.NASPortID,
accounting.CallingStationID,
accounting.CalledStationID,
accounting.AcctSessionID,
accounting.FramedIPAddress,
accounting.AcctInputOctets,
accounting.AcctInputGigawords,
accounting.AcctOutputOctets,
accounting.AcctOutputGigawords,
accounting.AcctTerminateCause,
accounting.AcctSessionTime
@TP@accounting.ID,
@TP@accounting.EventTimestamp,
@TP@accounting.AcctStatusType,
@TP@accounting.ServiceType,
@TP@accounting.FramedProtocol,
@TP@accounting.NASPortType,
@TP@accounting.NASPortID,
@TP@accounting.CallingStationID,
@TP@accounting.CalledStationID,
@TP@accounting.AcctSessionID,
@TP@accounting.FramedIPAddress,
@TP@accounting.AcctInputOctets / 1024 / 1024 +
@TP@accounting.AcctInputGigawords * 4096 AS AcctInput,
@TP@accounting.AcctOutputOctets / 1024 / 1024 +
@TP@accounting.AcctOutputGigawords * 4096 AS AcctOutput,
@TP@accounting.AcctTerminateCause,
@TP@accounting.AcctSessionTime / 60 AS AcctSessionTime
FROM
accounting, users
@TP@accounting, @TP@users
WHERE
users.Username = accounting.Username
@TP@users.Username = @TP@accounting.Username
AND
users.ID = ".DBQuote($params[0])."
@TP@users.ID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1];
......@@ -354,31 +420,21 @@ function getWiSPUserLogs($params) {
while ($row = $sth->fetchObject()) {
# Input
$acctInputMbyte = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$acctInputMbyte += ($row->acctinputgigawords * 4096);
$acctInput = 0;
if (isset($row->acctinput) && $row->acctinput > 0) {
$acctInput += $row->acctinput;
}
# Output
$acctOutputMbyte = 0;
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
$acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
$acctOutput += $row->acctoutput;
}
# Uptime
$acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += ($row->acctsessiontime / 60);
$acctSessionTime += $row->acctsessiontime;
}
ceil($acctSessionTime);
# Build array for this row
$item = array();
......@@ -397,10 +453,10 @@ function getWiSPUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte;
$item['AcctOutputMbyte'] = $acctOutputMbyte;
$item['AcctSessionTime'] = $acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype);
$item['AcctInput'] = $acctInput;
$item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# Push this row onto main array
array_push($resultArray,$item);
......
<?php
# WiSP User Topups functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -10,7 +26,7 @@ function createWiSPUserTopup($params) {
$timestamp = date('Y-m-d H:i:s');
# Perform query
$res = DBDo("INSERT INTO topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
$res = DBDo("INSERT INTO @TP@topups (UserID,Timestamp,Type,Value,ValidFrom,ValidTo) VALUES (?,?,?,?,?,?)",
array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo'])
);
......@@ -27,7 +43,7 @@ function createWiSPUserTopup($params) {
function updateWiSPUserTopup($params) {
# Perform query
$res = DBDo("UPDATE topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
$res = DBDo("UPDATE @TP@topups SET Value = ?, Type = ?, ValidFrom = ?, ValidTo = ? WHERE ID = ?",
array($params[0]['Value'],
$params[0]['Type'],
$params[0]['ValidFrom'],
......@@ -47,7 +63,7 @@ function updateWiSPUserTopup($params) {
function removeWiSPUserTopup($params) {
# Perform query
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return result
if ($res !== TRUE) {
......@@ -61,7 +77,7 @@ function removeWiSPUserTopup($params) {
function getWiSPUserTopup($params) {
# Perform query
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM topups WHERE ID = ?",array($params[0]));
$res = DBSelect("SELECT ID, Type, Value, ValidFrom, ValidTo FROM @TP@topups WHERE ID = ?",array($params[0]));
# Return if error or no result
if (!is_object($res)) {
......@@ -93,11 +109,11 @@ function getWiSPUserTopups($params) {
# Filters and sorts are the same here
$filtersorts = array(
'ID' => 'topups.ID',
'Type' => 'topups.Type',
'Value' => 'topups.Value',
'ValidFrom' => 'topups.ValidFrom',
'ValidTo' => 'topups.ValidTo'
'ID' => '@TP@topups.ID',
'Type' => '@TP@topups.Type',
'Value' => '@TP@topups.Value',
'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => '@TP@topups.ValidTo'
);
# Perform query
......@@ -105,7 +121,7 @@ function getWiSPUserTopups($params) {
SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM
topups
@TP@topups
WHERE
Depleted = 0
AND
......
<?php
# WiSP Users functions
# Copyright (C) 2007-2011, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
include_once("include/db.php");
......@@ -8,29 +24,29 @@ function getWiSPUsers($params) {
# Filters and sorts are the same here
$filtersorts = array(
'Username' => 'users.Username',
'Disabled' => 'users.Disabled',
'ID' => 'wisp_userdata.UserID',
'Firstname' => 'wisp_userdata.Firstname',
'Lastname' => 'wisp_userdata.Lastname',
'Email' => 'wisp_userdata.Email',
'Phone' => 'wisp_userdata.Phone'
'Username' => '@TP@users.Username',
'Disabled' => '@TP@users.Disabled',
'ID' => '@TP@wisp_userdata.UserID',
'Firstname' => '@TP@wisp_userdata.Firstname',
'Lastname' => '@TP@wisp_userdata.Lastname',
'Email' => '@TP@wisp_userdata.Email',
'Phone' => '@TP@wisp_userdata.Phone'
);
# Perform query
$res = DBSelectSearch("
SELECT
users.Username,
users.Disabled,
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Email,
wisp_userdata.Phone
@TP@users.Username,
@TP@users.Disabled,
@TP@wisp_userdata.UserID,
@TP@wisp_userdata.FirstName,
@TP@wisp_userdata.LastName,
@TP@wisp_userdata.Email,
@TP@wisp_userdata.Phone
FROM
users, wisp_userdata
@TP@users, @TP@wisp_userdata
WHERE
wisp_userdata.UserID = users.ID
@TP@wisp_userdata.UserID = @TP@users.ID
",$params[1],$filtersorts,$filtersorts
);
$sth = $res[0]; $numResults = $res[1];
......@@ -69,19 +85,20 @@ function getWiSPUser($params) {
# Query for userdata and username
$res = DBSelect("
SELECT
wisp_userdata.UserID,
wisp_userdata.FirstName,
wisp_userdata.LastName,
wisp_userdata.Phone,
wisp_userdata.Email,
wisp_userdata.LocationID,
users.Username
@TP@wisp_userdata.UserID,
@TP@wisp_userdata.FirstName,
@TP@wisp_userdata.LastName,
@TP@wisp_userdata.Phone,
@TP@wisp_userdata.Email,
@TP@wisp_userdata.LocationID,
@TP@users.Username,
@TP@users.Disabled
FROM
wisp_userdata, users
@TP@wisp_userdata, @TP@users
WHERE
wisp_userdata.UserID = ?
@TP@wisp_userdata.UserID = ?
AND
users.ID = wisp_userdata.UserID
@TP@users.ID = @TP@wisp_userdata.UserID
",array($params[0])
);
......@@ -97,6 +114,7 @@ function getWiSPUser($params) {
# Set userdata fields
$resultArray['ID'] = $row->userid;
$resultArray['Username'] = $row->username;
$resultArray['Disabled'] = $row->disabled;
if (isset($row->firstname)) {
$resultArray['Firstname'] = $row->firstname;
} else {
......@@ -128,10 +146,10 @@ function getWiSPUser($params) {
SELECT
Value
FROM
user_attributes
@TP@user_attributes
WHERE
Name = ?
AND user_attributes.UserID = ?
AND @TP@user_attributes.UserID = ?
",array('User-Password',$params[0])
);
......@@ -163,9 +181,9 @@ function getWiSPUserAttributes($params) {
SELECT
ID, Name, Operator, Value
FROM
user_attributes
@TP@user_attributes
WHERE
user_attributes.UserID = ?",
@TP@user_attributes.UserID = ?",
array($params[0])
);
......@@ -199,12 +217,12 @@ function getWiSPUserGroups($params) {
# Groups query
$res = DBSelect("
SELECT
groups.Name, groups.ID
@TP@groups.Name, @TP@groups.ID
FROM
users_to_groups, groups
@TP@users_to_groups, @TP@groups
WHERE
users_to_groups.GroupID = groups.ID
AND users_to_groups.UserID = ?",
@TP@users_to_groups.GroupID = @TP@groups.ID
AND @TP@users_to_groups.UserID = ?",
array($params[0])
);
......@@ -236,16 +254,16 @@ function removeWiSPUser($params) {
DBBegin();
# Delete user information
$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@wisp_userdata WHERE UserID = ?",array($params[0]));
# Delete user attribtues
if ($res !== FALSE) {
$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE UserID = ?",array($params[0]));
}
# Remove user from groups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users_to_groups WHERE UserID = ?",array($params[0]));
}
# Get list of topups and delete summaries
......@@ -253,12 +271,12 @@ function removeWiSPUser($params) {
$topupList = array();
$res = DBSelect("
SELECT
topups_summary.TopupID
@TP@topups_summary.TopupID
FROM
topups_summary, topups
@TP@topups_summary, topups
WHERE
topups_summary.TopupID = topups.ID
AND topups.UserID = ?",
@TP@topups_summary.TopupID = @TP@topups.ID
AND @TP@topups.UserID = ?",
array($params[0])
);
......@@ -276,7 +294,7 @@ function removeWiSPUser($params) {
if ($res !== FALSE) {
$res = DBDo("
DELETE FROM
topups_summary
@TP@topups_summary
WHERE
TopupID = ?",
array($id)
......@@ -288,12 +306,12 @@ function removeWiSPUser($params) {
# Remove topups
if ($res !== FALSE) {
$res = DBDo("DELETE FROM topups WHERE UserID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@topups WHERE UserID = ?",array($params[0]));
}
# Delete user
if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
$res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
}
# Return result
......@@ -319,14 +337,14 @@ function createWiSPUser($params) {
# If we adding single user
if (empty($params[0]['Number']) && !empty($params[0]['Username'])) {
# Insert username
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($params[0]['Username']));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($params[0]['Username'],$params[0]['Disabled']));
# Continue with others if successful
if ($res !== FALSE) {
$userID = DBLastInsertID();
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array($userID,
......@@ -338,24 +356,24 @@ function createWiSPUser($params) {
# Link users ID to make user a wisp user
if ($res !== FALSE) {
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",array($userID));
$res = DBDo("INSERT INTO @TP@wisp_userdata (UserID) VALUES (?)",array($userID));
}
# Add personal information
if ($res !== FALSE && isset($params[0]['Firstname'])) {
$res = DBDo("UPDATE wisp_userdata SET FirstName = ? WHERE UserID = ?",array($params[0]['Firstname'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET FirstName = ? WHERE UserID = ?",array($params[0]['Firstname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Lastname'])) {
$res = DBDo("UPDATE wisp_userdata SET LastName = ? WHERE UserID = ?",array($params[0]['Lastname'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET LastName = ? WHERE UserID = ?",array($params[0]['Lastname'],$userID));
}
if ($res !== FALSE && isset($params[0]['Phone'])) {
$res = DBDo("UPDATE wisp_userdata SET Phone = ? WHERE UserID = ?",array($params[0]['Phone'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET Phone = ? WHERE UserID = ?",array($params[0]['Phone'],$userID));
}
if ($res !== FALSE && isset($params[0]['Email'])) {
$res = DBDo("UPDATE wisp_userdata SET Email = ? WHERE UserID = ?",array($params[0]['Email'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET Email = ? WHERE UserID = ?",array($params[0]['Email'],$userID));
}
if ($res !== FALSE && !empty($params[0]['LocationID'])) {
$res = DBDo("UPDATE wisp_userdata SET LocationID = ? WHERE UserID = ?",array($params[0]['LocationID'],$userID));
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = ? WHERE UserID = ?",array($params[0]['LocationID'],$userID));
}
# Grab each attribute and add it's details to the database
......@@ -363,7 +381,11 @@ function createWiSPUser($params) {
foreach ($params[0]['Attributes'] as $attr) {
# We only want to add attributes with all values
if (isset($attr['Name']) && isset($attr['Operator']) && isset($attr['Value'])) {
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
......@@ -373,22 +395,31 @@ function createWiSPUser($params) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
......@@ -396,7 +427,7 @@ function createWiSPUser($params) {
# Add attribute
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
......@@ -422,7 +453,7 @@ function createWiSPUser($params) {
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($userID,$groupID));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($userID,$groupID));
}
}
......@@ -452,11 +483,11 @@ function createWiSPUser($params) {
# Check if username used
$res = DBSelect("
SELECT
users.Username
@TP@users.Username
FROM
users
@TP@users
WHERE
users.Username = ?
@TP@users.Username = ?
",array($thisUsername)
);
......@@ -478,10 +509,10 @@ function createWiSPUser($params) {
# Insert users from array into database
foreach ($wispUser as $username => $password) {
$res = DBDo("INSERT INTO users (Username) VALUES (?)",array($username));
$res = DBDo("INSERT INTO @TP@users (Username,Disabled) VALUES (?,?)",array($username,$params[0]['Disabled']));
if ($res !== FALSE) {
$id = DBLastInsertID();
$res = DBDo("INSERT INTO user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)",
$res = DBDo("INSERT INTO @TP@user_attributes (UserID,Name,Operator,Value) VALUES (?,?,?,?)",
array($id,'User-Password','==',$password)
);
......@@ -489,7 +520,12 @@ function createWiSPUser($params) {
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
if (isset($attr['Name']) && isset($attr['Operator']) && isset($attr['Value'])) {
# We only want to add attributes with all values
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
......@@ -499,22 +535,31 @@ function createWiSPUser($params) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
......@@ -522,7 +567,7 @@ function createWiSPUser($params) {
# Add attribute
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
......@@ -548,13 +593,13 @@ function createWiSPUser($params) {
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($id,$groupID));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($id,$groupID));
}
}
# Link to wisp users
if ($res !== FALSE) {
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)",
$res = DBDo("INSERT INTO @TP@wisp_userdata (UserID) VALUES (?)",
array($id)
);
}
......@@ -624,19 +669,18 @@ function updateWiSPUser($params) {
$res = TRUE;
# Perform query
if (!empty($params[0]['Username'])) {
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
}
$res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
# Change password
if ($res !== FALSE) {
$res = DBDo("UPDATE user_attributes SET Value = ? WHERE UserID = ? AND Name = ?",
$res = DBDo("UPDATE @TP@user_attributes SET Value = ? WHERE UserID = ? AND Name = ?",
array($params[0]['Password'],$params[0]['ID'],'User-Password'));
}
# If successful, continue
if ($res !== FALSE) {
$res = DBDo("
UPDATE
wisp_userdata
@TP@wisp_userdata
SET
FirstName = ?,
LastName = ?,
......@@ -653,7 +697,7 @@ function updateWiSPUser($params) {
}
# If successful, add location if any
if ($res !== FALSE && !empty($params[0]['LocationID'])) {
$res = DBDo("UPDATE wisp_userdata SET LocationID = ? WHERE UserID = ?",
$res = DBDo("UPDATE @TP@wisp_userdata SET LocationID = ? WHERE UserID = ?",
array($params[0]['LocationID'],$params[0]['ID'])
);
}
......@@ -663,7 +707,7 @@ function updateWiSPUser($params) {
foreach ($params[0]['RAttributes'] as $attr) {
if ($res !== FALSE) {
# Perform query
$res = DBDo("DELETE FROM user_attributes WHERE ID = ?",array($attr));
$res = DBDo("DELETE FROM @TP@user_attributes WHERE ID = ?",array($attr));
}
}
}
......@@ -675,7 +719,7 @@ function updateWiSPUser($params) {
# Perform query
$res = DBDo("
DELETE FROM
users_to_groups
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
......@@ -689,7 +733,12 @@ function updateWiSPUser($params) {
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
if (isset($attr['ID']) && isset($attr['Name']) && isset($attr['Operator']) && isset($attr['Value'])) {
# We only want to add attributes with all values
if (
isset($attr['Name']) && $attr['Name'] != "" &&
isset($attr['Operator']) && $attr['Operator'] != "" &&
isset($attr['Value']) && $attr['Value'] != ""
) {
# Default value without modifier
$attrValue = $attr['Value'];
......@@ -699,22 +748,31 @@ function updateWiSPUser($params) {
switch ($attr['Modifier']) {
case "Seconds":
$attrValue = $attr['Value'] / 60;
break;
case "Minutes":
$attrValue = $attr['Value'];
break;
case "Hours":
$attrValue = $attr['Value'] * 60;
break;
case "Days":
$attrValue = $attr['Value'] * 1440;
break;
case "Weeks":
$attrValue = $attr['Value'] * 10080;
break;
case "Months":
$attrValue = $attr['Value'] * 44640;
break;
case "MBytes":
$attrValue = $attr['Value'];
break;
case "GBytes":
$attrValue = $attr['Value'] * 1000;
break;
case "TBytes":
$attrValue = $attr['Value'] * 1000000;
break;
}
}
}
......@@ -725,7 +783,7 @@ function updateWiSPUser($params) {
if ($attr['ID'] < 0) {
$res = DBDo("
INSERT INTO
user_attributes (UserID,Name,Operator,Value)
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
......@@ -739,7 +797,7 @@ function updateWiSPUser($params) {
} else {
$res = DBDo("
UPDATE
user_attributes
@TP@user_attributes
SET
Name = ?,
Operator = ?,
......@@ -771,7 +829,7 @@ function updateWiSPUser($params) {
SELECT
ID
FROM
users_to_groups
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
......@@ -781,7 +839,7 @@ function updateWiSPUser($params) {
if (is_object($res)) {
if ($res->rowCount() == 0) {
$res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['ID'],$groupID));
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['ID'],$groupID));
} else {
$res = TRUE;
}
......
<?php
# JSON interface
# Copyright (C) 2007-2009, AllWorldIT
# Copyright (C) 2007-2015, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......