public function demo()
 {
     if (Config::get('app.mode' == 'testing')) {
         $db_config = Config::get('database.connections');
         $mysql_username = $db_config['mysql']['username'];
         $mysql_password = $db_config['mysql']['password'];
         $mysql_database = $db_config['mysql']['database'];
         $mysql_host = $db_config['mysql']['host'];
         import_db($mysql_username, $mysql_password, $mysql_host, $mysql_database);
         echo "Demo Data Import Successful";
     } else {
         echo "ERROR your app is live mode. Switch back to test mode and then test it again";
     }
 }
function save()
{
    global $corem_db;
    $sqlm = new SQL();
    $sqlm->connect($corem_db["addr"], $corem_db["user"], $corem_db["pass"], $corem_db["name"], $corem_db["encoding"]);
    // then we get the config data
    // General Database Settings
    if ($_GET["host"] != "") {
        $host = $sqlm->quote_smart($_GET["host"]);
    } else {
        redirect("setup.php?error=1");
    }
    if ($_GET["port"] != "") {
        $port = $sqlm->quote_smart($_GET["port"]);
    } else {
        redirect("setup.php?error=1");
    }
    if ($_GET["user"] != "") {
        $user = $sqlm->quote_smart($_GET["user"]);
    } else {
        redirect("setup.php?error=1");
    }
    if ($_GET["pass"] != "") {
        $pass = $sqlm->quote_smart($_GET["pass"]);
    } else {
        redirect("setup.php?error=1");
    }
    // Authentication DB Name
    if ($_GET["name"] != "") {
        $name = $sqlm->quote_smart($_GET["name"]);
    } else {
        redirect("setup.php?error=1");
    }
    // DBC DB Name
    if ($_GET["dbcname"] != "") {
        $dbcname = $sqlm->quote_smart($_GET["dbcname"]);
    } else {
        redirect("setup.php?error=1");
    }
    if ($_GET["acctname"] != "") {
        $acctname = $sqlm->quote_smart($_GET["acctname"]);
    } else {
        redirect("setup.php?error=1");
    }
    if ($_GET["screenname"] != "") {
        $screenname = $sqlm->quote_smart($_GET["screenname"]);
    } else {
        redirect("setup.php?error=1");
    }
    // first, we import databases
    import_db($host, $port, $user, $pass, $dbcname);
    // save logon database configs
    $logon_count = $sqlm->fetch_assoc($sqlm->query("SELECT COUNT(*) FROM config_logon_database"));
    if ($logon_count["COUNT(*)"] == 1) {
        $logon_upper = $sqlm->fetch_assoc($sqlm->query("SELECT MAX(`Index`) FROM config_logon_database"));
        $result = $sqlm->query("UPDATE config_logon_database SET Address='" . $host . "', Port='" . $port . "', Name='" . $name . "', User='******', Password='******', Encoding='utf8' WHERE `Index`='" . $logon_upper["MAX(`Index`)"] . "'");
    } elseif ($logon_count["COUNT(*)"] > 1) {
        $result = $sqlm->query("TRUNCATE TABLE config_logon_database");
        $result = $sqlm->query("INSERT INTO config_logon_database (Address, Port, User, Name, Password, Encoding) VALUES ('" . $host . "', '" . $port . "', '" . $user . "', '" . $name . "', '" . $pass . "', 'utf8')");
    } else {
        $result = $sqlm->query("INSERT INTO config_logon_database (Address, Port, User, Name, Password, Encoding) VALUES ('" . $host . "', '" . $port . "', '" . $user . "', '" . $name . "', '" . $pass . "', 'utf8')");
    }
    // save dbc database configs
    $dbc_count = $sqlm->fetch_assoc($sqlm->query("SELECT COUNT(*) FROM config_dbc_database"));
    if ($dbc_count["COUNT(*)"] == 1) {
        $dbc_upper = $sqlm->fetch_assoc($sqlm->query("SELECT MAX(`Index`) FROM config_dbc_database"));
        $result = $sqlm->query("UPDATE config_dbc_database SET Address='" . $host . "', Port='" . $port . "', Name='" . $dbcname . "', User='******', Password='******', Encoding='utf8' WHERE `Index`='" . $dbc_upper["MAX(`Index`)"] . "'");
    } elseif ($dbc_count["COUNT(*)"] > 1) {
        $result = $sqlm->query("TRUNCATE TABLE config_dbc_database");
        $result = $sqlm->query("INSERT INTO config_dbc_database (Address, Port, User, Name, Password, Encoding) VALUES ('" . $host . "', '" . $port . "', '" . $user . "', '" . $dbcname . "', '" . $pass . "', 'utf8')");
    } else {
        $result = $sqlm->query("INSERT INTO config_dbc_database (Address, Port, User, Name, Password, Encoding) VALUES ('" . $host . "', '" . $port . "', '" . $user . "', '" . $dbcname . "', '" . $pass . "', 'utf8')");
    }
    // set up web admin account
    $account = $sqlm->fetch_assoc($sqlm->query("SELECT * FROM config_accounts WHERE Login='******'"));
    if ($account["Login"] != '') {
        $result = $sqlm->query("UPDATE config_accounts SET ScreenName='" . $screenname . "', SecurityLevel=(4+1073741824) WHERE Login='******'");
    } else {
        $result = $sqlm->query("INSERT INTO config_accounts (Login, ScreenName, SecurityLevel) VALUES (UPPER('" . $acctname . "'), '" . $screenname . "', (4+1073741824))");
    }
    $result = $sqlm->query("UPDATE config_misc SET Value='1' WHERE `Key`='Installed'");
    redirect("admin.php");
}
				border-bottom:2px solid #78ab00;
			}
			a:hover{
				color:#fff;
			}
	</style>
</head>
<body>

<img src="/application/assets/img/logo.png" height="32" style="margin:20px auto; height:32px; width:auto; display:block" />
<h4>Hello Video Installation</h4>
<div id="system_requirements">
<?php 
require __DIR__ . '/application/bootstrap/autoload.php';
run_checks();
import_db();
function new_line()
{
    echo '<br />';
}
function run_checks()
{
    if (version_compare(PHP_VERSION, "5.4", ">=")) {
        echo '<span class="success">PHP 5.4 or greater installed (<i class="fa fa-check-square-o"></i> PASS)</span>';
    } else {
        echo '<span class="failed">Minumum version of PHP 5.4 is required (<i class="fa fa-times"></i> FAIL)</span>';
    }
    new_line();
    if (!ini_get('safe_mode')) {
        echo '<span class="success">Safe mode is not enabled (<i class="fa fa-check-square-o"></i> PASS)</span>';
    } else {
 public function install_submit()
 {
     $username = Input::get('username');
     $password = Input::get('password');
     $admin_username = Input::get('admin_username');
     $admin_password = Input::get('admin_password');
     $sitename = Input::get('sitename');
     $database_name = Input::get('database_name');
     $picture = Input::file('picture');
     $mandrill_username = Input::get('mandrill_username');
     $mandrill_secret = Input::get('mandrill_secret');
     $timezone = Input::get('timezone');
     $validator = Validator::make(array('password' => $password, 'username' => $username, 'database_name' => $database_name, 'admin_username' => $admin_username, 'admin_password' => $admin_password, 'sitename' => $sitename, 'picture' => $picture, 'mandrill_username' => $mandrill_username, 'timezone' => $timezone, 'mandrill_secret' => $mandrill_secret), array('password' => '', 'username' => 'required', 'sitename' => 'required', 'database_name' => 'required', 'admin_password' => 'required', 'admin_username' => 'required', 'mandrill_username' => 'required', 'mandrill_secret' => 'required', 'timezone' => 'required', 'picture' => 'mimes:png,jpg'));
     if ($validator->fails()) {
         $error_messages = $validator->messages()->all();
         return Redirect::back()->with('flash_errors', $error_messages);
     } else {
         $file_name = time();
         $file_name .= rand();
         $ext = Input::file('picture')->getClientOriginalExtension();
         Input::file('picture')->move(public_path() . "/uploads", $file_name . "." . $ext);
         $local_url = $file_name . "." . $ext;
         $s3_url = URL::to('/') . '/uploads/' . $local_url;
         Setting::set('sitename', $sitename);
         Setting::set('footer', "Powered by Appoets");
         Setting::set('username', $username);
         Setting::set('password', $password);
         Setting::set('database_name', $database_name);
         Setting::set('mandrill_secret', $mandrill_secret);
         Setting::set('mandrill_username', $mandrill_username);
         Setting::set('timezone', $timezone);
         Setting::set('logo', $s3_url);
         import_db($username, $password, 'localhost', $database_name);
         $admin = new User();
         $admin->email = $admin_username;
         $admin->is_activated = 1;
         $admin->password = Hash::make($admin_password);
         $admin->role_id = 2;
         $admin->save();
         return Redirect::to('/');
     }
 }
 public function finish_install()
 {
     // Modifying Database Config
     $host = Session::get('host');
     $username = Session::get('username');
     $password = Session::get('password');
     $database = Session::get('database');
     $dbfile = fopen(app_path() . "/config/database.php", "w") or die("Unable to open file!");
     $dbfile_config = generate_db_config($host, $username, $password, $database);
     fwrite($dbfile, $dbfile_config);
     fclose($dbfile);
     // Modifying App Config File
     $url = Session::get('url');
     $website_title = Session::get('website_title');
     $timezone = Session::get('timezone');
     $twillo_account_sid = Session::get('twillo_account_sid');
     $twillo_auth_token = Session::get('twillo_auth_token');
     $twillo_number = Session::get('twillo_number');
     $default_payment = Session::get('default_payment');
     $default_storage = Session::get('default_storage');
     if ($default_payment == 'stripe') {
         $stripe_secret_key = Session::get('stripe_secret_key');
         $stripe_publishable_key = Session::get('stripe_publishable_key');
         $braintree_environment = '';
         $braintree_merchant_id = '';
         $braintree_public_key = '';
         $braintree_private_key = '';
         $braintree_cse = '';
     } else {
         $stripe_secret_key = '';
         $stripe_publishable_key = '';
         $braintree_environment = Session::get('braintree_environment');
         $braintree_merchant_id = Session::get('braintree_merchant_id');
         $braintree_public_key = Session::get('braintree_public_key');
         $braintree_private_key = Session::get('braintree_private_key');
         $braintree_cse = Session::get('braintree_cse');
     }
     if ($default_storage == 2) {
         $s3_bucket = Session::get('s3_bucket');
     } else {
         $s3_bucket = '';
     }
     $appfile = fopen(app_path() . "/config/app.php", "w") or die("Unable to open file!");
     $appfile_config = generate_app_config($braintree_cse, $stripe_publishable_key, $url, $timezone, $website_title, $s3_bucket, $twillo_account_sid, $twillo_auth_token, $twillo_number, $default_payment, $stripe_secret_key, $braintree_environment, $braintree_merchant_id, $braintree_public_key, $braintree_private_key);
     fwrite($appfile, $appfile_config);
     fclose($appfile);
     // Importing Database
     $re = mysqli_connect($host, $username, $password, $database);
     $result = mysqli_query($re, "SHOW TABLES FROM {$database}");
     if (!$result) {
         import_db($username, $password, $host, $database);
     }
     // Modifying Mail Config File
     $mail_driver = Session::get('mail_driver');
     $email_name = Session::get('email_name');
     $email_address = Session::get('email_address');
     $mandrill_secret = Session::get('mandrill_secret');
     $mailfile = fopen(app_path() . "/config/mail.php", "w") or die("Unable to open file!");
     $mailfile_config = generate_mail_config($host, $mail_driver, $email_name, $email_address);
     fwrite($mailfile, $mailfile_config);
     fclose($mailfile);
     if ($mail_driver == 'mandrill') {
         $mandrill_username = Input::get('mandrill_username');
         $servicesfile = fopen(app_path() . "/config/services.php", "w") or die("Unable to open file!");
         $servicesfile_config = generate_services_config($mandrill_secret, $mandrill_username);
         fwrite($servicesfile, $servicesfile_config);
         fclose($servicesfile);
     }
     return View::make("installer.step7");
 }