Location: PHPKode > projects > Entier Studio > entierstudio/studio/handlers/ctrl.RepositoryElementExport.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.RepositoryElementExport.php 81 2008-01-17 23:08:21Z 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.TemporaryElement.php");
        @include_once (COMPONENTS_DATA . "data.ObjectoryElement.php");
        //
        $element = new TemporaryElement();
        //
        $element->set_field_value("OBJELEMPKID", $userRequest->Parameter("link"));
        $element->set_field_value("REPMELEPKID", $userRequest->Parameter("bind"));
        //
        if ($element->selectRow($database, FOREIGNKEY) == false) {
            //
            $element->set_field_value("OBJECTOPKID", $userRequest->Parameter("fkid"));
            $element->set_field_value("OBJETYPPKID", $userRequest->Parameter("type"));
            $element->set_field_value("REPCELEPKID", $userRequest->Parameter("core"));
            $element->set_field_value("TMPELEMNAME", $userRequest->Parameter("name"));
            $element->set_field_value("TMPELEMCODE", $userRequest->Parameter("code"));
            $element->set_field_value("TMPELEMINAM", $userRequest->Parameter("inam"));
            $element->set_field_value("TMPELEMRANK", $userRequest->Parameter("rank"));
            $element->set_field_value("TMPELEMTEXT", $userRequest->Parameter("text"));
            //
            $success = $element->insertRow($database);
            if (true == $success) {
                //
                $pkid = $element->get_field_value("TMPELEMPKID");
                //	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.TemporaryElementPropertyValue.php");
                    //
                    for ($i = 0;$i < count($pvals);$i++) {
                        //
                        if (!empty($pvals[$i]) && (true == $success)) {
                            //
                            $property = new TemporaryElementPropertyValue();
                            //
                            $property->set_field_value(TMPELEMPKID, $pkid); // Temporary element
                            $property->set_field_value(DICPROPPKID, $props[$i]); // Dictionary property
                            $property->set_field_value(DICPVALPKID, $pvals[$i]); // Dictionary property value
                            $property->set_field_value(TMPEPRODATA, $pdats[$i]); // Objectory property value data
                            $property->set_field_value(TMPEPROTYPE, 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.TemporaryElementPropertyValue.php");
                    //
                    for ($i = 0;$i < count($cvals);$i++) {
                        //
                        if (!empty($cvals[$i]) && (true == $success)) {
                            //
                            $property = new TemporaryElementPropertyValue();
                            //
                            $property->set_field_value(TMPELEMPKID, $pkid); // Temporary element
                            $property->set_field_value(DICPROPPKID, $crops[$i]); // Dictionary property
                            $property->set_field_value(DICPVALPKID, $cvals[$i]); // Dictionary property value
                            $property->set_field_value(TMPEPRODATA, $cdats[$i]); // Objectory property value data
                            $property->set_field_value(TMPEPROTYPE, 2); // Objectory property type
                            //
                            $success = $property->insertRow($database);
                            //
                            unset($property);
                        }
                    }
                }
            }
        }
        //
        
    break;
    case UPDATE_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.TemporaryElement.php");
        //
        $element = new TemporaryElement($userRequest->Parameter("pkid"));
        $success = $element->selectRow($database);
        if (true == $success) {
            //
            $reset = ($element->get_field_value("TMPELEMCODE") != trim($userRequest->Parameter("code")));
            //
            $element->set_field_value("TMPELEMNAME", $userRequest->Parameter("name"));
            $element->set_field_value("TMPELEMCODE", $userRequest->Parameter("code"));
            $element->set_field_value("TMPELEMINAM", $userRequest->Parameter("inam"));
            $element->set_field_value("TMPELEMTEXT", $userRequest->Parameter("text"));
            $element->set_field_value("TMPELEMRANK", $userRequest->Parameter("rank"));
            //
            $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.TemporaryElementReference.php");
                            //
                            $reference = new TemporaryElementReference();
                            //
                            $reference->set_field_value("TMPELEMPKID", $element->get_field_value("TMPELEMPKID"));
                            //
                            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("TMPELEMRFID", $userRequest->Parameter("end1"));
                                    $reference->set_field_value("TMPELEMLINK", $element->get_field_value("TMPELEMLINK"));
                                    $reference->set_field_value("OBJERETPKID", $referenceType->get_field_value("OBJERETPKID"));
                                    //
                                    $success = $reference->insertRow($database);
                                }
                            } else {
                                // Update reference
                                $reference->set_field_value("TMPELEMRFID", $userRequest->Parameter("end1"));
                                //
                                $success = $reference->updateRow($database, FOREIGNKEY);
                            }
                        }
                        //
                        
                    break;
                }
                //
                // * Properties update
                //	Delete all existing properties values 4 element
                @include_once (COMPONENTS_DATA . "data.TemporaryElementPropertyValueSet.php");
                //
                $propertySet = new TemporaryElementPropertyValueSet($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.TemporaryElementPropertyValue.php");
                        //
                        for ($i = 0;$i < count($pvals);$i++) {
                            //
                            if (!empty($pvals[$i]) && (true == $success)) {
                                //
                                $property = new TemporaryElementPropertyValue();
                                //
                                $property->set_field_value(TMPELEMPKID, $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(TMPEPRODATA, $pdats[$i]); // Objectory property value data
                                $property->set_field_value(TMPEPROTYPE, 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.TemporaryElementPropertyValue.php");
                        //
                        for ($i = 0;$i < count($cvals);$i++) {
                            //
                            if (!empty($cvals[$i]) && (true == $success)) {
                                //
                                $property = new TemporaryElementPropertyValue();
                                //
                                $property->set_field_value(TMPELEMPKID, $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(TMPEPRODATA, $cdats[$i]); // Objectory property value data
                                $property->set_field_value(TMPEPROTYPE, 2); // Objectory property type
                                //
                                $success = $property->insertRow($database);
                                //
                                unset($property);
                            }
                        }
                    }
                }
            }
        }
        //
        
    break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.TemporaryElement.php");
        //
        $element = new TemporaryElement($userRequest->Parameter("dkey"));
        $success = $element->selectRow($database);
        if (true == $success) $element->deleteRow($database);
        $reset = $success;
        //
        break;
    case STATUS_CMD:
        //
        # Update status=0
        //
        //
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	View Handler
    //
    @include_once (COMPONENTS_VIEW . "view.RepositoryModelElementExporter.php");
    //
    $elementView = new RepositoryModelElementExporter();
    //
    //	Mode Handler
    //
    $viewMode = NULLVIEW;
    $failMode = NULLVIEW;
    $viewHTML = "";
    $failHTML = "";
    $formMark = "";
    //
    switch ($__mode) {
        case "form":
            //
            $failMode = FORMVIEW;
            $failHTML = "$__ctrl-$__fail.html";
            //
            $elementView->set_field_value("TMPELEMPKID", $userRequest->Parameter("pkid"));
            $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("link"));
            $elementView->set_field_value("REPMELEPKID", $userRequest->Parameter("bind"));
            $elementView->set_field_value("TMPPROCSTEP", $userRequest->Parameter("step"));
            //
            if (($__verb == INSERT_CMD) && (true == $success)) $elementView->set_field_value("REPMELEPKID", $element->get_field_value("REPMELEPKID"));
            //
            break;
        case "view":
            //
            $failMode = ITEMVIEW;
            $failHTML = "$__ctrl-$__fail.html";
            //
            $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("link"));
            //
            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("OBJETYPPKID") == true) || ($element->get_error_value("OBJELEMROOT") == true) || ($element->get_error_value("OBJELEMLINK") == true) || ($element->get_error_value("OBJECTOPKID") == 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;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    
                break;
                case "view":
                    //
                    $viewMode = ITEMVIEW;
                    $viewHTML = "$__ctrl-$__view.$type.html";
                    //
                    $elementView->set_field_value("REPMELEPKID", $userRequest->Parameter("bind"));
                    //
                    
                break;
                case "pane":
                    //
                    $viewMode = PANEVIEW;
                    $viewHTML = "$__ctrl-$__view.$type.html";
                    //
                    $elementView->set_field_value("TMPPROCSTEP", $userRequest->Parameter("step"));
                    $elementView->set_field_value("REPMELEPKID", $userRequest->Parameter("bind"));
                    $elementView->set_field_value("TMPPREFNAME", $userRequest->Parameter("name"));
                    $elementView->set_field_value("TMPPREFCODE", $userRequest->Parameter("code"));
                    $elementView->set_field_value("TMPPREFINAM", $userRequest->Parameter("inam"));
                    $elementView->set_field_value("USEPREFNAME", ($userRequest->Parameter("namepref") == "on"));
                    $elementView->set_field_value("USEPREFCODE", ($userRequest->Parameter("codepref") == "on"));
                    $elementView->set_field_value("USEPREFINAM", ($userRequest->Parameter("inampref") == "on"));
                    //
                    
                break;
                case "proc":
                    //
                    $viewMode = PROCVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    $elementView->set_field_value("TMPPROCSTEP", $userRequest->Parameter("step"));
                    $elementView->set_field_value("REPMELEPKID", $userRequest->Parameter("bind"));
                    $elementView->set_field_value("TMPPREFNAME", $userRequest->Parameter("name"));
                    $elementView->set_field_value("TMPPREFCODE", $userRequest->Parameter("code"));
                    $elementView->set_field_value("TMPPREFINAM", $userRequest->Parameter("inam"));
                    $elementView->set_field_value("_POSTVERB_", 1);
                    //
                    
                break;
                case "grid":
                    //
                    $viewMode = LISTVIEW;
                    $viewHTML = "$__ctrl-$__view.$type.html";
                    $formMark = array(
                        "list",
                        "tree"
                    );
                    //
                    $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("pkid"));
                    //
                    
                break;
                case "tree":
                    //
                    $viewMode = TREEVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    $formMark = array(
                        "root",
                        "tree",
                        "base",
                        "list"
                    );
                    //
                    $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("pkid"));
                    $elementView->set_field_value("REPOSITPKID", $userRequest->Parameter("root"));
                    //
                    
                break;
                case "menu":
                    //
                    $viewMode = MENUVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("link"));
                    $elementView->set_field_value("TMPPROCSTEP", $userRequest->Parameter("step"));
                    //
                    
                break;
                case "frame":
                    //
                    $viewMode = FRAMEVIEW;
                    $viewHTML = "$__ctrl-$__view.html";
                    //
                    $elementView->set_field_value("OBJELEMPKID", $userRequest->Parameter("pkid"));
                    $elementView->set_field_value("OBJETYPPKID", $userRequest->Parameter("type"));
                    //
                    
                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