From cdef6d4211a4c3894e95336a898361c601a19af5 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 11 Mar 2006 00:03:51 +0000 Subject: [PATCH] New-improved installer. Now it allows to download the langpack from download.moodle.org and some other minor tweaks solved. --- install.php | 207 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 143 insertions(+), 64 deletions(-) diff --git a/install.php b/install.php index 96ffb29579..3136f3bbdb 100644 --- a/install.php +++ b/install.php @@ -56,10 +56,19 @@ if ( empty($INSTALL['language']) and empty($_POST['language']) ) { $INSTALL['showskipdbencodingtest'] = false; $INSTALL['skipdbencodingtest'] = false; + $INSTALL['downloadlangpack'] = false; + $INSTALL['showdownloadlangpack'] = true; + $INSTALL['downloadlangpackerror'] = ''; + +/// To be used by the Installer $INSTALL['wwwroot'] = ''; $INSTALL['dirroot'] = dirname(__FILE__); $INSTALL['dataroot'] = dirname(dirname(__FILE__)) . '/moodledata'; +/// To be configured in the Installer + $INSTALL['wwwrootform'] = ''; + $INSTALL['dirrootform'] = dirname(__FILE__); + $INSTALL['admindirname'] = 'admin'; $INSTALL['stage'] = WELCOME; @@ -76,8 +85,10 @@ if (isset($_POST['stage'])) { if ( $goforward = (! empty( $_POST['next'] )) ) { $nextstage = $_POST['stage'] + 1; - } else { + } else if (! empty( $_POST['prev'])) { $nextstage = $_POST['stage'] - 1; + } else if (! empty( $_POST['same'] )) { + $nextstage = $_POST['stage']; } @@ -129,6 +140,7 @@ $db = &ADONewConnection($INSTALL['dbtype']); /// guess the www root if ($INSTALL['wwwroot'] == '') { list($INSTALL['wwwroot'], $xtra) = explode('/install.php', qualified_me()); + $INSTALL['wwwrootform'] = $INSTALL['wwwroot']; } $headstagetext = array(WELCOME => get_string('chooselanguagehead', 'install'), @@ -186,29 +198,26 @@ if ($INSTALL['stage'] == DIRECTORY) { error_reporting(0); - - /// check dirroot - if (($fh = @fopen($INSTALL['dirroot'].'/install.php', 'r')) === false ) { - $CFG->dirroot = dirname(__FILE__); - $INSTALL['dirroot'] = dirname(__FILE__); - $errormsg .= get_string('dirrooterror', 'install').'
'; - } - if ($fh) fclose($fh); - - $CFG->dirroot = $INSTALL['dirroot']; - /// check wwwroot if (ini_get('allow_url_fopen')) { - if (($fh = @fopen($INSTALL['wwwroot'].'/install.php', 'r')) === false) { + if (($fh = @fopen($INSTALL['wwwrootform'].'/install.php', 'r')) === false) { $errormsg .= get_string('wwwrooterror', 'install').'
'; + $INSTALL['wwwrootform'] = $INSTALL['wwwroot']; } } if ($fh) fclose($fh); + + /// check dirroot + if (($fh = @fopen($INSTALL['dirrootform'].'/install.php', 'r')) === false ) { + $errormsg .= get_string('dirrooterror', 'install').'
'; + $INSTALL['dirrootform'] = $INSTALL['dirroot']; + } + if ($fh) fclose($fh); /// check dataroot $CFG->dataroot = $INSTALL['dataroot']; if (make_upload_directory('sessions', false) === false ) { - $errormsg = get_string('datarooterror', 'install').'
'; + $errormsg .= get_string('datarooterror', 'install').'
'; } if ($fh) fclose($fh); @@ -365,6 +374,65 @@ if ($INSTALL['stage'] == ENVIRONMENT) { } } + + +//==========================================================================// + +// Try to download the lang pack if it has been selected + +if ($INSTALL['stage'] == DOWNLOADLANG && $INSTALL['downloadlangpack']) { + + $downloadsuccess = false; + $downloaderror = ''; + + error_reporting(0); // Hide errors + +/// Create necessary lang dir + if (!make_upload_directory('lang', false)) { + $downloaderror = get_string('cannotcreatelangdir', 'error'); + } + +/// Download and install component + if (($cd = new component_installer('http://download.moodle.org', 'lang16', + $INSTALL['language'].'.zip', 'languages.md5', 'lang')) && empty($errormsg)) { + $status = $cd->install(); //returns ERROR | UPTODATE | INSTALLED + switch ($status) { + case ERROR: + if ($cd->get_error() == 'remotedownloadnotallowed') { + $a = new stdClass(); + $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip'; + $a->dest= $CFG->dataroot.'/lang'; + $downloaderror = get_string($cd->get_error(), 'error', $a); + } else { + $downloaderror = get_string($cd->get_error(), 'error'); + } + break; + case UPTODATE: + case INSTALLED: + $downloadsuccess = true; + break; + default: + //We shouldn't reach this point + } + } else { + //We shouldn't reach this point + } + + error_reporting(7); // Show errors + + if ($downloadsuccess) { + $INSTALL['downloadlangpack'] = false; + $INSTALL['showdownloadlangpack'] = false; + $INSTALL['downloadlangpackerror'] = $downloaderror; + } else { + $INSTALL['downloadlangpack'] = false; + $INSTALL['showdownloadlangpack'] = false; + $INSTALL['downloadlangpackerror'] = $downloaderror; + } +} + + + //==========================================================================// /// Display or print the data @@ -390,8 +458,8 @@ if ($nextstage == SAVE) { $str .= '$CFG->prefix = \''.$INSTALL['prefix']."';\r\n"; $str .= "\r\n"; - $str .= '$CFG->wwwroot = \''.$INSTALL['wwwroot']."';\r\n"; - $str .= '$CFG->dirroot = \''.$INSTALL['dirroot']."';\r\n"; + $str .= '$CFG->wwwroot = \''.$INSTALL['wwwrootform']."';\r\n"; + $str .= '$CFG->dirroot = \''.$INSTALL['dirrootform']."';\r\n"; $str .= '$CFG->dataroot = \''.$INSTALL['dataroot']."';\r\n"; $str .= '$CFG->admin = \''.$INSTALL['admindirname']."';\r\n"; $str .= "\r\n"; @@ -559,11 +627,19 @@ function print_object($object) { function form_table($nextstage = WELCOME, $formaction = "install.php") { global $INSTALL, $db; - /// standard lines for all forms + /// Print the standard form if we aren't in the DOWNLOADLANG page + /// because it has its own form. + if ($nextstage != DOWNLOADLANG) { + $needtoopenform = false; ?> +
+ - - + @@ -718,50 +794,30 @@ function form_table($nextstage = WELCOME, $formaction = "install.php") { @@ -776,16 +832,39 @@ function form_table($nextstage = WELCOME, $formaction = "install.php") {

- +

- +
install(); //returns ERROR | UPTODATE | INSTALLED - switch ($status) { - case ERROR: - if ($cd->get_error() == 'remotedownloadnotallowed') { - $a = new stdClass(); - $a->url = 'http://download.moodle.org/lang16/'.$pack.'zip'; - $a->dest= $CFG->dataroot.'/lang'; - $errormsg = get_string($cd->get_error(), 'error', $a); - } else { - $errormsg = get_string($cd->get_error(), 'error'); - } - break; - case UPTODATE: - case INSTALLED: - $downloadsuccess = true; - break; - default: - //We shouldn't reach this point - } + /// 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', $options, get_string('downloadlanguagebutton','install', $languages[$INSTALL['language']]), 'POST'); + print_simple_box_end(); } else { - //We shouldn't reach this point - } - - if (!empty($errormsg)) echo "

$errormsg

\n"; - - error_reporting(7); // Show errors - - if ($downloadsuccess) { - print_simple_box(get_string('langdownloadok', 'install', $INSTALL['language']), 'center'); - } else { - print_simple_box(get_string('langdownloaderror', 'install', $INSTALL['language']), 'center'); + /// 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 "

".$INSTALL['downloadlangpackerror']."

\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%'); + } + } } ?>
+ + + + + \n" : " \n" ?> WELCOME) ? "\n" : " \n" ?> + + + +
+ +