/**
  * Install website
  *
  * @access	private
  */
 private function install()
 {
     $this->_db_host = VPost::db_host();
     $this->_db_name = VPost::db_name();
     $this->_db_user = VPost::db_user();
     $this->_db_pwd = VPost::db_pwd();
     $this->_db_prefix = VPost::db_prefix();
     $this->_ws_url = VPost::ws_url();
     $this->_ws_name = VPost::ws_name();
     $this->_ws_email = VPost::ws_email();
     $this->_username = VPost::username();
     $this->_password = VPost::password();
     $conf = "<?php\n";
     $conf .= "\n";
     $conf .= "\t/**\n";
     $conf .= "\t\t* @author\t\tBaptiste Langlade\n";
     $conf .= "\t\t* @copyright\t2011-2012\n";
     $conf .= "\t\t* @license\t\thttp://www.gnu.org/licenses/gpl.html GNU GPL V3\n";
     $conf .= "\t\t* @package\t\tLynxpress\n";
     $conf .= "\t\t*\n";
     $conf .= "\t\t* This file is part of Lynxpress.\n";
     $conf .= "\t\t*\n";
     $conf .= "\t\t*   Lynxpress is free software: you can redistribute it and/or modify\n";
     $conf .= "\t\t*   it under the terms of the GNU General Public License as published by\n";
     $conf .= "\t\t*   the Free Software Foundation, either version 3 of the License, or\n";
     $conf .= "\t\t*   (at your option) any later version.\n";
     $conf .= "\t\t*\n";
     $conf .= "\t\t*   Lynxpress is distributed in the hope that it will be useful,\n";
     $conf .= "\t\t*   but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
     $conf .= "\t\t*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
     $conf .= "\t\t*   GNU General Public License for more details.\n";
     $conf .= "\t\t*\n";
     $conf .= "\t\t*   You should have received a copy of the GNU General Public License\n";
     $conf .= "\t\t*   along with Lynxpress.  If not, see http://www.gnu.org/licenses/.\n";
     $conf .= "\t*/\n";
     $conf .= "\n";
     $conf .= "\t/**\n";
     $conf .= "\t\t* Configuration of the website\n";
     $conf .= "\t*/\n";
     $conf .= "\n";
     $conf .= "\tdefine('WS_NAME', '" . $this->_ws_name . "');\n";
     $conf .= "\tdefine('WS_URL', '" . $this->_ws_url . "');\n";
     $conf .= "\tdefine('WS_EMAIL', '" . $this->_ws_email . "');\n";
     $conf .= "\tdefine('DB_HOST', '" . $this->_db_host . "');\n";
     $conf .= "\tdefine('DB_NAME', '" . $this->_db_name . "');\n";
     $conf .= "\tdefine('DB_USER', '" . $this->_db_user . "');\n";
     $conf .= "\tdefine('DB_PWD', '" . $this->_db_pwd . "');\n";
     $conf .= "\tdefine('DB_PREFIX', '" . $this->_db_prefix . "');\n";
     $conf .= "\n";
     $conf .= "\tdefine('SALT', '" . Helper::generate_salt() . "');\t\t//after installation, don't change this constant\n";
     $conf .= "\n";
     $conf .= "\tdefine('WS_VERSION', '" . self::VERSION . "');\n";
     $conf .= "\n";
     $conf .= "?>";
     $this->_conf = $conf;
     try {
         //config.php creation
         $config = @fopen('config.php', 'w');
         if (!$config) {
             throw new Exception('false fopen');
         }
         fwrite($config, $conf);
         fclose($config);
         //end config creation
         //try to connect to database, if not exception raisen and we create it
         $this->_db = new PDO('mysql:dbname=' . $this->_db_name . ';host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
         require 'config.php';
         //create tables
         $this->create_activity();
         $this->create_category();
         $this->create_comment();
         $this->create_link();
         $this->create_media();
         $this->create_post();
         $this->create_setting();
         $this->create_user();
         $this->_result = 'successful';
     } catch (Exception $e) {
         if ($e->getMessage() == 'false fopen') {
             $this->_result = 'false fopen';
         } elseif ($e->getMessage() == 'SQLSTATE[28000] [1045] Access denied for user \'' . $this->_db_user . '\'@\'' . $this->_db_host . '\' (using password: YES)') {
             $this->_result = 'false connect';
             unlink('config.php');
         } elseif ($e->getMessage() == 'SQLSTATE[42000] [1049] Unknown database \'' . $this->_db_name . '\'') {
             try {
                 $this->_db = new PDO('mysql:host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
                 $this->create_database();
                 $this->_db = new PDO('mysql:dbname=' . $this->_db_name . ';host=' . $this->_db_host . ';', $this->_db_user, $this->_db_pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
                 require 'config.php';
                 $this->create_activity();
                 $this->create_category();
                 $this->create_comment();
                 $this->create_link();
                 $this->create_media();
                 $this->create_post();
                 $this->create_setting();
                 $this->create_user();
                 $this->_result = 'successful';
             } catch (Exception $e) {
                 if ($e->getMessage() == 'false create') {
                     $this->_result = 'false create';
                 } else {
                     $this->_result = 'unknown';
                 }
                 unlink('config.php');
             }
         } elseif ($e->getMessage() == 'false create') {
             $this->_result = 'false create';
             unlink('config.php');
         } else {
             $this->_result = 'unknown';
             unlink('config.php');
         }
     }
 }