Location: PHPKode > projects > Entier Studio > entierstudio/framework/view/view.ErrorMessage.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.framework
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: view.ErrorMessage.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-----------------------------------------------------------------------------
//	namespace
if (!defined("DefErrorMessage")) {
    //-------------------------------------------------------------------------
    //	Define
    define("DefErrorMessage", "1");
    //-------------------------------------------------------------------------
    //	Include
    @require_once (FRAMEWORK_DIR . VIEWHELPER);
    //-------------------------------------------------------------------------
    //	Class
    class ErrorMessage extends ViewObject {
        //---------------------------------------------------------------------
        //	Constructor
        /*
        *
        */
        function ErrorMessage($errorSet, $language = "en") {
            //
            $this->m_errorSet = $errorSet;
        }
        //---------------------------------------------------------------------
        //	Methods
        
        /**
         *
         * @access	public
         *
         * @param	string	template
         * @param	string	error block name in layout
         * @param	integer	view type	{ FORMVIEW, ITEMVIEW, LISTVIEW, TREEVIEW... }
         * @param	integer	outputmode	RENDER
         * @return	boolean
         */
        function renderView(&$template, $block, $view = NULL, $mode = RENDER) {
            //
            if (!is_object($template)) return (false);
            //
            if (!is_array($this->m_errorSet)) return (false);
            //
            if (count($this->m_errorSet) == 0) return (false);
            //
            $ERRORMESSAGE = "";
            $DBERRNUMBER = $this->m_errorSet["DBERRNUMBER"];
            $DBERRSTRING = $this->m_errorSet["DBERRSTRING"];
            $DATAERRORSET = $this->m_errorSet["DATAERRORSET"];
            $DATAFIELDSET = $this->m_errorSet["DATAFIELDSET"];
            //
            /*
            * 1- Check database error
            */
            //
            if ($DBERRNUMBER != "0") {
                //
                /*
                * 1.1- Format database error
                */
                //
                switch ($DBERRNUMBER) {
                    case "1062":
                        //
                        $ERRORMESSAGE = "Duplicate entry";
                        //
                        
                    break;
                    default:
                        //
                        $ERRORMESSAGE = $DBERRNUMBER . $DBERRSTRING;
                        //
                        
                    break;
                }
            } else {
                //
                /*
                * 1.2- Format input error
                */
                //
                $ERRORMESSAGE = "Errors found: underlined fields must be properly filled";
            }
            //
            /*
            * 2- error block
            */
            //
            $template->select($block);
            $template->assign("ERRORMESSAGE", $ERRORMESSAGE);
            $template->render($block);
            //
            /*
            * 3- view requirements
            */
            //
            switch ($view) {
                case FORMVIEW:
                    //
                    /*
                    * 2- Clean input fields
                    */
                    //
                    if (($DBERRNUMBER == "0") && @is_array($DATAERRORSET) && @is_array($DATAFIELDSET)) {
                        //
                        @reset($DATAERRORSET);
                        @reset($DATAFIELDSET);
                        //
                        foreach($DATAERRORSET as $field => $error) {
                            if ($error) $DATAFIELDSET["$field"] = "";
                        }
                        //
                        $template->assign($DATAFIELDSET);
                    }
                    //
                    break;
                default:
                    //
                    break;
                }
                //
                $template->output($mode);
                //
                return (true);
        }
    };
    //	Class
    //-------------------------------------------------------------------------
    
}
//	namespace
//-----------------------------------------------------------------------------
?>
Return current item: Entier Studio