Location: PHPKode > projects > Entier Studio > entierstudio/office/classes/datas/data.DirectoryUser.php
<?php
/**
 * Entier Studio
 *
 * LICENSE
 *
 *	Copyright 2006 Entier Studio team.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 *
 * @package    entier.office
 * @version	   $Id: data.DirectoryUser.php 90 2008-01-31 22:02:05Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDirectoryUser")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDirectoryUser", "1");
    //	User authorization enumeration
    //
    define("AUTH_NONE", 0);
    define("AUTH_USER_CREATE", 1);
    define("AUTH_USER_MODIFY", 2);
    define("AUTH_USER_DELETE", 4);
    //
    define("AUTH_PROJ_CREATE", 8);
    define("AUTH_PROJ_MODIFY", 16);
    define("AUTH_PROJ_DELETE", 32);
    //
    define("AUTH_ORGN_CREATE", 64);
    define("AUTH_ORGN_MODIFY", 128);
    define("AUTH_ORGN_DELETE", 256);
    //
    define("AUTH_SITE_SUPER", 65536);
    //
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.email.php");
    //-------------------------------------------------------------------------
    //	Class
    class DirectoryUser extends DataRow {
        //---------------------------------------------------------------------
        //	Constructor        
        /**
         *
         * @param	integer	 DirectoryUser	pkid			//	primary key
         */
        function DirectoryUser($pkid = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_directory_user";
            $this->m_indexSet[PRIMARYKEY] = "DIRUSERPKID";
            //
            $this->m_fieldSet["DIRUSERPKID"] = $pkid;
        }
        //---------------------------------------------------------------------
        //	Properties        
        /**
         *
         * @param	integer		$right
         * @return	boolean
         */
        function get_authorization($right) {
            //
            return (($this->m_fieldSet["DIRUSERAUTH"]&$right) || ($this->m_fieldSet["DIRUSERAUTH"] == AUTH_SITE_SUPER));
        }
        /**
         *
         * @param	array	 rights
         * @return
         *
         */
        function set_authorization($rights) {
            //
            if (AUTH_SITE_SUPER == $this->m_fieldSet["DIRUSERAUTH"])
			    return;
            //
            if (@!is_array($rights)) {
			    $this->m_fieldSet["DIRUSERAUTH"] = AUTH_NONE;
                //
                return;
			}
            //
            if ($rights[AUTH_SITE_SUPER] == "on") {
                $this->m_fieldSet["DIRUSERAUTH"] = AUTH_SITE_SUPER;
                //
                return;
            }
            //
            $DIRUSERAUTH = AUTH_NONE;
            //
            foreach($rights as $index => $check) {
                //
			   $DIRUSERAUTH|= $index;
			}			
            //
            $this->m_fieldSet["DIRUSERAUTH"] = $DIRUSERAUTH;
        }
        //---------------------------------------------------------------------
        //	Methods        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	DIRUNITPKID = DirectoryUnit (foreign key)
            $value = $this->m_fieldSet["DIRUNITPKID"];
            if (!empty($value)) {
                $insertSQL.= "  DIRUNITPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["DIRUNITPKID"] = true;
                return ("");
            }
            //	DIRUSERNAME = DirectoryUser name : required
            $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,DIRUSERNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DIRUSERNAME"] = true;
                return ("");
            }
            //	DIRUSERSIGN = DirectoryUser login : required
            $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERSIGN"]);
            if (!empty($value)) {
                $insertSQL.= " ,DIRUSERSIGN";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DIRUSERSIGN"] = true;
                return ("");
            }
            //	DIRUSERPASS = DirectoryUser password : required
            $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERPASS"]);
            if (!empty($value)) {
                $insertSQL.= " ,DIRUSERPASS";
                $valuesSQL.= " ,MD5($value)";
            } else {
                $this->m_errorSet["DIRUSERPASS"] = true;
                return ("");
            }
            //	DIRUSERMAIL = DirectoryUser mail
            $value = @trim($this->m_fieldSet["DIRUSERMAIL"]);
            if (ValidatorEmail::isValid($value)) {
                $insertSQL.= " ,DIRUSERMAIL";
                $valuesSQL.= " ,\"$value\"";
            }
            //	DIRUSERAUTH = DirectoryUser authorizations
            $value = $this->m_fieldSet["DIRUSERAUTH"];
            if (!empty($value)) {
                $insertSQL.= " ,DIRUSERAUTH";
                $valuesSQL.= " ,$value";
            }
            //	DIRUSERDATE = DirectoryUser creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,DIRUSERDATE";
            $valuesSQL.= " ,\"$value\"";
            //	DIRUSERSTAT = DirectoryUser status
            $value = 1;
            $insertSQL.= " ,DIRUSERSTAT";
            $valuesSQL.= " ,$value";
            //	DIRUSERTYPE = DirectoryUser type
            $value = $this->m_fieldSet["DIRUSERTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,DIRUSERTYPE";
                $valuesSQL.= " ,$value";
            }
            //
            return ($insertSQL . ") " . $valuesSQL . ")");
        }
        /**
         *
         * @access	protected
         *
         * @param	integer	index type
         */
        function getUpdateQuery($indexType = PRIMARYKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            switch ($indexType) {
                case PRIMARYKEY:
                    /*
                    *	UPDATE
                    *			tbl_directory_user
                    *	ON
                    *			DIRUSERPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	DIRUSERNAME = DirectoryUser name
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERNAME"]);
                        if (!empty($value)) $updateSQL.= " DIRUSERNAME=$value";
                        else {
                            $this->m_errorSet["DIRUSERNAME"] = true;
                            return ("");
                        }
                        //	DIRUSERSIGN = DirectoryUser login
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERSIGN"]);
                        if (!empty($value)) $updateSQL.= ",DIRUSERSIGN=$value";
                        else {
                            $this->m_errorSet["DIRUSERSIGN"] = true;
                            return ("");
                        }
                        //	DIRUSERPASS = DirectoryUser password
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRUSERPASS"]);
                        if (!empty($value))
                            $updateSQL.= ",DIRUSERPASS=MD5($value)";
                        //	DIRUSERMAIL = DirectoryUser mail
                        $value = @trim($this->m_fieldSet["DIRUSERMAIL"]);
                        if (ValidatorEmail::isValid($value))
                            $updateSQL.= ",DIRUSERMAIL=\"$value\"";
                        //	DIRUSERAUTH = DirectoryUser authorizations
                        $value = $this->m_fieldSet["DIRUSERAUTH"];
                        $updateSQL.= ",DIRUSERAUTH=$value";
                        //	DIRUSERSTAT = DirectoryUser status
                        $value = $this->m_fieldSet["DIRUSERSTAT"];
                        $updateSQL.= ",DIRUSERSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_directory_user
                    *	SET
                    *			DIRUSERSIGN='DIRUSERPKID'
                    *			DIRUSERSTAT=0
                    *	ON
                    *			DIRUSERPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET 
									DIRUSERSIGN='$index',
									DIRUSERSTAT=0 
								WHERE 
									$field=$index
								AND
									DIRUSERSTAT=1");
                    //
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @access protected
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *	SELECT
                        *			tbl_directory_user
                        *		<->	tbl_directory_unit
                        *	ON
                        *		DIRUSERPKID
                        */
                        //
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("SELECT 
									t1.*,
									t2.DIRECTOPKID, 
									t2.DIRUNITNAME 
								FROM 
									tbl_directory_user as t1, 
									tbl_directory_unit as t2 
								WHERE 
									t1.DIRUSERPKID=$index 
								AND 
									t1.DIRUSERSTAT>0 
								AND 
									t1.DIRUNITPKID=t2.DIRUNITPKID 
								AND 
									t2.DIRUNITSTAT>0");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio