Location: PHPKode > projects > Entier Studio > entierstudio/studio/handlers/ctrl.RepositoryCoreElement.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.RepositoryCoreElement.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-------------------------------------------------------------------------
// Safe mode
if (!defined('__ENTIER_FRONT_CONTROLLER__')) die(403);
//
//-------------------------------------------------------------------------
//	Post Request
//
$element = NULL;
$postback = !(empty($__verb));
$success = true;
$reset = false;
//
switch ($__verb) {
    case INSERT_CMD:
        //
        # Insert
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElement.php");
        //
        $element = new RepositoryCoreElement();
        // set fields
        $element->set_field_value("REPOSITPKID", $userRequest->Parameter("root"));
        $element->set_field_value("REPCELTPKID", $userRequest->Parameter("type"));
        $element->set_field_value("REPCELENAME", $userRequest->Parameter("name"));
        $element->set_field_value("REPCELECODE", $userRequest->Parameter("code"));
        $element->set_field_value("REPCELETEXT", $userRequest->Parameter("text"));
        $element->set_field_value("REPCELESTAT", $userRequest->Parameter("stat"));
        //
        $success = $element->insertRow($database);
        $reset = $success;
        //
        if (true == $success) {
            //
            $pkid = $element->get_field_value("REPCELEPKID");
            //
            if (is_array($userRequest->Parameter("pvals"))) {
                //
                $repos = $userRequest->Parameter("repos");
                $pvals = $userRequest->Parameter("pvals");
                $datas = $userRequest->Parameter("datas");
                //
                @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementPropertyValue.php");
                //
                for ($i = 0;$i < count($pvals);$i++) {
                    //
                    if (!empty($pvals[$i]) && (true == $success)) {
                        //
                        $property = new RepositoryCoreElementPropertyValue();
                        //
                        $property->set_field_value("REPCELEPKID", $pkid);
                        $property->set_field_value("REPCEPRPKID", $repos[$i]); // Repository core element property
                        $property->set_field_value("DICPVALPKID", $pvals[$i]); // Dictionary property value
                        $property->set_field_value("REPCEPVDATA", $datas[$i]); // extended value
                        //
                        $success = $property->insertRow($database);
                        //
                        unset($property);
                    }
                }
            }
        }
        //
        
    break;
    case UPDATE_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElement.php");
        //
        $element = new RepositoryCoreElement($userRequest->Parameter("pkid"));
        $success = $element->selectRow($database);
        if (true == $success) {
            //
            $reset = ($element->get_field_value("REPCELENAME") != trim($userRequest->Parameter("name")));
            //
            $element->set_field_value("REPCELENAME", $userRequest->Parameter("name"));
            $element->set_field_value("REPCELECODE", $userRequest->Parameter("code"));
            $element->set_field_value("REPCELETEXT", $userRequest->Parameter("text"));
            $element->set_field_value("REPCELESTAT", $userRequest->Parameter("stat"));
            //
            $success = $element->updateRow($database);
            if (true == $success) {
                //	element properties
                if (is_array($userRequest->Parameter("pvals"))) {
                    //	#Delete all existing properties values
                    @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementPropertyValueSet.php");
                    $properties = new RepositoryCoreElementPropertyValueSet($userRequest->Parameter("pkid"));
                    if ($properties->deleteSet($database) == true) {
                        //
                        $repos = $userRequest->Parameter("repos");
                        $pvals = $userRequest->Parameter("pvals");
                        $datas = $userRequest->Parameter("datas");
                        //
                        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElementPropertyValue.php");
                        //
                        for ($i = 0;$i < count($pvals);$i++) {
                            if (!empty($pvals[$i]) && (true == $success)) {
                                //
                                $property = new RepositoryCoreElementPropertyValue();
                                //
                                $property->set_field_value(REPCELEPKID, $userRequest->Parameter("pkid"));
                                $property->set_field_value(REPCEPRPKID, $repos[$i]); // Repository core element property
                                $property->set_field_value(DICPVALPKID, $pvals[$i]); // Dictionary property value
                                $property->set_field_value(REPCEPVDATA, $datas[$i]); // extended value
                                //
                                $success = $property->insertRow($database);
                                //
                                unset($property);
                            }
                        }
                    }
                }
            }
        }
        //
        
    break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElement.php");
        //
        $element = new RepositoryCoreElement($userRequest->Parameter("dkey"));
        $success = $element->selectRow($database);
        if (true == $success) $success = $element->deleteRow($database);
        $reset = $success;
        //
        break;
    case STATUS_CMD:
        //
        # Update status=0
        //
        @include_once (COMPONENTS_DATA . "data.RepositoryCoreElement.php");
        //
        $element = new RepositoryCoreElement($userRequest->Parameter("dkey"));
        $success = $element->selectRow($database);
        if (true == $success) $success = $element->updateRow($database, DISPLAYKEY);
        $reset = $success;
        //
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	View Handler
    //
    @include_once (COMPONENTS_VIEW . "view.RepositoryCoreElementExplorer.php");
    //
    $elementView = new RepositoryCoreElementExplorer();
    //
    //	Mode Handler
    //
    $viewMode = NULLVIEW;
    $viewHTML = "$__ctrl-$__view.html";
    $failHTML = "$__ctrl-$__fail.html";
    $formMark = "";
    //
    switch ($__mode) {
        case "form":
            //
            $failMode = FORMVIEW;
            //
            $elementView->set_field_value("REPOSITPKID", $userRequest->Parameter("root"));
            $elementView->set_field_value("REPCELTPKID", $userRequest->Parameter("type"));
            //
            if (($__verb == INSERT_CMD) && (true == $success)) $elementView->set_field_value("REPCELEPKID", $element->get_field_value("REPCELEPKID"));
            //
            break;
        case "view":
            //
            $failMode = ITEMVIEW;
            //
            $elementView->set_field_value("REPCELEPKID", $userRequest->Parameter("pkid"));
            //
            break;
        }
        //
        //	Error test
        if (false == $success) {
            //---------------------------------------------------------------------
            //	Post failure
            //
            $elementView->set_error_value("DBERRNUMBER", $database->errorNumber());
            $elementView->set_error_value("DBERRSTRING", $database->errorString());
            //
            if (is_object($element)) {
                // Check critical errors
                if (($element->get_error_value("REPOSITPKID") == true) || ($element->get_error_value("REPCELTPKID") == true)) {
                    //
                    $viewMode = FAILVIEW;
                    $viewHTML = "system.errors.html";
                } else {
                    //
                    // get input errors
                    //
                    $elementView->set_error_value("DATAERRORSET", $element->errorSet());
                    $elementView->set_error_value("DATAFIELDSET", $element->fieldSet());
                    //
                    $formMark = "error";
                    $viewMode = $failMode;
                    $viewHTML = $failHTML;
                }
            }
            //
            //---------------------------------------------------------------------
            
        } else {
            //---------------------------------------------------------------------
            //	Reset handler
            if (($postback == true) && ($reset == true)) $template->assign_global("_POSTVERB_", "$__verb");
            //
            //	View Handler
            switch ($__view) {
                case "form":
                    //
                    $viewMode = FORMVIEW;
                    //
                    
                break;
                case "view":
                    //
                    $viewMode = ITEMVIEW;
                    //
                    
                break;
            }
            //
            //---------------------------------------------------------------------
            
        }
        //-------------------------------------------------------------------------
        //	Display View
        //
        if ($elementView->renderView($database, $template, $viewHTML, $formMark, $viewMode) == false) {
            if ($elementView->get_error_count() > 0) {
                //
                $viewMode = FAILVIEW;
                $viewHTML = "action.errors.html";
                //
                @include_once (FRAMEWORK_VIEW . "view.ExceptionView.php");
                //
                $exceptionView = new ExceptionView($elementView->errorSet());
                $exceptionView->renderView($viewHTML, $formMark, $viewMode);
            }
        }
        //
        //-------------------------------------------------------------------------
        
?>
Return current item: Entier Studio