Toolbox::commonCheckForUseGLPI PHP Méthode

commonCheckForUseGLPI() static public méthode

Common Checks needed to use GLPI
static public commonCheckForUseGLPI ( ) : 2
Résultat 2
    static function commonCheckForUseGLPI()
    {
        global $CFG_GLPI;
        $error = 0;
        // Title
        echo "<tr><th>" . __('Test done') . "</th><th >" . __('Results') . "</th></tr>";
        // Parser test
        echo "<tr class='tab_bg_1'><td class='b left'>" . __('Testing PHP Parser') . "</td>";
        // PHP Version  - exclude PHP3, PHP 4 and zend.ze1 compatibility
        if (version_compare(PHP_VERSION, GLPI_MIN_PHP) >= 0) {
            // PHP version ok, now check PHP zend.ze1_compatibility_mode
            if (ini_get("zend.ze1_compatibility_mode") == 1) {
                $error = 2;
                echo "<td class='red'>\n                  <img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('GLPI is not compatible with the option zend.ze1_compatibility_mode = On.') . "</td>";
            } else {
                echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . sprintf(__s('PHP version is at least %s - Perfect!'), GLPI_MIN_PHP) . "\"\n                       title=\"" . sprintf(__s('PHP version is at least %s - Perfect!'), GLPI_MIN_PHP) . "\"></td>";
            }
        } else {
            // PHP <5
            $error = 2;
            echo "<td class='red'>\n               <img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . sprintf(__('You must install at least PHP %s.'), GLPI_MIN_PHP) . "</td>";
        }
        echo "</tr>";
        // session test
        echo "<tr class='tab_bg_1'><td class='b left'>" . __('Sessions test') . "</td>";
        // check whether session are enabled at all!!
        if (!extension_loaded('session')) {
            $error = 2;
            echo "<td class='red b'>" . __('Your parser PHP is not installed with sessions support!') . "</td>";
        } else {
            if (isset($_SESSION["Test_session_GLPI"]) && $_SESSION["Test_session_GLPI"] == 1 || isset($_SESSION["glpi_currenttime"])) {
                // From Update
                echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Sessions support is available - Perfect!') . "\" title=\"" . __s('Sessions support is available - Perfect!') . "\"></td>";
            } else {
                if ($error != 2) {
                    echo "<td class='red'>";
                    echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/warning_min.png'>" . __('Make sure that sessions support has been activated in your php.ini') . "</td>";
                    $error = 1;
                }
            }
        }
        echo "</tr>";
        // Test for session auto_start
        if (ini_get('session.auto_start') == 1) {
            echo "<tr class='tab_bg_1'><td class='b'>" . __('Test session auto start') . "</td>";
            echo "<td class='red'>";
            echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('session.auto_start is activated. See .htaccess file in the GLPI root for more information.') . "</td></tr>";
            $error = 2;
        }
        // Test for option session use trans_id loaded or not.
        echo "<tr class='tab_bg_1'>";
        echo "<td class='left b'>" . __('Test if Session_use_trans_sid is used') . "</td>";
        if (isset($_POST[session_name()]) || isset($_GET[session_name()])) {
            echo "<td class='red'>";
            echo "<img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . __('You must desactivate the Session_use_trans_id option in your php.ini') . "</td>";
            $error = 2;
        } else {
            echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\" title=\"" . __s('Ok - the sessions works (no problem with trans_id) - Perfect!') . "\"></td>";
        }
        echo "</tr>";
        $extensions_to_check = ['mysqli' => ['required' => true], 'ctype' => ['required' => true, 'function' => 'ctype_digit'], 'fileinfo' => ['required' => true, 'class' => 'finfo'], 'json' => ['required' => true, 'function' => 'json_encode'], 'mbstring' => ['required' => true], 'zlib' => ['required' => true], 'curl' => ['required' => true], 'gd' => ['required' => false], 'ldap' => ['required' => false], 'imap' => ['required' => false]];
        //check for PHP extensions
        foreach ($extensions_to_check as $ext => $params) {
            $success = true;
            if (isset($params['function'])) {
                if (!function_exists($params['function'])) {
                    $success = false;
                }
            } else {
                if (isset($param['class'])) {
                    if (!class_exists($params['class'])) {
                        $success = false;
                    }
                } else {
                    if (!extension_loaded($ext)) {
                        $success = false;
                    }
                }
            }
            echo "<tr class=\"tab_bg_1\"><td class=\"left b\">" . sprintf(__('%s extension test'), $ext) . "</td>";
            if ($success) {
                $msg = sprintf(__('%s extension is installed'), $ext);
                echo "<td><img src=\"{$CFG_GLPI['root_doc']}/pics/ok_min.png\"\n                    alt=\"{$msg}\"\n                    title=\"{$msg}\"></td>";
            } else {
                if (isset($params['required']) && $params['required'] === true) {
                    if ($error < 2) {
                        $error = 2;
                    }
                    echo "<td class=\"red\"><img src=\"{$CFG_GLPI['root_doc']}/pics/ko_min.png\"> " . sprintf(__('%s extension is missing'), $ext) . "</td>";
                } else {
                    if ($error < 1) {
                        $error = 1;
                    }
                    echo "<td><img src=\"{$CFG_GLPI['root_doc']}/pics/warning_min.png\"> " . sprintf(__('%s extension is not present'), $ext) . "</td>";
                }
            }
            echo "</tr>";
        }
        // memory test
        echo "<tr class='tab_bg_1'><td class='left b'>" . __('Allocated memory test') . "</td>";
        //Get memory limit
        $mem = self::getMemoryLimit();
        switch (self::checkMemoryLimit()) {
            case 0:
                // memory_limit not compiled -> no memory limit
            // memory_limit not compiled -> no memory limit
            case 1:
                // memory_limit compiled and unlimited
                echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Unlimited memory - Perfect!') . "\" title=\"" . __s('Unlimited memory - Perfect!') . "\"></td>";
                break;
            case 2:
                //Insufficient memory
                $showmem = $mem / 1048576;
                echo "<td class='red'><img src='" . $CFG_GLPI['root_doc'] . "/pics/ko_min.png'>" . "<span class='b'>" . sprintf(__('%1$s: %2$s'), __('Allocated memory'), sprintf(__('%1$s %2$s'), $showmem, __('Mio'))) . "</span>" . "<br>" . __('A minimum of 64Mio is commonly required for GLPI.') . "<br>" . __('Try increasing the memory_limit parameter in the php.ini file.') . "</td>";
                $error = 2;
                break;
            case 3:
                //Got enough memory, going to the next step
                echo "<td><img src='" . $CFG_GLPI['root_doc'] . "/pics/ok_min.png' alt=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\" title=\"" . __s('Allocated memory > 64Mio - Perfect!') . "\"></td>";
                break;
        }
        echo "</tr>";
        $suberr = Config::checkWriteAccessToDirs();
        if ($suberr > $error) {
            $error = $suberr;
        }
        $suberr = self::checkSELinux();
        if ($suberr > $error) {
            $error = $suberr;
        }
        return $error;
    }

Usage Example

function step1($update)
{
    global $CFG_GLPI;
    $error = 0;
    echo "<h3>" . __s('Checking of the compatibility of your environment with the execution of GLPI') . "</h3>";
    echo "<table class='tab_check'>";
    $error = Toolbox::commonCheckForUseGLPI();
    echo "</table>";
    switch ($error) {
        case 0:
            echo "<form action='install.php' method='post'>";
            echo "<input type='hidden' name='update' value='" . $update . "'>";
            echo "<input type='hidden' name='language' value='" . $_SESSION['glpilanguage'] . "'>";
            echo "<p class='submit'><input type='hidden' name='install' value='Etape_1'>";
            echo "<input type='submit' name='submit' class='submit' value=\"" . __('Continue') . "\">";
            echo "</p>";
            Html::closeForm();
            break;
        case 1:
            echo "<h3>" . __('Do you want to continue?') . "</h3>";
            echo "<div class='submit'><form action='install.php' method='post' class='inline'>";
            echo "<input type='hidden' name='install' value='Etape_1'>";
            echo "<input type='hidden' name='update' value='" . $update . "'>";
            echo "<input type='hidden' name='language' value='" . $_SESSION['glpilanguage'] . "'>";
            echo "<input type='submit' name='submit' class='submit' value=\"" . __('Continue') . "\">";
            Html::closeForm();
            echo "&nbsp;&nbsp;";
            echo "<form action='install.php' method='post' class='inline'>";
            echo "<input type='hidden' name='update' value='" . $update . "'>";
            echo "<input type='hidden' name='language' value='" . $_SESSION['glpilanguage'] . "'>";
            echo "<input type='hidden' name='install' value='Etape_0'>";
            echo "<input type='submit' name='submit' class='submit' value=\"" . __('Try again') . "\">";
            Html::closeForm();
            echo "</div>";
            break;
        case 2:
            echo "<h3>" . __('Do you want to continue?') . "</h3>";
            echo "<form action='install.php' method='post'>";
            echo "<input type='hidden' name='update' value='" . $update . "'>";
            echo "<p class='submit'><input type='hidden' name='install' value='Etape_0'>";
            echo "<input type='submit' name='submit' class='submit' value=\"" . __('Try again') . "\">";
            echo "</p>";
            Html::closeForm();
            break;
    }
}
All Usage Examples Of Toolbox::commonCheckForUseGLPI