Location: PHPKode > projects > Entier Studio > entierstudio/office/classes/datas/data.DirectoryUnit.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
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: data.DirectoryUnit.php 121 2008-03-11 20:17:41Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDirectoryUnit")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDirectoryUnit", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.email.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.classpath.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.websitename.php");
    //-------------------------------------------------------------------------
    //	Class
    class DirectoryUnit extends DataRow {
        /*
        *
        *
        * @see index.php
        /
        
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
        *
        * @param	integer	 DirectoryUnit	pkid			//	primary key
        */
        function DirectoryUnit($DIRUNITPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_directory_unit";
            $this->m_indexSet[PRIMARYKEY] = "DIRUNITPKID";
            $this->m_indexSet[FOREIGNKEY] = "DIRECTOPKID";
            //
            $this->m_fieldSet["DIRUNITPKID"] = $DIRUNITPKID;
        }
        //-------------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @param	integer	 index type
         * @return	string
         */
        function getInsertQuery($indexType = FOREIGNKEY) {
            //
            $table = $this->m_tableSet[PRIMARYKEY];
            //
            $insertSQL = "INSERT INTO $table ( ";
            $valuesSQL = "VALUES ( ";
            //	DIRECTOPKID = Directory (foreign key)
            $value = $this->m_fieldSet["DIRECTOPKID"];
            if (!empty($value)) {
                $insertSQL.= "  DIRECTOPKID";
                $valuesSQL.= "  $value";
            } else {
                $this->m_errorSet["DIRUNITPKID"] = true;
                return ("");
            }
            //	DIRUNITNAME = DirectoryUnit name
            $value = FilterFormInput::filter($this->m_fieldSet["DIRUNITNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,DIRUNITNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DIRUNITNAME"] = true;
                return ("");
            }
            //	DIRUNITPATH = DirectoryUnit path
            $value = @trim($this->m_fieldSet["DIRUNITPATH"]);
            if (ValidatorClasspath::isValid($value)) {
                $insertSQL.= " ,DIRUNITPATH";
                $valuesSQL.= " ,\"$value\"";
            }
            //	DIRUNITTEXT = DirectoryUnit description
            $value = FilterFormInput::filter($this->m_fieldSet["DIRUNITTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,DIRUNITTEXT";
                $valuesSQL.= " ,$value";
            }
            //	DIRUNITMAIL = DirectoryUnit mail
            $value = @trim($this->m_fieldSet["DIRUNITMAIL"]);
            if (ValidatorEmail::isValid($value)) {
                $insertSQL.= " ,DIRUNITMAIL";
                $valuesSQL.= " ,\"$value\"";
            }
            //	DIRUNITSITE = DirectoryUnit site
            $value = @trim($this->m_fieldSet["DIRUNITSITE"]);
            if (ValidatorWebSiteName::isValid($value)) {
                $insertSQL.= " ,DIRUNITSITE";
                $valuesSQL.= " ,\"$value\"";
            }
            //	DIRUNITDATE = DirectoryUnit creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,DIRUNITDATE";
            $valuesSQL.= " ,\"$value\"";
            //	DIRUNITSTAT = DirectoryUnit status
            $value = 1;
            $insertSQL.= " ,DIRUNITSTAT";
            $valuesSQL.= " ,$value";
            //	DIRUNITTYPE = DirectoryUnit type
            $value = $this->m_fieldSet["DIRUNITTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,DIRUNITTYPE";
                $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_unit
                    *	ON
                    *			DIRUSERPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
 
                        //	DIRUNITNAME = DirectoryUnit login
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRUNITNAME"]);
                        if (!empty($value))
                            $updateSQL.= " DIRUNITNAME=$value";
                        else {
                            $this->m_errorSet["DIRUNITNAME"] = true;
                            return ("");
                        }
                        //	DIRUNITPATH = DirectoryUnit path
                        $value = @trim($this->m_fieldSet["DIRUNITPATH"]);
                        if (ValidatorClasspath::isValid($value) || empty($value))
							$updateSQL.= ",DIRUNITPATH=\"$value\"";

                        //	DIRUNITMAIL = DirectoryUnit mail
                        $value = @trim($this->m_fieldSet["DIRUNITMAIL"]);
                        if (ValidatorEmail::isValid($value))
                            $updateSQL.= ",DIRUNITMAIL=\"$value\"";
                        
                        //	DIRUNITSITE = DirectoryUnit site
                        $value = @trim($this->m_fieldSet["DIRUNITSITE"]);
                        if (ValidatorWebSiteName::isValid($value))
                            $updateSQL.= ",DIRUNITSITE=\"$value\"";
                        
                        //	DIRUNITTEXT = DirectoryUnit description
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRUNITTEXT"], true);
                        $updateSQL.= ",DIRUNITTEXT=$value";
                        
                        //	DIRUNITSTAT = DirectoryUnit status
                        $value = $this->m_fieldSet["DIRUNITSTAT"];
                        $updateSQL.= ",DIRUNITSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_directory_unit
                    *	SET
                    *			DIRUNITNAME='DIRUSERPKID'
                    *			DIRUNITSTAT=0
                    *	ON
                    *			DIRUSERPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET 
									DIRUNITNAME= CONCAT('~', DIRUNITNAME, '$index' ),
									DIRUNITSTAT=0 
								WHERE 
									$field=$index
								AND
									DIRUNITSTAT=1");
                    //
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @access protected
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *	SELECT
                        *		<->	tbl_directory_unit	as t1
                        *	ON
                        *		DIRPROJPKID
                        */
                        //
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("SELECT
									t1.*
								FROM 
									tbl_directory_unit as t1
								WHERE 
									t1.$field=$index 								
								AND 
									t1.DIRUNITSTAT>0");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio