0,0 → 1,281 |
<?php |
/* |
|
*/ |
require_once('mysql.class.php');// the mysql class in already OK! |
|
class radiusMysqlUser |
{ |
// public properties |
// no public properties |
|
// private properties |
private $database = null; |
private $username = null; |
private $userid = 0; |
private $userInfos = Array("Username"=>"","Name"=>"","Mail"=>"","Department"=>"","WorkPhone"=>"","HomePhone"=>"","Mobile"=>""); |
private $checkItems = Array(); |
private $replyItems = Array(); |
|
//TO DO : init $userInfos, $checkItems and $replyItems fields and operator from config file !!!! URGENT |
|
|
// protected properties |
// no protected properties |
|
// Class constructor |
public function __construct($dbOptions = Array(), $attributeConfig = Array()) |
{ |
/* |
Db init and config init to do! |
*/ |
$this->database = new mysql("127.0.0.1","root","","radius"); |
} |
// Class destructor |
public function __destruct() |
{ |
//$this->mysql->close(); //is private ! |
$this->database = null; |
} |
// public methods |
public static function find($options = Array(), $escape=false) |
{ |
$database = new mysql("127.0.0.1","root","","radius"); |
/* |
If the options are not xss clean, escape all options string by calling _escapeDatas() method. |
*/ |
if ($escape == true) { |
//$this->_extractArray($options, true); //create variable from $options array and get xss clean for mysql database |
$options = $this->_escapeDatas($options); //create variable from $options array and get xss clean for mysql database |
} |
/* |
The differents $options values are : |
|
$distinct -> only distinct response ? |
$username -> only for this username |
$fields -> fields to return (default : username) |
$search -> search value to find |
$search_IN -> search in this/those field(s)(text or array) |
$limit -> to limit the resultset |
$offset -> offset (work with $limit for pagination) |
$sortby -> sort by x field (default : no sorting) |
$sortdir -> sort direction (ASC/DESC) (default : no sorting) |
$radius_attr-> radius attribute to find (text or array) if search_IN = radius |
*/ |
|
//mysql_real_escape_string |
|
|
$sql = "SELECT "; |
// distinct option |
if ((isset($distinct))&&($distinct=="distinct")) |
$sql .= "DISTINCT "; |
// field option (make sure that the field exist!) |
if ((isset($options['fields']))&&($options['fields']!='')){ |
$sql .= $options['fields'].", username "; |
}else{ |
$sql .= "username "; |
} |
$sql .= "FROM userinfo "; |
// search option |
if ((isset($options['username']))&&($options['username']!='')){ |
|
} |
// where option |
if ((isset($options['username']))&&($options['username']!="")) |
{ |
$sql .= "WHERE username='".$options['username']."'"; |
$this->username = $options['username']; |
} |
// sort |
if ((isset($options['sortby']))&&($options['sortby']!='')){ |
$sql .= "ORDER BY ".$options['sortby']." "; |
if ((isset($options['sortdir']))&&($options['sortdir']!='')){ |
$sql .= "LIMIT ".$options['sortdir']." "; |
} |
} |
// limit / offset |
if ((isset($options['limit']))&&($options['limit']!='')){ |
if ((isset($options['offset']))&&($options['offset']!='')){ |
$sql .= "LIMIT $offset $limit "; |
} else { |
$sql .= "LIMIT $limit "; |
} |
|
} |
$sql .= ";"; |
|
// query |
$result = $database->query($sql); |
// return the result values |
return $result; |
} |
public function load($username, $attribute = false) //ok |
{ |
/* |
Load an user from mysql database. If $attribute==true, get all chekitems and replyitems attributes too. |
*/ |
$sql = "SELECT * FROM userinfo WHERE UserName='$username';"; |
$result = $this->database->query($sql); |
|
if (count($result) != 1) return false; |
|
$this->userInfos = $result[0]; |
|
if ($attribute === true){ |
|
// get from radcheck table |
$result=null; |
$sql = "SELECT * FROM radcheck WHERE username='$username';"; |
$result = $this->database->query($sql); |
if (count($result) != 1) return false; |
$this->checkItems = $result[0]; |
|
// get from radreply table |
$result=null; |
$sql = "SELECT * FROM radreply WHERE username='$username';"; |
$result = $this->database->query($sql); |
if (count($result) != 1) return false; |
$this->replyItems = $result[0]; |
} |
|
return true; |
} |
public function add() |
{ |
/* |
Add the current user with all his attribute in the mysql database |
(only if the user not already exist) |
*/ |
$sql = ""; |
//INSERT INTO table (a,b,c) VALUES (1,2,3) |
|
//INSERT userinfo table (insert) |
$sql = "INSERT INTO userinfo (UserName, Name, Mail, Department, WorkPhone, HomePhone, Mobile) VALUES ()"; |
//INSERT radcheck table (insert) |
$sql = ""; |
//INSERT radreply table (insert) |
$sql = ""; |
//INSERT radusergroup table (insert) |
$sql = ""; |
//INSERT radpostauth table (insert) |
|
|
} |
public function delete() //ok |
{ |
/* |
Delete the current user from the mysql database |
note : this function doesn't delete any accounting record of the current user |
*/ |
if ($this->userid == 0) return 0; //0 record deleted |
|
//can be better with transaction |
$sql1 = "DELETE FROM radreply WHERE username = $this->username ;"; |
$sql2 = "DELETE FROM radcheck WHERE username = $this->username ;"; |
$sql3 = "DELETE FROM radpostauth WHERE username = $this->username ;"; |
$sql4 = "DELETE FROM radusergroup WHERE username = $this->username ;"; |
$sql5 = "DELETE FROM userinfo WHERE username = $this->username ;"; |
|
$nb1 = $this->database->exec($sql1); |
$nb2 = $this->database->exec($sql2); |
$nb3 = $this->database->exec($sql3); |
$nb4 = $this->database->exec($sql4); |
$nb5 = $this->database->exec($sql5); |
|
return ($nb1+$nb2+$nb3+$nb4+$nb5); // n record deleted |
} |
public function update() |
{ |
/* |
Update the current user with all his attribute in the mysql database |
(only if the user does not already exist) |
*/ |
if ($this->userid == 0) return 0; //0 record deleted |
|
//UPDATE userinfo table (update) |
|
//UPDATE radcheck table (update) |
|
//UPDATE radreply table (update) |
|
//UPDATE radusergroup table (update) |
|
//UPDATE radpostauth table (update) |
} |
public function save() //ok |
{ |
/* |
insert or Update the current user with all his attribute in the mysql database |
(use add() and update() method) |
*/ |
if ($this->userid == 0){ |
return $this->add(); |
} else { |
return $this->update(); |
} |
} |
public function get($userInfo = 'null') //ok |
{ |
/* |
return userInfos |
*/ |
if (array_key_exists($userInfo, $this->userInfos)){ |
return $this->userInfos[$userInfo]; |
} else { |
return $this->userInfos; |
} |
} |
public function set($userInfo) //ok |
{ |
/* |
Set a checkItem or replyItem of the user |
*/ |
if (array_key_exists($userInfo, $this->userInfos)){ |
$this->userInfos[$userInfo] = $userInfo; |
} |
if (strtolower($userInfo) == "username") $this->username = $userInfo; |
} |
public function getAttribute($attribute = null) |
{ |
/* |
Get a checkItem or replyItem from the user or get the value from the mysql database |
*/ |
if (array_key_exists($attribute, $this->userInfos)){ |
|
} elseif (array_key_exists($attribute, $this->checkItems)){ |
|
} elseif (array_key_exists($attribute, $this->replyItems)){ |
|
} else{ |
|
} |
} |
public function setAttribute($attribute) |
{ |
/* |
Set a checkItem or replyItem of the user |
*/ |
} |
public function checkPassword($pwd) |
{ |
// Check the user password |
// Return true or false |
} |
public function setPassword($pwd) |
{ |
// Set or change the user password |
} |
// private methods |
private function _escapeDatas($options) |
{ |
|
} |
private function _init($configFile) |
{ |
|
} |
// protected methods |
// no protected method |
} |
?> |