Location: PHPKode > projects > Entier Studio > entierstudio/office/handlers/ctrl.DirectoryUser.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.DirectoryUser.php 81 2008-01-17 23:08:21Z yannromefort $
 */
//-------------------------------------------------------------------------
// Safe mode
if (!defined('__ENTIER_FRONT_CONTROLLER__')) die(403);
//
//----------------------------------------------------------------------------
//	Post Handler
//
$user = NULL;
$postback = ($__verb == INSERT_CMD);
$success = true;
//
//
switch ($__verb) {
    case INSERT_CMD:
        //
        # Insert
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryUser.php");
        //
        $user = new DirectoryUser();
        //
        //
        $user->set_field_value("DIRUNITPKID", $userRequest->Parameter("fkid"));
        //
        $user->set_field_value("DIRUSERNAME", $userRequest->Parameter("name"));
        $user->set_field_value("DIRUSERSIGN", $userRequest->Parameter("sign"));
        $user->set_field_value("DIRUSERPASS", $userRequest->Parameter("pass"));
        $user->set_field_value("DIRUSERMAIL", $userRequest->Parameter("mail"));
        $user->set_field_value("DIRUSERSTAT", $userRequest->Parameter("stat"));
        //
        $success = $user->insertRow($database);
        //
        
    break;
    case UPDATE_CMD:
        //
        # Modify
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryUser.php");
        //
        $user = new DirectoryUser($userRequest->Parameter("pkid"));
        $success = $user->selectRow($database);
        if (true == $success) {
            //
            $user->set_authorization($userRequest->Parameter("rights"));
            //
            $user->set_field_value("DIRUSERNAME", $userRequest->Parameter("name"));
            $user->set_field_value("DIRUSERSIGN", $userRequest->Parameter("sign"));
            $user->set_field_value("DIRUSERPASS", $userRequest->Parameter("pass"));
            $user->set_field_value("DIRUSERMAIL", $userRequest->Parameter("mail"));
            $user->set_field_value("DIRUSERSTAT", $userRequest->Parameter("stat"));
            //
            $success = $user->updateRow($database);
        }
        //
        
    break;
    case DELETE_CMD:
        //
        # Delete
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryUser.php");
        //
        $user = new DirectoryUser($userRequest->Parameter("pkid"));
        $success = $user->selectRow($database);
        if (true == $success) {
            $success = $user->deleteRow($database);
        }
        //
        
    break;
    case STATUS_CMD:
        //
        # Update
        //
        @include_once (COMPONENTS_DATA . "data.DirectoryUser.php");
        //
        $user = new DirectoryUser($userRequest->Parameter("pkid"));
        $success = $user->selectRow($database);
        if (true == $success) {
            $success = $user->updateRow($database, DISPLAYKEY);
        }
        //
        
    break;
}
//
//-------------------------------------------------------------------------
//	View Helper invocation
//
@include_once (COMPONENTS_VIEW . "view.DirectoryUserExplorer.php");
//
$userView = new DirectoryUserExplorer($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;
        //
        $userView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
        //
        
    break;
    case "view":
        //
        $failMode = ITEMVIEW;
        //
        $userView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
        $userView->set_field_value("DIRUSERPKID", $userRequest->Parameter("pkid"));
        //
        
    break;
    case "list":
        //
        $failMode = ($__verb == INSERT_CMD) ? FORMVIEW : ITEMVIEW;
        //
        $userView->set_field_value("LOGUSERPKID", $userRequest->Parameter("__user"));
        $userView->set_field_value("DIRUSERPKID", $userRequest->Parameter("pkid"));
        $userView->set_field_value("DIRUNITPKID", $userRequest->Parameter("fkid"));
        $userView->set_field_value("LISTVIEWSRT", $userRequest->Parameter("sort"));
        $userView->set_field_value("LISTVIEWORD", $userRequest->Parameter("ord"));
        //
        
    break;
}
//
//-------------------------------------------------------------------------
//	Error test
if (false == $success) {
    //---------------------------------------------------------------------
    //	Error Handler:
    //
    $userView->set_error_value("DBERRNUMBER", $database->errorNumber());
    $userView->set_error_value("DBERRSTRING", $database->errorString());
    //
    if (is_object($user)) {
        //
        // Check critical errors
        if (($user->get_error_value("DIRUSERPKID") == true)) {
            //
            $viewMode = ERROR;
            $viewHTML = "system.errors.html";
        } else {
            //
            // get input errors
            //
            $userView->set_error_value("DATAFIELDSET", $user->fieldSet());
            $userView->set_error_value("DATAERRORSET", $user->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_USER_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_USER_MODIFY)) $viewHTML = "$__ctrl-$__view.power.html";
                else $viewHTML = "$__ctrl-$__view.guest.html";
            }
            //
            $viewMode = ITEMVIEW;
            //
            break;
        case "pane":
            //
            $viewHTML = "$__ctrl-$__view.html";
            //
            $viewMode = ITEMVIEW;
            //
            break;
        case "list":
            //
            if ($userLogin->checkUserRights(AUTH_SITE_SUPER)) $viewHTML = "$__ctrl-$__view.super.html";
            else {
                if ($userLogin->checkUserRights(AUTH_USER_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 ($userView->renderView($viewHTML, $formMark, $viewMode) == false) {
        if ($userView->get_error_count() > 0) {
            //
            @include_once (FRAMEWORK_VIEW . "view.ExceptionView.php");
            //
            $exceptionView = new ExceptionView($userView->errorSet());
            $exceptionView->renderView($viewHTML, $formMark, $viewMode);
        }
    }
    //
    //-------------------------------------------------------------------------
    
?>
Return current item: Entier Studio