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 1559 additions and 938 deletions
body .x-panel {
margin-bottom:20px;
}
.icon-grid {
background-image:url(resources/extjs/icons/fam/grid.png) !important;
}
#button-grid .x-panel-body {
border:1px solid #99bbe8;
border-top:0 none;
}
.add {
background-image:url(resources/extjs/icons/fam/add.gif) !important;
}
.edit {
background-image:url(resources/extjs/icons/fam/plugin.gif) !important;
}
.option {
background-image:url(resources/extjs/icons/fam/cog.png) !important;
}
.remove {
background-image:url(resources/extjs/icons/fam/delete.gif) !important;
}
.save {
background-image:url(resources/extjs/icons/save.gif) !important;
}
.logs {
background-image:url(resources/extjs/images/find.png) !important;
}
.attributes {
background-image:url(resources/extjs/icons/fam/table_refresh.png) !important;
}
.groups {
background-image:url(resources/extjs/icons/fam/grid.png) !important;
}
<?php <?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"); include_once("include/db.php");
...@@ -8,7 +24,7 @@ function addAdminClientAttribute($params) { ...@@ -8,7 +24,7 @@ function addAdminClientAttribute($params) {
# Perform query # Perform query
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
client_attributes (ClientID,Name,Operator,Value,Disabled) @TP@client_attributes (ClientID,Name,Operator,Value,Disabled)
VALUES VALUES
(?,?,?,?,?)", (?,?,?,?,?)",
array( $params[0]['ClientID'], array( $params[0]['ClientID'],
...@@ -19,7 +35,7 @@ function addAdminClientAttribute($params) { ...@@ -19,7 +35,7 @@ function addAdminClientAttribute($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -30,10 +46,10 @@ function addAdminClientAttribute($params) { ...@@ -30,10 +46,10 @@ function addAdminClientAttribute($params) {
function removeAdminClientAttribute($params) { function removeAdminClientAttribute($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -44,7 +60,7 @@ function removeAdminClientAttribute($params) { ...@@ -44,7 +60,7 @@ function removeAdminClientAttribute($params) {
function updateAdminClientAttribute($params) { function updateAdminClientAttribute($params) {
# Perform query # 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'], array($params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
...@@ -53,7 +69,7 @@ function updateAdminClientAttribute($params) { ...@@ -53,7 +69,7 @@ function updateAdminClientAttribute($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -64,7 +80,7 @@ function updateAdminClientAttribute($params) { ...@@ -64,7 +80,7 @@ function updateAdminClientAttribute($params) {
function getAdminClientAttribute($params) { function getAdminClientAttribute($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -90,11 +106,11 @@ function getAdminClientAttributes($params) { ...@@ -90,11 +106,11 @@ function getAdminClientAttributes($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'client_attributes.ID', 'ID' => '@TP@client_attributes.ID',
'Name' => 'client_attributes.Name', 'Name' => '@TP@client_attributes.Name',
'Operator' => 'client_attributes.Operator', 'Operator' => '@TP@client_attributes.Operator',
'Value' => 'client_attributes.Value', 'Value' => '@TP@client_attributes.Value',
'Disabled' => 'client_attributes.Disabled' 'Disabled' => '@TP@client_attributes.Disabled'
); );
# Perform query # Perform query
...@@ -102,7 +118,7 @@ function getAdminClientAttributes($params) { ...@@ -102,7 +118,7 @@ function getAdminClientAttributes($params) {
SELECT SELECT
ID, Name, Operator, Value, Disabled ID, Name, Operator, Value, Disabled
FROM FROM
client_attributes @TP@client_attributes
WHERE WHERE
ClientID = ".DBQuote($params[0])." ClientID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
......
<?php <?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"); include_once("include/db.php");
...@@ -7,10 +23,10 @@ include_once("include/db.php"); ...@@ -7,10 +23,10 @@ include_once("include/db.php");
function addAdminClientRealm($params) { function addAdminClientRealm($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -21,10 +37,10 @@ function addAdminClientRealm($params) { ...@@ -21,10 +37,10 @@ function addAdminClientRealm($params) {
function removeAdminClientRealm($params) { function removeAdminClientRealm($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -36,19 +52,19 @@ function getAdminClientRealms($params) { ...@@ -36,19 +52,19 @@ function getAdminClientRealms($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'clients_to_realms.ID', 'ID' => '@TP@clients_to_realms.ID',
'Name' => 'realms.Name' 'Name' => '@TP@realms.Name'
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
clients_to_realms.ID, realms.Name @TP@clients_to_realms.ID, @TP@realms.Name
FROM FROM
clients_to_realms, realms @TP@clients_to_realms, @TP@realms
WHERE WHERE
clients_to_realms.RealmID = realms.ID @TP@clients_to_realms.RealmID = @TP@realms.ID
AND clients_to_realms.ClientID = ".DBQuote($params[0])." AND @TP@clients_to_realms.ClientID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
...@@ -63,7 +79,7 @@ function getAdminClientRealms($params) { ...@@ -63,7 +79,7 @@ function getAdminClientRealms($params) {
$item = array(); $item = array();
$item['ID'] = $row->id; $item['ID'] = $row->id;
$item['Name'] = $row->name; $item['Name'] = htmlspecialchars($row->name);
# Push this row onto array # Push this row onto array
array_push($resultArray,$item); array_push($resultArray,$item);
......
<?php <?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"); include_once("include/db.php");
...@@ -8,13 +24,13 @@ function getAdminClients($params) { ...@@ -8,13 +24,13 @@ function getAdminClients($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'clients.ID', 'ID' => '@TP@clients.ID',
'Name' => 'clients.Name', 'Name' => '@TP@clients.Name',
'AccessList' => 'clients.AccessList' 'AccessList' => '@TP@clients.AccessList'
); );
# Perform query # 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]; $sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data # If STH is blank, return the error back to whoever requested the data
...@@ -43,7 +59,7 @@ function getAdminClients($params) { ...@@ -43,7 +59,7 @@ function getAdminClients($params) {
function getAdminClient($params) { function getAdminClient($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -69,25 +85,24 @@ function removeAdminClient($params) { ...@@ -69,25 +85,24 @@ function removeAdminClient($params) {
DBBegin(); DBBegin();
# Perform query # 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 # Remove client from realms
if ($res !== FALSE) { 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 # Perform next query if successful
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("DELETE FROM clients WHERE ID = ?",array($params[0])); $res = DBDo("DELETE FROM @TP@clients WHERE ID = ?",array($params[0]));
} }
# Commit and return if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Else rollback database
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
...@@ -97,10 +112,10 @@ function removeAdminClient($params) { ...@@ -97,10 +112,10 @@ function removeAdminClient($params) {
function createAdminClient($params) { function createAdminClient($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -111,11 +126,11 @@ function createAdminClient($params) { ...@@ -111,11 +126,11 @@ function createAdminClient($params) {
function updateAdminClient($params) { function updateAdminClient($params) {
# Perform query # 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'])); array($params[0]['Name'],$params[0]['AccessList'],$params[0]['ID']));
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
......
<?php <?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/db.php");
include_once("include/util.php");
# Add group attribute # Add group attribute
function addAdminGroupAttribute($params) { function addAdminGroupAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
group_attributes (GroupID,Name,Operator,Value,Disabled) @TP@group_attributes (GroupID,Name,Operator,Value,Disabled)
VALUES VALUES
(?,?,?,?,?)", (?,?,?,?,?)",
array( $params[0]['GroupID'], array( $params[0]['GroupID'],
$params[0]['Name'], $params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
$params[0]['Disabled']) $disabled)
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -28,10 +51,10 @@ function addAdminGroupAttribute($params) { ...@@ -28,10 +51,10 @@ function addAdminGroupAttribute($params) {
# Remove group attribute # Remove group attribute
function removeAdminGroupAttribute($params) { 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -41,16 +64,22 @@ function removeAdminGroupAttribute($params) { ...@@ -41,16 +64,22 @@ function removeAdminGroupAttribute($params) {
# Edit group attribute # Edit group attribute
function updateAdminGroupAttribute($params) { 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'], array($params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
$params[0]['Disabled'], $disabled,
$params[0]['ID']) $params[0]['ID'])
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -60,7 +89,7 @@ function updateAdminGroupAttribute($params) { ...@@ -60,7 +89,7 @@ function updateAdminGroupAttribute($params) {
# Return specific attribute row # Return specific attribute row
function getAdminGroupAttribute($params) { 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)) { if (!is_object($res)) {
return $res; return $res;
} }
...@@ -83,11 +112,11 @@ function getAdminGroupAttributes($params) { ...@@ -83,11 +112,11 @@ function getAdminGroupAttributes($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'group_attributes.ID', 'ID' => '@TP@group_attributes.ID',
'Name' => 'group_attributes.Name', 'Name' => '@TP@group_attributes.Name',
'Operator' => 'group_attributes.Operator', 'Operator' => '@TP@group_attributes.Operator',
'Value' => 'group_attributes.Value', 'Value' => '@TP@group_attributes.Value',
'Disabled' => 'group_attributes.Disabled' 'Disabled' => '@TP@group_attributes.Disabled'
); );
# Fetch attributes # Fetch attributes
...@@ -95,7 +124,7 @@ function getAdminGroupAttributes($params) { ...@@ -95,7 +124,7 @@ function getAdminGroupAttributes($params) {
SELECT SELECT
ID, Name, Operator, Value, Disabled ID, Name, Operator, Value, Disabled
FROM FROM
group_attributes @TP@group_attributes
WHERE WHERE
GroupID = ".DBQuote($params[0])." GroupID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
......
<?php <?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"); include_once("include/db.php");
# Remove group member # Remove group member
function removeAdminGroupMember($params) { 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -20,21 +36,21 @@ function getAdminGroupMembers($params) { ...@@ -20,21 +36,21 @@ function getAdminGroupMembers($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'users_to_groups.ID', 'ID' => '@TP@users_to_groups.ID',
'Username' => 'group_attributes.Username', 'Username' => '@TP@group_attributes.Username',
'Disabled' => 'group_attributes.Disabled' 'Disabled' => '@TP@group_attributes.Disabled'
); );
# Fetch members # Fetch members
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
users_to_groups.ID, users.Username, users.Disabled @TP@users_to_groups.ID, @TP@users.Username, @TP@users.Disabled
FROM FROM
users_to_groups, users @TP@users_to_groups, @TP@users
WHERE WHERE
users.ID = users_to_groups.UserID @TP@users.ID = @TP@users_to_groups.UserID
AND AND
users_to_groups.GroupID = ".DBQuote($params[0])." @TP@users_to_groups.GroupID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
......
<?php <?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"); include_once("include/db.php");
...@@ -8,15 +24,15 @@ function getAdminGroups($params) { ...@@ -8,15 +24,15 @@ function getAdminGroups($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'groups.ID', 'ID' => '@TP@groups.ID',
'Name' => 'groups.Name', 'Name' => '@TP@groups.Name',
'Priority' => 'groups.Priority', 'Priority' => '@TP@groups.Priority',
'Disabled' => 'groups.Disabled', 'Disabled' => '@TP@groups.Disabled',
'Comment' => 'groups.Comment' 'Comment' => '@TP@groups.Comment'
); );
# Perform query # 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]; $sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data # If STH is blank, return the error back to whoever requested the data
...@@ -47,7 +63,7 @@ function getAdminGroups($params) { ...@@ -47,7 +63,7 @@ function getAdminGroups($params) {
function getAdminGroup($params) { function getAdminGroup($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -75,25 +91,24 @@ function removeAdminGroup($params) { ...@@ -75,25 +91,24 @@ function removeAdminGroup($params) {
DBBegin(); DBBegin();
# Unlink users from group # 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 # Delete group attribtues
if ($res !== FALSE) { 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 # Delete group
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("DELETE FROM groups WHERE ID = ?",array($params[0])); $res = DBDo("DELETE FROM @TP@groups WHERE ID = ?",array($params[0]));
} }
# Commit and return if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Else rollback database
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
...@@ -103,10 +118,10 @@ function removeAdminGroup($params) { ...@@ -103,10 +118,10 @@ function removeAdminGroup($params) {
function createAdminGroup($params) { function createAdminGroup($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -117,10 +132,10 @@ function createAdminGroup($params) { ...@@ -117,10 +132,10 @@ function createAdminGroup($params) {
function updateAdminGroup($params) { function updateAdminGroup($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
......
<?php <?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"); include_once("include/db.php");
...@@ -8,7 +24,7 @@ function addAdminRealmAttribute($params) { ...@@ -8,7 +24,7 @@ function addAdminRealmAttribute($params) {
# Perform query # Perform query
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
realm_attributes (RealmID,Name,Operator,Value,Disabled) @TP@realm_attributes (RealmID,Name,Operator,Value,Disabled)
VALUES VALUES
(?,?,?,?,?)", (?,?,?,?,?)",
array( $params[0]['RealmID'], array( $params[0]['RealmID'],
...@@ -19,7 +35,7 @@ function addAdminRealmAttribute($params) { ...@@ -19,7 +35,7 @@ function addAdminRealmAttribute($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -30,10 +46,10 @@ function addAdminRealmAttribute($params) { ...@@ -30,10 +46,10 @@ function addAdminRealmAttribute($params) {
function removeAdminRealmAttribute($params) { function removeAdminRealmAttribute($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -44,7 +60,7 @@ function removeAdminRealmAttribute($params) { ...@@ -44,7 +60,7 @@ function removeAdminRealmAttribute($params) {
function updateAdminRealmAttribute($params) { function updateAdminRealmAttribute($params) {
# Perform query # 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'], array($params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
...@@ -53,7 +69,7 @@ function updateAdminRealmAttribute($params) { ...@@ -53,7 +69,7 @@ function updateAdminRealmAttribute($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -64,7 +80,7 @@ function updateAdminRealmAttribute($params) { ...@@ -64,7 +80,7 @@ function updateAdminRealmAttribute($params) {
function getAdminRealmAttribute($params) { function getAdminRealmAttribute($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -90,11 +106,11 @@ function getAdminRealmAttributes($params) { ...@@ -90,11 +106,11 @@ function getAdminRealmAttributes($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'realm_attributes.ID', 'ID' => '@TP@realm_attributes.ID',
'Name' => 'realm_attributes.Name', 'Name' => '@TP@realm_attributes.Name',
'Operator' => 'realm_attributes.Operator', 'Operator' => '@TP@realm_attributes.Operator',
'Value' => 'realm_attributes.Value', 'Value' => '@TP@realm_attributes.Value',
'Disabled' => 'realm_attributes.Disabled' 'Disabled' => '@TP@realm_attributes.Disabled'
); );
# Perform query # Perform query
...@@ -102,7 +118,7 @@ function getAdminRealmAttributes($params) { ...@@ -102,7 +118,7 @@ function getAdminRealmAttributes($params) {
SELECT SELECT
ID, Name, Operator, Value, Disabled ID, Name, Operator, Value, Disabled
FROM FROM
realm_attributes @TP@realm_attributes
WHERE WHERE
RealmID = ".DBQuote($params[0])." RealmID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
......
<?php <?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"); include_once("include/db.php");
# Remove realm member # Remove realm member
function removeAdminRealmMember($params) { 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -20,20 +36,20 @@ function getAdminRealmMembers($params) { ...@@ -20,20 +36,20 @@ function getAdminRealmMembers($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'clients_to_realms.ID', 'ID' => '@TP@clients_to_realms.ID',
'Name' => 'realm_attributes.Name' 'Name' => '@TP@realm_attributes.Name'
); );
# Fetch members # Fetch members
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
clients_to_realms.ID, clients.Name @TP@clients_to_realms.ID, @TP@clients.Name
FROM FROM
clients_to_realms, clients @TP@clients_to_realms, @TP@clients
WHERE WHERE
clients.ID = clients_to_realms.ClientID @TP@clients.ID = @TP@clients_to_realms.ClientID
AND AND
clients_to_realms.RealmID = ".DBQuote($params[0])." @TP@clients_to_realms.RealmID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
......
<?php <?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"); include_once("include/db.php");
...@@ -8,13 +24,13 @@ function getAdminRealms($params) { ...@@ -8,13 +24,13 @@ function getAdminRealms($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'realms.ID', 'ID' => '@TP@realms.ID',
'Name' => 'realms.Name', 'Name' => '@TP@realms.Name',
'Disabled' => 'realms.Disabled' 'Disabled' => '@TP@realms.Disabled'
); );
# Perform query # 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]; $sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data # If STH is blank, return the error back to whoever requested the data
...@@ -43,7 +59,7 @@ function getAdminRealms($params) { ...@@ -43,7 +59,7 @@ function getAdminRealms($params) {
function getAdminRealm($params) { function getAdminRealm($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -55,7 +71,7 @@ function getAdminRealm($params) { ...@@ -55,7 +71,7 @@ function getAdminRealm($params) {
$row = $res->fetchObject(); $row = $res->fetchObject();
$resultArray['ID'] = $row->id; $resultArray['ID'] = $row->id;
$resultArray['Name'] = htmlspecialchars($row->name); $resultArray['Name'] = $row->name;
$resultArray['Disabled'] = $row->disabled; $resultArray['Disabled'] = $row->disabled;
# Return results # Return results
...@@ -69,20 +85,19 @@ function removeAdminRealm($params) { ...@@ -69,20 +85,19 @@ function removeAdminRealm($params) {
DBBegin(); DBBegin();
# Perform query # 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 # Perform next query if successful
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("DELETE FROM realms WHERE ID = ?",array($params[0])); $res = DBDo("DELETE FROM @TP@realms WHERE ID = ?",array($params[0]));
} }
# Commit and return if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Else rollback database
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
...@@ -92,10 +107,10 @@ function removeAdminRealm($params) { ...@@ -92,10 +107,10 @@ function removeAdminRealm($params) {
function createAdminRealm($params) { function createAdminRealm($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -106,10 +121,10 @@ function createAdminRealm($params) { ...@@ -106,10 +121,10 @@ function createAdminRealm($params) {
function updateAdminRealm($params) { function updateAdminRealm($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
......
<?php <?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/db.php");
include_once("include/util.php");
# Add user attribute # Add user attribute
function addAdminUserAttribute($params) { function addAdminUserAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
# Perform query # Perform query
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
user_attributes (UserID,Name,Operator,Value,Disabled) @TP@user_attributes (UserID,Name,Operator,Value,Disabled)
VALUES VALUES
(?,?,?,?,?)", (?,?,?,?,?)",
array( $params[0]['UserID'], array( $params[0]['UserID'],
$params[0]['Name'], $params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
$params[0]['Disabled']) $disabled)
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -30,10 +53,10 @@ function addAdminUserAttribute($params) { ...@@ -30,10 +53,10 @@ function addAdminUserAttribute($params) {
function removeAdminUserAttribute($params) { function removeAdminUserAttribute($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -43,17 +66,23 @@ function removeAdminUserAttribute($params) { ...@@ -43,17 +66,23 @@ function removeAdminUserAttribute($params) {
# Edit attribute # Edit attribute
function updateAdminUserAttribute($params) { function updateAdminUserAttribute($params) {
# Check Disabled param
$disabled = isBoolean($params[0]['Disabled']);
if ($disabled < 0) {
return NULL;
}
# Perform query # 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'], array($params[0]['Name'],
$params[0]['Operator'], $params[0]['Operator'],
$params[0]['Value'], $params[0]['Value'],
$params[0]['Disabled'], $disabled,
$params[0]['ID']) $params[0]['ID'])
); );
# Return result # Return error
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -64,7 +93,7 @@ function updateAdminUserAttribute($params) { ...@@ -64,7 +93,7 @@ function updateAdminUserAttribute($params) {
function getAdminUserAttribute($params) { function getAdminUserAttribute($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -90,11 +119,11 @@ function getAdminUserAttributes($params) { ...@@ -90,11 +119,11 @@ function getAdminUserAttributes($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'user_attributes.ID', 'ID' => '@TP@user_attributes.ID',
'Name' => 'user_attributes.Name', 'Name' => '@TP@user_attributes.Name',
'Operator' => 'user_attributes.Operator', 'Operator' => '@TP@user_attributes.Operator',
'Value' => 'user_attributes.Value', 'Value' => '@TP@user_attributes.Value',
'Disabled' => 'user_attributes.Disabled' 'Disabled' => '@TP@user_attributes.Disabled'
); );
# Perform query # Perform query
...@@ -102,7 +131,7 @@ function getAdminUserAttributes($params) { ...@@ -102,7 +131,7 @@ function getAdminUserAttributes($params) {
SELECT SELECT
ID, Name, Operator, Value, Disabled ID, Name, Operator, Value, Disabled
FROM FROM
user_attributes @TP@user_attributes
WHERE WHERE
UserID = ".DBQuote($params[0])." UserID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
......
<?php <?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"); include_once("include/db.php");
...@@ -7,10 +23,10 @@ include_once("include/db.php"); ...@@ -7,10 +23,10 @@ include_once("include/db.php");
function addAdminUserGroup($params) { function addAdminUserGroup($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -21,10 +37,10 @@ function addAdminUserGroup($params) { ...@@ -21,10 +37,10 @@ function addAdminUserGroup($params) {
function removeAdminUserGroup($params) { function removeAdminUserGroup($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -36,19 +52,19 @@ function getAdminUserGroups($params) { ...@@ -36,19 +52,19 @@ function getAdminUserGroups($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'users_to_groups.ID', 'ID' => '@TP@users_to_groups.ID',
'Name' => 'groups.Name' 'Name' => '@TP@groups.Name'
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
users_to_groups.ID, groups.Name @TP@users_to_groups.ID, @TP@groups.Name
FROM FROM
users_to_groups, groups @TP@users_to_groups, @TP@groups
WHERE WHERE
users_to_groups.GroupID = groups.ID @TP@users_to_groups.GroupID = @TP@groups.ID
AND users_to_groups.UserID = ".DBQuote($params[0])." AND @TP@users_to_groups.UserID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
......
<?php <?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"); include_once("include/db.php");
...@@ -6,14 +22,18 @@ include_once("include/db.php"); ...@@ -6,14 +22,18 @@ include_once("include/db.php");
# Return user logs summary # Return user logs summary
function getAdminUserLogsSummary($params) { function getAdminUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
user_attributes.Name, @TP@group_attributes.Name,
user_attributes.Value @TP@group_attributes.Value
FROM FROM
user_attributes @TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE 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']) array($params[0]['ID'])
); );
...@@ -22,10 +42,7 @@ function getAdminUserLogsSummary($params) { ...@@ -22,10 +42,7 @@ function getAdminUserLogsSummary($params) {
return $res; return $res;
} }
# Array of results # Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$resultArray = array();
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$trafficCap = -1; $trafficCap = -1;
$uptimeCap = -1; $uptimeCap = -1;
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
...@@ -37,31 +54,65 @@ function getAdminUserLogsSummary($params) { ...@@ -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['trafficCap'] = $trafficCap;
$resultArray['uptimeCap'] = $uptimeCap; $resultArray['uptimeCap'] = $uptimeCap;
# Dates we want to use to search search # Dates we want to use to search search
$dateFrom = new DateTime($params[0]['From']); $periodKey = new DateTime($params[0]['PeriodKey']."-01");
$dateTo = new DateTime($params[0]['To']);
# Return if error
if (!is_object($periodKey)) {
return $periodKey;
}
# Fetch user uptime and traffic summary # Fetch user uptime and traffic summary
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
topups_summary.Balance, @TP@topups_summary.Balance,
topups.Type, @TP@topups.ID,
topups.Value @TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM FROM
topups_summary, @TP@topups_summary,
topups @TP@topups
WHERE WHERE
topups_summary.TopupID = topups.ID @TP@topups_summary.TopupID = @TP@topups.ID
AND topups.UserID = ? AND @TP@topups.UserID = ?
AND topups_summary.PeriodKey = ? AND @TP@topups_summary.PeriodKey = ?
AND topups.Depleted = 0 AND @TP@topups_summary.Depleted = 0
ORDER BY ORDER BY
topups.Timestamp", @TP@topups.Timestamp ASC",
array($params[0]['ID'],$dateFrom->format('Y-m')) array($params[0]['ID'],$periodKey->format('Y-m'))
); );
# Return if error # Return if error
...@@ -74,26 +125,30 @@ function getAdminUserLogsSummary($params) { ...@@ -74,26 +125,30 @@ function getAdminUserLogsSummary($params) {
$i = 0; $i = 0;
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
$topups[$i] = array(); $topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type; $topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->balance; $topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['OriginalLimit'] = $row->value; $topups[$i]['Limit'] = $row->value;
$i++; $i++;
} }
# Fetch user uptime and traffic topups # Fetch user uptime and traffic topups
$periodKeyEnd = new DateTime($periodKey->format('Y-m-d'));
$periodKeyEnd->modify("+1 month");
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
Value, Type ID, Value, Type, ValidTo
FROM FROM
topups @TP@topups
WHERE WHERE
topups.UserID = ? UserID = ?
AND topups.ValidFrom = ? AND ValidFrom = ?
AND topups.ValidTo >= ? AND ValidTo >= ?
AND topups.Depleted = 0 AND Depleted = 0
ORDER BY ORDER BY
topups.Timestamp", Timestamp ASC",
array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d')) array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
); );
# Return if error # Return if error
...@@ -104,6 +159,8 @@ function getAdminUserLogsSummary($params) { ...@@ -104,6 +159,8 @@ function getAdminUserLogsSummary($params) {
# Store normal topups # Store normal topups
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
$topups[$i] = array(); $topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type; $topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value; $topups[$i]['Limit'] = $row->value;
$i++; $i++;
...@@ -111,18 +168,18 @@ function getAdminUserLogsSummary($params) { ...@@ -111,18 +168,18 @@ function getAdminUserLogsSummary($params) {
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
accounting.AcctSessionTime, SUM(@TP@accounting.AcctSessionTime) / 60 AS TotalSessionTime,
accounting.AcctInputOctets, SUM(@TP@accounting.AcctInputOctets) / 1024 / 1024 +
accounting.AcctInputGigawords, SUM(@TP@accounting.AcctInputGigawords) * 4096 +
accounting.AcctOutputOctets, SUM(@TP@accounting.AcctOutputOctets) / 1024 / 1024 +
accounting.AcctOutputGigawords SUM(@TP@accounting.AcctOutputGigawords) * 4096 AS TotalTraffic
FROM FROM
accounting, users @TP@accounting, @TP@users
WHERE WHERE
users.ID = ? @TP@users.ID = ?
AND EventTimestamp >= ? AND @TP@accounting.PeriodKey = ?
AND accounting.Username = users.Username", AND @TP@accounting.Username = @TP@users.Username",
array($params[0]['ID'],$dateFrom->format('Y-m-d')) array($params[0]['ID'],$periodKey->format('Y-m'))
); );
if (!is_object($res)) { if (!is_object($res)) {
...@@ -130,169 +187,178 @@ function getAdminUserLogsSummary($params) { ...@@ -130,169 +187,178 @@ function getAdminUserLogsSummary($params) {
} }
# Set total traffic and uptime used # Set total traffic and uptime used
$totalTraffic = 0; $row = $res->fetchObject();
$totalUptime = 0;
while ($row = $res->fetchObject()) {
# Traffic in # Add usage to our return array
$inputDataItem = 0; $resultArray['trafficUsage'] = 0;
$resultArray['uptimeUsage'] = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$inputDataItem += ($row->acctinputoctets / 1024) / 1024; $resultArray['trafficUsage'] += $row->totaltraffic;
} }
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) { if (isset($row->totalsessiontime) && $row->totalsessiontime > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096); $resultArray['uptimeUsage'] += $row->totalsessiontime;
}
$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);
} }
# Set excess traffic usage # Excess usage
$excessTraffic = 0; $excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) { if ($trafficCap == -1) {
$excessTraffic += $totalTraffic - $trafficCap; $excessTraffic = $resultArray['trafficUsage'];
} else { } else {
$excessTraffic += $totalTraffic; $excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
} }
# Set excess uptime usage
$excessUptime = 0; $excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) { if ($uptimeCap == -1) {
$excessUptime += $totalUptime - $uptimeCap; $excessUptime = $resultArray['uptimeUsage'];
} else { } else {
$excessUptime += $totalUptime; $excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
} }
$currentTrafficTopup = array(); # Loop through topups and add to return array
$topupTrafficRemaining = 0; $resultArray['trafficTopups'] = 0;
# Loop through traffic topups and check for current topup, total topups not being used $resultArray['uptimeTopups'] = 0;
if (is_string($trafficCap) || $trafficCap != 0) { $resultArray['TotalTrafficTopups'] = 0;
$i = 0; $resultArray['TotalUptimeTopups'] = 0;
# User is using traffic from topups # Traffic and uptime topups
if ($excessTraffic > 0) { $resultArray['AllTrafficTopups'] = array();
foreach ($topups as $topupItem) { $resultArray['AllUptimeTopups'] = array();
if ($topupItem['Type'] == 1) { $t = 0; $u = 0;
if ($excessTraffic <= 0) { foreach ($topups as $topupItem) {
$topupTrafficRemaining += $topupItem['Limit']; if ($topupItem['Type'] == 1) {
next($topupItem); # Topup not currently in use
} elseif ($excessTraffic >= $topupItem['Limit']) { if ($excessTraffic <= 0) {
$excessTraffic -= $topupItem['Limit'];
} else { # Add stats to topup array
if (isset($topupItem['OriginalLimit'])) { $resultArray['AllTrafficTopups'][$t] = array();
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; $resultArray['AllTrafficTopups'][$t]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
} else { $resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$currentTrafficTopup['Cap'] = $topupItem['Limit']; $resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
} $resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$currentTrafficTopup['Used'] = $excessTraffic; $t++;
$excessTraffic -= $topupItem['Limit'];
} # Set total available topups
} $resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
} $resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# User has not used traffic topups yet
} else { # Topup currently in use
foreach ($topups as $topupItem) { } elseif (!isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['Limit']) {
if ($topupItem['Type'] == 1) {
if ($i == 0) { # Add stats to topup array
if (isset($topupItem['OriginalLimit'])) { $resultArray['AllTrafficTopups'][$t] = array();
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; $resultArray['AllTrafficTopups'][$t]['Used'] = $excessTraffic;
} else { $resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$currentTrafficTopup['Cap'] = $topupItem['Limit']; $resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
} $resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$i = 1; $t++;
$currentTrafficTopup['Used'] = 0;
} else { # Set total available topups
$topupTrafficRemaining += $topupItem['Limit']; $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'];
} }
} }
} if ($topupItem['Type'] == 2) {
# Topup not currently in use
$currentUptimeTopup = array(); if ($excessUptime <= 0) {
$topupUptimeRemaining = 0;
# Loop through uptime topups and check for current topup, total topups not being used # Add stats to topup array
if (is_string($uptimeCap) || $uptimeCap != 0) { $resultArray['AllUptimeTopups'][$u] = array();
$i = 0; $resultArray['AllUptimeTopups'][$u]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
# User is using uptime from topups $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
if ($excessUptime > 0) { $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
foreach ($topups as $topupItem) { $resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
if ($topupItem['Type'] == 2) { $u++;
if ($excessUptime <= 0) {
$topupUptimeRemaining += $topupItem['Limit']; # Set total available topups
next($topupItem); $resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
} elseif ($excessUptime >= $topupItem['Limit']) { $resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
$excessUptime -= $topupItem['Limit'];
} else { # Topup currently in use
if (isset($topupItem['OriginalLimit'])) { } elseif (!isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['Limit']) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else { # Add stats to topup array
$currentUptimeTopup['Cap'] = $topupItem['Limit']; $resultArray['AllUptimeTopups'][$u] = array();
} $resultArray['AllUptimeTopups'][$u]['Used'] = $excessTraffic;
$currentUptimeTopup['Used'] = $excessUptime; $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$excessUptime -= $topupItem['Limit']; $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
} $resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
} $u++;
}
# User has not used uptime topups yet # Set total available topups
} else { $resultArray['uptimeTopups'] += $topupItem['Limit'];
foreach ($topups as $topupItem) { $resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
if ($topupItem['Type'] == 2) {
if ($i == 0) { # If we hit this topup then all the rest of them are available
if (isset($topupItem['OriginalLimit'])) { $excessUptime = 0;
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; } elseif (isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['CurrentLimit']) {
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit']; # Add stats to topup array
} $resultArray['AllUptimeTopups'][$u] = array();
$i = 1; $resultArray['AllUptimeTopups'][$u]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$currentUptimeTopup['Used'] = 0; $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
} else { $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$topupUptimeRemaining += $topupItem['Limit']; $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 results
return array($resultArray, 1); return array($resultArray, 1);
} }
...@@ -302,45 +368,45 @@ function getAdminUserLogs($params) { ...@@ -302,45 +368,45 @@ function getAdminUserLogs($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'accounting.ID', 'ID' => '@TP@accounting.ID',
'EventTimestamp' => 'accounting.EventTimestamp', 'EventTimestamp' => '@TP@accounting.EventTimestamp',
'AcctStatusType' => 'accounting.AcctStatusType', 'AcctStatusType' => '@TP@accounting.AcctStatusType',
'ServiceType' => 'accounting.ServiceType', 'ServiceType' => '@TP@accounting.ServiceType',
'FramedProtocol' => 'accounting.FramedProtocol', 'FramedProtocol' => '@TP@accounting.FramedProtocol',
'NASPortType' => 'accounting.NASPortType', 'NASPortType' => '@TP@accounting.NASPortType',
'NASPortID' => 'accounting.NASPortID', 'NASPortID' => '@TP@accounting.NASPortID',
'CallingStationID' => 'accounting.CallingStationID', 'CallingStationID' => '@TP@accounting.CallingStationID',
'CalledStationID' => 'accounting.CalledStationID', 'CalledStationID' => '@TP@accounting.CalledStationID',
'AcctSessionID' => 'accounting.AcctSessionID', 'AcctSessionID' => '@TP@accounting.AcctSessionID',
'FramedIPAddress' => 'accounting.FramedIPAddress', 'FramedIPAddress' => '@TP@accounting.FramedIPAddress',
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
accounting.ID, @TP@accounting.ID,
accounting.EventTimestamp, @TP@accounting.EventTimestamp,
accounting.AcctStatusType, @TP@accounting.AcctStatusType,
accounting.ServiceType, @TP@accounting.ServiceType,
accounting.FramedProtocol, @TP@accounting.FramedProtocol,
accounting.NASPortType, @TP@accounting.NASPortType,
accounting.NASPortID, @TP@accounting.NASPortID,
accounting.CallingStationID, @TP@accounting.CallingStationID,
accounting.CalledStationID, @TP@accounting.CalledStationID,
accounting.AcctSessionID, @TP@accounting.AcctSessionID,
accounting.FramedIPAddress, @TP@accounting.FramedIPAddress,
accounting.AcctInputOctets, @TP@accounting.AcctInputOctets / 1024 / 1024 +
accounting.AcctInputGigawords, @TP@accounting.AcctInputGigawords * 4096 AS AcctInput,
accounting.AcctOutputOctets, @TP@accounting.AcctOutputOctets / 1024 / 1024 +
accounting.AcctOutputGigawords, @TP@accounting.AcctOutputGigawords * 4096 AS AcctOutput,
accounting.AcctTerminateCause, @TP@accounting.AcctTerminateCause,
accounting.AcctSessionTime @TP@accounting.AcctSessionTime / 60 AS AcctSessionTime
FROM FROM
accounting, users @TP@accounting, @TP@users
WHERE WHERE
users.Username = accounting.Username @TP@users.Username = @TP@accounting.Username
AND AND
users.ID = ".DBQuote($params[0])." @TP@users.ID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
...@@ -354,38 +420,27 @@ function getAdminUserLogs($params) { ...@@ -354,38 +420,27 @@ function getAdminUserLogs($params) {
while ($row = $sth->fetchObject()) { while ($row = $sth->fetchObject()) {
# Input # Input
$acctInputMbyte = 0; $acctInput = 0;
if (isset($row->acctinput) && $row->acctinput > 0) {
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { $acctInput += $row->acctinput;
$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
} }
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$acctInputMbyte += ($row->acctinputgigawords * 4096);
}
# Output # Output
$acctOutputMbyte = 0; $acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) { $acctOutput += $row->acctoutput;
$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
} }
# Uptime # Uptime
$acctSessionTime = 0; $acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += ($row->acctsessiontime / 60); $acctSessionTime += $row->acctsessiontime;
} }
ceil($acctSessionTime);
# Build array for this row # Build array for this row
$item = array(); $item = array();
$item['ID'] = $row->id; $item['ID'] = $row->id;
# Convert to ISO format # Convert to ISO format
$date = new DateTime($row->eventtimestamp); $date = new DateTime($row->eventtimestamp);
$value = $date->format("Y-m-d H:i:s"); $value = $date->format("Y-m-d H:i:s");
$item['EventTimestamp'] = $value; $item['EventTimestamp'] = $value;
...@@ -398,10 +453,10 @@ function getAdminUserLogs($params) { ...@@ -398,10 +453,10 @@ function getAdminUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid; $item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid; $item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress; $item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte; $item['AcctInput'] = $acctInput;
$item['AcctOutputMbyte'] = $acctOutputMbyte; $item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = $acctSessionTime; $item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype); $item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# Push this row onto main array # Push this row onto main array
array_push($resultArray,$item); array_push($resultArray,$item);
......
<?php <?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"); include_once("include/db.php");
...@@ -10,13 +26,13 @@ function createAdminUserTopup($params) { ...@@ -10,13 +26,13 @@ function createAdminUserTopup($params) {
$timestamp = date('Y-m-d H:i:s'); $timestamp = date('Y-m-d H:i:s');
# Perform query # 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'], array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo']) $params[0]['ValidTo'])
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -27,7 +43,7 @@ function createAdminUserTopup($params) { ...@@ -27,7 +43,7 @@ function createAdminUserTopup($params) {
function updateAdminUserTopup($params) { function updateAdminUserTopup($params) {
# Perform query # 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'], array($params[0]['Value'],
$params[0]['Type'], $params[0]['Type'],
$params[0]['ValidFrom'], $params[0]['ValidFrom'],
...@@ -36,7 +52,7 @@ function updateAdminUserTopup($params) { ...@@ -36,7 +52,7 @@ function updateAdminUserTopup($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -46,11 +62,19 @@ function updateAdminUserTopup($params) { ...@@ -46,11 +62,19 @@ function updateAdminUserTopup($params) {
# Delete user topup # Delete user topup
function removeAdminUserTopup($params) { function removeAdminUserTopup($params) {
# Perform query # Delete topup summary
$res = DBDo("DELETE FROM topups WHERE ID = ?",array($params[0])); $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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -61,7 +85,7 @@ function removeAdminUserTopup($params) { ...@@ -61,7 +85,7 @@ function removeAdminUserTopup($params) {
function getAdminUserTopup($params) { function getAdminUserTopup($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -93,11 +117,11 @@ function getAdminUserTopups($params) { ...@@ -93,11 +117,11 @@ function getAdminUserTopups($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'topups.ID', 'ID' => '@TP@topups.ID',
'Type' => 'topups.Type', 'Type' => '@TP@topups.Type',
'Value' => 'topups.Value', 'Value' => '@TP@topups.Value',
'ValidFrom' => 'topups.ValidFrom', 'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => 'topups.ValidTo' 'ValidTo' => '@TP@topups.ValidTo'
); );
# Perform query # Perform query
...@@ -105,7 +129,7 @@ function getAdminUserTopups($params) { ...@@ -105,7 +129,7 @@ function getAdminUserTopups($params) {
SELECT SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM FROM
topups @TP@topups
WHERE WHERE
Depleted = 0 Depleted = 0
AND AND
......
<?php <?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"); include_once("include/db.php");
...@@ -8,13 +24,13 @@ function getAdminUsers($params) { ...@@ -8,13 +24,13 @@ function getAdminUsers($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'users.ID', 'ID' => '@TP@users.ID',
'Username' => 'users.Username', 'Username' => '@TP@users.Username',
'Disabled' => 'users.Disabled', 'Disabled' => '@TP@users.Disabled',
); );
# Perform query # 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]; $sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data # If STH is blank, return the error back to whoever requested the data
...@@ -45,7 +61,7 @@ function getAdminUsers($params) { ...@@ -45,7 +61,7 @@ function getAdminUsers($params) {
function getAdminUser($params) { function getAdminUser($params) {
# Perform query # 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 # Return error if failed
if (!is_object($res)) { if (!is_object($res)) {
...@@ -71,16 +87,16 @@ function removeAdminUser($params) { ...@@ -71,16 +87,16 @@ function removeAdminUser($params) {
DBBegin(); DBBegin();
# Delete user information, if any # 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 # Delete user attribtues
if ($res !== FALSE) { 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 # Remove user from groups
if ($res !== FALSE) { 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 # Get list of topups and delete summaries
...@@ -88,12 +104,12 @@ function removeAdminUser($params) { ...@@ -88,12 +104,12 @@ function removeAdminUser($params) {
$topupList = array(); $topupList = array();
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
topups_summary.TopupID @TP@topups_summary.TopupID
FROM FROM
topups_summary, topups @TP@topups_summary, @TP@topups
WHERE WHERE
topups_summary.TopupID = topups.ID @TP@topups_summary.TopupID = @TP@topups.ID
AND topups.UserID = ?", AND @TP@topups.UserID = ?",
array($params[0]) array($params[0])
); );
...@@ -112,7 +128,7 @@ function removeAdminUser($params) { ...@@ -112,7 +128,7 @@ function removeAdminUser($params) {
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo(" $res = DBDo("
DELETE FROM DELETE FROM
topups_summary @TP@topups_summary
WHERE WHERE
TopupID = ?", TopupID = ?",
array($id) array($id)
...@@ -124,23 +140,21 @@ function removeAdminUser($params) { ...@@ -124,23 +140,21 @@ function removeAdminUser($params) {
# Remove topups # Remove topups
if ($res !== FALSE) { 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 # Delete user
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0])); $res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
} }
# Commit and return if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Else rollback database
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
} }
...@@ -148,10 +162,10 @@ function removeAdminUser($params) { ...@@ -148,10 +162,10 @@ function removeAdminUser($params) {
function createAdminUser($params) { function createAdminUser($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -162,10 +176,10 @@ function createAdminUser($params) { ...@@ -162,10 +176,10 @@ function createAdminUser($params) {
function updateAdminUser($params) { function updateAdminUser($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
......
<?php <?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"); include_once("include/db.php");
...@@ -6,10 +22,10 @@ include_once("include/db.php"); ...@@ -6,10 +22,10 @@ include_once("include/db.php");
function removeWiSPLocationMember($params) { function removeWiSPLocationMember($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -21,20 +37,20 @@ function getWiSPLocationMembers($params) { ...@@ -21,20 +37,20 @@ function getWiSPLocationMembers($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'users.ID', 'ID' => '@TP@users.ID',
'Username' => 'users.Username' 'Username' => '@TP@users.Username'
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
users.ID, users.Username @TP@users.ID, @TP@users.Username
FROM FROM
wisp_userdata, users @TP@wisp_userdata, @TP@users
WHERE WHERE
wisp_userdata.LocationID = ".DBQuote($params[0])." @TP@wisp_userdata.LocationID = ".DBQuote($params[0])."
AND AND
users.ID = wisp_userdata.UserID @TP@users.ID = @TP@wisp_userdata.UserID
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
......
<?php <?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"); include_once("include/db.php");
...@@ -8,12 +24,12 @@ function getWiSPLocations($params) { ...@@ -8,12 +24,12 @@ function getWiSPLocations($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'wisp_locations.ID', 'ID' => '@TP@wisp_locations.ID',
'Name' => 'wisp_locations.Name' 'Name' => '@TP@wisp_locations.Name'
); );
# Perform query # 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]; $sth = $res[0]; $numResults = $res[1];
# If STH is blank, return the error back to whoever requested the data # If STH is blank, return the error back to whoever requested the data
...@@ -43,7 +59,7 @@ function getWiSPLocations($params) { ...@@ -43,7 +59,7 @@ function getWiSPLocations($params) {
function getWiSPLocation($params) { function getWiSPLocation($params) {
# Perform query # 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 # Return if error or nothing to return
if (!is_object($res)) { if (!is_object($res)) {
...@@ -68,20 +84,19 @@ function removeWiSPLocation($params) { ...@@ -68,20 +84,19 @@ function removeWiSPLocation($params) {
DBBegin(); DBBegin();
# Unlink users from this location # 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 # Delete location
if ($res !== FALSE) { 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]));
} }
# Commit changes if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Rollback database if error
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
...@@ -91,10 +106,10 @@ function removeWiSPLocation($params) { ...@@ -91,10 +106,10 @@ function removeWiSPLocation($params) {
function createWiSPLocation($params) { function createWiSPLocation($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -105,10 +120,10 @@ function createWiSPLocation($params) { ...@@ -105,10 +120,10 @@ function createWiSPLocation($params) {
function updateWiSPLocation($params) { function updateWiSPLocation($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
......
<?php <?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"); include_once("include/db.php");
...@@ -6,14 +22,18 @@ include_once("include/db.php"); ...@@ -6,14 +22,18 @@ include_once("include/db.php");
# Return user logs summary # Return user logs summary
function getWiSPUserLogsSummary($params) { function getWiSPUserLogsSummary($params) {
# Get group attributes
# fixme - user might be member of multiple groups
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
user_attributes.Name, @TP@group_attributes.Name,
user_attributes.Value @TP@group_attributes.Value
FROM FROM
user_attributes @TP@group_attributes, @TP@users_to_groups, @TP@groups
WHERE 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']) array($params[0]['ID'])
); );
...@@ -22,10 +42,7 @@ function getWiSPUserLogsSummary($params) { ...@@ -22,10 +42,7 @@ function getWiSPUserLogsSummary($params) {
return $res; return $res;
} }
# Array of results # Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$resultArray = array();
# Fetch uptime and traffic limits, if not found, this is prepaid account.. use -1 as we need int
$trafficCap = -1; $trafficCap = -1;
$uptimeCap = -1; $uptimeCap = -1;
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
...@@ -37,31 +54,65 @@ function getWiSPUserLogsSummary($params) { ...@@ -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['trafficCap'] = $trafficCap;
$resultArray['uptimeCap'] = $uptimeCap; $resultArray['uptimeCap'] = $uptimeCap;
# Dates we want to use to search search # Dates we want to use to search search
$dateFrom = new DateTime($params[0]['From']); $periodKey = new DateTime($params[0]['PeriodKey']."-01");
$dateTo = new DateTime($params[0]['To']);
# Return if error
if (!is_object($periodKey)) {
return $periodKey;
}
# Fetch user uptime and traffic summary # Fetch user uptime and traffic summary
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
topups_summary.Balance, @TP@topups_summary.Balance,
topups.Type, @TP@topups.ID,
topups.Value @TP@topups.Type,
@TP@topups.Value,
@TP@topups.ValidTo
FROM FROM
topups_summary, @TP@topups_summary,
topups @TP@topups
WHERE WHERE
topups_summary.TopupID = topups.ID @TP@topups_summary.TopupID = @TP@topups.ID
AND topups.UserID = ? AND @TP@topups.UserID = ?
AND topups_summary.PeriodKey = ? AND @TP@topups_summary.PeriodKey = ?
AND topups.Depleted = 0 AND @TP@topups_summary.Depleted = 0
ORDER BY ORDER BY
topups.Timestamp", @TP@topups.Timestamp ASC",
array($params[0]['ID'],$dateFrom->format('Y-m')) array($params[0]['ID'],$periodKey->format('Y-m'))
); );
# Return if error # Return if error
...@@ -74,26 +125,30 @@ function getWiSPUserLogsSummary($params) { ...@@ -74,26 +125,30 @@ function getWiSPUserLogsSummary($params) {
$i = 0; $i = 0;
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
$topups[$i] = array(); $topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type; $topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->balance; $topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['OriginalLimit'] = $row->value; $topups[$i]['Limit'] = $row->value;
$i++; $i++;
} }
# Fetch user uptime and traffic topups # Fetch user uptime and traffic topups
$periodKeyEnd = new DateTime($periodKey->format('Y-m-d'));
$periodKeyEnd->modify("+1 month");
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
Value, Type ID, Value, Type, ValidTo
FROM FROM
topups @TP@topups
WHERE WHERE
topups.UserID = ? UserID = ?
AND topups.ValidFrom = ? AND ValidFrom = ?
AND topups.ValidTo >= ? AND ValidTo >= ?
AND topups.Depleted = 0 AND Depleted = 0
ORDER BY ORDER BY
topups.Timestamp", Timestamp ASC",
array($params[0]['ID'],$dateFrom->format('Y-m-d'),$dateTo->format('Y-m-d')) array($params[0]['ID'],$periodKey->format('Y-m-d'),$periodKeyEnd->format('Y-m-d'))
); );
# Return if error # Return if error
...@@ -104,6 +159,8 @@ function getWiSPUserLogsSummary($params) { ...@@ -104,6 +159,8 @@ function getWiSPUserLogsSummary($params) {
# Store normal topups # Store normal topups
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
$topups[$i] = array(); $topups[$i] = array();
$topups[$i]['ID'] = $row->id;
$topups[$i]['ValidTo'] = $row->validto;
$topups[$i]['Type'] = $row->type; $topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value; $topups[$i]['Limit'] = $row->value;
$i++; $i++;
...@@ -111,18 +168,18 @@ function getWiSPUserLogsSummary($params) { ...@@ -111,18 +168,18 @@ function getWiSPUserLogsSummary($params) {
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
accounting.AcctSessionTime, SUM(@TP@accounting.AcctSessionTime) / 60 AS TotalSessionTime,
accounting.AcctInputOctets, SUM(@TP@accounting.AcctInputOctets) / 1024 / 1024 +
accounting.AcctInputGigawords, SUM(@TP@accounting.AcctInputGigawords) * 4096 +
accounting.AcctOutputOctets, SUM(@TP@accounting.AcctOutputOctets) / 1024 / 1024 +
accounting.AcctOutputGigawords SUM(@TP@accounting.AcctOutputGigawords) * 4096 AS TotalTraffic
FROM FROM
accounting, users @TP@accounting, @TP@users
WHERE WHERE
users.ID = ? @TP@users.ID = ?
AND EventTimestamp >= ? AND @TP@accounting.PeriodKey = ?
AND accounting.Username = users.Username", AND @TP@accounting.Username = @TP@users.Username",
array($params[0]['ID'],$dateFrom->format('Y-m-d')) array($params[0]['ID'],$periodKey->format('Y-m'))
); );
if (!is_object($res)) { if (!is_object($res)) {
...@@ -130,169 +187,178 @@ function getWiSPUserLogsSummary($params) { ...@@ -130,169 +187,178 @@ function getWiSPUserLogsSummary($params) {
} }
# Set total traffic and uptime used # Set total traffic and uptime used
$totalTraffic = 0; $row = $res->fetchObject();
$totalUptime = 0;
while ($row = $res->fetchObject()) {
# Traffic in # Add usage to our return array
$inputDataItem = 0; $resultArray['trafficUsage'] = 0;
$resultArray['uptimeUsage'] = 0;
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { if (isset($row->totaltraffic) && $row->totaltraffic > 0) {
$inputDataItem += ($row->acctinputoctets / 1024) / 1024; $resultArray['trafficUsage'] += $row->totaltraffic;
} }
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) { if (isset($row->totalsessiontime) && $row->totalsessiontime > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096); $resultArray['uptimeUsage'] += $row->totalsessiontime;
}
$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);
} }
# Set excess traffic usage # Excess usage
$excessTraffic = 0; $excessTraffic = 0;
if (is_numeric($trafficCap) && $trafficCap > 0) { if ($trafficCap == -1) {
$excessTraffic += $totalTraffic - $trafficCap; $excessTraffic = $resultArray['trafficUsage'];
} else { } else {
$excessTraffic += $totalTraffic; $excessTraffic = $resultArray['trafficUsage'] > $trafficCap ? ($resultArray['trafficUsage'] - $trafficCap) : 0;
} }
# Set excess uptime usage
$excessUptime = 0; $excessUptime = 0;
if (is_numeric($uptimeCap) && $uptimeCap > 0) { if ($uptimeCap == -1) {
$excessUptime += $totalUptime - $uptimeCap; $excessUptime = $resultArray['uptimeUsage'];
} else { } else {
$excessUptime += $totalUptime; $excessUptime = $resultArray['uptimeUsage'] > $uptimeCap ? ($resultArray['uptimeUsage'] - $uptimeCap) : 0;
} }
$currentTrafficTopup = array(); # Loop through topups and add to return array
$topupTrafficRemaining = 0; $resultArray['trafficTopups'] = 0;
# Loop through traffic topups and check for current topup, total topups not being used $resultArray['uptimeTopups'] = 0;
if (is_string($trafficCap) || $trafficCap != 0) { $resultArray['TotalTrafficTopups'] = 0;
$i = 0; $resultArray['TotalUptimeTopups'] = 0;
# User is using traffic from topups # Traffic and uptime topups
if ($excessTraffic > 0) { $resultArray['AllTrafficTopups'] = array();
foreach ($topups as $topupItem) { $resultArray['AllUptimeTopups'] = array();
if ($topupItem['Type'] == 1) { $t = 0; $u = 0;
if ($excessTraffic <= 0) { foreach ($topups as $topupItem) {
$topupTrafficRemaining += $topupItem['Limit']; if ($topupItem['Type'] == 1) {
next($topupItem); # Topup not currently in use
} elseif ($excessTraffic >= $topupItem['Limit']) { if ($excessTraffic <= 0) {
$excessTraffic -= $topupItem['Limit'];
} else { # Add stats to topup array
if (isset($topupItem['OriginalLimit'])) { $resultArray['AllTrafficTopups'][$t] = array();
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; $resultArray['AllTrafficTopups'][$t]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
} else { $resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$currentTrafficTopup['Cap'] = $topupItem['Limit']; $resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
} $resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$currentTrafficTopup['Used'] = $excessTraffic; $t++;
$excessTraffic -= $topupItem['Limit'];
} # Set total available topups
} $resultArray['trafficTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
} $resultArray['TotalTrafficTopups'] += $topupItem['Limit'];
# User has not used traffic topups yet
} else { # Topup currently in use
foreach ($topups as $topupItem) { } elseif (!isset($topupItem['CurrentLimit']) && $excessTraffic < $topupItem['Limit']) {
if ($topupItem['Type'] == 1) {
if ($i == 0) { # Add stats to topup array
if (isset($topupItem['OriginalLimit'])) { $resultArray['AllTrafficTopups'][$t] = array();
$currentTrafficTopup['Cap'] = $topupItem['OriginalLimit']; $resultArray['AllTrafficTopups'][$t]['Used'] = $excessTraffic;
} else { $resultArray['AllTrafficTopups'][$t]['Cap'] = (int)$topupItem['Limit'];
$currentTrafficTopup['Cap'] = $topupItem['Limit']; $resultArray['AllTrafficTopups'][$t]['ID'] = $topupItem['ID'];
} $resultArray['AllTrafficTopups'][$t]['ValidTo'] = $topupItem['ValidTo'];
$i = 1; $t++;
$currentTrafficTopup['Used'] = 0;
} else { # Set total available topups
$topupTrafficRemaining += $topupItem['Limit']; $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'];
} }
} }
} if ($topupItem['Type'] == 2) {
# Topup not currently in use
$currentUptimeTopup = array(); if ($excessUptime <= 0) {
$topupUptimeRemaining = 0;
# Loop through uptime topups and check for current topup, total topups not being used # Add stats to topup array
if (is_string($uptimeCap) || $uptimeCap != 0) { $resultArray['AllUptimeTopups'][$u] = array();
$i = 0; $resultArray['AllUptimeTopups'][$u]['Used'] = isset($topupItem['CurrentLimit']) ? ($topupItem['Limit'] - $topupItem['CurrentLimit']) : 0;
# User is using uptime from topups $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
if ($excessUptime > 0) { $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
foreach ($topups as $topupItem) { $resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
if ($topupItem['Type'] == 2) { $u++;
if ($excessUptime <= 0) {
$topupUptimeRemaining += $topupItem['Limit']; # Set total available topups
next($topupItem); $resultArray['uptimeTopups'] += isset($topupItem['CurrentLimit']) ? $topupItem['CurrentLimit'] : $topupItem['Limit'];
} elseif ($excessUptime >= $topupItem['Limit']) { $resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
$excessUptime -= $topupItem['Limit'];
} else { # Topup currently in use
if (isset($topupItem['OriginalLimit'])) { } elseif (!isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['Limit']) {
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit'];
} else { # Add stats to topup array
$currentUptimeTopup['Cap'] = $topupItem['Limit']; $resultArray['AllUptimeTopups'][$u] = array();
} $resultArray['AllUptimeTopups'][$u]['Used'] = $excessTraffic;
$currentUptimeTopup['Used'] = $excessUptime; $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
$excessUptime -= $topupItem['Limit']; $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
} $resultArray['AllUptimeTopups'][$u]['ValidTo'] = $topupItem['ValidTo'];
} $u++;
}
# User has not used uptime topups yet # Set total available topups
} else { $resultArray['uptimeTopups'] += $topupItem['Limit'];
foreach ($topups as $topupItem) { $resultArray['TotalUptimeTopups'] += $topupItem['Limit'];
if ($topupItem['Type'] == 2) {
if ($i == 0) { # If we hit this topup then all the rest of them are available
if (isset($topupItem['OriginalLimit'])) { $excessUptime = 0;
$currentUptimeTopup['Cap'] = $topupItem['OriginalLimit']; } elseif (isset($topupItem['CurrentLimit']) && $excessUptime < $topupItem['CurrentLimit']) {
} else {
$currentUptimeTopup['Cap'] = $topupItem['Limit']; # Add stats to topup array
} $resultArray['AllUptimeTopups'][$u] = array();
$i = 1; $resultArray['AllUptimeTopups'][$u]['Used'] = ($topupItem['Limit'] - $topupItem['CurrentLimit']) + $excessTraffic;
$currentUptimeTopup['Used'] = 0; $resultArray['AllUptimeTopups'][$u]['Cap'] = (int)$topupItem['Limit'];
} else { $resultArray['AllUptimeTopups'][$u]['ID'] = $topupItem['ID'];
$topupUptimeRemaining += $topupItem['Limit']; $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 results
return array($resultArray, 1); return array($resultArray, 1);
} }
...@@ -302,45 +368,45 @@ function getWiSPUserLogs($params) { ...@@ -302,45 +368,45 @@ function getWiSPUserLogs($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'accounting.ID', 'ID' => '@TP@accounting.ID',
'EventTimestamp' => 'accounting.EventTimestamp', 'EventTimestamp' => '@TP@accounting.EventTimestamp',
'AcctStatusType' => 'accounting.AcctStatusType', 'AcctStatusType' => '@TP@accounting.AcctStatusType',
'ServiceType' => 'accounting.ServiceType', 'ServiceType' => '@TP@accounting.ServiceType',
'FramedProtocol' => 'accounting.FramedProtocol', 'FramedProtocol' => '@TP@accounting.FramedProtocol',
'NASPortType' => 'accounting.NASPortType', 'NASPortType' => '@TP@accounting.NASPortType',
'NASPortID' => 'accounting.NASPortID', 'NASPortID' => '@TP@accounting.NASPortID',
'CallingStationID' => 'accounting.CallingStationID', 'CallingStationID' => '@TP@accounting.CallingStationID',
'CalledStationID' => 'accounting.CalledStationID', 'CalledStationID' => '@TP@accounting.CalledStationID',
'AcctSessionID' => 'accounting.AcctSessionID', 'AcctSessionID' => '@TP@accounting.AcctSessionID',
'FramedIPAddress' => 'accounting.FramedIPAddress', 'FramedIPAddress' => '@TP@accounting.FramedIPAddress',
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
accounting.ID, @TP@accounting.ID,
accounting.EventTimestamp, @TP@accounting.EventTimestamp,
accounting.AcctStatusType, @TP@accounting.AcctStatusType,
accounting.ServiceType, @TP@accounting.ServiceType,
accounting.FramedProtocol, @TP@accounting.FramedProtocol,
accounting.NASPortType, @TP@accounting.NASPortType,
accounting.NASPortID, @TP@accounting.NASPortID,
accounting.CallingStationID, @TP@accounting.CallingStationID,
accounting.CalledStationID, @TP@accounting.CalledStationID,
accounting.AcctSessionID, @TP@accounting.AcctSessionID,
accounting.FramedIPAddress, @TP@accounting.FramedIPAddress,
accounting.AcctInputOctets, @TP@accounting.AcctInputOctets / 1024 / 1024 +
accounting.AcctInputGigawords, @TP@accounting.AcctInputGigawords * 4096 AS AcctInput,
accounting.AcctOutputOctets, @TP@accounting.AcctOutputOctets / 1024 / 1024 +
accounting.AcctOutputGigawords, @TP@accounting.AcctOutputGigawords * 4096 AS AcctOutput,
accounting.AcctTerminateCause, @TP@accounting.AcctTerminateCause,
accounting.AcctSessionTime @TP@accounting.AcctSessionTime / 60 AS AcctSessionTime
FROM FROM
accounting, users @TP@accounting, @TP@users
WHERE WHERE
users.Username = accounting.Username @TP@users.Username = @TP@accounting.Username
AND AND
users.ID = ".DBQuote($params[0])." @TP@users.ID = ".DBQuote($params[0])."
",$params[1],$filtersorts,$filtersorts); ",$params[1],$filtersorts,$filtersorts);
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
...@@ -354,31 +420,21 @@ function getWiSPUserLogs($params) { ...@@ -354,31 +420,21 @@ function getWiSPUserLogs($params) {
while ($row = $sth->fetchObject()) { while ($row = $sth->fetchObject()) {
# Input # Input
$acctInputMbyte = 0; $acctInput = 0;
if (isset($row->acctinput) && $row->acctinput > 0) {
if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) { $acctInput += $row->acctinput;
$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
}
if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
$acctInputMbyte += ($row->acctinputgigawords * 4096);
} }
# Output # Output
$acctOutputMbyte = 0; $acctOutput = 0;
if (isset($row->acctoutput) && $row->acctoutput > 0) {
if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) { $acctOutput += $row->acctoutput;
$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
}
if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
} }
# Uptime # Uptime
$acctSessionTime = 0; $acctSessionTime = 0;
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) { if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$acctSessionTime += ($row->acctsessiontime / 60); $acctSessionTime += $row->acctsessiontime;
} }
ceil($acctSessionTime);
# Build array for this row # Build array for this row
$item = array(); $item = array();
...@@ -397,10 +453,10 @@ function getWiSPUserLogs($params) { ...@@ -397,10 +453,10 @@ function getWiSPUserLogs($params) {
$item['CalledStationID'] = $row->calledstationid; $item['CalledStationID'] = $row->calledstationid;
$item['AcctSessionID'] = $row->acctsessionid; $item['AcctSessionID'] = $row->acctsessionid;
$item['FramedIPAddress'] = $row->framedipaddress; $item['FramedIPAddress'] = $row->framedipaddress;
$item['AcctInputMbyte'] = $acctInputMbyte; $item['AcctInput'] = $acctInput;
$item['AcctOutputMbyte'] = $acctOutputMbyte; $item['AcctOutput'] = $acctOutput;
$item['AcctSessionTime'] = $acctSessionTime; $item['AcctSessionTime'] = (int)$acctSessionTime;
$item['ConnectTermReason'] = strRadiusTermCode($row->servicetype); $item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
# Push this row onto main array # Push this row onto main array
array_push($resultArray,$item); array_push($resultArray,$item);
......
<?php <?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"); include_once("include/db.php");
...@@ -10,13 +26,13 @@ function createWiSPUserTopup($params) { ...@@ -10,13 +26,13 @@ function createWiSPUserTopup($params) {
$timestamp = date('Y-m-d H:i:s'); $timestamp = date('Y-m-d H:i:s');
# Perform query # 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'], array($params[0]['UserID'],$timestamp,$params[0]['Type'],$params[0]['Value'],$params[0]['ValidFrom'],
$params[0]['ValidTo']) $params[0]['ValidTo'])
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -27,7 +43,7 @@ function createWiSPUserTopup($params) { ...@@ -27,7 +43,7 @@ function createWiSPUserTopup($params) {
function updateWiSPUserTopup($params) { function updateWiSPUserTopup($params) {
# Perform query # 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'], array($params[0]['Value'],
$params[0]['Type'], $params[0]['Type'],
$params[0]['ValidFrom'], $params[0]['ValidFrom'],
...@@ -36,7 +52,7 @@ function updateWiSPUserTopup($params) { ...@@ -36,7 +52,7 @@ function updateWiSPUserTopup($params) {
); );
# Return result # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -47,10 +63,10 @@ function updateWiSPUserTopup($params) { ...@@ -47,10 +63,10 @@ function updateWiSPUserTopup($params) {
function removeWiSPUserTopup($params) { function removeWiSPUserTopup($params) {
# Perform query # 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 # Return result
if (is_bool($res)) { if ($res !== TRUE) {
return $res; return $res;
} }
...@@ -61,7 +77,7 @@ function removeWiSPUserTopup($params) { ...@@ -61,7 +77,7 @@ function removeWiSPUserTopup($params) {
function getWiSPUserTopup($params) { function getWiSPUserTopup($params) {
# Perform query # 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 # Return if error or no result
if (!is_object($res)) { if (!is_object($res)) {
...@@ -93,11 +109,11 @@ function getWiSPUserTopups($params) { ...@@ -93,11 +109,11 @@ function getWiSPUserTopups($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'ID' => 'topups.ID', 'ID' => '@TP@topups.ID',
'Type' => 'topups.Type', 'Type' => '@TP@topups.Type',
'Value' => 'topups.Value', 'Value' => '@TP@topups.Value',
'ValidFrom' => 'topups.ValidFrom', 'ValidFrom' => '@TP@topups.ValidFrom',
'ValidTo' => 'topups.ValidTo' 'ValidTo' => '@TP@topups.ValidTo'
); );
# Perform query # Perform query
...@@ -105,7 +121,7 @@ function getWiSPUserTopups($params) { ...@@ -105,7 +121,7 @@ function getWiSPUserTopups($params) {
SELECT SELECT
ID, Timestamp, Type, Value, ValidFrom, ValidTo ID, Timestamp, Type, Value, ValidFrom, ValidTo
FROM FROM
topups @TP@topups
WHERE WHERE
Depleted = 0 Depleted = 0
AND AND
......
<?php <?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"); include_once("include/db.php");
...@@ -8,29 +24,29 @@ function getWiSPUsers($params) { ...@@ -8,29 +24,29 @@ function getWiSPUsers($params) {
# Filters and sorts are the same here # Filters and sorts are the same here
$filtersorts = array( $filtersorts = array(
'Username' => 'users.Username', 'Username' => '@TP@users.Username',
'Disabled' => 'users.Disabled', 'Disabled' => '@TP@users.Disabled',
'ID' => 'wisp_userdata.UserID', 'ID' => '@TP@wisp_userdata.UserID',
'Firstname' => 'wisp_userdata.Firstname', 'Firstname' => '@TP@wisp_userdata.Firstname',
'Lastname' => 'wisp_userdata.Lastname', 'Lastname' => '@TP@wisp_userdata.Lastname',
'Email' => 'wisp_userdata.Email', 'Email' => '@TP@wisp_userdata.Email',
'Phone' => 'wisp_userdata.Phone' 'Phone' => '@TP@wisp_userdata.Phone'
); );
# Perform query # Perform query
$res = DBSelectSearch(" $res = DBSelectSearch("
SELECT SELECT
users.Username, @TP@users.Username,
users.Disabled, @TP@users.Disabled,
wisp_userdata.UserID, @TP@wisp_userdata.UserID,
wisp_userdata.FirstName, @TP@wisp_userdata.FirstName,
wisp_userdata.LastName, @TP@wisp_userdata.LastName,
wisp_userdata.Email, @TP@wisp_userdata.Email,
wisp_userdata.Phone @TP@wisp_userdata.Phone
FROM FROM
users, wisp_userdata @TP@users, @TP@wisp_userdata
WHERE WHERE
wisp_userdata.UserID = users.ID @TP@wisp_userdata.UserID = @TP@users.ID
",$params[1],$filtersorts,$filtersorts ",$params[1],$filtersorts,$filtersorts
); );
$sth = $res[0]; $numResults = $res[1]; $sth = $res[0]; $numResults = $res[1];
...@@ -68,21 +84,22 @@ function getWiSPUser($params) { ...@@ -68,21 +84,22 @@ function getWiSPUser($params) {
# Query for userdata and username # Query for userdata and username
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
wisp_userdata.UserID, @TP@wisp_userdata.UserID,
wisp_userdata.FirstName, @TP@wisp_userdata.FirstName,
wisp_userdata.LastName, @TP@wisp_userdata.LastName,
wisp_userdata.Phone, @TP@wisp_userdata.Phone,
wisp_userdata.Email, @TP@wisp_userdata.Email,
wisp_userdata.LocationID, @TP@wisp_userdata.LocationID,
users.Username @TP@users.Username,
FROM @TP@users.Disabled
wisp_userdata, users FROM
WHERE @TP@wisp_userdata, @TP@users
wisp_userdata.UserID = ? WHERE
AND @TP@wisp_userdata.UserID = ?
users.ID = wisp_userdata.UserID AND
",array($params[0]) @TP@users.ID = @TP@wisp_userdata.UserID
",array($params[0])
); );
# Return if error # Return if error
...@@ -97,24 +114,43 @@ function getWiSPUser($params) { ...@@ -97,24 +114,43 @@ function getWiSPUser($params) {
# Set userdata fields # Set userdata fields
$resultArray['ID'] = $row->userid; $resultArray['ID'] = $row->userid;
$resultArray['Username'] = $row->username; $resultArray['Username'] = $row->username;
$resultArray['Firstname'] = $row->firstname; $resultArray['Disabled'] = $row->disabled;
$resultArray['Lastname'] = $row->lastname; if (isset($row->firstname)) {
$resultArray['Phone'] = $row->phone; $resultArray['Firstname'] = $row->firstname;
$resultArray['Email'] = $row->email; } else {
$resultArray['LocationID'] = $row->locationid; $resultArray['Firstname'] = null;
$resultArray['Attributes'] = array(); }
if (isset($row->lastname)) {
$resultArray['Lastname'] = $row->lastname;
} else {
$resultArray['Lastname'] = null;
}
if (isset($row->phone)) {
$resultArray['Phone'] = $row->phone;
} else {
$resultArray['Phone'] = null;
}
if (isset($row->email)) {
$resultArray['Email'] = $row->email;
} else {
$resultArray['Email'] = null;
}
if (isset($row->locationid)) {
$resultArray['LocationID'] = $row->locationid;
} else {
$resultArray['LocationID'] = null;
}
# Query to get user password # Password query
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
user_attributes.Value Value
FROM FROM
user_attributes @TP@user_attributes
WHERE WHERE
user_attributes.Name = 'User-Password' Name = ?
AND AND @TP@user_attributes.UserID = ?
user_attributes.UserID = ? ",array('User-Password',$params[0])
",array($params[0])
); );
# Return if error # Return if error
...@@ -122,22 +158,33 @@ function getWiSPUser($params) { ...@@ -122,22 +158,33 @@ function getWiSPUser($params) {
return $res; return $res;
} }
# Set user password field # Set password
$row = $res->fetchObject(); $row = $res->fetchObject();
$resultArray['Password'] = $row->value; if (isset($row->value)) {
$resultArray['Password'] = $row->value;
} else {
$resultArray['Password'] = null;
}
# Set number of results
$numResults = count($resultArray);
# Return results
return array($resultArray,$numResults);
}
# Query to get all other attributes # Get wisp user attributes
function getWiSPUserAttributes($params) {
# Attributes query
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
user_attributes.ID, ID, Name, Operator, Value
user_attributes.Name, FROM
user_attributes.Operator, @TP@user_attributes
user_attributes.Value WHERE
FROM @TP@user_attributes.UserID = ?",
user_attributes array($params[0])
WHERE
user_attributes.UserID = ?
",array($params[0])
); );
# Return if error # Return if error
...@@ -145,21 +192,59 @@ function getWiSPUser($params) { ...@@ -145,21 +192,59 @@ function getWiSPUser($params) {
return $res; return $res;
} }
# Array for multiple attributes # Set attributes
$i = 0; $i = 0;
$attributes = array();
while ($row = $res->fetchObject()) { while ($row = $res->fetchObject()) {
$resultsArray['Attributes'][$i]['ID'] = $row->id; $attributes[$i] = array();
$resultsArray['Attributes'][$i]['Name'] = $row->name; $attributes[$i]['ID'] = $row->id;
$resultsArray['Attributes'][$i]['Operator'] = $row->operator; $attributes[$i]['Name'] = $row->name;
$resultsArray['Attributes'][$i]['Value'] = $row->value; $attributes[$i]['Operator'] = $row->operator;
$attributes[$i]['Value'] = $row->value;
$i++; $i++;
} }
# Get number of results # Set number of results
$numResults = $res->rowCount(); $numResults = count($attributes);
# Return results # Return results
return array($resultArray,$numResults); return array($attributes,$numResults);
}
# Get wisp user groups
function getWiSPUserGroups($params) {
# Groups query
$res = DBSelect("
SELECT
@TP@groups.Name, @TP@groups.ID
FROM
@TP@users_to_groups, @TP@groups
WHERE
@TP@users_to_groups.GroupID = @TP@groups.ID
AND @TP@users_to_groups.UserID = ?",
array($params[0])
);
# Return if error
if (!is_object($res)) {
return $res;
}
# Set groups
$i = 0;
$groups = array();
while ($row = $res->fetchObject()) {
$groups[$i]['ID'] = $row->id;
$groups[$i]['Name'] = $row->name;
$i++;
}
# Set number of results
$numResults = count($groups);
# Return results
return array($groups,$numResults);
} }
# Remove wisp user # Remove wisp user
...@@ -169,16 +254,16 @@ function removeWiSPUser($params) { ...@@ -169,16 +254,16 @@ function removeWiSPUser($params) {
DBBegin(); DBBegin();
# Delete user information # 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 # Delete user attribtues
if ($res !== FALSE) { 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 # Remove user from groups
if ($res !== FALSE) { 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 # Get list of topups and delete summaries
...@@ -186,12 +271,12 @@ function removeWiSPUser($params) { ...@@ -186,12 +271,12 @@ function removeWiSPUser($params) {
$topupList = array(); $topupList = array();
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
topups_summary.TopupID @TP@topups_summary.TopupID
FROM FROM
topups_summary, topups @TP@topups_summary, topups
WHERE WHERE
topups_summary.TopupID = topups.ID @TP@topups_summary.TopupID = @TP@topups.ID
AND topups.UserID = ?", AND @TP@topups.UserID = ?",
array($params[0]) array($params[0])
); );
...@@ -209,7 +294,7 @@ function removeWiSPUser($params) { ...@@ -209,7 +294,7 @@ function removeWiSPUser($params) {
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo(" $res = DBDo("
DELETE FROM DELETE FROM
topups_summary @TP@topups_summary
WHERE WHERE
TopupID = ?", TopupID = ?",
array($id) array($id)
...@@ -221,21 +306,20 @@ function removeWiSPUser($params) { ...@@ -221,21 +306,20 @@ function removeWiSPUser($params) {
# Remove topups # Remove topups
if ($res !== FALSE) { 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 # Delete user
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0])); $res = DBDo("DELETE FROM @TP@users WHERE ID = ?",array($params[0]));
} }
# Commit and return if successful # Return result
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
# Else rollback database
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
...@@ -249,18 +333,18 @@ function createWiSPUser($params) { ...@@ -249,18 +333,18 @@ function createWiSPUser($params) {
# Begin transaction # Begin transaction
DBBegin(); DBBegin();
# Perform first query # Perform first query
$res = "Username & Password required for single user. For adding multiple users an integer is required."; $res = "Username required for single user. For adding multiple users an integer is required.";
# If we adding single user # If we adding single user
if (empty($params[0]['Number']) && !empty($params[0]['Password']) && !empty($params[0]['Username'])) { if (empty($params[0]['Number']) && !empty($params[0]['Username'])) {
# Insert 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 # Continue with others if successful
if ($res !== FALSE) { if ($res !== FALSE) {
$userID = DBLastInsertID(); $userID = DBLastInsertID();
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
user_attributes (UserID,Name,Operator,Value) @TP@user_attributes (UserID,Name,Operator,Value)
VALUES VALUES
(?,?,?,?)", (?,?,?,?)",
array($userID, array($userID,
...@@ -272,77 +356,93 @@ function createWiSPUser($params) { ...@@ -272,77 +356,93 @@ function createWiSPUser($params) {
# Link users ID to make user a wisp user # Link users ID to make user a wisp user
if ($res !== FALSE) { 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 # Add personal information
if ($res !== FALSE && isset($params[0]['Firstname'])) { 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'])) { 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'])) { 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'])) { 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'])) { 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 # Grab each attribute and add it's details to the database
if ($res !== FALSE && isset($params[0]['Attributes'])) { if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) { foreach ($params[0]['Attributes'] as $attr) {
# Default value without modifier # We only want to add attributes with all values
$attrValue = $attr['Value']; if (
isset($attr['Name']) && $attr['Name'] != "" &&
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') { isset($attr['Operator']) && $attr['Operator'] != "" &&
# If modifier is set we need to work out attribute value isset($attr['Value']) && $attr['Value'] != ""
if (isset($attr['Modifier'])) { ) {
switch ($attr['Modifier']) { # Default value without modifier
case "Seconds": $attrValue = $attr['Value'];
$attrValue = $attr['Value'] / 60;
case "Minutes": if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
$attrValue = $attr['Value']; # If modifier is set we need to work out attribute value
case "Hours": if (isset($attr['Modifier'])) {
$attrValue = $attr['Value'] * 60; switch ($attr['Modifier']) {
case "Days": case "Seconds":
$attrValue = $attr['Value'] * 1440; $attrValue = $attr['Value'] / 60;
case "Weeks": break;
$attrValue = $attr['Value'] * 10080; case "Minutes":
case "Months": $attrValue = $attr['Value'];
$attrValue = $attr['Value'] * 44640; break;
case "MBytes": case "Hours":
$attrValue = $attr['Value']; $attrValue = $attr['Value'] * 60;
case "GBytes": break;
$attrValue = $attr['Value'] * 1000; case "Days":
case "TBytes": $attrValue = $attr['Value'] * 1440;
$attrValue = $attr['Value'] * 1000000; 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;
}
} }
} }
}
# Add attribute # Add attribute
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
user_attributes (UserID,Name,Operator,Value) @TP@user_attributes (UserID,Name,Operator,Value)
VALUES VALUES
(?,?,?,?)", (?,?,?,?)",
array( array(
$userID, $userID,
$attr['Name'], $attr['Name'],
$attr['Operator'], $attr['Operator'],
$attrValue $attrValue
) )
); );
}
} }
} }
# Link user to groups if any selected # Link user to groups if any selected
if ($res !== FALSE && isset($params[0]['Groups'])) { if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array(); $refinedGroups = array();
# Filter out unique group ID's # Filter out unique group ID's
...@@ -353,7 +453,7 @@ function createWiSPUser($params) { ...@@ -353,7 +453,7 @@ function createWiSPUser($params) {
} }
# Loop through groups # Loop through groups
foreach ($refinedGroups as $groupID) { 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));
} }
} }
...@@ -383,11 +483,11 @@ function createWiSPUser($params) { ...@@ -383,11 +483,11 @@ function createWiSPUser($params) {
# Check if username used # Check if username used
$res = DBSelect(" $res = DBSelect("
SELECT SELECT
users.Username @TP@users.Username
FROM FROM
users @TP@users
WHERE WHERE
users.Username = ? @TP@users.Username = ?
",array($thisUsername) ",array($thisUsername)
); );
...@@ -409,64 +509,80 @@ function createWiSPUser($params) { ...@@ -409,64 +509,80 @@ function createWiSPUser($params) {
# Insert users from array into database # Insert users from array into database
foreach ($wispUser as $username => $password) { 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) { if ($res !== FALSE) {
$id = DBLastInsertID(); $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) array($id,'User-Password','==',$password)
); );
# Grab each attribute and add it's details to the database # Grab each attribute and add it's details to the database
if ($res !== FALSE && isset($params[0]['Attributes'])) { if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) { foreach ($params[0]['Attributes'] as $attr) {
# Default value without modifier # We only want to add attributes with all values
$attrValue = $attr['Value']; if (
isset($attr['Name']) && $attr['Name'] != "" &&
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') { isset($attr['Operator']) && $attr['Operator'] != "" &&
# If modifier is set we need to work out attribute value isset($attr['Value']) && $attr['Value'] != ""
if (isset($attr['Modifier'])) { ) {
switch ($attr['Modifier']) { # Default value without modifier
case "Seconds": $attrValue = $attr['Value'];
$attrValue = $attr['Value'] / 60;
case "Minutes": if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
$attrValue = $attr['Value']; # If modifier is set we need to work out attribute value
case "Hours": if (isset($attr['Modifier'])) {
$attrValue = $attr['Value'] * 60; switch ($attr['Modifier']) {
case "Days": case "Seconds":
$attrValue = $attr['Value'] * 1440; $attrValue = $attr['Value'] / 60;
case "Weeks": break;
$attrValue = $attr['Value'] * 10080; case "Minutes":
case "Months": $attrValue = $attr['Value'];
$attrValue = $attr['Value'] * 44640; break;
case "MBytes": case "Hours":
$attrValue = $attr['Value']; $attrValue = $attr['Value'] * 60;
case "GBytes": break;
$attrValue = $attr['Value'] * 1000; case "Days":
case "TBytes": $attrValue = $attr['Value'] * 1440;
$attrValue = $attr['Value'] * 1000000; 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;
}
} }
} }
}
# Add attribute # Add attribute
$res = DBDo(" $res = DBDo("
INSERT INTO INSERT INTO
user_attributes (UserID,Name,Operator,Value) @TP@user_attributes (UserID,Name,Operator,Value)
VALUES VALUES
(?,?,?,?)", (?,?,?,?)",
array( array(
$id, $id,
$attr['Name'], $attr['Name'],
$attr['Operator'], $attr['Operator'],
$attrValue $attrValue
) )
); );
}
} }
} }
# Link user to groups if any selected # Link user to groups if any selected
if ($res !== FALSE && isset($params[0]['Groups'])) { if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array(); $refinedGroups = array();
# Filter out unique group ID's # Filter out unique group ID's
...@@ -477,13 +593,13 @@ function createWiSPUser($params) { ...@@ -477,13 +593,13 @@ function createWiSPUser($params) {
} }
# Loop through groups # Loop through groups
foreach ($refinedGroups as $groupID) { 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 # Link to wisp users
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)", $res = DBDo("INSERT INTO @TP@wisp_userdata (UserID) VALUES (?)",
array($id) array($id)
); );
} }
...@@ -535,12 +651,11 @@ function createWiSPUser($params) { ...@@ -535,12 +651,11 @@ function createWiSPUser($params) {
} }
# Commit changes if all was successful, else rollback # Commit changes if all was successful, else rollback
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit();
return $res;
} else {
DBRollback(); DBRollback();
return $res; return $res;
} else {
DBCommit();
} }
return NULL; return NULL;
...@@ -554,18 +669,18 @@ function updateWiSPUser($params) { ...@@ -554,18 +669,18 @@ function updateWiSPUser($params) {
$res = TRUE; $res = TRUE;
# Perform query # Perform query
if (!empty($params[0]['Username'])) { $res = DBDo("UPDATE @TP@users SET Username = ?, Disabled = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['Disabled'],$params[0]['ID']));
$res = DBDo("UPDATE users SET Username = ? WHERE ID = ?",array($params[0]['Username'],$params[0]['ID']));
} # Change password
# If successful, continue
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo("UPDATE user_attributes SET User-Password = ? WHERE UserID = ?",array($params[0]['Username'],$params[0]['ID'])); $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 successful, continue
if ($res !== FALSE) { if ($res !== FALSE) {
$res = DBDo(" $res = DBDo("
UPDATE UPDATE
wisp_userdata @TP@wisp_userdata
SET SET
FirstName = ?, FirstName = ?,
LastName = ?, LastName = ?,
...@@ -582,17 +697,162 @@ function updateWiSPUser($params) { ...@@ -582,17 +697,162 @@ function updateWiSPUser($params) {
} }
# If successful, add location if any # If successful, add location if any
if ($res !== FALSE && !empty($params[0]['LocationID'])) { 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']) array($params[0]['LocationID'],$params[0]['ID'])
); );
} }
# Process attributes being removed
if ($res !== FALSE && count($params[0]['RAttributes']) > 0) {
foreach ($params[0]['RAttributes'] as $attr) {
if ($res !== FALSE) {
# Perform query
$res = DBDo("DELETE FROM @TP@user_attributes WHERE ID = ?",array($attr));
}
}
}
# Process groups being removed
if ($res !== FALSE && count($params[0]['RGroups']) > 0) {
foreach ($params[0]['RGroups'] as $attr) {
if ($res !== FALSE) {
# Perform query
$res = DBDo("
DELETE FROM
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
array($params[0]['ID'],$attr)
);
}
}
}
# Grab each attribute and add it's details to the database
if ($res !== FALSE && count($params[0]['Attributes']) > 0) {
foreach ($params[0]['Attributes'] as $attr) {
# 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'];
if ($attr['Name'] == 'SMRadius-Capping-Traffic-Limit' || $attr['Name'] == 'SMRadius-Capping-Uptime-Limit') {
# If modifier is set we need to work out attribute value
if (isset($attr['Modifier'])) {
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;
}
}
}
# Check if we adding or updating
if ($res !== FALSE) {
# We adding an attribute..
if ($attr['ID'] < 0) {
$res = DBDo("
INSERT INTO
@TP@user_attributes (UserID,Name,Operator,Value)
VALUES
(?,?,?,?)",
array(
$params[0]['ID'],
$attr['Name'],
$attr['Operator'],
$attrValue
)
);
# We updating an attribute..
} else {
$res = DBDo("
UPDATE
@TP@user_attributes
SET
Name = ?,
Operator = ?,
Value = ?
WHERE
ID = ?",
array($attr['Name'],$attr['Operator'],$attrValue,$attr['ID'])
);
}
}
}
}
}
# Link user to groups if any selected
if ($res !== FALSE && count($params[0]['Groups']) > 0) {
$refinedGroups = array();
# Filter out unique group ID's
foreach ($params[0]['Groups'] as $group) {
foreach ($group as $ID=>$value) {
$refinedGroups[$value] = $value;
}
}
# Loop through groups
foreach ($refinedGroups as $groupID) {
if ($res !== FALSE) {
$res = DBSelect("
SELECT
ID
FROM
@TP@users_to_groups
WHERE
UserID = ?
AND GroupID = ?",
array($params[0]['ID'],$groupID)
);
}
if (is_object($res)) {
if ($res->rowCount() == 0) {
$res = DBDo("INSERT INTO @TP@users_to_groups (UserID,GroupID) VALUES (?,?)",array($params[0]['ID'],$groupID));
} else {
$res = TRUE;
}
}
}
}
# Commit changes if all was successful, else break # Commit changes if all was successful, else break
if (is_bool($res)) { if ($res !== TRUE) {
DBCommit(); DBRollback();
return $res; return $res;
} else { } else {
DBRollback(); DBCommit();
} }
return NULL; return NULL;
......