2009-01-20 00:54:02 +00:00
<? php defined ( "SYSPATH" ) or die ( "No direct script access." );
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2008 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
if ( installer :: already_installed ()) {
2009-01-20 04:37:55 +00:00
$content = render ( "success.html.php" );
2009-01-20 00:54:02 +00:00
} else {
switch ( $_GET [ "step" ]) {
default :
case "welcome" :
$errors = check_environment ();
if ( $errors ) {
2009-01-20 04:37:55 +00:00
$content = render ( "environment_errors.html.php" , array ( "errors" => $errors ));
2009-01-20 00:54:02 +00:00
} else {
2009-01-20 04:37:55 +00:00
$content = render ( "get_db_info.html.php" );
2009-01-20 00:54:02 +00:00
}
break ;
case "save_db_info" :
$config = array ( "host" => $_POST [ "dbhost" ],
"user" => $_POST [ "dbuser" ],
"password" => $_POST [ "dbpass" ],
"dbname" => $_POST [ "dbname" ],
2009-02-27 19:26:21 +00:00
"prefix" => $_POST [ "prefix" ],
2009-01-22 19:51:52 +00:00
"type" => function_exists ( "mysqli_set_charset" ) ? "mysqli" : "mysql" );
2009-01-20 00:54:02 +00:00
if ( ! installer :: connect ( $config )) {
2009-01-20 04:37:55 +00:00
$content = render ( "invalid_db_info.html.php" );
2009-01-20 00:54:02 +00:00
} else if ( ! installer :: select_db ( $config )) {
2009-01-20 04:37:55 +00:00
$content = render ( "missing_db.html.php" );
2009-01-20 00:54:02 +00:00
} else if ( ! installer :: db_empty ( $config )) {
2009-01-20 04:37:55 +00:00
$content = render ( "db_not_empty.html.php" );
2009-01-20 00:54:02 +00:00
} else if ( ! installer :: unpack_var ()) {
$content = oops ( "Unable to create files inside the <code>var</code> directory" );
2009-02-27 19:26:21 +00:00
} else if ( ! installer :: unpack_sql ( $config )) {
2009-01-20 00:54:02 +00:00
$content = oops ( "Failed to create tables in your database:" . mysql_error ());
} else if ( ! installer :: create_database_config ( $config )) {
$content = oops ( "Couldn't create var/database.php" );
} else {
2009-02-15 09:14:03 +00:00
try {
list ( $user , $password ) = installer :: create_admin ( $config );
2009-03-08 21:21:09 +00:00
installer :: create_admin_session ( $config );
2009-02-15 09:14:03 +00:00
$content = render ( "success.html.php" , array ( "user" => $user , "password" => $password ));
2009-02-17 07:03:40 +00:00
2009-02-27 19:26:21 +00:00
installer :: create_private_key ( $config );
2009-02-15 09:14:03 +00:00
} catch ( Exception $e ) {
$content = oops ( $e -> getMessage ());
}
2009-01-20 00:54:02 +00:00
}
break ;
}
}
2009-01-20 04:39:24 +00:00
include ( "views/install.html.php" );
2009-01-20 00:54:02 +00:00
2009-01-20 04:37:55 +00:00
function render ( $view , $args = array ()) {
2009-01-20 00:54:02 +00:00
ob_start ();
extract ( $args );
2009-01-20 04:37:55 +00:00
include ( DOCROOT . "installer/views/" . $view );
2009-01-20 00:54:02 +00:00
return ob_get_clean ();
}
function oops ( $error ) {
2009-01-20 04:37:55 +00:00
return render ( "oops.html.php" , array ( "error" => $error ));
2009-01-20 00:54:02 +00:00
}
function check_environment () {
2009-01-22 19:51:52 +00:00
if ( ! function_exists ( "mysql_query" ) && ! function_exists ( "mysqli_set_charset" )) {
2009-01-20 00:54:02 +00:00
$errors [] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the the <a href= \" http://php.net/mysql \" >MySQL</a> or the <a href= \" http://php.net/mysqli \" >MySQLi</a> extension." ;
}
if ( !@ preg_match ( "/^.$/u" , utf8_encode ( " \xF1 " ))) {
$errors [] = "PHP is missing <a href= \" http://php.net/pcre \" >Perl-Compatible Regular Expression</a> support." ;
}
if ( ! ( class_exists ( "ReflectionClass" ))) {
$errors [] = "PHP is missing <a href= \" http://php.net/reflection \" >reflection</a> support" ;
}
if ( ! ( function_exists ( "filter_list" ))) {
$errors [] = "PHP is missing the <a href= \" http://php.net/filter \" >filter extension</a>" ;
}
if ( ! ( extension_loaded ( "iconv" ))) {
$errors [] = "PHP is missing the <a href= \" http://php.net/iconv \" >iconv extension</a>" ;
}
if ( extension_loaded ( "mbstring" ) && ( ini_get ( "mbstring.func_overload" ) & MB_OVERLOAD_STRING )) {
$errors [] = "The <a href= \" http://php.net/mbstring \" >mbstring extension</a> is overloading PHP's native string functions. Please disable it." ;
}
return $errors ;
}