Location: PHPKode > projects > Entier Studio > entierstudio/install.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
 * @version	   $Id: install.php 104 2008-02-07 21:30:22Z yannromefort $
 * @copyright  Copyright (c) 2006 Entier Studio team. All rights reserved.
 */
//-------------------------------------------------------------------------
# Configuration file
@require ("./config/cfg.config.php");
#
//-------------------------------------------------------------------------
# User Request
//
@include_once (FRAMEWORK_DIR . "httprequest.php");
//
$userRequest = new HttpRequest(HTTP_VARS_REQUEST);
#
//-------------------------------------------------------------------------
# Template locator
//
@include_once (FRAMEWORK_DIR . "viewtemplate.locator.php");
//
$template = &ViewTemplateLocator::getInstance();
#
//-------------------------------------------------------------------------
# User Browser
@include_once (FRAMEWORK_DIR . "userbrowser.php");
//
$userBrowser = new UserBrowser();
$template->assign_global("USERBROWSER", $userBrowser->Browser());
#
//-------------------------------------------------------------------------
# Post handler
//
@include_once (CLASSES_DIR . "view.EntierStudioInstaller.php");
//
$installerView = new EntierStudioInstaller($template, NULL);
//
$step = $userRequest->Parameter("step");
$step = (isset($step) ? $step : 1);
//
switch ($step) {
    case 5:
        // HTML Template : install.5.html
        $step = 6;
        //        
    break;
    case 6:
        // HTML Template : install.4.html
        @include_once (CLASSES_DIR . "proc.DbInstallation.php");
        //
        $dbInstall = new DBInstallation($userRequest->Parameter("host") , $userRequest->Parameter("port") , $userRequest->Parameter("user") , $userRequest->Parameter("pass") , $userRequest->Parameter("base"));
        //
        if ($dbInstall->checkParameters() == true) {
            //
            if ($dbInstall->createDatabase() == true) {
                if ($dbInstall->createConfigFile() == false) {
                    // configuration file creation failed
                    $step = 5;
                    //
                    $installerView->set_field_value("DBINSTHOST", $userRequest->Parameter("host"));
                    $installerView->set_field_value("DBINSTPORT", $userRequest->Parameter("port"));
                    $installerView->set_field_value("DBINSTUSER", $userRequest->Parameter("user"));
                    $installerView->set_field_value("DBINSTPASS", $userRequest->Parameter("pass"));
                    $installerView->set_field_value("DBINSTBASE", $userRequest->Parameter("base"));
                    $installerView->set_error_value("DBINSTSTEP", 3);
                } else {
                    // next step
                    $step = 6;
                }
            } else {
                //database creation failed
                $step = 4;
                $installerView->set_error_value("DBINSTSTEP", 2);
                $installerView->set_error_value("DBERRORNUM", $dbInstall->errorNumber());
                $installerView->set_error_value("DBERRORSTR", $dbInstall->errorString());
                $installerView->set_error_value("DBERRORQRY", $dbInstall->queryString());
            }
        } else {
            // wrong parameters
            $step = 4;
            $installerView->set_error_value("DBINSTSTEP", 1);
            $installerView->set_error_value("DBERRORNUM", $dbInstall->errorNumber());
        }
        //        
    break;
    case 7:
        // HTML Template : install.6.html
        //-----------------------------------------------------------------
        # Database locator
        //
        @include_once (FRAMEWORK_DIR . "datasource.locator.php");
        //
        $database = &DataSourceLocator::getInstance();
        #
        //-----------------------------------------------------------------
        //
        # Insert
        //
        @include_once (CLASSES_DIR . "data.DirectoryUser.php");
        //
        $team = null;
        $user = new DirectoryUser($userRequest->Parameter("pkid"));        
        //
        $user->set_field_value("DIRUNITPKID", $userRequest->Parameter("fkid"));
        //
        $user->set_field_value("DIRUSERSIGN", $userRequest->Parameter("sign"));
        $user->set_field_value("DIRUSERPASS", $userRequest->Parameter("pass"));
        $user->set_field_value("DIRUSERNAME", $userRequest->Parameter("name"));
        $user->set_field_value("DIRUSERMAIL", $userRequest->Parameter("mail"));
        //
        $success = $user->updateRow($database);
        if (true == $success) {
            //
            @include_once (CLASSES_DIR . "data.DirectoryTeam.php");
            //
            $team = new DirectoryTeam($userRequest->Parameter("fkid"));
            //
            $team->set_field_value("DIRUNITNAME", $userRequest->Parameter("team"));
            //
            $success = $team->updateRow($database);
        }
        //
        if (true == $success) {
            //
            $step = 7;
        } else {
            //
            //---------------------------------------------------------------------
            //	Error Handler:
            //
            $installerView->set_error_value("DBERRNUMBER", $database->errorNumber());
            $installerView->set_error_value("DBERRSTRING", $database->errorString());
            if (is_object($user)) {
                $installerView->set_error_value("DATAERRORSET", $user->errorSet());
                $installerView->set_error_value("DATAFIELDSET", $user->fieldSet());
            }
            if (is_object($team)) {
                $installerView->set_error_value("DATAERRORSET", $team->errorSet());
                $installerView->set_error_value("DATAFIELDSET", $team->fieldSet());
            }
            //
            $step = 6;
        }
        //        
    break;
}
//
if ($installerView->renderView("install.$step.html", NULL, $step) == false) {
    //
    if ($installerView->get_error_count() > 0) {
        //
        $viewMode = FAILVIEW;
        $viewHTML = "action.errors.html";
        //
        @include_once (FRAMEWORK_VIEW . "view.ExceptionView.php");
        //
        $exceptionView = new ExceptionView($installerView->errorSet());
        $exceptionView->renderView($viewHTML, "", $viewMode);
    }
}
//
//-------------------------------------------------------------------------
?>
Return current item: Entier Studio