Location: PHPKode > projects > Entier Studio > entierstudio/office/classes/datas/data.DirectoryProject.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.DirectoryProject.php 121 2008-03-11 20:17:41Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefDirectoryProject")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefDirectoryProject", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . DATAROWOBJECT);
    @require_once (FRAMEWORK_DIR . "./filters/filter.forminput.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.classpath.php");
    @require_once (FRAMEWORK_DIR . "./validators/validator.identifier.php");
    //-------------------------------------------------------------------------
    //	Class
    class DirectoryProject extends DataRow {
        /*
        *
        *
        * @see index.php
        /
        
        //---------------------------------------------------------------------
        //	Constructor
        
        /**
        *
        * @param	integer	 DirectoryProjectAccount	pkid			//	primary key
        */
        function DirectoryProject($DIRPROJPKID = 0) {
            //
            $this->m_tableSet[PRIMARYKEY] = "tbl_directory_project";
            $this->m_indexSet[PRIMARYKEY] = "DIRPROJPKID";
            //
            $this->m_fieldSet["DIRPROJPKID"] = $DIRPROJPKID;
        }
        //---------------------------------------------------------------------
        //	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 ("");
            }
            //	DIRPROJNAME = DirectoryProject name
            $value = FilterFormInput::filter($this->m_fieldSet["DIRPROJNAME"]);
            if (!empty($value)) {
                $insertSQL.= " ,DIRPROJNAME";
                $valuesSQL.= " ,$value";
            } else {
                $this->m_errorSet["DIRPROJNAME"] = true;
                return ("");
            }
            //	DIRPROJCODE = DirectoryProject identifier
            $value = @trim($this->m_fieldSet["DIRPROJCODE"]);
            if (ValidatorIdentifier::isValid($value)) {
                $insertSQL.= " ,DIRPROJCODE";
                $valuesSQL.= " ,\"$value\"";
            } else {
                $this->m_errorSet["DIRPROJCODE"] = true;
                return ("");
            }
            //	DIRPROJPATH = DirectoryProject path
            $value = @trim($this->m_fieldSet["DIRPROJPATH"]);
            if (ValidatorClasspath::isValid($value)) {
                $insertSQL.= " ,DIRPROJPATH";
                $valuesSQL.= " ,\"$value\"";
            }
            //	DIRPROJTEXT = DirectoryProject description
            $value = FilterFormInput::filter($this->m_fieldSet["DIRPROJTEXT"], true);
            if (!empty($value)) {
                $insertSQL.= " ,DIRPROJTEXT";
                $valuesSQL.= " ,$value";
            }
            //	DIRPROJDATE = DirectoryProject creation date
            $value = Date("Y-m-d H:i:s");
            $insertSQL.= " ,DIRPROJDATE";
            $valuesSQL.= " ,\"$value\"";
            //	DIRPROJSTAT = DirectoryProject status
            $value = 1;
            $insertSQL.= " ,DIRPROJSTAT";
            $valuesSQL.= " ,$value";
            //	DIRPROJTYPE = DirectoryProject type
            $value = $this->m_fieldSet["DIRPROJTYPE"];
            if (!empty($value)) {
                $insertSQL.= " ,DIRPROJTYPE";
                $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_project_user
                    *	ON
                    *			DIRUSERPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) {
                        //
                        $updateSQL = "UPDATE $table SET ";
                        //	DIRPROJNAME = DirectoryProject name
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRPROJNAME"]);
                        if (!empty($value)) $updateSQL.= " DIRPROJNAME=$value";
                        else {
                            $this->m_errorSet["DIRPROJNAME"] = true;
                            return ("");
                        }
                        //	DIRPROJCODE = DirectoryProject identifier
                        $value = @trim($this->m_fieldSet["DIRPROJCODE"]);
                        if (ValidatorIdentifier::isValid($value)) $updateSQL.= ",DIRPROJCODE=\"$value\"";
                        else {
                            $this->m_errorSet["DIRPROJCODE"] = true;
                            return ("");
                        }                        
						//	DIRPROJPATH = DirectoryProject path
                        $value = @trim($this->m_fieldSet["DIRPROJPATH"]);
                        if (ValidatorClasspath::isValid($value) || empty($value))
							$updateSQL.= ",DIRPROJPATH=\"$value\"";

                        //	DIRPROJTEXT = DirectoryProject description
                        $value = FilterFormInput::filter($this->m_fieldSet["DIRPROJTEXT"], true);
                        $updateSQL.= ",DIRPROJTEXT=$value";

                        //	DIRPROJSTAT = DirectoryProject status
                        $value = $this->m_fieldSet["DIRPROJSTAT"];
                        $updateSQL.= ",DIRPROJSTAT=$value";
                        //
                        return ($updateSQL . " WHERE $field=$index");
                    }
                    break;
                case DISPLAYKEY:
                    /*
                    *	UPDATE
                    *			tbl_directory_project_user
                    *	SET
                    *			DIRUSERSIGN='DIRPROJPKID'
                    *			DIRPROJSTAT=0
                    *	ON
                    *			DIRPROJPKID
                    *
                    */
                    //
                    $field = $this->m_indexSet[PRIMARYKEY];
                    $index = $this->m_fieldSet["$field"];
                    if ($index != 0) return ("UPDATE $table 
								SET																		
									DIRPROJCODE= CONCAT('~', DIRPROJCODE, '$index' ),
									DIRPROJSTAT=0 
								WHERE 
									$field=$index
								AND
									DIRPROJSTAT=1");
                    //
                    break;
                }
                //
                return ("");
            }
            /**
             *
             * @access protected
             *
             * @param	integer	 index type
             * @return	string
             */
            function getSelectQuery($indexType = PRIMARYKEY) {
                //
                switch ($indexType) {
                    case PRIMARYKEY:
                        /*
                        *	SELECT
                        *			tbl_directory_project			as t1
                        *		<->	tbl_directory_unit	as t2
                        *	ON
                        *		DIRPROJPKID
                        */
                        //
                        $field = $this->m_indexSet[PRIMARYKEY];
                        $index = $this->m_fieldSet["$field"];
                        if ($index != 0) return ("SELECT
									t1.*, 
									t2.DIRUNITNAME 
								FROM 
									tbl_directory_project as t1, 
									tbl_directory_unit as t2 
								WHERE 
									t1.$field=$index 
								AND 
									t1.DIRPROJSTAT>0 
								AND
									t1.DIRUNITPKID=t2.DIRUNITPKID
								AND 
									t2.DIRUNITSTAT>0");
                        //
                        break;
                    }
                    //
                    return ("");
            }
        };
        //	Class
        //-------------------------------------------------------------------------
        
    }
    //	namespace
    //-----------------------------------------------------------------------------
    
?>
Return current item: Entier Studio