From 721e1e774af5feaca01a2e7f853b39f0ab42a969 Mon Sep 17 00:00:00 2001
From: Pierre-Lin Bonnemaison <pierre.lin@free.fr>
Date: Sun, 9 Aug 2015 21:58:31 +0200
Subject: [PATCH] Fix de bugs

---
 controllers/connect.php    |  4 +++-
 controllers/contacts.php   |  2 +-
 controllers/groups.php     |  6 +++---
 controllers/profile.php    | 10 +++++-----
 controllers/scheduleds.php | 11 +++++------
 templates/commands.php     |  2 +-
 templates/contacts.php     |  2 +-
 templates/groups.php       |  2 +-
 templates/profile.php      |  2 +-
 templates/scheduleds.php   |  2 +-
 templates/users.php        |  2 +-
 11 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/controllers/connect.php b/controllers/connect.php
index 6d59ccb..12683e2 100755
--- a/controllers/connect.php
+++ b/controllers/connect.php
@@ -52,7 +52,9 @@
 				return false;
 			}
 
-			if (sha1($password) != $users[0]['password'])
+			$user = $users[0];
+
+			if (sha1($password) != $user['password'])
 			{
 				$_SESSION['errormessage'] = 'Cet e-mail n\'existe pas.';
 				header('Location: ' . $this->generateUrl('connect', 'login'));
diff --git a/controllers/contacts.php b/controllers/contacts.php
index c48fd0f..b0fa3ad 100755
--- a/controllers/contacts.php
+++ b/controllers/contacts.php
@@ -162,7 +162,7 @@
 					continue;
 				}
 
-				$db->updateTableWhere('contacts', ['name' => $contact['name'], 'number' => $number], ['id' => $contact['id']]);
+				$db->updateTableWhere('contacts', ['name' => $contact['name'], 'number' => $number], ['id' => $id]);
 			}
 
 			//Si on a eu des erreurs
diff --git a/controllers/groups.php b/controllers/groups.php
index 9d88fdf..bcb7ecf 100755
--- a/controllers/groups.php
+++ b/controllers/groups.php
@@ -48,7 +48,7 @@
 			//On vérifie que le jeton csrf est bon
 			if (!internalTools::verifyCSRF($csrf))
 			{
-				$_SESSION['errormessage'] => 'Jeton CSRF invalide !';
+				$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
 				header('Location: ' . $this->generateUrl('groups', 'showAll'));
 				return false;
 			}
@@ -110,7 +110,7 @@
 			global $db;
 			
 			$nom = $_POST['name'];
-			if (!$db->insertIntoTable('groups' ['name' => $nom]))
+			if (!$db->insertIntoTable('groups', ['name' => $nom]))
 			{
 				$_SESSION['errormessage'] = 'Impossible de créer ce groupe.';
 				header('Location: ' . $this->generateUrl('groups', 'showAll'));
@@ -170,6 +170,6 @@
 		{
 			global $db;
 			
-			echo json_encode($db->getAll('groups'));
+			echo json_encode($db->getFromTableWhere('groups'));
 		}
 	}
diff --git a/controllers/profile.php b/controllers/profile.php
index 80d23be..8ce3177 100755
--- a/controllers/profile.php
+++ b/controllers/profile.php
@@ -44,7 +44,7 @@
 			if (!internalTools::verifyCSRF($csrf))
 			{
 				$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
-				header('Location: ' . $this->generateUrl('profile', 'showAll');
+				header('Location: ' . $this->generateUrl('profile', 'showAll'));
 				return false;
 			}
 
@@ -61,7 +61,7 @@
 			$user = $db->getFromTableWhere('users', ['email' => $_SESSION['email']]);
 			$password = sha1($_POST['password']);
 			
-			if (!$db->updateTableWhere('users', ['password' => $password], ['id' => $user['id']]))
+			if (!$db->updateTableWhere('users', ['password' => $password], ['id' => $user[0]['id']]))
 			{
 				$_SESSION['errormessage'] = 'Impossible de mettre à jour le mot de passe.';
 				header('Location: ' . $this->generateUrl('profile', 'show'));
@@ -86,7 +86,7 @@
 			if (!internalTools::verifyCSRF($csrf))
 			{
 				$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
-				header('Location: ' . $this->generateUrl('profile', 'showAll');
+				header('Location: ' . $this->generateUrl('profile', 'showAll'));
 				return false;
 			}
 
@@ -114,7 +114,7 @@
 
 			$user = $db->getFromTableWhere('users', ['email' => $_SESSION['email']]);
 
-			if (!$db->updateTableWhere('users', ['email' => $email], ['id' => $user['id']]))
+			if (!$db->updateTableWhere('users', ['email' => $email], ['id' => $user[0]['id']]))
 			{
 				$_SESSION['errormessage'] = 'Cette adresse e-mail est déjà utilisée.';
 				header('Location: ' . $this->generateUrl('profile', 'show'));
@@ -139,7 +139,7 @@
 			if (!internalTools::verifyCSRF($csrf))
 			{
 				$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
-				header('Location: ' . $this->generateUrl('profile', 'showAll');
+				header('Location: ' . $this->generateUrl('profile', 'showAll'));
 				return false;
 			}
 
diff --git a/controllers/scheduleds.php b/controllers/scheduleds.php
index ac01c0e..daab3fc 100755
--- a/controllers/scheduleds.php
+++ b/controllers/scheduleds.php
@@ -49,7 +49,7 @@
 			if (!internalTools::verifyCSRF($csrf))
 			{
 				$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
-				header('Location: ' . $this->generateUrl('profile', 'showAll');
+				header('Location: ' . $this->generateUrl('profile', 'showAll'));
 				return false;
 			}
 
@@ -119,13 +119,12 @@
 				if (!internalTools::verifyCSRF($csrf))
 				{
 					$_SESSION['errormessage'] = 'Jeton CSRF invalide !';
-					header('Location: ' . $this->generateUrl('profile', 'showAll');
+					header('Location: ' . $this->generateUrl('profile', 'showAll'));
 					return false;
 				}
 			}
 
 			global $db;
-			
 
 			$date = $_POST['date'];
 			$content = $_POST['content'];
@@ -215,7 +214,7 @@
 				if (!$api)
 				{
 					$_SESSION['errormessage'] = 'Le SMS a bien été créé, mais certains numéro ne sont pas valides.';
-					header('Location: ' . $this->generateUrl('scheduleds', 'showAll');
+					header('Location: ' . $this->generateUrl('scheduleds', 'showAll'));
 				}
 				return true;
 			}
@@ -223,7 +222,7 @@
 			if (!$api)
 			{
 				$_SESSION['successmessage'] = 'Le SMS a bien été créé.';
-				header('Location: ' . $this->generateUrl('scheduleds', 'showAll');
+				header('Location: ' . $this->generateUrl('scheduleds', 'showAll'));
 			}
 			return true;
 		}
@@ -239,7 +238,7 @@
 			if (!internalTools::verifyCSRF($csrf))
 			{
 				$_SESSION['successmessage'] = 'Jeton CSRF invalide !';
-				header('Location: ' . $this->generateUrl('scheduleds', 'showAll');
+				header('Location: ' . $this->generateUrl('scheduleds', 'showAll'));
 				return false;
 			}
 
diff --git a/templates/commands.php b/templates/commands.php
index 28838d4..96d1a05 100755
--- a/templates/commands.php
+++ b/templates/commands.php
@@ -96,7 +96,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/command' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});
diff --git a/templates/contacts.php b/templates/contacts.php
index 6ab076f..5739d19 100755
--- a/templates/contacts.php
+++ b/templates/contacts.php
@@ -94,7 +94,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/contacts' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});
diff --git a/templates/groups.php b/templates/groups.php
index 6c08015..1f277d5 100755
--- a/templates/groups.php
+++ b/templates/groups.php
@@ -94,7 +94,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/groups' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});
diff --git a/templates/profile.php b/templates/profile.php
index 4052b8a..aae5483 100755
--- a/templates/profile.php
+++ b/templates/profile.php
@@ -121,7 +121,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/users' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});
diff --git a/templates/scheduleds.php b/templates/scheduleds.php
index abfc85b..f2bf798 100755
--- a/templates/scheduleds.php
+++ b/templates/scheduleds.php
@@ -94,7 +94,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/scheduleds' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});
diff --git a/templates/users.php b/templates/users.php
index d9673b8..e4312d2 100755
--- a/templates/users.php
+++ b/templates/users.php
@@ -93,7 +93,7 @@
 			var url = jQuery(this).attr('href');
 			jQuery(target).find('input:checked').each(function ()
 			{
-				url += '/users' + jQuery(this).val() + '_' + jQuery(this).val();
+				url += '/' + jQuery(this).val();
 			});
 			window.location = url;
 		});