Skip to content

Commit

Permalink
Merge pull request #5 from mverma16/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
mverma16 committed Feb 25, 2016
2 parents 8e53d3c + b86ab0b commit 74648b1
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 75 deletions.
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ function check_have_inno($link)
<p class="wc-setup-actions step">
<a href="#" class="button button-large button-next" style="float: left">Previous</a>

<input type="submit" id="submitme" class="button-primary button button-large button-next" value="Continue" <?php if ($php_ok && $memory_ok && $extensions_ok && $module_ok) {
<input type="submit" id="submitme" name="submit" class="button-primary button button-large button-next" value="Continue" <?php if ($php_ok && $memory_ok && $extensions_ok && $module_ok) {
} else {
?> disabled <?php
} ?>
Expand Down
41 changes: 33 additions & 8 deletions step2.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<?php
$var = isset($_POST['submit']);
$redirect = isset($_GET['return']);
if (!($var || $redirect)) {
header('Location: index.php');
die();
} else {
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

Expand Down Expand Up @@ -45,6 +54,18 @@

<p>
Below you should enter your database connection details. If you’re not sure about these, contact your host.</p>

<?php if (isset($_GET['error_message'])) {
?>
<div class="woocommerce-message woocommerce-tracker " >

<p id="fail"><?= $_GET['error_message']?></p>
</div>
<?php

}
?>


<form action="step2a.php" method="post">
<table>
Expand All @@ -57,14 +78,14 @@
<td>
<div class="side-by-side clearfix moveleftthre">
<div>
<select id="database-type" name="database-type" data-placeholder="Choose a SQL format..." class="chosen-select" style="width:290px;" tabindex="2">
<option value=""></option>
<select id="database-type" name="database-type" data-placeholder="Choose a SQL format..." class="chosen-select" style="width:290px;" tabindex="2" required>
<option name="database-type" value=""></option>


<option value="MySQL">MySQL</option>
<option name="database-type" value="MySQL">MySQL</option>

<option value="mm/dd/yyyy">PgSQL</option>
<option value="SQLSRV">SQLSRV</option>
<!-- <option value="mm/dd/yyyy">PgSQL</option> -->
<!-- <option value="SQLSRV">SQLSRV</option> -->

</select>
</div>
Expand Down Expand Up @@ -224,15 +245,15 @@

</table>

</form>

</div>

<br>
<form action="step2a.php" method="post">

<div class="border-line">
<p class="wc-setup-actions step">
<a href="index.php" class="button button-large button-next" style="float: left">Previous</a>
<input type="submit" id="submitme" class="button-primary button button-large button-next" value="Continue">
<input type="submit" name="submit" id="submitme" class="button-primary button button-large button-next" value="Continue">

</p>

Expand Down Expand Up @@ -364,3 +385,7 @@


</html>
<?php

}
?>
173 changes: 107 additions & 66 deletions step2a.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<?php
// error_reporting(0);
$var = isset($_POST['submit']) && isset($_POST['host-name'])
&& isset($_POST['database-name']) && isset($_POST['user-name'])
&& isset($_POST['database-type']);

if ($var) {
if (empty($_POST['host-name']) ||
empty($_POST['user-name']) ||
empty($_POST['database-type']) ||
empty($_POST['database-name'])) {
header('Location: step2.php?return=1&error_message=Please fill all the required fields.');
} else {
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

Expand All @@ -19,19 +33,19 @@

<body class="wc-setup wp-core-ui">

<?php
<?php
define('PROBE_VERSION', '4.2');
define('PROBE_FOR', 'activeCollab 4.2 and Newer');
define('STATUS_OK', 'ok');
define('STATUS_WARNING', 'warning');
define('STATUS_ERROR', 'error');

$database_type = $_POST['database-type'];
$database_name = $_POST['database-name'];
$database_host = $_POST['host-name'];
$database_portno = $_POST['port-no'];
$database_username = $_POST['user-name'];
$database_password = $_POST['password'];
define('PROBE_FOR', 'activeCollab 4.2 and Newer');
define('STATUS_OK', 'ok');
define('STATUS_WARNING', 'warning');
define('STATUS_ERROR', 'error');

$database_type = $_POST['database-type'];
$database_name = $_POST['database-name'];
$database_host = $_POST['host-name'];
$database_portno = $_POST['port-no'];
$database_username = $_POST['user-name'];
$database_password = $_POST['password'];
// Unit Testing
// echo "db" . $database_type."<br/>";
// echo $database_name."<br/>";
Expand All @@ -40,29 +54,29 @@
// echo $database_username."<br/>";
// echo $database_password."<br/>";

class TestResult
{
public $message;
public $status;

public function TestResult($message, $status = STATUS_OK)
{
$this->message = $message;
$this->status = $status;
}
} // TestResult
function check_have_inno($link)
{
// if($result = mysqli_query('SHOW ENGINES', $link)) {
if ($result = $link('SHOW ENGINES')) {
while ($engine = mysqli_fetch_assoc($result)) {
if (strtolower($engine['Engine']) == 'innodb' && in_array(strtolower($engine['Support']), ['yes', 'default'])) {
return true;
} // if
} // while
} // if
return true;
} // check_have_inno
class TestResult
{
public $message;
public $status;

public function testResult($message, $status = STATUS_OK)
{
$this->message = $message;
$this->status = $status;
}
} // TestResult
function check_have_inno($link)
{
// if($result = mysqli_query('SHOW ENGINES', $link)) {
if ($result = $link('SHOW ENGINES')) {
while ($engine = mysqli_fetch_assoc($result)) {
if (strtolower($engine['Engine']) == 'innodb' && in_array(strtolower($engine['Support']), ['yes', 'default'])) {
return true;
} // if
} // while
} // if
return true;
} // check_have_inno

?>
<h1 id="wc-logo"><a href="http://www.faveohelpdesk.com" target="_blank"><img src="images/logo.png" alt="faveo"></a></h1>
Expand All @@ -89,25 +103,33 @@ function check_have_inno($link)

<?php
$mysql_ok = true;
$results = [];
$results = [];

//if($connection = mysql_connect($database_host, $database_username, $database_password)) {
// $results[] = new TestResult('Connected to database as ' . $database_username . '@' . $database_host, STATUS_OK);

if ($connection = $connection = mysqli_connect($database_host, $database_username, $database_password, $database_name)) {
$results[] = new TestResult('Connected to database as '.$database_username.'@'.$database_host, STATUS_OK);
if ($connection = mysqli_connect($database_host, $database_username, $database_password)) {
$results[] = new TestResult('Connected to database as '.$database_username.'@'.$database_host, STATUS_OK);

//if(mysql_select_db($database_name, $connection)) {
// $results[] = new TestResult('Database "' . $database_username . '" selected', STATUS_OK);
//
if ($connection->select_db($database_name)) {
// $results[] = new TestResult('Database "' . $database_username . '" selected', STATUS_OK);
$sql = "SELECT COUNT(DISTINCT `table_name`) FROM `information_schema`.`columns` WHERE `table_schema` = '$database_name'";
$res = mysqli_query($connection, $sql);
$value = mysqli_fetch_assoc($res);
foreach ($value as $val) {
if ($val == 0) {
$mysqli_version = $connection->server_version;
$results[] = new TestResult("Database '$database_name' looks fine.", STATUS_OK);
$mysql_ok = true;
if ($connection->select_db($database_name)) {
// $results[] = new TestResult('Database "' . $database_username . '" selected', STATUS_OK);
//$mysql_version = mysql_get_server_info($connection);
$mysqli_version = $connection->server_version;
$results[] = new TestResult('Connected to database as '.$database_username.'@'.$database_host, STATUS_OK);
$mysqli_version = $connection->server_version;
$results[] = new TestResult('Connected to database as '.$database_username.'@'.$database_host, STATUS_OK);

if (version_compare($mysqli_version, '5.0') >= 0) {
$results[] = new TestResult('MySQL version is '.$mysqli_version, STATUS_OK);
if (version_compare($mysqli_version, '5.0') >= 0) {
$results[] = new TestResult('MySQL version is '.$mysqli_version, STATUS_OK);
$mysql_ok = true;

//$have_inno = check_have_inno($connection);

Expand All @@ -117,55 +139,67 @@ function check_have_inno($link)
// $results[] = new TestResult('No InnoDB support. Although activeCollab can use MyISAM storage engine InnoDB is HIGHLY recommended!', STATUS_WARNING);
// }
// } else {
$results[] = new TestResult('Your MySQL version is '.$mysqli_version.'. We recommend upgrading to at least MySQL5!', STATUS_ERROR);
$mysql_ok = false;
} // if
} else {
$results[] = new TestResult('Your MySQL version is '.$mysqli_version.'. We recommend upgrading to at least MySQL5!', STATUS_ERROR);
$mysql_ok = false;
}
// if
} else {
$results[] = new TestResult('Failed to select database. MySQL said: '.mysqli_error($connection), STATUS_ERROR);
$mysql_ok = false;
} // if
} else {
$results[] = new TestResult('Faveo installation needs an empty database.', STATUS_ERROR);
$mysql_ok = false;
}
// code...
}
} else {
$results[] = new TestResult('Failed to select database. MySQL said: '.mysqli_error(), STATUS_ERROR);
$results[] = new TestResult('Failed to connect to database. MySQL said: '.mysqli_error($connection), STATUS_ERROR);
$mysql_ok = false;
} // if
} else {
$results[] = new TestResult('Failed to connect to database. MySQL said: '.mysqli_error(), STATUS_ERROR);
$mysql_ok = false;
} // if

// ---------------------------------------------------
// Validators
// ---------------------------------------------------

foreach ($results as $result) {
echo '<br/><span class="'.$result->status.'">'.$result->status.'</span> &mdash; '.$result->message.'';
} // foreach
foreach ($results as $result) {
echo '<br/><span class="'.$result->status.'">'.$result->status.'</span> &mdash; '.$result->message.'';
} // foreach
?><br/>

<?php $mysql_ok = null; ?>

<?php // if ?>


<?php if ($mysql_ok !== null && $mysql_ok) {
<?php if ($mysql_ok) {
?>
<div class="woocommerce-message woocommerce-tracker" >
<p id="pass">Database connection successful. This system can run Faveo</p>

</div>
<?php
<?php

} else {
?>
<div class="woocommerce-message woocommerce-tracker " >
<p id="fail">Database connection unsuccessful. This system does not meet Faveo system requirements</p>
</div>
<?php
<?php

} // if ?>
<form action="step3.html" method="post">
<form action="step3.php" method="post">
<div style="border-bottom: 1px solid #eee;">
<p class="wc-setup-actions step" >

<input type="submit" id="submitme" class="button-primary button button-large button-next" value="Continue" <?php if ($mysql_ok !== null && $mysql_ok) {
<input type="submit" name="submit" id="submitme" class="button-primary button button-large button-next" value="Continue" <?php if ($mysql_ok !== null && $mysql_ok) {
} else {
?>disabled<?php
}?>>
?>disabled<?php

}
?>>

<a href="index.php" class="button button-large button-next" style="float: left">Previous</a>
<a href="step2.php?return=1" class="button button-large button-next" style="float: left">Previous</a>

</p>
</div> </form>
Expand All @@ -185,4 +219,11 @@ function check_have_inno($link)

</body>

</html>
</html>
<?php

}
} else {
header('Location: step2.php?return=1&error_message=Please fill all the required fields.');
}
?>
Loading

0 comments on commit 74648b1

Please sign in to comment.