Starting to create the classes
This commit is contained in:
parent
3bd81f3d62
commit
561af52a31
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
*~
|
||||
.*.sw*
|
||||
old
|
||||
|
16
humans.txt
16
humans.txt
@ -0,0 +1,16 @@
|
||||
/* TEAM */
|
||||
Name : Phyks
|
||||
Site : http://www.phyks.me
|
||||
E-mail : phyks@phyks.me
|
||||
Location : France.
|
||||
|
||||
Name : Cphyc
|
||||
Site : http://www.cphyc.me
|
||||
E-mail : contact@cphyc.me
|
||||
Location : France.
|
||||
|
||||
/* THANKS */
|
||||
Baltazar for the algorithm to simplify the matrix of debts
|
||||
|
||||
/* LICENSE */
|
||||
BEER-WARE LICENSE (see LICENSE or README.md file for more infos)
|
0
inc/Invoices.class.php
Normal file
0
inc/Invoices.class.php
Normal file
0
inc/Payback.class.php
Normal file
0
inc/Payback.class.php
Normal file
95
inc/Storage.class.php
Normal file
95
inc/Storage.class.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
require_once('config.php');
|
||||
|
||||
class Storage {
|
||||
private $host, $login, $password, $db;
|
||||
private $connection = null;
|
||||
|
||||
private function __construct($connection_params = null) {
|
||||
if(is_array($connection_params) && !empty($connection_params)) {
|
||||
$this->setHost($connection_params['host']);
|
||||
$this->setLogin($connection_params['login']);
|
||||
$this->setPassword($connection_params['password']);
|
||||
$this->setDb($connection_params['db']);
|
||||
|
||||
$this->connect();
|
||||
}
|
||||
}
|
||||
|
||||
private function __destruct() {
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
//Connect / Disconnect functions
|
||||
public function connect() {
|
||||
$this->connection = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_LOGIN, MYSQL_PASSWORD);
|
||||
$this->connection->query('SET NAMES utf8');
|
||||
}
|
||||
|
||||
public function disconnect() {
|
||||
$this->connection = null;
|
||||
}
|
||||
|
||||
//Function to get and set vars
|
||||
public function getHost() {
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
public function getLogin() {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
public function getPassword() {
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getDb() {
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function setHost($host) {
|
||||
$this->host = host;
|
||||
}
|
||||
|
||||
public function setLogin($login) {
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function setDb($db) {
|
||||
this->db = $db;
|
||||
}
|
||||
|
||||
public function typeToSQL($type) {
|
||||
$return = false;
|
||||
switch($type) {
|
||||
case 'key':
|
||||
$return = 'INT(11) NOT NULL AUTO_INCREMENT PRIMARY_KEY';
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
$return = 'VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci';
|
||||
break;
|
||||
|
||||
case 'bool':
|
||||
$return = 'TINYINT(1)';
|
||||
break;
|
||||
|
||||
default:
|
||||
$return = 'TEXT CHARACTER SET utf8 COLLATE utf8_general_ci';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function createTable($table_name = null) {
|
||||
|
||||
}
|
||||
|
||||
public function initTables() {
|
||||
$this->createTable('users');
|
||||
$this->createTable('invoices');
|
||||
}
|
||||
}
|
41
inc/User.class.php
Normal file
41
inc/User.class.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once('config.php');
|
||||
|
||||
class User extends Storage {
|
||||
protected $id, $login, $password;
|
||||
protected $TALE_NAME = "users";
|
||||
protected $fields = array(
|
||||
'id'=>'key',
|
||||
'nom'=>'string',
|
||||
'password'=>'string',
|
||||
'admin'=>'bool'
|
||||
);
|
||||
|
||||
private function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getLogin() {
|
||||
return $this->login;
|
||||
}
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setLogin($login) {
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = User::encrypt($password);
|
||||
}
|
||||
|
||||
public function encrypt($text) {
|
||||
return crypt($text, SALT);
|
||||
}
|
||||
|
||||
public function check_password($password) {
|
||||
return User::encrypt($password) == $this->password;
|
||||
}
|
||||
}
|
@ -4,7 +4,9 @@
|
||||
define('MYSQL_HOST', 'localhost');
|
||||
define('MYSQL_LOGIN', '');
|
||||
define('MYSQL_PASSWORD', '');
|
||||
define('MYSQL_BDD', '');
|
||||
define('MYSQL_DB', '');
|
||||
define('MYSQL_PREFIX', '');
|
||||
|
||||
define('TITLE', 'Bouffe@Ulm');
|
||||
define('BASE_URL', 'http://monsite.com/BouffeAtUlm/');
|
||||
define('SALT', 'longandcomplicatedstring');
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
if(!file_exists('config.php')) header('location: install.php');
|
||||
|
||||
session_start();
|
||||
|
||||
require_once('config.php');
|
||||
|
21
index.php
21
index.php
@ -1,2 +1,23 @@
|
||||
<?php
|
||||
require_once('inc/header.php');
|
||||
|
||||
init(true,false) {
|
||||
global $bdd;
|
||||
|
||||
$bdd = new PDO('mysql:host='.MYSQL_HOST.';dbname='.MYSQL_DB, MYSQL_LOGIN, MYSQL_PASSWORD);
|
||||
$bdd->query("SET NAMES 'utf8'");
|
||||
|
||||
session_start();
|
||||
|
||||
date_default_timezone_set(TIMEZONE);
|
||||
|
||||
if($protect && empty($_SESSION['login'])) {
|
||||
header('location: connexion.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if($admin && $_SESSION['admin']) {
|
||||
header('location: message.php?id=7');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
62
install.php
62
install.php
@ -6,7 +6,7 @@
|
||||
$block_form = true;
|
||||
}
|
||||
|
||||
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db'])) {
|
||||
if(!empty($_POST['mysql_host']) && !empty($_POST['mysql_login']) && !empty($_POST['mysql_db']) && !empty($_POST['admin_login']) && !empty($_POST['admin_pass'])) {
|
||||
$mysql_host = $_POST['mysql_host'];
|
||||
$mysql_login = $_POST['mysql_login'];
|
||||
$mysql_db = $_POST['mysql_login'];
|
||||
@ -15,24 +15,50 @@
|
||||
$instance_title = (!empty($_POST['instance_title'])) ? $_POST['instance_title'] : 'Bouffe@Ulm';
|
||||
|
||||
try {
|
||||
$db = new PDO("mysql:host=".$mysql_host.";dbname=".$mysql_db, $mysql_login, $mysql_password);
|
||||
}
|
||||
catch (PDOException $e) {
|
||||
$db = new Storage(array('host'=>$mysql_host, 'login'=>$mysql_login, 'password'=>$mysql_password, 'db'=>$mysql_db);
|
||||
//TODO : Create tables
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Unable to connect to database, check your credentials.';
|
||||
}
|
||||
|
||||
if(empty($error)) {
|
||||
$config = "
|
||||
define('VERSION_NUMBER', '2.0');
|
||||
if(function_exists('mcrypt_create_iv')) {
|
||||
$salt = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
|
||||
}
|
||||
else {
|
||||
mt_srand(microtime(true)*100000 + memory_get_usage(true));
|
||||
$salt = md5(uniqid(mt_rand(), true));
|
||||
}
|
||||
|
||||
define('MYSQL_HOST', '".$mysql_host."');
|
||||
define('MYSQL_LOGIN', '".$mysql_login."');
|
||||
define('MYSQL_PASSWORD', '".$mysql_password."');
|
||||
define('MYSQL_DB', '".$mysql_db."');
|
||||
define('MYSQL_PREFIX', '".$mysql_prefix."');
|
||||
define('SALT', $salt);
|
||||
|
||||
$config = "
|
||||
define('VERSION_NUMBER', '2.0');
|
||||
define('MYSQL_HOST', '".$mysql_host."');
|
||||
define('MYSQL_LOGIN', '".$mysql_login."');
|
||||
define('MYSQL_PASSWORD', '".$mysql_password."');
|
||||
define('MYSQL_DB', '".$mysql_db."');
|
||||
define('MYSQL_PREFIX', '".$mysql_prefix."');
|
||||
define('INSTANCE_TITLE', '".$instance_title."');
|
||||
define('BASE_URL', '".$_POST['base_url']."');
|
||||
define('SALT', '".$salt."');";
|
||||
|
||||
define('INSTANCE_TITLE', '".$instance_title."');";
|
||||
file_put_contents("inc/config.php", $config);
|
||||
if(file_put_contents("inc/config.php", $config)) {
|
||||
try {
|
||||
$admin = new User();
|
||||
$admin->setLogin($_POST['admin_login']);
|
||||
$admin->setPassword($_POST['admin_password']);
|
||||
$admin->setAdmin(true);
|
||||
$admin->save();
|
||||
header('location: index.php');
|
||||
exit();
|
||||
} catch ($e) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
else
|
||||
$error = 'Unable to write configuration to config file inc/config.php.';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -70,8 +96,16 @@
|
||||
<fieldset>
|
||||
<legend>General options</legend>
|
||||
<p><label for="instance_title">Title to display in pages : </label><input type="text" name="instance_title" id="instance_title" value="Bouffe@Ulm"/></p>
|
||||
<p>
|
||||
<label for="base_url">Base URL : </label><input type="text" size="30" name="base_url" id="base_url" value="<?php echo 'http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME'].str_replace("install.php", "", $_SERVER['REQUEST_URI']); ?>"/><br/>
|
||||
<em>Note :</em> This is the base URL from which you access this website. You must keep the trailing "/" in the above address.
|
||||
</p>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Administrator</legend>
|
||||
<p><label for="admin_login">Username of the admin : </label><input type="text" name="admin_login" id="admin_login"/></p>
|
||||
<p><label for="admin_mdp">Password for the admin : </label><input type="password" name="admin_pass" id="admin_pass"/></p>
|
||||
</fieldset>
|
||||
|
||||
<p><input <?php echo (!empty($block_form)) ? 'disabled ' : '';?>type="submit" class="center"></p>
|
||||
</form>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user