PageRenderTime 18ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/install/install_step3.php

https://code.google.com/
PHP | 144 lines | 129 code | 10 blank | 5 comment | 36 complexity | c630d406a02592d79fe26b9d4b09c16f MD5 | raw file
  1<?php
  2/**
  3 * @package EDK
  4 */
  5
  6if(!$installrunning) {header('Location: index.php');die();}
  7$stoppage = true;
  8$pass_img = '../img/sta_alliance.png';
  9$fail_img = '../img/sta_horrible.png';
 10$amb_img = '../img/sta_bad.png';
 11global $smarty;
 12$smarty->assign('db_image', $fail_img);
 13
 14if (!empty($_POST['submit']) && $_POST['submit'] == 'Test')
 15{
 16	$_SESSION['sql']['host'] = $_POST['host'];
 17	$_SESSION['sql']['user'] = $_POST['user'];
 18	$_SESSION['sql']['pass'] = $_POST['dbpass'];
 19	$_SESSION['sql']['db'] = $_POST['db'];
 20	$_SESSION['sql']['engine'] = $_POST['engine'];
 21}
 22
 23if (empty($_SESSION['sql']['host']))
 24{
 25	$host = 'localhost';
 26}
 27else $host = $_SESSION['sql']['host'];
 28
 29//check if we already have a config file
 30    
 31if (file_exists('../kbconfig.php') && (empty($_POST['submit']) || $_POST['submit'] != 'Test'))
 32{
 33	if (filesize('../kbconfig.php') > 0)
 34	{
 35		$smarty->assign('conf_exists', true);
 36		$smarty->assign('conf_image', $amb_img);
 37		include_once('../kbconfig.php');
 38		$_SESSION['sql'] = array();
 39		$_SESSION['sql']['host'] = DB_HOST;
 40
 41		if($_SESSION['sql']['host'] != "DB_HOST")
 42		{
 43			$_SESSION['sql']['user'] = DB_USER;
 44			$_SESSION['sql']['pass'] = DB_PASS;
 45			$_SESSION['sql']['db'] = DB_NAME;
 46			$_SESSION['sql']['engine'] = "InnoDB";
 47		}
 48		else {
 49			clearConnectionStrings();
 50			$_SESSION['sql']['host'] = $host;
 51			$smarty->assign('conf_exists', false);
 52		}
 53	}
 54	else
 55	{
 56		clearConnectionStrings();
 57	}
 58}
 59if (empty($_SESSION['sql']['host']))
 60	$smarty->assign('db_host', $host);
 61else $smarty->assign('db_host', $_SESSION['sql']['host']);
 62$smarty->assign('db_user', $_SESSION['sql']['user']);
 63$smarty->assign('db_pass', $_SESSION['sql']['pass']);
 64$smarty->assign('db_db', $_SESSION['sql']['db']);
 65$smarty->assign('db_engine', $_SESSION['sql']['engine']);
 66
 67if ($_SESSION['sql']['db'])
 68{
 69    $db = @mysql_connect($_SESSION['sql']['host'], $_SESSION['sql']['user'], $_SESSION['sql']['pass']);
 70
 71    $smarty->assign('test_db', is_resource($db));
 72    if (is_resource($db))
 73    {
 74	    $result = mysql_query('SELECT VERSION() AS version');
 75	    $result = mysql_fetch_assoc($result);
 76	    $smarty->assign('test_sql', $result);
 77	    if (!$result)
 78	    {
 79		    $stoppage = true;
 80		    $smarty->assign('test_error', mysql_error());
 81	    }
 82	    else
 83	    {
 84		    $smarty->assign('test_version', $result['version']);
 85		    $version_ok = $result['version'] >= "5";
 86		    $smarty->assign("version_ok", $version_ok);
 87		    if (!$version_ok)
 88				$stoppage = true;
 89			else
 90			{
 91				$smarty->assign('test_select', mysql_select_db($_SESSION['sql']['db']));
 92				if (mysql_select_db($_SESSION['sql']['db']))
 93				{
 94					$stoppage = false;
 95					$smarty->assign('db_image', $pass_img);
 96					//InnoDB check
 97					if ($stoppage == false && $_SESSION['sql']['engine'] == 'InnoDB')
 98					{
 99						$smarty->assign('test_inno', true);
100						$stoppage = true;
101
102						$result = mysql_query('SHOW ENGINES;');
103						while (($row = mysql_fetch_row($result)) &&  $stoppage == true){
104							if ($row[0] == 'InnoDB'){
105								if ($row[1] == 'YES' || $row[1] == 'DEFAULT'){ // (YES / NO / DEFAULT)
106									$stoppage = false;
107								}
108							}
109						}
110						if ($stoppage){
111							$smarty->assign('db_image', $fail_img);
112							$smarty->assign('test_error_inno', true);
113						}
114					}
115				}
116				else
117				{
118					$smarty->assign('test_error', mysql_error());
119				}
120		    }
121	    }
122    }
123    else
124    {
125	    $smarty->assign('test_error', mysql_error());
126    }
127}
128$smarty->assign('stoppage', $stoppage);
129$smarty->assign('nextstep', $_SESSION['state']+1);
130$smarty->display('install_step3.tpl');
131
132function clearConnectionStrings()
133{
134	if(!isset($_SESSION['sql']['db']))
135	{
136		$_SESSION['sql'] = array();
137		$_SESSION['sql']['host'] = '';
138		$_SESSION['sql']['user'] = '';
139		$_SESSION['sql']['pass'] = '';
140		$_SESSION['sql']['db'] = '';
141		$_SESSION['sql']['engine'] = '';
142	}
143}
144?>