Subversion Repositories ALCASAR

Rev

Go to most recent revision | Blame | Last modification | View Log

<?php
/*

*/
require_once('mysql.class.php');// the mysql class in already OK!

class user // rename to radius_user!
{
        // public properties
        public $username = null;
        public $properties = Array();
        
        // private properties
        private $database = null;

        // protected properties

        
        // Class constructor
        public function __construct($options = Array()) //see later how tp do the mysql init (init value in option or included with this file)
        {
                $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 function find($options = Array(), $escape=false)
        {
                /*
                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 = $this->database->query($sql);
                // return the result values
                return $result;
        }
        public function add($username, $options = array())
        {
                /*
                $username : user to add
                $options  : others user infos or attribute to add 
                        userinfo table : Name, Mail, Departement, WorkPhone, HomePhone, Mobile)
                        radcheck table : see in attrmap.php (i get it from the "freeradius dialupadmin" package)
                        radreply table : see in attrmap.php             
                */
        }
        public function addAttribute($attribute)
        {
                // add attribute in radcheck or radreply table
                // return true or false
        }
        public function delete($username)
        {
                // $username : user to delete
        }
        public function deleteAttribute($attribute)
        {
                // delete attribute in radcheck or radreply table
                // return true or false
        }
        public function update($username, $options = array())
        {
                /*
                $username : user to update
                $options  : user infos or attribute to update 
                        userinfo table : Name, Mail, Departement, WorkPhone, HomePhone, Mobile)
                        radcheck table : see in attrmap.php (i get it from the "freeradius dialupadmin" package)
                        radreply table : see in attrmap.php             
                */
        }
        public function updateAttribute($attribute)
        {
                // update attribute in radcheck or radreply table
                // return true or false
        }
        public function passwordCheck($pwd, $username ="") // make it static?
        {
                //      Check the user password
                //      Return true or false
        }
        public function passwordSet($pwd, $username ="") // make it static?
        {
                //      Set or change the user password
        }
        
        // private methods
        
        // protected methods
}
?>

Generated by GNU Enscript 1.6.6.