Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно


Сообщения: 595
Благодарности: 5

Профиль | Отправить PM | Цитировать


PHP код: Выделить весь код

<?php

//==========================================================================//

function form_table($nextstage WELCOME$formaction "install.php") {
    global 
$INSTALL$db;

    
$enablenext true;

    
/// Print the standard form if we aren't in the DOWNLOADLANG page
    /// because it has its own form.
    
if ($nextstage != DOWNLOADLANG) {
        
$needtoopenform false;
?>
        <form id="installform" method="post" action="<?php echo $formaction ?>">
        <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>

<?php
    
} else {
        
$needtoopenform true;
    }
?>
    <table class="install_table" cellspacing="3" cellpadding="3">

<?php
    
/// what we do depends on the stage we're at
    
switch ($nextstage) {
        case 
WELCOME/// Welcome and language settings
?>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('language'?></p></td>
                <td class="td_right">
                <?php choose_from_menu (get_installer_list_of_languages(), 'language'$INSTALL['language'], ''?>
                </td>
            </tr>

<?php
            
break;
        case 
COMPATIBILITY/// Compatibilty check
            
$compatsuccess true;

            
/// Check that PHP is of a sufficient version
            
print_compatibility_row(inst_check_php_version(), get_string('phpversion''install'), get_string('phpversionerror''install'), 'phpversionhelp');
            
$enablenext $enablenext && inst_check_php_version();
            
/// Check session auto start
            
print_compatibility_row(!ini_get_bool('session.auto_start'), get_string('sessionautostart''install'), get_string('sessionautostarterror''install'), 'sessionautostarthelp');
            
$enablenext $enablenext && !ini_get_bool('session.auto_start');
            
/// Check magic quotes
            
print_compatibility_row(!ini_get_bool('magic_quotes_runtime'), get_string('magicquotesruntime''install'), get_string('magicquotesruntimeerror''install'), 'magicquotesruntimehelp');
            
$enablenext $enablenext && !ini_get_bool('magic_quotes_runtime');
            
/// Check unsupported PHP configuration
            
print_compatibility_row(!ini_get_bool('register_globals'), get_string('globalsquotes''install'), get_string('globalswarning''install'));
            
$enablenext $enablenext && !ini_get_bool('register_globals');
            
/// Check safe mode
            
print_compatibility_row(!ini_get_bool('safe_mode'), get_string('safemode''install'), get_string('safemodeerror''install'), 'safemodehelp'true);
            
/// Check file uploads
            
print_compatibility_row(ini_get_bool('file_uploads'), get_string('fileuploads''install'), get_string('fileuploadserror''install'), 'fileuploadshelp'true);
            
/// Check GD version
            
print_compatibility_row(check_gd_version(), get_string('gdversion''install'), get_string('gdversionerror''install'), 'gdversionhelp'true);
            
/// Check memory limit
            
print_compatibility_row(check_memory_limit(), get_string('memorylimit''install'), get_string('memorylimiterror''install'), 'memorylimithelp'true);


            break;
        case 
DIRECTORY/// Directory settings
?>

            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('wwwroot''install'?></p></td>
                <td class="td_right">
                    <input type="text" size="40"name="wwwrootform" value="<?php p($INSTALL['wwwrootform'],true?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('dirroot''install'?></p></td>
                <td class="td_right">
                    <input type="text" size="40" name="dirrootform" disabled="disabled" value="<?php p($INSTALL['dirrootform'],true?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('dataroot''install'?></p></td>
                <td class="td_right">
                    <input type="text" size="40" name="dataroot" value="<?php p($INSTALL['dataroot'],true?>" />
                </td>
            </tr>

<?php
            
break;
        case 
DATABASE/// Database settings
?>

            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('dbtype''install'?></p></td>
                <td class="td_right">
                <?php choose_from_menu (array('mysql' => get_string('mysql''install'),
                                              
'mysqli' => get_string('mysqli''install'),
                                              
'oci8po' => get_string('oci8po''install'),
                                              
'postgres7' => get_string('postgres7''install'),
                                              
'mssql' => get_string('mssql''install'),
                                              
'mssql_n' => get_string('mssql_n''install'),
                                              
'odbc_mssql' => get_string('odbc_mssql''install')),
                                        
'dbtype'$INSTALL['dbtype'], '''toggledbinfo();'?>
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('dbhost''install'?></p></td>
                <td class="td_right">
                    <input type="text" class="input_database" name="dbhost" value="<?php p($INSTALL['dbhost']) ?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('database''install'?></p></td>
                <td class="td_right">
                    <input type="text" class="input_database" name="dbname" value="<?php p($INSTALL['dbname']) ?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('user'?></p></td>
                <td class="td_right">
                    <input type="text" class="input_database" name="dbuser" value="<?php p($INSTALL['dbuser']) ?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('password'?></p></td>
                <td class="td_right">
                    <input type="password" class="input_database" name="dbpass" value="<?php p($INSTALL['dbpass']) ?>" />
                </td>
            </tr>
            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('dbprefix''install'?></p></td>
                <td class="td_right">
                    <input type="text" class="input_database" name="prefix" value="<?php p($INSTALL['prefix']) ?>" />
                </td>
            </tr>

<?php
            
break;
        case 
ADMIN/// Administration directory setting
?>

            <tr>
                <td class="td_left"><p class="p_install"><?php print_string('admindirname''install'?></p></td>
                <td class="td_right">
                    <input type="text" size="40" name="admindirname" value="<?php p($INSTALL['admindirname']) ?>" />
                </td>
            </tr>


<?php
            
break;
        case 
ENVIRONMENT/// Environment checks
?>

            <tr>
                <td colspan="2">
                <?php
                    error_reporting
(0);  // Hide errors
                    
$dbconnected $db->Connect($INSTALL['dbhost'],$INSTALL['dbuser'],$INSTALL['dbpass'],$INSTALL['dbname']);
                    
error_reporting(7);  // Show errors
                    
if ($dbconnected) {
                    
/// Execute environment check, printing results
                        
@remove_dir($INSTALL['dataroot'] . '/environment'); /// Always delete downloaded env. info to force use of the released one. MDL-9796
                        
check_moodle_environment($INSTALL['release'], $environment_resultstrue);
                    } else {
                    
/// We never should reach this because DB has been tested before arriving here
                        
$errormsg get_string('dbconnectionerror''install');
                        
$nextstage DATABASE;
                        echo 
'<p class="errormsg" style="text-align:center">'.get_string('dbconnectionerror''install').'</p>';
                    }
                
?>
                </td>
            </tr>

<?php
            
break;
        case 
DOWNLOADLANG/// Download language from download.moodle.org
?>

            <tr>
                <td colspan="2">
                <?php
                
/// Get array of languages, we are going to use it
                    
$languages=get_installer_list_of_languages();
                
/// Print the download form (button) if necessary
                    
if ($INSTALL['showdownloadlangpack'] == true && substr($INSTALL['language'],0,2) != 'en') {
                        
$options = array();
                        
$options['downloadlangpack'] = true;
                        
$options['stage'] = DOWNLOADLANG;
                        
$options['same'] = true;
                        
print_simple_box_start('center');
                        
print_single_button('install.php'$optionsget_string('downloadlanguagebutton','install'$languages[$INSTALL['language']]), 'post');
                        
print_simple_box_end();
                    } else {
                
/// Show result info
                    /// English lang packs aren't downloaded
                        
if (substr($INSTALL['language'],0,2) == 'en') {
                            
print_simple_box(get_string('downloadlanguagenotneeded''install'$languages[$INSTALL['language']]), 'center''80%');
                        } else {
                            if (
$INSTALL['downloadlangpackerror']) {
                                echo 
"<p class=\"errormsg\" align=\"center\">".$INSTALL['downloadlangpackerror']."</p>\n";
                                
print_simple_box(get_string('langdownloaderror''install'$languages[$INSTALL['language']]), 'center''80%');
                            } else {
                                
print_simple_box(get_string('langdownloadok''install'$languages[$INSTALL['language']]), 'center''80%');
                            }
                        }
                    }
                
?>
                </td>
            </tr>

<?php
            
break;
        default:
    }
?>

    <tr>
        <td colspan="<?php echo ($nextstage == COMPATIBILITY) ? 2?>">

<?php
    
if ($needtoopenform) {
?>
            <form id="installform" method="post" action="<?php echo $formaction ?>">
            <div><input type="hidden" name="stage" value="<?php echo $nextstage ?>" /></div>
<?php
    
}

    
$disabled $enablenext '' 'disabled="disabled"';
?>

            <?php echo ($nextstage SAVE) ? "<div><input $disabled type=\"submit\" name=\"next\" value=\"".get_string('next')."  »\" style=\"float: ".fix_align_rtl("right")."\"/></div>\n" " \n" ?>
            <?php echo ($nextstage WELCOME) ? "<div><input type=\"submit\" name=\"prev\" value=\"«  ".get_string('previous')."\" style=\"float: ".fix_align_rtl("left")."\"/></div>\n" " \n" ?>

<?php
    
if ($needtoopenform) {
?>
            </form>
<?php
    
}
?>


        </td>

    </tr>

    </table>
<?php
    
if (!$needtoopenform) {
?>
    </form>
<?php
    
}
?>

<?php
}



//==========================================================================//

function print_compatibility_row($success$testtext$errormessage$helpfield=''$caution=false) {
    echo 
"<tr>\n";
    echo 
"<td class=\"td_left_nowrap\" valign=\"top\"><p class=\"p_install\">$testtext</p></td>\n";
    if (
$success) {
        echo 
"<td valign=\"top\"><p class=\"p_pass\">".get_string('pass''install')."</p></td>\n";
        echo 
"<td valign=\"top\"> </td>\n";
    } else {
        echo 
"<td valign=\"top\">";
        echo (
$caution) ? "<p class=\"p_caution\">".get_string('caution''install') : "<p class=\"p_fail\">".get_string('fail''install');
        echo 
"</p></td>\n";
        echo 
"<td valign=\"top\">";
        echo 
"<p class=\"p_install\">$errormessage ";
        if (
$helpfield !== '') {
            
install_helpbutton("install.php?help=$helpfield");
        }
        echo 
"</p></td>\n";
    }
    echo 
"</tr>\n";
    return 
$success;
}


//==========================================================================//

function install_helpbutton($url$title='') {
    if (
$title == '') {
        
$title get_string('help');
    }
    echo 
"<a href=\"javascript:void(0)\" ";
    echo 
"onclick=\"return window.open('$url','Help','menubar=0,location=0,scrollbars,resizable,width=500,height=400')\"";
    echo 
">";
    echo 
"<img src=\"pix/help.gif\" class=\"iconhelp\" alt=\"$title\" title=\"$title\"/>";
    echo 
"</a>\n";
}



//==========================================================================//

function print_install_help($help) {
    switch (
$help) {
        case 
'phpversionhelp':
            
print_string($help'install'phpversion());
            break;
        case 
'memorylimithelp':
            
print_string($help'install'get_memory_limit());
            break;
        default:
            
print_string($help'install');
    }
}


//==========================================================================//

function get_memory_limit() {
    if (
$limit ini_get('memory_limit')) {
        return 
$limit;
    } else {
        return 
get_cfg_var('memory_limit');
    }
}

//==========================================================================//

function check_memory_limit() {

    
/// if limit is already 40 or more then we don't care if we can change it or not
    
if ((int)str_replace('M'''get_memory_limit()) >= 40) {
        return 
true;
    }

    
/// Otherwise, see if we can change it ourselves
    
raise_memory_limit('40M');
    return ((int)
str_replace('M'''get_memory_limit()) >= 40);
}

//==========================================================================//

function inst_check_php_version() {
    if (!
check_php_version("4.3.0")) {
        return 
false;
    } else if (
check_php_version("5.0.0")) {
        return 
check_php_version("5.1.0"); // 5.0.x is too buggy
    
}
    return 
true// 4.3.x or 4.4.x is fine
}
//==========================================================================//

/* This function returns a list of languages and their full names. The
 * list of available languages is fetched from install/lang/xx/installer.php
 * and it's used exclusively by the installation process
 * @return array An associative array with contents in the form of LanguageCode => LanguageName
 */
function get_installer_list_of_languages() {

    global 
$CFG;

    
$languages = array();

/// Get raw list of lang directories
    
$langdirs get_list_of_plugins('install/lang');
    
asort($langdirs);
/// Get some info from each lang
    
foreach ($langdirs as $lang) {
        if (
file_exists($CFG->dirroot .'/install/lang/'$lang .'/installer.php')) {
            include(
$CFG->dirroot .'/install/lang/'$lang .'/installer.php');
            if (
substr($lang, -5) == '_utf8') {   //Remove the _utf8 suffix from the lang to show
                
$shortlang substr($lang0, -5);
            } else {
                
$shortlang $lang;
            }
            if (
$lang == 'en') {  //Explain this is non-utf8 en
                
$shortlang 'non-utf8 en';
            }
            if (!empty(
$string['thislanguage'])) {
                
$languages[$lang] = $string['thislanguage'] .' ('$shortlang .')';
            }
            unset(
$string);
        }
    }
/// Return array
    
return $languages;
}

//==========================================================================//

function css_styles() {
?>

<style type="text/css">

    body { background-color: #ffeece; }
    p, li, td {
        font-family: helvetica, arial, sans-serif;
        font-size: 10pt;
    }
    a { text-decoration: none; color: blue; }
    a img {
        border: none;
    }
    .errormsg {
        color: red;
        font-weight: bold;
    }
    blockquote {
        font-family: courier, monospace;
        font-size: 10pt;
    }
    .input_database {
        width: 270px;
    }
    .install_table {
        width: 500px;
        margin-left:auto;
        margin-right:auto;
    }
    .td_left {
        text-align: <?php echo fix_align_rtl("right"?>;
        font-weight: bold;
    }
    .td_left_nowrap{
        text-align: <?php echo fix_align_rtl("right"?>;
        font-weight: bold;
        white-space: nowrap;
        width: 160px;
        padding-left: 10px;
    }
    .td_right {
        text-align: <?php echo fix_align_rtl("left"?>;
    }
    .main {
        width: 80%;
        border-width: 1px;
        border-style: solid;
        border-color: #ffc85f;
        margin-left:auto;
        margin-right:auto;
        -moz-border-radius-bottomleft: 15px;
        -moz-border-radius-bottomright: 15px;
    }
    .td_mainheading {
        background-color: #fee6b9;
        padding-left: 10px;
    }
    .td_main {
        text-align: center;
    }
    .td_mainlogo {
        vertical-align: middle;
    }
    .p_mainlogo {
        margin-top: 0px;
        margin-bottom: 0px;
    }
    .p_mainheading {
        font-size: 11pt;
        margin-top: 16px;
        margin-bottom: 16px;
    }
    .p_subheading {
        font-size: 10pt;
        padding-left: 10px;
        margin-top: 16px;
        margin-bottom: 16px;
    }
    .p_mainheader{
        text-align: right; 
        font-size: 20pt;
        font-weight: bold;
        margin-top: 0px;
        margin-bottom: 0px;
    }
    .p_pass {
        color: green;
        font-weight: bold;
        margin-top: 0px;
        margin-bottom: 0px;
    }
    .p_fail {
        color: red;
        font-weight: bold;
        margin-top: 0px;
        margin-bottom: 0px;
    }
    .p_caution {
        color: #ff6600;
        font-weight: bold;
        margin-top: 0px;
        margin-bottom: 0px;
    }
    .p_help {
        text-align: center;
        font-family: helvetica, arial, sans-serif;
        font-size: 14pt;
        font-weight: bold;
        color: #333333;
        margin-top: 0px;
        margin-bottom: 0px;
    }
    /* This override the p tag for every p tag in this installation script,
       but not in lang\xxx\installer.php 
      */
    .p_install {
        margin-top: 0px;
        margin-bottom: 0px; 
    }
    .environmenttable {
        font-size: 10pt;
        border-color: #ffc85f;
    }
    table.environmenttable .error {
        background-color : red;
        color : inherit;
    }

    table.environmenttable .warn {
        background-color : yellow;
    }

    table.environmenttable .ok {
        background-color : lightgreen;
    }
    .header {
        background-color: #fee6b9;
        font-size: 10pt;
    }
    .cell {
        background-color: #ffeece;
        font-size: 10pt;
    }
    .error {
        color: #ff0000;
    }
    .errorboxcontent {
        text-align: center;
        font-weight: bold;
        padding-left: 20px;
        color: #ff0000;
    }
    .invisiblefieldset {
      display:inline;
      border:0px;
      padding:0px;
      margin:0px;
    }
    #mysql, #mysqli, #postgres7, #mssql, #mssql_n, #odbc_mssql, #oci8po {
        display: none;
    }

</style>

<?php
}

//==========================================================================//

function database_js() {
?>

<script type="text/javascript" defer="defer">
function toggledbinfo() {
    //Calculate selected value
    var showid = 'mysql';
    if (document.getElementById('installform').dbtype.value) {
        showid = document.getElementById('installform').dbtype.value;
    }
    if (document.getElementById) {
        //Hide all the divs
        document.getElementById('mysql').style.display = '';
        document.getElementById('mysqli').style.display = '';
        document.getElementById('postgres7').style.display = '';
        document.getElementById('mssql').style.display = '';
        document.getElementById('mssql_n').style.display = '';
        document.getElementById('odbc_mssql').style.display = '';
        document.getElementById('oci8po').style.display = '';
        //Show the selected div
        document.getElementById(showid).style.display = 'block';
    } else if (document.all) {
        //This is the way old msie versions work
        //Hide all the divs
        document.all['mysql'].style.display = '';
        document.all['mysqli'].style.display = '';
        document.all['postgres7'].style.display = '';
        document.all['mssql'].style.display = '';
        document.all['mssql_n'].style.display = '';
        document.all['odbc_mssql'].style.display = '';
        document.all['oci8po'].style.display = '';
        //Show the selected div
        document.all[showid].style.display = 'block';
    } else if (document.layers) {
        //This is the way nn4 works
        //Hide all the divs
        document.layers['mysql'].style.display = '';
        document.layers['mysqli'].style.display = '';
        document.layers['postgres7'].style.display = '';
        document.layers['mssql'].style.display = '';
        document.layers['mssql_n'].style.display = '';
        document.layers['odbc_mssql'].style.display = '';
        document.layers['oci8po'].style.display = '';
        //Show the selected div
        document.layers[showid].style.display = 'block';
    }
}
</script>

<?php
}

/**
 * Add slashes for single quotes and backslashes
 * so they can be included in single quoted string
 * (for config.php)
 */
function addsingleslashes($input){
    return 
preg_replace("/(['\\\])/""\\\\$1"$input);
}
?>


Последний раз редактировалось Sham, 10-03-2010 в 00:49. Причина: оформление


Отправлено: 14:38, 08-03-2010 | #4