From 2e2233eb8174ba9bd2d6722d7e07c4a3f9873548 Mon Sep 17 00:00:00 2001 From: Phyks Date: Mon, 26 Aug 2013 09:29:30 +0200 Subject: [PATCH] Added a check that tables don't exist in install.php + don't version tmp/ --- .gitignore | 1 + TODO | 6 +- install.php | 36 +++++++-- ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 15 ---- ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 76 ------------------- ....36ba0f7e771a8681573a91518b54b424.rtpl.php | 4 - ....36ba0f7e771a8681573a91518b54b424.rtpl.php | 33 -------- ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 66 ---------------- ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 66 ---------------- 9 files changed, 33 insertions(+), 270 deletions(-) delete mode 100644 tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php delete mode 100644 tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php delete mode 100644 tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php delete mode 100644 tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php delete mode 100644 tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php delete mode 100644 tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php diff --git a/.gitignore b/.gitignore index bdc750e..6e24876 100755 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .*.sw* old data/ +tmp/ diff --git a/TODO b/TODO index 05a5b1d..a7e0429 100755 --- a/TODO +++ b/TODO @@ -5,10 +5,6 @@ * Refactor load method to avoir load_* methods ! * Test remember_me -install.php : -============= -* TRUNCATE before CREATE TABLE in install.php - inc/Invoices.class.php : ======================== * Better way to store users in ? => reprendre cette partie @@ -24,7 +20,6 @@ Tests : * Remember me ? * Add a bill * Edit a bill -* Change settings Tests passed (quick tests) : ============================ @@ -32,3 +27,4 @@ Tests passed (quick tests) : * Edit notice * Add / Edit user * Change password +* Change settings diff --git a/install.php b/install.php index 77e36ee..f7c554d 100644 --- a/install.php +++ b/install.php @@ -26,16 +26,36 @@ //Create table "Users" $db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, login VARCHAR(255), display_name VARCHAR(255), password VARCHAR(130), admin TINYINT(1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'); + + $count_users = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Users'); + $count_users = $count_users->fetch(); + if($count_users[0] > 0) { + $warning = 'Table '.$mysql_prefix.'Users already exists. Not doing anything on this table. Please check manually that this table is correct.
'; + } + //Create table "Invoices" $db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Invoices (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, date INT(11), users_in VARCHAR(255), buyer INT(11), amount FLOAT, what TEXT) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'); - //Create table "Users_in_invoice" + $count_invoices = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Invoices'); + $count_invoices = $count_users->fetch(); + if($count_invoices[0] > 0) { + $warning .= 'Table '.$mysql_prefix.'Users already exists. Not doing anything on this table. Please check manually that this table is correct.
'; + } + + + //Create table "Users_in_invoices" $db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users_in_invoices (invoice_id INT(11) NOT NULL, KEY invoice_id (invoice_id), user_id INT(11), KEY user_id (user_id), guests INT(11)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci'); + + $count_users_in_invoices = $db->query('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = "'.$mysql_db.'" AND table_name = "'.$mysql_prefix.'"Users_in_invoices'); + $count_users_in_invoices = $count_users_in_invoices->fetch(); + if($count_users_in_invoices[0] > 0) { + $warning .= 'Table '.$mysql_prefix.'Users_in_invoices already exists. Not doing anything on this table. Please check manually that this table is correct.
'; + } //Create table "Payback" - TODO } catch (PDOException $e) { - $error = 'Unable to connect to database, check your credentials and config.
Error message : '.$e->getMessage().'.'; + $error = 'Unable to connect to database and create database, check your credentials and config.
Error message : '.$e->getMessage().'.'; } if(!filter_var($_POST['email_webmaster'], FILTER_VALIDATE_EMAIL)) { @@ -53,7 +73,7 @@ $salt = sprintf("$2a$%02d$", 10) . $salt; //prefix for blowfish $config = "setPassword($admin->encrypt($_POST['admin_password'])); $admin->setAdmin(true); $admin->save(); - header('location: index.php'); - exit(); + + if(empty($warning)) { + header('location: index.php'); + exit(); + } + else { + echo '

'.$warning.'Go to your instance.

'; + } } catch (Exception $e) { $erreur = 'An error occurred when inserting user in the database.
Error message : '.$e->getMessage().'.'; } diff --git a/tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php deleted file mode 100644 index 7f35588..0000000 --- a/tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ /dev/null @@ -1,15 +0,0 @@ -assign( $this->var );$tpl->draw( dirname("header") . ( substr("header",-1,1) != "/" ? "/" : "" ) . basename("header") );?> - - -

- Connexion

- -
-

-

-

-

-

Forgotten password ?

-
- -assign( $this->var );$tpl->draw( dirname("footer") . ( substr("footer",-1,1) != "/" ? "/" : "" ) . basename("footer") );?> - diff --git a/tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php deleted file mode 100644 index acf8606..0000000 --- a/tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ /dev/null @@ -1,76 +0,0 @@ -assign( $this->var );$tpl->draw( dirname("header") . ( substr("header",-1,1) != "/" ? "/" : "" ) . basename("header") );?> - - - - -

- - - - - -

List of users

-

You can also add a user.

- - - - - - - - - - $value1 ){ $counter1++; ?> - - - - - - - - - - - -
IdLoginDisplay NameIs admin ?EditDelete
getId();?>getLogin();?>getDisplayName();?>getAdmin() ? "Yes" : "No";?>EditgetId() != $current_user->getId() ){ ?>Delete
- - -

a user

-
-

- value="" getLogin().'"' : '';?> /> -

-

- value="" getDisplayName().'"' : '';?> /> -

-

- - - -
Note : Leave blank this field if you don't want to edit password. - - -

-

- Give admin rights to this user ?
- getAdmin()) ){ ?> checked/>
- getAdmin())) ){ ?> checked/> -

-

- - - - -

-
- - - -

Edit your password

-
-

-

-

-

- - diff --git a/tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php b/tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php deleted file mode 100644 index 4a96630..0000000 --- a/tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php b/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php deleted file mode 100644 index 39f9034..0000000 --- a/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php +++ /dev/null @@ -1,33 +0,0 @@ - - - - - <?php echo $instance_title;?> - - - - - - -

- - - - diff --git a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php deleted file mode 100644 index d02587f..0000000 --- a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ /dev/null @@ -1,66 +0,0 @@ -assign( $this->var );$tpl->draw( dirname("header") . ( substr("header",-1,1) != "/" ? "/" : "" ) . basename("header") );?> - - - - -

- - - -
-

Balance

-

Read line owes case to column. You can click on links to confirm the payback. - - - - $value1 ){ $counter1++; ?> - - - - - - $value1 ){ $counter1++; ?> - - - - $value2 ){ $counter2++; ?> - - - - - - - -
Owes\TogetDisplayName();?>
getDisplayName();?>getDisplayName();?>
-

-
-

Detailed list of bills for last month

- - - - - - - - - - - - $value1 ){ $counter1++; ?> - - - - - - - - - - - - -
DatePaid byUsers inAmountWhat ?EditDelete
getDate();?>getBuyer();?>getUsersIn();?>getAmount();?>getWhat();?>EditDelete
-
- -assign( $this->var );$tpl->draw( dirname("footer") . ( substr("footer",-1,1) != "/" ? "/" : "" ) . basename("footer") );?> - diff --git a/tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php deleted file mode 100644 index 6d72e6d..0000000 --- a/tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ /dev/null @@ -1,66 +0,0 @@ -assign( $this->var );$tpl->draw( dirname("header") . ( substr("header",-1,1) != "/" ? "/" : "" ) . basename("header") );?> - - - - -

Edit homepage notice

-

- -
-

-
- -

-

Note : You can use HTML formatting in this form.

-

- - -

-
- - - -

Change settings of your Bouffe@Ulm installation

-

- -
-
- Database -

Note : Use these settings carefully. Your database won't be updated by the script as it was during install and you'll have to manually update it.

-

- -

-

- Toggle visible
- Note : Leave the above field blank if you don't want to change your password. -

-

-
- Note : You must create this database first. -

-

-
- Note : Leave the field blank to not use any.

-
-
- General options -

-

-
- Note : This is the base URL from which you access this page. You must keep the trailing "/" in the above address. -

-

-

-
- For example : Europe/Paris. See the doc for more info. -

-

-
-

-
- - - - -assign( $this->var );$tpl->draw( dirname("footer") . ( substr("footer",-1,1) != "/" ? "/" : "" ) . basename("footer") );?> -