Location: PHPKode > projects > Entier Studio > entierstudio/studio/handlers/ctrl.ObjectoryElement.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.ObjectoryElement.php 86 2008-01-23 21:54:51Z yannromefort $
 */
//-------------------------------------------------------------------------
// Safe mode
if (!defined('__ENTIER_FRONT_CONTROLLER__')) die(403);
//
//-------------------------------------------------------------------------
//	Post Handler
//
$element = NULL;
$postback = !(empty($__verb));
$success = true;
$reset = false;
//
switch ($__verb) {
    case INSERT_CMD:
        //
        # Insert
        //
        @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
        //
        $element = new ObjectoryElement();
        //
        $element->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
        $element->set_field_value("OBJETYPPKID", $userRequest->Parameter("type"));
        $element->set_field_value("OBJELEMNAME", $userRequest->Parameter("name"));
        $element->set_field_value("OBJELEMCODE", $userRequest->Parameter("code"));
        $element->set_field_value("OBJELEMINAM", $userRequest->Parameter("inam"));
        $element->set_field_value("OBJELEMTEXT", $userRequest->Parameter("text"));
        $element->set_field_value("OBJELEMSTAT", $userRequest->Parameter("stat"));
        // root
        //
        if ($__mode == "form") {
            //
            $element->set_field_value("OBJELEMROOT", $userRequest->Parameter("root"));
            $element->set_field_value("OBJELEMLINK", $userRequest->Parameter("link"));
            $success = $element->insertRow($database, REFLECTKEY);
        } else $success = $element->insertRow($database);
        //
        $reset = $success;
        //
        if (true == $success) {
            //
            switch ($element->get_field_value("OBJETYPPKID")) {
                case ASSOCIATION_TYPE:
                    // Add both association ends
                    // Add end 1
                    $element1 = new ObjectoryElement();
                    $element1->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
                    $element1->set_field_value("OBJETYPPKID", ASSOCIATIONEND_TYPE);
                    $element1->set_field_value("OBJELEMROOT", $userRequest->Parameter("root"));
                    $element1->set_field_value("OBJELEMLINK", $element->get_field_value("OBJELEMPKID"));
                    $element1->set_field_value("OBJELEMNAME", $userRequest->Parameter("name") . " End 1");
                    $element1->set_field_value("OBJELEMCODE", $userRequest->Parameter("code") . "_end1");
                    $element1->set_field_value("OBJELEMINAM", $userRequest->Parameter("inam") . "End1");
                    $element1->set_field_value("OBJELEMRANK", 1);
                    $element1->set_field_value("OBJELEMTEXT", "");
                    //
                    $success = $element1->insertRow($database, REFLECTKEY);
                    if (true == $success) {
                        // Add end 2
                        $element1->set_field_value("OBJELEMNAME", $userRequest->Parameter("name") . " End 2");
                        $element1->set_field_value("OBJELEMCODE", $userRequest->Parameter("code") . "_end2");
                        $element1->set_field_value("OBJELEMINAM", $userRequest->Parameter("inam") . "End2");
                        $element1->set_field_value("OBJELEMRANK", 2);
                        //
                        $success = $element1->insertRow($database, REFLECTKEY);
                    }
                    //
                    
                break;
            }
        }
        //
        break;
    case UPDATE_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
        //
        $element = new ObjectoryElement($userRequest->Parameter("pkid"));
        $success = $element->selectRow($database);
        $reset = $success;
        //
        if (true == $success) {
            //
            $reset = ($element->get_field_value("OBJELEMNAME") != trim($userRequest->Parameter("name"))) || ($element->get_field_value("OBJELEMLINK") != trim($userRequest->Parameter("link")));
            //
            $element->set_field_value("OBJELEMLINK", $userRequest->Parameter("link"));
            //
            $element->set_field_value("OBJELEMNAME", $userRequest->Parameter("name"));
            $element->set_field_value("OBJELEMCODE", $userRequest->Parameter("code"));
            $element->set_field_value("OBJELEMINAM", $userRequest->Parameter("inam"));
            $element->set_field_value("OBJELEMTEXT", $userRequest->Parameter("text"));
            $element->set_field_value("OBJELEMRANK", $userRequest->Parameter("rank"));
            $element->set_field_value("OBJELEMSTAT", $userRequest->Parameter("stat"));
            //
            $success = $element->updateRow($database);
            if (true == $success) {
                // * References update
                switch ($element->get_field_value("OBJETYPPKID")) {
                    case PARAMETER_TYPE: //  Parameter attribute
                        
                    case ASSOCIATIONEND_TYPE:
                        //
                        //	Update references
                        //
                        //if( !empty( $userRequest->Parameter("end1") ) ) // empty problems <ith functions parameters
                        if ($userRequest->Parameter("end1") != "") {
                            // End reference
                            //
                            @include_once (COMPONENTS_DATA . "data.ObjectoryElementReference.php");
                            //
                            $reference = new ObjectoryElementReference();
                            //
                            $reference->set_field_value("OBJELEMPKID", $element->get_field_value("OBJELEMPKID"));
                            //
                            if ($reference->selectRow($database, FOREIGNKEY) == false) {
                                //ObjectoryReferenceType
                                @include_once (COMPONENTS_DATA . "data.ObjectoryElementReferenceType.php");
                                //
                                $referenceType = new ObjectoryElementReferenceType($element->get_field_value("OBJETYPPKID"));
                                $success = $referenceType->selectRow($database, FOREIGNKEY);
                                if (true == $success) {
                                    // Insert reference
                                    $reference->set_field_value("OBJELEMRFID", $userRequest->Parameter("end1"));
                                    $reference->set_field_value("OBJELEMLINK", $element->get_field_value("OBJELEMLINK"));
                                    $reference->set_field_value("OBJERETPKID", $referenceType->get_field_value("OBJERETPKID"));
                                    //
                                    $success = $reference->insertRow($database);
                                }
                            } else {
                                // Update reference
                                $reference->set_field_value("OBJELEMRFID", $userRequest->Parameter("end1"));
                                //
                                $success = $reference->updateRow($database, FOREIGNKEY);
                            }
                        }
                        //
                        
                    break;
                }
                //
                // * Properties update
                //	Delete all existing properties values
                @include_once (COMPONENTS_DATA . "data.ObjectoryElementPropertyValueSet.php");
                //
                $propertySet = new ObjectoryElementPropertyValueSet($userRequest->Parameter("pkid"));
                if ($propertySet->deleteSet($database) == true) {
                    //	element properties
                    if (is_array($userRequest->Parameter("pvals"))) {
                        //
                        $props = $userRequest->Parameter("props");
                        $pvals = $userRequest->Parameter("pvals");
                        $pdats = $userRequest->Parameter("pdats");
                        //
                        @include_once (COMPONENTS_DATA . "data.ObjectoryElementPropertyValue.php");
                        //
                        for ($i = 0;$i < count($pvals);$i++) {
                            //
                            if (!empty($pvals[$i]) && (true == $success)) {
                                //
                                $property = new ObjectoryElementPropertyValue();
                                //
                                $property->set_field_value(OBJELEMPKID, $userRequest->Parameter("pkid"));
                                $property->set_field_value(DICPROPPKID, $props[$i]); // Dictionary property
                                $property->set_field_value(DICPVALPKID, $pvals[$i]); // Dictionary property value
                                $property->set_field_value(OBJEPRODATA, $pdats[$i]); // Objectory property value data
                                $property->set_field_value(OBJEPROTYPE, 1); // Objectory property type
                                //
                                $success = $property->insertRow($database);
                                //
                                unset($property);
                            }
                        }
                    }
                    //
                    //	element constraint
                    if (is_array($userRequest->Parameter("cvals"))) {
                        //
                        $crops = $userRequest->Parameter("crops");
                        $cvals = $userRequest->Parameter("cvals");
                        $cdats = $userRequest->Parameter("cdats");
                        //
                        @include_once (COMPONENTS_DATA . "data.ObjectoryElementPropertyValue.php");
                        //
                        for ($i = 0;$i < count($cvals);$i++) {
                            //
                            if (!empty($cvals[$i]) && (true == $success)) {
                                //
                                $property = new ObjectoryElementPropertyValue();
                                //
                                $property->set_field_value(OBJELEMPKID, $userRequest->Parameter("pkid"));
                                $property->set_field_value(DICPROPPKID, $crops[$i]); // Dictionary property
                                $property->set_field_value(DICPVALPKID, $cvals[$i]); // Dictionary property value
                                $property->set_field_value(OBJEPRODATA, $cdats[$i]); // Objectory property value data
                                $property->set_field_value(OBJEPROTYPE, 2); // Objectory property type
                                //
                                $success = $property->insertRow($database);
                                //
                                unset($property);
                            }
                        }
                    }
                }
            }
        }
        //
        break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
        //
        $element = new ObjectoryElement($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.ObjectoryElement.php");
        //
        $element = new ObjectoryElement($userRequest->Parameter("dkey"));
        $success = $element->selectRow($database);
        if (true == $success) $success = $element->updateRow($database, DISPLAYKEY);
        $reset = $success;
        //
        break;
    case 5:
        //
        # Modify ranks
        //
        @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
        //
        $element = new ObjectoryElement($userRequest->Parameter("link"));
        $success = $element->selectRow($database);
        if (true == $success) {
            //
            @include_once (COMPONENTS_DATA . "data.ObjectoryElementRank.php");
            //
            $pkids = $userRequest->Parameter("pkids");
            $ranks = $userRequest->Parameter("ranks");
            //
            $n = count($pkids);
            for ($i = 0;$i < $n;$i++) {
                //
                $elementRank = new ObjectoryElementRank($pkids[$i], $ranks[$i]);
                $elementRank->updateRow($database);
                unset($elementRank);
            }
        }
        //
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	View Handler
    //
    @include_once (COMPONENTS_VIEW . "view.ObjectoryElementExplorer.php");
    //
    $elementView = new ObjectoryElementExplorer();
    //
    //	Mode Handler
    //
    $viewMode = NULLVIEW;
    $viewHTML = "";
    $failHTML = "";
    $formMark = "";
    //
    switch ($__mode) {
        case "root":
            //
            $failMode = ROOTVIEW;
            $failHTML = "$__ctrl-$__fail.html";
            //
            $elementView->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
            //
            if (($__verb == INSERT_CMD) && (true == $success))
                $elementView->set_field_value("OBJELEMPKID", $element->get_field_value("OBJELEMPKID"));
            //
            break;
        case "form":
            //
            $failMode = FORMVIEW;
            $failHTML = "$__ctrl-$__fail.html";
            //
            $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("link"));
            $elementView->set_field_value("OBJETYPPKID", $userRequest->Parameter("type"));
            //
            if (($__verb == INSERT_CMD) && (true == $success))
                $elementView->set_field_value("OBJELEMPKID", $element->get_field_value("OBJELEMPKID"));
            //
            break;
        case "view":
            //
            $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("pkid"));
            //
            switch ($__view) {
                case "view":
                case "pane":
                    //
                    $failMode = ITEMVIEW;
                    $failHTML = "$__ctrl-$__fail.$type.html";
                    //
                    
                break;
            }
            //
            break;
        }
        //
        //	Error test
        if (false == $success) {
            //---------------------------------------------------------------------
            //	Error Handler:
            //
            $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("OBJECTOPKID") == true) || ($element->get_error_value("OBJELEMROOT") == true) || ($element->get_error_value("OBJELEMLINK") == 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 "root":
                    //
                    $viewMode = ROOTVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    
                break;
                case "form":
                    //
                    $viewMode = FORMVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    
                break;
                case "view":
                case "pane":
                    //
                    $viewMode = ITEMVIEW;
                    $viewHTML = "$__ctrl-$__view.$type.html";
                    //
                    if ($postback == true) //	Reset handler
                       $template->assign_global("_POSTVERB_", "$__verb");
                    //
                    break;
                case "grid":
                    //
                    $viewMode = LISTVIEW;
                    $viewHTML = "$__ctrl-$__view.$type.html";
                    $formMark = "list";
                    //
                    $elementView->set_field_value("OBJELEMLINK", $userRequest->Parameter("link"));
                    $elementView->set_field_value("OBJETYPPKID", $userRequest->Parameter("type"));
                    //
                    break;
                case "tree.rep":
                    //
                    $viewMode = TREEVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    $formMark = array(
                        "list",
                        "tree"
                    );
                    //
                    $elementView->set_field_value("REPMCOMPKID", $userRequest->Parameter("pkid"));
                    $elementView->set_field_value("REPMCOTTYPE", $userRequest->Parameter("type"));
                    $elementView->set_field_value("REPFILELANG", $userRequest->Parameter("lang"));
                    $elementView->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
                    //
                    break;
                case "tree.obj":
                    //
                    $viewMode = TREEVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    $formMark = array(
                        "list",
                        "tree"
                    );
                    //
                    $elementView->set_field_value("OBJCOMPPKID", $userRequest->Parameter("pkid"));
                    $elementView->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
                    $elementView->set_field_value("OBJFILELANG", $userRequest->Parameter("lang"));
                    //
                    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