Location: PHPKode > projects > Entier Studio > entierstudio/office/handlers/ctrl.DirectoryProject.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.office
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 * @version	   $Id: ctrl.DirectoryProject.php 121 2008-03-11 20:17:41Z yannromefort $
 */
//-------------------------------------------------------------------------
// Safe mode
if (!defined('__ENTIER_FRONT_CONTROLLER__')) die(403);
//
//-------------------------------------------------------------------------
//	Post Handler
//
$project = NULL;
$postback = ($__verb == INSERT_CMD);
$success = true;
//
switch ($__verb) {
    case INSERT_CMD:
        //
        # Insert
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryProject.php");
        //
        $project = new DirectoryProject();
        //
        $project->set_field_value("DIRUNITPKID", $userRequest->Parameter("fkid"));
        //
        $project->set_field_value("DIRPROJNAME", $userRequest->Parameter("name"));
        $project->set_field_value("DIRPROJCODE", $userRequest->Parameter("code"));
        $project->set_field_value("DIRPROJPATH", $userRequest->Parameter("path"));
        $project->set_field_value("DIRPROJTEXT", $userRequest->Parameter("text"));
        $project->set_field_value("DIRPROJSTAT", $userRequest->Parameter("stat"));
        //
        $success = $project->insertRow($database);
        if (true == $success) {
            // insert default user
            //
            @include_once (COMPONENTS_DATA . "data.DirectoryProjectUser.php");
            //
            $user = new DirectoryProjectUser();
            //
            $user->set_field_value("DIRPROJPKID", $project->get_field_value("DIRPROJPKID"));
            $user->set_field_value("DIRUSERPKID", $userRequest->Parameter("__user"));
            //
            $success = $user->insertRow($database);
            if (false == $success) $project->deleteRow($database);
            else {
                // insert project objectory
                //
                @include_once (COMPONENTS_DATA . "data.Objectory.php");
                //
                $objectory = new Objectory();
                //
                //
                $objectory->set_field_value("DIRPROJPKID", $project->get_field_value("DIRPROJPKID"));
                $objectory->set_field_value("REPTYPEPKID", $userRequest->Parameter("root"));
                //
                $success = $objectory->insertRow($database);
                if (false == $success) {
                    $user->deleteRow($database);
                    $project->deleteRow($database);
                }
            }
        }
        //
        break;
    case UPDATE_CMD:
        //
        # Modify
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryProject.php");
        //
        $project = new DirectoryProject($userRequest->Parameter("pkid"));
        $success = $project->selectRow($database);
        if (true == $success) {
            //
            $project->set_field_value("DIRPROJNAME", $userRequest->Parameter("name"));
            $project->set_field_value("DIRPROJCODE", $userRequest->Parameter("code"));
            $project->set_field_value("DIRPROJPATH", $userRequest->Parameter("path"));
            $project->set_field_value("DIRPROJTEXT", $userRequest->Parameter("text"));
            $project->set_field_value("DIRPROJSTAT", $userRequest->Parameter("stat"));
            //
            $success = $project->updateRow($database);
        }
        //
        break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryProject.php");
        //
        $project = new DirectoryProject($userRequest->Parameter("pkid"));
        $success = $project->selectRow($database);
        if (true == $success) {
            $success = $project->deleteRow($database);
        }
        //
        break;
    case STATUS_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryProject.php");
        //
        $project = new DirectoryProject($userRequest->Parameter("pkid"));
        $success = $project->selectRow($database);
        if (true == $success) {
            $success = $project->updateRow($database, DISPLAYKEY);
        }
        //
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	View Helper invocation
    //
    @include_once (COMPONENTS_VIEW . "view.DirectoryProjectExplorer.php");
    //
    $projectView = new DirectoryProjectExplorer($template, $database);
    //
    //	Mode Handler
    //
    $viewMode = NULLVIEW;
    $failMode = NULLVIEW;
    $failHTML = "";
    $formMark = "";
    //
    if ($userLogin->checkUserRights(AUTH_SITE_SUPER)) $failHTML = "$__ctrl-$__fail.super.html";
    else {
        if ($userLogin->checkUserRights(AUTH_PROJ_CREATE)) $failHTML = "$__ctrl-$__fail.power.html";
        else $failHTML = "$__ctrl-$__fail.guest.html";
    }
    //
    switch ($__mode) {
        case "form":
            //
            $failMode = FORMVIEW;
            //
            $projectView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
            //
            
        break;
        case "view":
            //
            $failMode = ITEMVIEW;
            //
            $projectView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
            $projectView->set_field_value("DIRPROJPKID", $userRequest->Parameter("pkid"));
            //
            
        break;
        case "list":
            //
            $failMode = ($__verb == INSERT_CMD) ? FORMVIEW : ITEMVIEW;
            //
            $projectView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
            $projectView->set_field_value("DIRPROJPKID", $userRequest->Parameter("pkid"));
            $projectView->set_field_value("DIRUNITPKID", $userRequest->Parameter("fkid"));
            $projectView->set_field_value("LISTVIEWSRT", $userRequest->Parameter("sort"));
            $projectView->set_field_value("LISTVIEWORD", $userRequest->Parameter("ord"));
            //
            
        break;
    }
    //
    //-------------------------------------------------------------------------
    //	Error test
    if (false == $success) {
        //---------------------------------------------------------------------
        //	Error Handler:
        //
        $projectView->set_error_value("DBERRNUMBER", $database->errorNumber());
        $projectView->set_error_value("DBERRSTRING", $database->errorString());
        //
        if (is_object($project)) {
            //
            // Check critical errors
            if (($project->get_error_value("DIRPROJPKID") == true)) {
                //
                $viewMode = ERROR;
                $viewHTML = "system.errors.html";
            } else {
                //
                // get input errors
                //
                $projectView->set_error_value("DATAFIELDSET", $project->fieldSet());
                $projectView->set_error_value("DATAERRORSET", $project->errorSet());
                //
                $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":
                //
                if ($userLogin->checkUserRights(AUTH_SITE_SUPER)) $viewHTML = "$__ctrl-$__view.super.html";
                else {
                    if ($userLogin->checkUserRights(AUTH_PROJ_CREATE)) $viewHTML = "$__ctrl-$__view.power.html";
                    else $viewHTML = "$__ctrl-$__view.guest.html";
                }
                //
                $viewMode = FORMVIEW;
                //
                break;
            case "view":
                //
                if ($userLogin->checkUserRights(AUTH_SITE_SUPER)) $viewHTML = "$__ctrl-$__view.super.html";
                else {
                    if ($userLogin->checkUserRights(AUTH_PROJ_MODIFY)) $viewHTML = "$__ctrl-$__view.power.html";
                    else $viewHTML = "$__ctrl-$__view.guest.html";
                }
                //
                $viewMode = ITEMVIEW;
                //
                break;
            case "pane":
                //
                $viewHTML = "$__ctrl-$__view.html";
                //
                $viewMode = ITEMVIEW;
                $formMark = "list";
                //
                break;
            case "list":
                //
                if ($userLogin->checkUserRights(AUTH_SITE_SUPER)) $viewHTML = "$__ctrl-$__view.super.html";
                else {
                    if ($userLogin->checkUserRights(AUTH_PROJ_DELETE)) $viewHTML = "$__ctrl-$__view.power.html";
                    else $viewHTML = "$__ctrl-$__view.guest.html";
                }
                //
                $viewMode = LISTVIEW;
                $formMark = "list";
                //
                break;
            case "grid":
                //
                $viewHTML = "$__ctrl-$__view.html";
                //
                $viewMode = GRIDVIEW;
                $formMark = "list";
                //
                break;
            }
            //
            //---------------------------------------------------------------------
            
        }
        //-------------------------------------------------------------------------
        //	Display View
        //
        if ($projectView->renderView($viewHTML, $formMark, $viewMode) == false) {
            if ($projectView->get_error_count() > 0) {
                //
                @include_once (FRAMEWORK_VIEW . "view.ExceptionView.php");
                //
                $exceptionView = new ExceptionView($projectView->errorSet());
                $exceptionView->renderView($viewHTML, $formMark, $viewMode);
            }
        }
        //
        //-------------------------------------------------------------------------
        
?>
Return current item: Entier Studio