install/includes/stages/database_mysql.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
child 1379 5cbd678df965
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    13  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    14  */
    14  */
    15 
    15 
    16 if ( !defined('IN_ENANO_INSTALL') )
    16 if ( !defined('IN_ENANO_INSTALL') )
    17   die();
    17 	die();
    18 
    18 
    19 if ( isset($_POST['_cont']) )
    19 if ( isset($_POST['_cont']) )
    20 {
    20 {
    21   $allow_go = true;
    21 	$allow_go = true;
    22   // Do we have everything? If so, continue with installation.
    22 	// Do we have everything? If so, continue with installation.
    23   foreach ( array('db_host', 'db_port', 'db_name', 'db_user', 'db_pass') as $field )
    23 	foreach ( array('db_host', 'db_port', 'db_name', 'db_user', 'db_pass') as $field )
    24   {
    24 	{
    25     if ( empty($_POST[$field]) )
    25 		if ( empty($_POST[$field]) )
    26     {
    26 		{
    27       $allow_go = false;
    27 			$allow_go = false;
    28     }
    28 		}
    29   }
    29 	}
    30   if ( $allow_go )
    30 	if ( $allow_go )
    31   {
    31 	{
    32     require( ENANO_ROOT . '/install/includes/stages/database_post.php' );
    32 		require( ENANO_ROOT . '/install/includes/stages/database_post.php' );
    33     return true;
    33 		return true;
    34   }
    34 	}
    35 }
    35 }
    36 
    36 
    37 if ( isset($_POST['ajax_test']) )
    37 if ( isset($_POST['ajax_test']) )
    38 {
    38 {
    39   // Test the database connection
    39 	// Test the database connection
    40   $return = array(
    40 	$return = array(
    41       'can_install' => false,
    41 			'can_install' => false,
    42       'host_good' => true,
    42 			'host_good' => true,
    43       'creating_user' => false,
    43 			'creating_user' => false,
    44       'db_exist' => false,
    44 			'db_exist' => false,
    45       'creating_db' => false,
    45 			'creating_db' => false,
    46       'creating_db_grant' => false,
    46 			'creating_db_grant' => false,
    47       'root_fail' => false,
    47 			'root_fail' => false,
    48       'version' => array(
    48 			'version' => array(
    49         'version' => 'unknown',
    49 				'version' => 'unknown',
    50         'good' => 'indeterminate'
    50 				'good' => 'indeterminate'
    51       ),
    51 			),
    52       'last_error' => ''
    52 			'last_error' => ''
    53     );
    53 		);
    54   
    54 	
    55   if ( !isset($_POST['info']) )
    55 	if ( !isset($_POST['info']) )
    56     die();
    56 		die();
    57   
    57 	
    58   $info = $_POST['info'];
    58 	$info = $_POST['info'];
    59   
    59 	
    60   // From here on out will be JSON responses
    60 	// From here on out will be JSON responses
    61   header('Content-type: application/json');
    61 	header('Content-type: application/json');
    62   
    62 	
    63   try
    63 	try
    64   {
    64 	{
    65     $info = @enano_json_decode($info);
    65 		$info = @enano_json_decode($info);
    66   }
    66 	}
    67   catch ( Zend_Json_Exception $e )
    67 	catch ( Zend_Json_Exception $e )
    68   {
    68 	{
    69     die(enano_json_encode(array(
    69 		die(enano_json_encode(array(
    70         'mode' => 'error',
    70 				'mode' => 'error',
    71         'error' => 'Exception in JSON decoder'
    71 				'error' => 'Exception in JSON decoder'
    72       )));
    72 			)));
    73   }
    73 	}
    74   
    74 	
    75   if ( preg_match('/^:/', $info['db_host']) && !@file_exists(substr($info['db_host'], 1)) )
    75 	if ( preg_match('/^:/', $info['db_host']) && !@file_exists(substr($info['db_host'], 1)) )
    76   {
    76 	{
    77     $return['host_good'] = false;
    77 		$return['host_good'] = false;
    78     echo enano_json_encode($return);
    78 		echo enano_json_encode($return);
    79     exit();
    79 		exit();
    80   }
    80 	}
    81   
    81 	
    82   if ( $info['db_host'] == 'localhost' && !empty($info['db_port']) && $info['db_port'] != 3306 )
    82 	if ( $info['db_host'] == 'localhost' && !empty($info['db_port']) && $info['db_port'] != 3306 )
    83     $info['db_host'] = '127.0.0.1';
    83 		$info['db_host'] = '127.0.0.1';
    84   
    84 	
    85   $dbhost = ( preg_match('/^:/', $info['db_host']) ) ? $info['db_host'] : "{$info['db_host']}:{$info['db_port']}";
    85 	$dbhost = ( preg_match('/^:/', $info['db_host']) ) ? $info['db_host'] : "{$info['db_host']}:{$info['db_port']}";
    86   
    86 	
    87   // Try to connect as the normal user
    87 	// Try to connect as the normal user
    88   $test = @mysql_connect($dbhost, $info['db_user'], $info['db_pass']);
    88 	$test = @mysql_connect($dbhost, $info['db_user'], $info['db_pass']);
    89   if ( !$test )
    89 	if ( !$test )
    90   {
    90 	{
    91     $return['creating_user'] = true;
    91 		$return['creating_user'] = true;
    92     $return['last_error'] = mysql_error();
    92 		$return['last_error'] = mysql_error();
    93     if ( strstr( $return['last_error'], 'Lost connection' ) || strstr( $return['last_error'], 'Unknown MySQL server host' ) )
    93 		if ( strstr( $return['last_error'], 'Lost connection' ) || strstr( $return['last_error'], 'Unknown MySQL server host' ) )
    94     {
    94 		{
    95       $return['host_good'] = false;
    95 			$return['host_good'] = false;
    96     }
    96 		}
    97     // Doing that failed. If we have root credentials, test those
    97 		// Doing that failed. If we have root credentials, test those
    98     if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) )
    98 		if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) )
    99     {
    99 		{
   100       // Log in with root rights and if that works, tell 'em we'll reset the password or create
   100 			// Log in with root rights and if that works, tell 'em we'll reset the password or create
   101       // the account if it doesn't exist already. This is done with GRANT ALL PRIVILEGES ON enano_db.*
   101 			// the account if it doesn't exist already. This is done with GRANT ALL PRIVILEGES ON enano_db.*
   102       // etc etc, a little hackish but known to work with MySQL >= 4.1.
   102 			// etc etc, a little hackish but known to work with MySQL >= 4.1.
   103       $test_root = @mysql_connect($dbhost, $info['db_root_user'], $info['db_root_pass']);
   103 			$test_root = @mysql_connect($dbhost, $info['db_root_user'], $info['db_root_pass']);
   104       if ( $test_root )
   104 			if ( $test_root )
   105       {
   105 			{
   106         // We logged in with root rights, assume that we have appropriate permissions.
   106 				// We logged in with root rights, assume that we have appropriate permissions.
   107         // If not, well, the installation will fail. Tough on the user, but creating
   107 				// If not, well, the installation will fail. Tough on the user, but creating
   108         // test databases/users is too risky.
   108 				// test databases/users is too risky.
   109         
   109 				
   110         // Does the database exist?
   110 				// Does the database exist?
   111         $q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test_root);
   111 				$q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test_root);
   112         if ( !$q )
   112 				if ( !$q )
   113         {
   113 				{
   114           // Nope, we'll have to create it
   114 					// Nope, we'll have to create it
   115           $return['creating_db'] = true;
   115 					$return['creating_db'] = true;
   116           $return['last_error'] = mysql_error();
   116 					$return['last_error'] = mysql_error();
   117         }
   117 				}
   118         
   118 				
   119         $version = mysql_get_server_info($test_root);
   119 				$version = mysql_get_server_info($test_root);
   120         $return['version'] = array(
   120 				$return['version'] = array(
   121           'version' => $version,
   121 					'version' => $version,
   122           'good' => version_compare($version, '4.0.17', '>=')
   122 					'good' => version_compare($version, '4.0.17', '>=')
   123         );
   123 				);
   124         
   124 				
   125         $return['can_install'] = ( $return['version']['good'] ) ? true : false;
   125 				$return['can_install'] = ( $return['version']['good'] ) ? true : false;
   126       }
   126 			}
   127       else
   127 			else
   128       {
   128 			{
   129         // Well that helped. Root credentials are bad.
   129 				// Well that helped. Root credentials are bad.
   130         $return['creating_db'] = true;
   130 				$return['creating_db'] = true;
   131         $return['root_fail'] = true;
   131 				$return['root_fail'] = true;
   132       }
   132 			}
   133     }
   133 		}
   134     else
   134 		else
   135     {
   135 		{
   136       // No root credentials, fail out
   136 			// No root credentials, fail out
   137       $return['root_fail'] = true;
   137 			$return['root_fail'] = true;
   138     }
   138 		}
   139   }
   139 	}
   140   else
   140 	else
   141   {
   141 	{
   142     // We're connected; do we have permission to use the database?
   142 		// We're connected; do we have permission to use the database?
   143     $have_database = false;
   143 		$have_database = false;
   144     $q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test);
   144 		$q = @mysql_query('USE `' . mysql_real_escape_string($info['db_name']) . '`;', $test);
   145     if ( $q )
   145 		if ( $q )
   146     {
   146 		{
   147       // Permissions are good and we're all connected. Perform version check...
   147 			// Permissions are good and we're all connected. Perform version check...
   148       $version = mysql_get_server_info($test);
   148 			$version = mysql_get_server_info($test);
   149       $return['version'] = array(
   149 			$return['version'] = array(
   150         'version' => $version,
   150 				'version' => $version,
   151         'good' => version_compare($version, '4.0.17', '>=')
   151 				'good' => version_compare($version, '4.0.17', '>=')
   152       );
   152 			);
   153       
   153 			
   154       $return['can_install'] = ( $return['version']['good'] ) ? true : false;
   154 			$return['can_install'] = ( $return['version']['good'] ) ? true : false;
   155     }
   155 		}
   156     else
   156 		else
   157     {
   157 		{
   158       $return['last_error'] = mysql_error();
   158 			$return['last_error'] = mysql_error();
   159       $return['creating_db'] = true;
   159 			$return['creating_db'] = true;
   160       
   160 			
   161       // We don't have permission to use the database or it doesn't exist.
   161 			// We don't have permission to use the database or it doesn't exist.
   162       // See if we have a root login to work with, if not then fail
   162 			// See if we have a root login to work with, if not then fail
   163       if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) )
   163 			if ( !empty($info['db_root_user']) && !empty($info['db_root_pass']) )
   164       {
   164 			{
   165         // Log in with root rights and if that works, tell 'em we'll create the database.
   165 				// Log in with root rights and if that works, tell 'em we'll create the database.
   166         $test_root = @mysql_connect($dbhost, $info['db_root_user'], $info['db_root_pass']);
   166 				$test_root = @mysql_connect($dbhost, $info['db_root_user'], $info['db_root_pass']);
   167         if ( $test_root )
   167 				if ( $test_root )
   168         {
   168 				{
   169           // We logged in with root rights, assume that we have appropriate permissions.
   169 					// We logged in with root rights, assume that we have appropriate permissions.
   170           // If not, well, the installation will fail. Tough on the user, but creating
   170 					// If not, well, the installation will fail. Tough on the user, but creating
   171           // test databases/users is too risky.
   171 					// test databases/users is too risky.
   172           
   172 					
   173           // See if the database already exists
   173 					// See if the database already exists
   174           $dbname = mysql_real_escape_string($info['db_name']);
   174 					$dbname = mysql_real_escape_string($info['db_name']);
   175           $q = @mysql_query("SHOW DATABASES LIKE '$dbname';", $test_root);
   175 					$q = @mysql_query("SHOW DATABASES LIKE '$dbname';", $test_root);
   176           if ( $q )
   176 					if ( $q )
   177           {
   177 					{
   178             if ( mysql_num_rows($q) > 0 )
   178 						if ( mysql_num_rows($q) > 0 )
   179             {
   179 						{
   180               $return['creating_db'] = false;
   180 							$return['creating_db'] = false;
   181               $return['creating_db_grant'] = true;
   181 							$return['creating_db_grant'] = true;
   182             }
   182 						}
   183             @mysql_free_result($q);
   183 						@mysql_free_result($q);
   184           }
   184 					}
   185           
   185 					
   186           $version = mysql_get_server_info($test);
   186 					$version = mysql_get_server_info($test);
   187           $return['version'] = array(
   187 					$return['version'] = array(
   188             'version' => $version,
   188 						'version' => $version,
   189             'good' => version_compare($version, '4.0.17', '>=')
   189 						'good' => version_compare($version, '4.0.17', '>=')
   190           );
   190 					);
   191           
   191 					
   192           $return['can_install'] = ( $return['version']['good'] ) ? true : false;
   192 					$return['can_install'] = ( $return['version']['good'] ) ? true : false;
   193         }
   193 				}
   194         else
   194 				else
   195         {
   195 				{
   196           // Well that helped. Root credentials are bad.
   196 					// Well that helped. Root credentials are bad.
   197           $return['creating_db'] = true;
   197 					$return['creating_db'] = true;
   198           $return['root_fail'] = true;
   198 					$return['root_fail'] = true;
   199         }
   199 				}
   200       }
   200 			}
   201       // No root credentials, fail out
   201 			// No root credentials, fail out
   202     }
   202 		}
   203   }
   203 	}
   204   
   204 	
   205   if ( isset($test) && @is_resource($test) )
   205 	if ( isset($test) && @is_resource($test) )
   206     @mysql_close($test);
   206 		@mysql_close($test);
   207   
   207 	
   208   if ( isset($test_root) && @is_resource($test_root) )
   208 	if ( isset($test_root) && @is_resource($test_root) )
   209     @mysql_close($test_root);
   209 		@mysql_close($test_root);
   210   
   210 	
   211   echo enano_json_encode($return);
   211 	echo enano_json_encode($return);
   212   
   212 	
   213   exit();
   213 	exit();
   214 }
   214 }
   215 
   215 
   216 $ui->add_header('<script type="text/javascript" src="includes/js/formutils.js"></script>');
   216 $ui->add_header('<script type="text/javascript" src="includes/js/formutils.js"></script>');
   217 $ui->show_header();
   217 $ui->show_header();
   218 
   218 
   219 ?>
   219 ?>
   220 
   220 
   221 <div style="float: right; padding: 10px 0 10px 10px;">
   221 <div style="float: right; padding: 10px 0 10px 10px;">
   222   <img alt="MySQL logo" src="../images/about-powered-mysql.png" />
   222 	<img alt="MySQL logo" src="../images/about-powered-mysql.png" />
   223 </div>
   223 </div>
   224 
   224 
   225 <p><?php echo $lang->get('dbmysql_blurb_needdb'); ?></p>
   225 <p><?php echo $lang->get('dbmysql_blurb_needdb'); ?></p>
   226 <p><?php echo $lang->get('dbmysql_blurb_howtomysql'); ?></p>
   226 <p><?php echo $lang->get('dbmysql_blurb_howtomysql'); ?></p>
   227 <?php
   227 <?php
   228 if ( @file_exists('/etc/enano-is-virt-appliance') )
   228 if ( @file_exists('/etc/enano-is-virt-appliance') )
   229 {
   229 {
   230   echo '<p>
   230 	echo '<p>
   231           ' . $lang->get('database_vm_login_info', array( 'host' => 'localhost', 'user' => 'enano', 'pass' => 'clurichaun', 'name' => 'enano_www1' )) . '
   231 					' . $lang->get('database_vm_login_info', array( 'host' => 'localhost', 'user' => 'enano', 'pass' => 'clurichaun', 'name' => 'enano_www1' )) . '
   232         </p>';
   232 				</p>';
   233 }
   233 }
   234 ?>
   234 ?>
   235 
   235 
   236 <script type="text/javascript">
   236 <script type="text/javascript">
   237 
   237 
   238   var tested = false;
   238 	var tested = false;
   239 
   239 
   240   function verify(field)
   240 	function verify(field)
   241   {
   241 	{
   242     if ( tested && !field )
   242 		if ( tested && !field )
   243       return true;
   243 			return true;
   244     tested = false;
   244 		tested = false;
   245     if ( document.getElementById('verify_error').className != '' )
   245 		if ( document.getElementById('verify_error').className != '' )
   246     {
   246 		{
   247       document.getElementById('verify_error').className = '';
   247 			document.getElementById('verify_error').className = '';
   248       document.getElementById('verify_error').innerHTML = '';
   248 			document.getElementById('verify_error').innerHTML = '';
   249     }
   249 		}
   250     var frm = document.forms.database_info;
   250 		var frm = document.forms.database_info;
   251     // List of fields
   251 		// List of fields
   252     var fields = {
   252 		var fields = {
   253       db_host: frm.db_host,
   253 			db_host: frm.db_host,
   254       db_port: frm.db_port,
   254 			db_port: frm.db_port,
   255       db_name: frm.db_name,
   255 			db_name: frm.db_name,
   256       db_user: frm.db_user,
   256 			db_user: frm.db_user,
   257       db_pass: frm.db_pass,
   257 			db_pass: frm.db_pass,
   258       table_prefix: frm.table_prefix,
   258 			table_prefix: frm.table_prefix,
   259       db_root_user: frm.db_root_user,
   259 			db_root_user: frm.db_root_user,
   260       db_root_pass: frm.db_root_pass
   260 			db_root_pass: frm.db_root_pass
   261     };
   261 		};
   262     var passed = true;
   262 		var passed = true;
   263     // Main validation
   263 		// Main validation
   264     if ( field == fields.db_host || !field )
   264 		if ( field == fields.db_host || !field )
   265     {
   265 		{
   266       var matches = fields.db_host.value.match(/^(([a-z0-9_-]+)((\.([a-z0-9_-]+))*)|:[A-z0-9_:\.\/-]+)$/);
   266 			var matches = fields.db_host.value.match(/^(([a-z0-9_-]+)((\.([a-z0-9_-]+))*)|:[A-z0-9_:\.\/-]+)$/);
   267       document.getElementById('s_db_host').src = ( matches ) ? img_neu : img_bad;
   267 			document.getElementById('s_db_host').src = ( matches ) ? img_neu : img_bad;
   268       if ( !matches )
   268 			if ( !matches )
   269         passed = false;
   269 				passed = false;
   270     }
   270 		}
   271     if ( field == fields.db_port || !field )
   271 		if ( field == fields.db_port || !field )
   272     {
   272 		{
   273       var matches = fields.db_port.value.match(/^[0-9]+$/);
   273 			var matches = fields.db_port.value.match(/^[0-9]+$/);
   274       document.getElementById('s_db_port').src = ( matches ) ? img_neu : img_bad;
   274 			document.getElementById('s_db_port').src = ( matches ) ? img_neu : img_bad;
   275       if ( !matches )
   275 			if ( !matches )
   276         passed = false;
   276 				passed = false;
   277     }
   277 		}
   278     if ( field == fields.db_name || !field )
   278 		if ( field == fields.db_name || !field )
   279     {
   279 		{
   280       var matches = fields.db_name.value.match(/^[A-z0-9_-]+$/);
   280 			var matches = fields.db_name.value.match(/^[A-z0-9_-]+$/);
   281       document.getElementById('s_db_name').src = ( matches ) ? img_neu : img_bad;
   281 			document.getElementById('s_db_name').src = ( matches ) ? img_neu : img_bad;
   282       if ( !matches )
   282 			if ( !matches )
   283         passed = false;
   283 				passed = false;
   284     }
   284 		}
   285     if ( field == fields.db_user || field == fields.db_pass || !field )
   285 		if ( field == fields.db_user || field == fields.db_pass || !field )
   286     {
   286 		{
   287       var matches = fields.db_user.value.match(/^[A-z0-9_-]+$/);
   287 			var matches = fields.db_user.value.match(/^[A-z0-9_-]+$/);
   288       document.getElementById('s_db_auth').src = ( matches ) ? img_neu : img_bad;
   288 			document.getElementById('s_db_auth').src = ( matches ) ? img_neu : img_bad;
   289       if ( !matches )
   289 			if ( !matches )
   290         passed = false;
   290 				passed = false;
   291     }
   291 		}
   292     if ( field == fields.table_prefix || !field )
   292 		if ( field == fields.table_prefix || !field )
   293     {
   293 		{
   294       var matches = fields.table_prefix.value.match(/^[a-z0-9_]*$/);
   294 			var matches = fields.table_prefix.value.match(/^[a-z0-9_]*$/);
   295       document.getElementById('s_table_prefix').src = ( matches ) ? img_good : img_bad;
   295 			document.getElementById('s_table_prefix').src = ( matches ) ? img_good : img_bad;
   296       if ( !matches )
   296 			if ( !matches )
   297         passed = false;
   297 				passed = false;
   298     }
   298 		}
   299     if ( field == fields.db_root_user || field == fields.db_root_pass || !field )
   299 		if ( field == fields.db_root_user || field == fields.db_root_pass || !field )
   300     {
   300 		{
   301       var matches = ( ( fields.db_root_user.value.match(/^[A-z0-9_-]+$/) && fields.db_root_pass.value.match(/^.+$/) ) || fields.db_root_user.value == '' );
   301 			var matches = ( ( fields.db_root_user.value.match(/^[A-z0-9_-]+$/) && fields.db_root_pass.value.match(/^.+$/) ) || fields.db_root_user.value == '' );
   302       document.getElementById('s_db_root').src = ( matches ) ? img_neu : img_bad;
   302 			document.getElementById('s_db_root').src = ( matches ) ? img_neu : img_bad;
   303       if ( !matches )
   303 			if ( !matches )
   304         passed = false;
   304 				passed = false;
   305     }
   305 		}
   306     return passed;
   306 		return passed;
   307   }
   307 	}
   308   
   308 	
   309   function ajaxTestConnection()
   309 	function ajaxTestConnection()
   310   {
   310 	{
   311     if ( !verify() )
   311 		if ( !verify() )
   312     {
   312 		{
   313       document.body.scrollTop = 0;
   313 			document.body.scrollTop = 0;
   314       $('enano-body').effect('shake', {}, 750);
   314 			$('enano-body').effect('shake', {}, 750);
   315       document.getElementById('verify_error').className = 'error-box-mini';
   315 			document.getElementById('verify_error').className = 'error-box-mini';
   316       document.getElementById('verify_error').innerHTML = $lang.get('meta_msg_err_verification');
   316 			document.getElementById('verify_error').innerHTML = $lang.get('meta_msg_err_verification');
   317       return false;
   317 			return false;
   318     }
   318 		}
   319     install_set_ajax_loading();
   319 		install_set_ajax_loading();
   320     
   320 		
   321     var frm = document.forms.database_info;
   321 		var frm = document.forms.database_info;
   322     var connection_info = 'info=' + ajaxEscape(toJSONString({
   322 		var connection_info = 'info=' + ajaxEscape(toJSONString({
   323         db_host: frm.db_host.value,
   323 				db_host: frm.db_host.value,
   324         db_port: frm.db_port.value,
   324 				db_port: frm.db_port.value,
   325         db_name: frm.db_name.value,
   325 				db_name: frm.db_name.value,
   326         db_user: frm.db_user.value,
   326 				db_user: frm.db_user.value,
   327         db_pass: frm.db_pass.value,
   327 				db_pass: frm.db_pass.value,
   328         db_root_user: frm.db_root_user.value,
   328 				db_root_user: frm.db_root_user.value,
   329         db_root_pass: frm.db_root_pass.value
   329 				db_root_pass: frm.db_root_pass.value
   330       }));
   330 			}));
   331     
   331 		
   332     ajaxPost(scriptPath + '/install/install.php?stage=database', connection_info + '&driver=mysql&ajax_test=on&language=' + enano_lang_code[ENANO_LANG_ID], function(ajax)
   332 		ajaxPost(scriptPath + '/install/install.php?stage=database', connection_info + '&driver=mysql&ajax_test=on&language=' + enano_lang_code[ENANO_LANG_ID], function(ajax)
   333       {
   333 			{
   334         if ( ajax.readyState == 4 && ajax.status == 200 )
   334 				if ( ajax.readyState == 4 && ajax.status == 200 )
   335         {
   335 				{
   336           setTimeout('install_unset_ajax_loading();', 750);
   336 					setTimeout('install_unset_ajax_loading();', 750);
   337           // Process response
   337 					// Process response
   338           var response = String(ajax.responseText + '');
   338 					var response = String(ajax.responseText + '');
   339           if ( response.substr(0, 1) != '{' )
   339 					if ( response.substr(0, 1) != '{' )
   340           {
   340 					{
   341             alert('Received an invalid JSON response from the server.');
   341 						alert('Received an invalid JSON response from the server.');
   342             return false;
   342 						return false;
   343           }
   343 					}
   344           response = parseJSON(response);
   344 					response = parseJSON(response);
   345           if ( response.mode == 'error' )
   345 					if ( response.mode == 'error' )
   346           {
   346 					{
   347             return false;
   347 						return false;
   348           }
   348 					}
   349           document.getElementById('e_db_host').innerHTML = '';
   349 					document.getElementById('e_db_host').innerHTML = '';
   350           document.getElementById('e_db_name').innerHTML = '';
   350 					document.getElementById('e_db_name').innerHTML = '';
   351           document.getElementById('e_db_auth').innerHTML = '';
   351 					document.getElementById('e_db_auth').innerHTML = '';
   352           document.getElementById('e_db_root').innerHTML = '';
   352 					document.getElementById('e_db_root').innerHTML = '';
   353           if ( response.can_install )
   353 					if ( response.can_install )
   354           {
   354 					{
   355             tested = true;
   355 						tested = true;
   356             var statuses = ['s_db_host', 's_db_name', 's_db_auth', 's_table_prefix', 's_db_root', 's_mysql_version'];
   356 						var statuses = ['s_db_host', 's_db_name', 's_db_auth', 's_table_prefix', 's_db_root', 's_mysql_version'];
   357             for ( var i in statuses )
   357 						for ( var i in statuses )
   358             {
   358 						{
   359               var img = document.getElementById(statuses[i]);
   359 							var img = document.getElementById(statuses[i]);
   360               if ( img )
   360 							if ( img )
   361                 img.src = img_good;
   361 								img.src = img_good;
   362             }
   362 						}
   363             document.getElementById('e_mysql_version').innerHTML = $lang.get('dbmysql_msg_info_mysql_good');
   363 						document.getElementById('e_mysql_version').innerHTML = $lang.get('dbmysql_msg_info_mysql_good');
   364             document.getElementById('verify_error').className = 'info-box-mini';
   364 						document.getElementById('verify_error').className = 'info-box-mini';
   365             document.getElementById('verify_error').innerHTML = $lang.get('dbmysql_msg_test_success');
   365 						document.getElementById('verify_error').innerHTML = $lang.get('dbmysql_msg_test_success');
   366             if ( response.creating_db )
   366 						if ( response.creating_db )
   367             {
   367 						{
   368               document.getElementById('e_db_name').innerHTML = $lang.get('dbmysql_msg_warn_creating_db');
   368 							document.getElementById('e_db_name').innerHTML = $lang.get('dbmysql_msg_warn_creating_db');
   369             }
   369 						}
   370             if ( response.creating_user )
   370 						if ( response.creating_user )
   371             {
   371 						{
   372               document.getElementById('e_db_auth').innerHTML = $lang.get('dbmysql_msg_warn_creating_user');
   372 							document.getElementById('e_db_auth').innerHTML = $lang.get('dbmysql_msg_warn_creating_user');
   373             }
   373 						}
   374           }
   374 					}
   375           else
   375 					else
   376           {
   376 					{
   377             // Oh dear, oh dear, oh dear, oh dear, oh dear...
   377 						// Oh dear, oh dear, oh dear, oh dear, oh dear...
   378             if ( response.creating_db )
   378 						if ( response.creating_db )
   379             {
   379 						{
   380               document.getElementById('e_db_name').innerHTML = $lang.get('dbmysql_msg_err_mysql_dbexist', { mysql_error: response.last_error });
   380 							document.getElementById('e_db_name').innerHTML = $lang.get('dbmysql_msg_err_mysql_dbexist', { mysql_error: response.last_error });
   381               document.getElementById('s_db_name').src = img_bad;
   381 							document.getElementById('s_db_name').src = img_bad;
   382             }
   382 						}
   383             if ( response.creating_user )
   383 						if ( response.creating_user )
   384             {
   384 						{
   385               document.getElementById('e_db_auth').innerHTML = $lang.get('dbmysql_msg_err_mysql_auth', { mysql_error: response.last_error });
   385 							document.getElementById('e_db_auth').innerHTML = $lang.get('dbmysql_msg_err_mysql_auth', { mysql_error: response.last_error });
   386               document.getElementById('s_db_auth').src = img_bad;
   386 							document.getElementById('s_db_auth').src = img_bad;
   387             }
   387 						}
   388             if ( !response.host_good )
   388 						if ( !response.host_good )
   389             {
   389 						{
   390               document.getElementById('e_db_host').innerHTML = $lang.get('dbmysql_msg_err_mysql_connect', { db_host: frm.db_host.value, mysql_error: response.last_error });
   390 							document.getElementById('e_db_host').innerHTML = $lang.get('dbmysql_msg_err_mysql_connect', { db_host: frm.db_host.value, mysql_error: response.last_error });
   391               document.getElementById('s_db_host').src = img_bad;
   391 							document.getElementById('s_db_host').src = img_bad;
   392             }
   392 						}
   393           }
   393 					}
   394         }
   394 				}
   395       });
   395 			});
   396   }
   396 	}
   397 
   397 
   398 </script>
   398 </script>
   399 
   399 
   400 <form action="install.php?stage=database" method="post" name="database_info">
   400 <form action="install.php?stage=database" method="post" name="database_info">
   401 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" />
   401 <input type="hidden" name="language" value="<?php echo $lang_id; ?>" />
   402 <input type="hidden" name="driver" value="mysql" />
   402 <input type="hidden" name="driver" value="mysql" />
   403 
   403 
   404 <table border="0" cellspacing="0" cellpadding="10" width="100%">
   404 <table border="0" cellspacing="0" cellpadding="10" width="100%">
   405   <tr>
   405 	<tr>
   406     <td colspan="3" style="text-align: center">
   406 		<td colspan="3" style="text-align: center">
   407       <h3><?php echo $lang->get('dbmysql_table_title'); ?></h3>
   407 			<h3><?php echo $lang->get('dbmysql_table_title'); ?></h3>
   408     </td>
   408 		</td>
   409   </tr>
   409 	</tr>
   410   <tr>
   410 	<tr>
   411     <td>
   411 		<td>
   412       <b><?php echo $lang->get('dbmysql_field_hostname_title'); ?></b>
   412 			<b><?php echo $lang->get('dbmysql_field_hostname_title'); ?></b>
   413       <br /><?php echo $lang->get('dbmysql_field_hostname_body'); ?>
   413 			<br /><?php echo $lang->get('dbmysql_field_hostname_body'); ?>
   414       <br /><span style="color: #993300" id="e_db_host"></span>
   414 			<br /><span style="color: #993300" id="e_db_host"></span>
   415     </td>
   415 		</td>
   416     <td>
   416 		<td>
   417       <input onkeyup="verify(this);" tabindex="1" name="db_host" size="30" type="text" />
   417 			<input onkeyup="verify(this);" tabindex="1" name="db_host" size="30" type="text" />
   418     </td>
   418 		</td>
   419     <td>
   419 		<td>
   420       <img id="s_db_host" alt="Good/bad icon" src="../images/checkbad.png" />
   420 			<img id="s_db_host" alt="Good/bad icon" src="../images/checkbad.png" />
   421     </td>
   421 		</td>
   422   </tr>
   422 	</tr>
   423   <tr>
   423 	<tr>
   424     <td>
   424 		<td>
   425       <b><?php echo $lang->get('dbmysql_field_port_title'); ?></b>
   425 			<b><?php echo $lang->get('dbmysql_field_port_title'); ?></b>
   426       <br /><?php echo $lang->get('dbmysql_field_port_body'); ?>
   426 			<br /><?php echo $lang->get('dbmysql_field_port_body'); ?>
   427       <br /><span style="color: #993300" id="e_db_port"></span>
   427 			<br /><span style="color: #993300" id="e_db_port"></span>
   428     </td>
   428 		</td>
   429     <td>
   429 		<td>
   430       <input onkeyup="verify(this);" tabindex="2" name="db_port" size="5" type="text" value="3306" />
   430 			<input onkeyup="verify(this);" tabindex="2" name="db_port" size="5" type="text" value="3306" />
   431     </td>
   431 		</td>
   432     <td>
   432 		<td>
   433       <img id="s_db_port" alt="Good/bad icon" src="../images/checkbad.png" />
   433 			<img id="s_db_port" alt="Good/bad icon" src="../images/checkbad.png" />
   434     </td>
   434 		</td>
   435   </tr>
   435 	</tr>
   436   <tr>
   436 	<tr>
   437     <td>
   437 		<td>
   438       <b><?php echo $lang->get('dbmysql_field_dbname_title'); ?></b><br />
   438 			<b><?php echo $lang->get('dbmysql_field_dbname_title'); ?></b><br />
   439       <?php echo $lang->get('dbmysql_field_dbname_body'); ?><br />
   439 			<?php echo $lang->get('dbmysql_field_dbname_body'); ?><br />
   440       <span style="color: #993300" id="e_db_name"></span>
   440 			<span style="color: #993300" id="e_db_name"></span>
   441     </td>
   441 		</td>
   442     <td>
   442 		<td>
   443       <input onkeyup="verify(this);" tabindex="3" name="db_name" size="30" type="text" />
   443 			<input onkeyup="verify(this);" tabindex="3" name="db_name" size="30" type="text" />
   444     </td>
   444 		</td>
   445     <td>
   445 		<td>
   446       <img id="s_db_name" alt="Good/bad icon" src="../images/checkbad.png" />
   446 			<img id="s_db_name" alt="Good/bad icon" src="../images/checkbad.png" />
   447     </td>
   447 		</td>
   448   </tr>
   448 	</tr>
   449   <tr>
   449 	<tr>
   450     <td>
   450 		<td>
   451       <b><?php echo $lang->get('dbmysql_field_dbauth_title'); ?></b><br />
   451 			<b><?php echo $lang->get('dbmysql_field_dbauth_title'); ?></b><br />
   452       <?php echo $lang->get('dbmysql_field_dbauth_body'); ?><br />
   452 			<?php echo $lang->get('dbmysql_field_dbauth_body'); ?><br />
   453       <span style="color: #993300" id="e_db_auth"></span>
   453 			<span style="color: #993300" id="e_db_auth"></span>
   454     </td>
   454 		</td>
   455     <td>
   455 		<td>
   456       <input onkeyup="verify(this);" tabindex="4" name="db_user" size="30" type="text" /><br />
   456 			<input onkeyup="verify(this);" tabindex="4" name="db_user" size="30" type="text" /><br />
   457       <br />
   457 			<br />
   458       <input name="db_pass" tabindex="5" size="30" type="password" />
   458 			<input name="db_pass" tabindex="5" size="30" type="password" />
   459     </td>
   459 		</td>
   460     <td>
   460 		<td>
   461       <img id="s_db_auth" alt="Good/bad icon" src="../images/checkbad.png" />
   461 			<img id="s_db_auth" alt="Good/bad icon" src="../images/checkbad.png" />
   462     </td>
   462 		</td>
   463   </tr>
   463 	</tr>
   464   <tr>
   464 	<tr>
   465     <td colspan="3" style="text-align: center">
   465 		<td colspan="3" style="text-align: center">
   466       <h3><?php echo $lang->get('database_heading_optionalinfo'); ?></h3>
   466 			<h3><?php echo $lang->get('database_heading_optionalinfo'); ?></h3>
   467     </td>
   467 		</td>
   468   </tr>
   468 	</tr>
   469   <tr>
   469 	<tr>
   470     <td>
   470 		<td>
   471       <b><?php echo $lang->get('dbmysql_field_tableprefix_title'); ?></b><br />
   471 			<b><?php echo $lang->get('dbmysql_field_tableprefix_title'); ?></b><br />
   472       <?php echo $lang->get('dbmysql_field_tableprefix_body'); ?>
   472 			<?php echo $lang->get('dbmysql_field_tableprefix_body'); ?>
   473     </td>
   473 		</td>
   474     <td>
   474 		<td>
   475       <input onkeyup="verify(this);" tabindex="6" name="table_prefix" size="30" type="text" />
   475 			<input onkeyup="verify(this);" tabindex="6" name="table_prefix" size="30" type="text" />
   476     </td>
   476 		</td>
   477     <td>
   477 		<td>
   478       <img id="s_table_prefix" alt="Good/bad icon" src="../images/check.png" />
   478 			<img id="s_table_prefix" alt="Good/bad icon" src="../images/check.png" />
   479     </td>
   479 		</td>
   480   </tr>
   480 	</tr>
   481   <tr>
   481 	<tr>
   482     <td>
   482 		<td>
   483       <b><?php echo $lang->get('dbmysql_field_rootauth_title'); ?></b><br />
   483 			<b><?php echo $lang->get('dbmysql_field_rootauth_title'); ?></b><br />
   484       <?php echo $lang->get('dbmysql_field_rootauth_body'); ?><br />
   484 			<?php echo $lang->get('dbmysql_field_rootauth_body'); ?><br />
   485       <span style="color: #993300" id="e_db_root"></span>
   485 			<span style="color: #993300" id="e_db_root"></span>
   486     </td>
   486 		</td>
   487     <td>
   487 		<td>
   488       <input onkeyup="verify(this);" tabindex="7" name="db_root_user" size="30" type="text" /><br />
   488 			<input onkeyup="verify(this);" tabindex="7" name="db_root_user" size="30" type="text" /><br />
   489       <br />
   489 			<br />
   490       <input onkeyup="verify(this);" tabindex="8" name="db_root_pass" size="30" type="password" />
   490 			<input onkeyup="verify(this);" tabindex="8" name="db_root_pass" size="30" type="password" />
   491     </td>
   491 		</td>
   492     <td>
   492 		<td>
   493       <img id="s_db_root" alt="Good/bad icon" src="../images/check.png" />
   493 			<img id="s_db_root" alt="Good/bad icon" src="../images/check.png" />
   494     </td>
   494 		</td>
   495   </tr>
   495 	</tr>
   496   <tr>
   496 	<tr>
   497     <td>
   497 		<td>
   498       <b><?php echo $lang->get('dbmysql_field_mysqlversion_title'); ?></b>
   498 			<b><?php echo $lang->get('dbmysql_field_mysqlversion_title'); ?></b>
   499     </td>
   499 		</td>
   500     <td id="e_mysql_version">
   500 		<td id="e_mysql_version">
   501       <?php echo $lang->get('dbmysql_field_mysqlversion_blurb_willbechecked'); ?>
   501 			<?php echo $lang->get('dbmysql_field_mysqlversion_blurb_willbechecked'); ?>
   502     </td>
   502 		</td>
   503     <td>
   503 		<td>
   504       <img id="s_mysql_version" alt="Good/bad icon" src="../images/checkunk.png" />
   504 			<img id="s_mysql_version" alt="Good/bad icon" src="../images/checkunk.png" />
   505     </td>
   505 		</td>
   506   </tr>
   506 	</tr>
   507   <tr>
   507 	<tr>
   508     <td>
   508 		<td>
   509       <b><?php echo $lang->get('dbmysql_field_droptables_title'); ?></b><br />
   509 			<b><?php echo $lang->get('dbmysql_field_droptables_title'); ?></b><br />
   510       <?php echo $lang->get('dbmysql_field_droptables_body'); ?>
   510 			<?php echo $lang->get('dbmysql_field_droptables_body'); ?>
   511     </td>
   511 		</td>
   512     <td colspan="2">
   512 		<td colspan="2">
   513       <input type="checkbox" tabindex="9" name="drop_tables" id="dtcheck" />  <label for="dtcheck"><?php echo $lang->get('dbmysql_field_droptables_lbl'); ?></label>
   513 			<input type="checkbox" tabindex="9" name="drop_tables" id="dtcheck" />  <label for="dtcheck"><?php echo $lang->get('dbmysql_field_droptables_lbl'); ?></label>
   514     </td>
   514 		</td>
   515   </tr>
   515 	</tr>
   516   <tr>
   516 	<tr>
   517     <td colspan="3" style="text-align: center">
   517 		<td colspan="3" style="text-align: center">
   518       <input type="button" tabindex="10" value="<?php echo $lang->get('dbmysql_btn_testconnection'); ?>" onclick="ajaxTestConnection();" />
   518 			<input type="button" tabindex="10" value="<?php echo $lang->get('dbmysql_btn_testconnection'); ?>" onclick="ajaxTestConnection();" />
   519       <div id="verify_error"></div>
   519 			<div id="verify_error"></div>
   520     </td>
   520 		</td>
   521   </tr>
   521 	</tr>
   522 
   522 
   523 </table>
   523 </table>
   524 
   524 
   525 <table border="0">
   525 <table border="0">
   526   <tr>
   526 	<tr>
   527     <td>
   527 		<td>
   528       <input type="submit" tabindex="11" value="<?php echo $lang->get('meta_btn_continue'); ?>" onclick="return verify();" name="_cont" />
   528 			<input type="submit" tabindex="11" value="<?php echo $lang->get('meta_btn_continue'); ?>" onclick="return verify();" name="_cont" />
   529     </td>
   529 		</td>
   530     <td>
   530 		<td>
   531       <p>
   531 			<p>
   532         <span style="font-weight: bold;"><?php echo $lang->get('meta_lbl_before_continue'); ?></span><br />
   532 				<span style="font-weight: bold;"><?php echo $lang->get('meta_lbl_before_continue'); ?></span><br />
   533         &bull; <?php echo $lang->get('database_objective_test'); ?><br />
   533 				&bull; <?php echo $lang->get('database_objective_test'); ?><br />
   534         &bull; <?php echo $lang->get('database_objective_uncrypt'); ?>
   534 				&bull; <?php echo $lang->get('database_objective_uncrypt'); ?>
   535       </p>
   535 			</p>
   536     </td>
   536 		</td>
   537   </tr>
   537 	</tr>
   538 </table>
   538 </table>
   539 
   539 
   540 </form>
   540 </form>
   541 
   541 
   542 <script type="text/javascript">
   542 <script type="text/javascript">
   543   verify();
   543 	verify();
   544 </script>
   544 </script>
   545 
   545