Location: PHPKode > projects > Entier Studio > entierstudio/studio/handlers/ctrl.DictionaryPropertyCoreScope.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.studio
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: ctrl.DictionaryPropertyCoreScope.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-------------------------------------------------------------------------
// Safe mode
if (!defined('__ENTIER_FRONT_CONTROLLER__')) die(403);
//
//-------------------------------------------------------------------------
//	Post Handler
//
$value = NULL;
$postback = !(empty($__verb));
$success = true;
$reset = false;
//
switch ($__verb) {
    case INSERT_CMD:
        //
        # Insert
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementProperty.php");
        @include_once (COMPONENTS_DATA . "data.RepositoryModelElementProperty.php");
        //
        $property = new RepositoryCoreElementProperty();
        $modelproperty = new RepositoryModelElementProperty();
        //
        $property->set_field_value("REPCELTPKID", $userRequest->Parameter("type"));
        $property->set_field_value("DICPROPPKID", $userRequest->Parameter("fkid"));
        //
        $modelproperty->set_field_value("REPMELTPKID", $userRequest->Parameter("type"));
        $modelproperty->set_field_value("DICPROPPKID", $userRequest->Parameter("fkid"));
        //
        /*
        * check if already a core or a model property
        * @quirk side effect on REPMELTPKID = REPCELTPKID
        * @todo error management setting $success = false
        */
        if (($property->selectRow($database, FOREIGNKEY) == false) && ($modelproperty->selectRow($database, FOREIGNKEY) == false)) {
            // 1- Insert property
            //
            $property->set_field_value("REPCEPRTYPE", 1);
            //
            $success = $property->insertRow($database);
            $reset = $success;
            if (true == $success) {
                // 2- Insert all dependent ruled PropertySet
                @include_once (COMPONENTS_DATA . "data.DictionaryRuledPropertySet.php");
                //
                $ruledPropertySet = new DictionaryRuledPropertySet($userRequest->Parameter("fkid"));
                if ($ruledPropertySet->selectSet($database) == true) {
                    //
                    for ($i = 0;$i < $ruledPropertySet->rowCount();$i++) {
                        //	select next row
                        if ($ruledPropertySet->fetchCursorRow($database) == false) return (false);
                        //
                        $ruledProperty = new RepositoryCoreElementProperty();
                        //
                        $ruledProperty->set_field_value("REPCELTPKID", $userRequest->Parameter("type"));
                        $ruledProperty->set_field_value("DICPROPPKID", $ruledPropertySet->get_field_value("DICPROPPKID"));
                        if ($ruledProperty->selectRow($database, FOREIGNKEY) == true) {
                            //
                            $ruledProperty->set_field_value("REPCEPRTYPE", 2);
                            //
                            $success = $ruledProperty->updateRow($database);
                        } else {
                            //
                            $ruledProperty->set_field_value("REPCEPRTYPE", 2);
                            //
                            $success = $ruledProperty->insertRow($database);
                        }
                    }
                }
            }
        }
        //
        break;
    case UPDATE_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementProperty.php");
        //
        $property = new RepositoryCoreElementProperty($userRequest->Parameter("pkid"));
        $success = $property->selectRow($database);
        if (true == $success) {
            //
            $property->set_field_value("REPCEPRTEXT", $userRequest->Parameter("text"));
            $property->set_field_value("REPCEPRSTAT", $userRequest->Parameter("stat"));
            //
            $success = $property->updateRow($database);
        }
        //
        break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementProperty.php");
        //
        $property = new RepositoryCoreElementProperty($userRequest->Parameter("dkey"));
        $success = $property->selectRow($database);
        if (true == $success) $success = $property->deleteRow($database);
        $reset = $success;
        //
        break;
    case STATUS_CMD:
        //
        # Update status=0
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementProperty.php");
        //
        $property = new RepositoryCoreElementProperty($userRequest->Parameter("dkey"));
        $success = $property->selectRow($database);
        if (true == $success) $success = $property->updateRow($database, DISPLAYKEY);
        $reset = $success;
        //
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	View Handler
    //
    $forwardView = NULL;
    //
    @include_once (COMPONENTS_VIEW . "view.DictionaryPropertyCoreScopeManager.php");
    //
    $scopeView = new DictionaryPropertyCoreScopeManager();
    //
    //	Mode Handler
    //
    $viewMode = NULLVIEW;
    $failMode = NULLVIEW;
    $viewHTML = "";
    $failHTML = "$__ctrl-$__fail.html";
    $formMark = "";
    //
    switch ($__mode) {
        case "view":
            //
            $failMode = ITEMVIEW;
            //
            $scopeView->set_field_value("REPCEPRPKID", $userRequest->Parameter("pkid"));
            //
            
        break;
        case "grid":
            //
            $failMode = LISTVIEW;
            //
            $scopeView->set_field_value("DICPROPPKID", $userRequest->Parameter("fkid"));
            //
            
        break;
    }
    //
    //	Error test
    if (false == $success) {
        //---------------------------------------------------------------------
        //	Error Handler:
        //
        $scopeView->set_error_value("DBERRNUMBER", $database->errorNumber());
        $scopeView->set_error_value("DBERRSTRING", $database->errorString());
        //
        if (is_object($property)) {
            // Check critical errors
            if (($property->get_error_value("DICPROPPKID") == true)) {
                //
                $viewMode = FAILVIEW;
                $viewHTML = "system.errors.html";
            } else {
                //
                // get input errors
                //
                $scopeView->set_error_value("DATAERRORSET", $property->errorSet());
                $scopeView->set_error_value("DATAFIELDSET", $property->fieldSet());
                //
                $formMark = "error";
                $viewMode = $failMode;
                $viewHTML = $failHTML;
            }
        }
        //
        $forwardView = $scopeView;
        //
        //---------------------------------------------------------------------
        
    } else {
        //---------------------------------------------------------------------
        //	Reset handler
        if (($postback == true) && ($reset == true)) $template->assign_global("_POSTVERB_", "$__verb");
        //
        //	View Handler
        switch ($__view) {
            case "view":
                //
                $viewMode = ITEMVIEW;
                //
                if ($postback == true) {
                    //
                    @include_once (COMPONENTS_VIEW . "view.DictionaryPropertyExplorer.php");
                    //
                    $forwardView = new DictionaryPropertyExplorer();
                    $forwardView->set_field_value("DICPROPPKID", $userRequest->Parameter("fkid"));
                    //
                    $viewHTML = "DictionaryProperty-$__view.html";
                } else {
                    //
                    $forwardView = $scopeView;
                    //
                    $viewHTML = "$__ctrl-$__view.html";
                }
                //
                
            break;
            case "grid":
                //
                $forwardView = $scopeView;
                //
                $viewHTML = "$__ctrl-$__view.html";
                $viewMode = LISTVIEW;
                $formMark = "list";
                //
                
            break;
        }
        //
        //---------------------------------------------------------------------
        
    }
    //-------------------------------------------------------------------------
    //	Display View
    //
    if ($forwardView->renderView($database, $template, $viewHTML, $formMark, $viewMode) == false) {
        if ($forwardView->get_error_count() > 0) {
            //
            $viewMode = FAILVIEW;
            $viewHTML = "action.errors.html";
            //
            @include_once (FRAMEWORK_VIEW . "view.ExceptionView.php");
            //
            $exceptionView = new ExceptionView($forwardView->errorSet());
            $exceptionView->renderView($viewHTML, $formMark, $viewMode);
        }
    }
    //
    //-------------------------------------------------------------------------
    
?>
Return current item: Entier Studio