Name is changed to concatenation of forename and surname, in order to
authorLadislav Láska <laska@kam.mff.cuni.cz>
Wed, 22 Jun 2011 19:28:10 +0000 (21:28 +0200)
committerLadislav Láska <laska@kam.mff.cuni.cz>
Wed, 22 Jun 2011 19:28:10 +0000 (21:28 +0200)
ensure consistency while sorting.

classes/auth.php
classes/bike.php
classes/bikeroom.php
classes/key.php
controllers/register.php
controllers/useredt.php
sql/database.sql
template/register.php
template/useredt.php

index d0b497153d73246de1eecd25e9e9d5c910885ed8..2c4049faeebeb8a6399a1b3a0352d7fdb0031635 100644 (file)
@@ -20,7 +20,8 @@ class User {
                $query = DB::query("SELECT *,
                        SUBSTRING(`room`,1,1) AS `building`, 
                        SUBSTRING(`room`,2,CHAR_LENGTH(`room`)-3) AS `floor`,
-                       SUBSTRING(`room`,-2) AS `roomNumber`
+                       SUBSTRING(`room`,-2) AS `roomNumber`,
+                       CONCAT_WS(' ', `surname`, `forename`) AS `name`
                        FROM `users` WHERE LOWER(`login`) = LOWER(?) $AND;");
                $query->set(0, $login);
                if (!is_null($passwd)) $query->set(1, $passwd);
@@ -34,7 +35,8 @@ class User {
 
        public static function listAll($cond = null) {
                /* Cond is not used! */
-               $query = DB::query("SELECT * FROM `users` ORDER BY login,name");
+               $query = DB::query("SELECT *,CONCAT_WS(' ', `surname`, `forename`) AS `name`
+                       FROM `users` ORDER BY login,surname,forename");
                $res = $query->commit();
                $array = array();
                while ($row = mysql_fetch_array($res)) {
@@ -52,16 +54,16 @@ class User {
        public function update() {
                if ($this->id == -1) {
                        /* New user */
-                       $query = DB::query("INSERT INTO `users` SET `login` = ?, `name` = ?, `room` = ?, `email` = ?, `phone` = ?, `password` = SHA1(?), `privileges` = 0;", 
-                               array($this->login, $this->name, $this->room, $this->email, $this->phone, $this->password));
+                       $query = DB::query("INSERT INTO `users` SET `login` = ?, `forename` = ?, `surname` = ?, `room` = ?, `email` = ?, `phone` = ?, `password` = SHA1(?), `privileges` = 0;", 
+                               array($this->login, $this->forename, $this->surname, $this->room, $this->email, $this->phone, $this->password));
                        if ($query->commit()) {
                                $this->data['id'] = $query->lastId();
                                $this->data['privileges'] = 0;
                        } else die("SQL query died in User::update.");
                } else {
                        /* Update */
-                       $query = DB::query("UPDATE `users` SET `login` = ?, `name` = ?, `room` = ?, `email` = ?, `phone` = ?, `privileges` = ? WHERE `id` = ?",
-                               array($this->login, $this->name, $this->room, $this->email, $this->phone, $this->privileges, $this->id) );
+                       $query = DB::query("UPDATE `users` SET `login` = ?, `forename` = ?, `surname` = ?, `room` = ?, `email` = ?, `phone` = ?, `privileges` = ? WHERE `id` = ?",
+                               array($this->login, $this->forename, $this->surname, $this->room, $this->email, $this->phone, $this->privileges, $this->id) );
                        $query->commit() or die("SQL query died in User::update.");
                        if ($this->newpass) {
                                $query = DB::query("UPDATE `users` SET `password` = SHA1(?) WHERE `id` = ?;",
@@ -95,10 +97,16 @@ class User {
                else { $this->lastErrorMessage = tr("Heslo musí mít alespoň 6 znaků."); return false; }
        }
 
-       public function setName($value) {
-               if ((strlen($value) >= 0) && (!(strpos($value, " ") === FALSE))) 
-                       { $this->data['name'] = $value; return true; }
-               else { $this->lastErrorMessage = tr("Použite prosím své celé jméno."); return false; }
+       public function setForename($value) {
+               if (strlen($value) > 0) 
+                       { $this->data['forename'] = $value; return true; }
+               else { $this->lastErrorMessage = tr("Zadejte prosím svě křestní jméno."); return false; }
+       }
+
+       public function setSurname($value) {
+               if (strlen($value) > 0) 
+                       { $this->data['surname'] = $value; return true; }
+               else { $this->lastErrorMessage = tr("Zadejte prosím své příjmení."); return false; }
        }
 
        public function setRoom($value) {
index 63628fe83c25f77dd4eaf22ac4f213c56db1867d..3ab4250fa97aa4f410dfa026ace255fdd9147a6e 100644 (file)
@@ -12,9 +12,9 @@ class Bike {
                $query = DB::query(
                        "SELECT 
                                `bikes`.*, 
-                               `users`.`name` as `userName`, 
                                `users`.`login` as `userLogin`,
-                               (CONCAT(UPPER(`bikerooms`.`building`), `bikerooms`.`floor`)) as `bikeroomName`
+                               (CONCAT(UPPER(`bikerooms`.`building`), `bikerooms`.`floor`)) as `bikeroomName`,
+                               CONCAT_WS(' ', `surname`, `forename`) as `userName`
                        FROM `bikes` 
                        LEFT JOIN `users` ON (`users`.`id` = `bikes`.`user`)
                        LEFT JOIN `bikerooms` ON (`bikes`.`bikeroom` = `bikerooms`.`id`)
index 7408d9ad1f5cfb549e3651c0d462285bd92e603a..695527ef09604e8f8abbb61e343f04abd67e4780 100644 (file)
@@ -12,7 +12,7 @@ class Bikeroom {
                        "SELECT 
                                `bikerooms`.*, 
                                CONCAT(UPPER(building),floor) AS `name`, 
-                               `users`.`name` AS `groundsmanName`, 
+                               CONCAT_WS(' ', `surname`, `forename`) AS `groundsmanName`, 
                                (`space` - (SELECT COUNT(*) FROM `bikes` WHERE `bikeroom` = `bikerooms`.`id`)) AS `freeSpace`
                        FROM `bikerooms` 
                        LEFT JOIN `users` ON (`users`.`id` = `bikerooms`.`groundsman`)
index 5983da5c0a9e06d12c150cc1dc87a1c3b4aac243..5065bb5f0d41a87bdcbfac9c5c50a77613702dd4 100644 (file)
@@ -61,18 +61,21 @@ class Key {
                $userId = (is_object($user) ? $user->id : $user);
                $bikeroomId = (is_object($bikeroom) ? $bikeroom->id : $bikeroom);
                /* In this variant, select _only_ valid keys! */
-               $query = DB::Query("SELECT `keys`.*,`users`.`login`,`users`.`name` AS `userName`,
-                       CONCAT(`bikerooms`.`building`,`bikerooms`.`floor`) AS `bikeroomName`
-                       FROM `keys` LEFT JOIN `users` ON (`keys`.`user` = `users`.`id`)
-                       LEFT JOIN `bikerooms` ON (`keys`.`bikeroom` = `bikerooms`.`id`)
-                       WHERE `user` = ? AND `bikeroom` = ? AND (`to` IS NULL);", array($userId, $bikeroomId));
+               $query = DB::Query("SELECT `keys`.*,`users`.`login`,
+               CONCAT_WS(' ', `surname`, `forename`) AS `userName`,
+               CONCAT(`bikerooms`.`building`,`bikerooms`.`floor`) AS `bikeroomName`
+               FROM `keys` LEFT JOIN `users` ON (`keys`.`user` = `users`.`id`) LEFT
+               JOIN `bikerooms` ON (`keys`.`bikeroom` = `bikerooms`.`id`) WHERE `user`
+               = ? AND `bikeroom` = ? AND (`to` IS NULL);", array($userId,
+               $bikeroomId));
                $res = $query->commit();
                if (!$res) die("SQL query failed.");
                if (mysql_num_rows($res) == 1) {
                        $this->data = mysql_fetch_array($res);
                } else {
                        $query = DB::Query(
-                               "SELECT *, `users`.`id` AS `user`, `users`.`login`,`users`.`name` AS `userName`,
+                               "SELECT *, `users`.`id` AS `user`, `users`.`login`,
+                                       CONCAT_WS(' ', `surname`, `forename`) AS `userName`,
                            CONCAT(`bikerooms`.`building`,`bikerooms`.`floor`) AS `bikeroomName`,
                                        `bikerooms`.`id` AS `bikeroom`, -1 AS `id`, NULL AS `to`, NULL AS `from`
                                 FROM `bikerooms` CROSS JOIN `users` WHERE `users`.`id` = ? AND `bikerooms`.`id` = ?;",
index 7a80a8333004edeae9ddc10f62367dfdd0aae943..82df2d2d03f7b70bc79db84c68bcf838b3a9c9d8 100644 (file)
@@ -16,7 +16,8 @@ if (isset($_POST['login'])) {
        }
        if (!$nu->setLogin($_POST['login'])) { $formok = false; $formmsg['login'] = $nu->lastErrorMessage; }
        if (!$nu->setPassword($_POST['password']))      { $formok = false; $formmsg['password'] = $nu->lastErrorMessage; }
-       if (!$nu->setName($_POST['name'])) { $formok = false; $formmsg['name'] = $nu->lastErrorMessage; }
+       if (!$nu->setForename($_POST['forename'])) { $formok = false; $formmsg['forename'] = $nu->lastErrorMessage; }
+       if (!$nu->setSurname($_POST['surname'])) { $formok = false; $formmsg['surname'] = $nu->lastErrorMessage; }
        if (!$nu->setRoom($_POST['room'])) { $formok = false; $formmsg['room'] = $nu->lastErrorMessage; }
        if (!$nu->setEmail($_POST['email'])) { $formok = false; $formmsg['email'] = $nu->lastErrorMessage; }
        if (!$nu->setPhone($_POST['phone'])) { $formok = false; $formmsg['phone'] = $nu->lastErrorMessage; }
index 1b16057f14c9883fff2062f4363ca3e10c2429f2..1ec74e17a9ed7be8b1b5c81d5438abe9875b322a 100644 (file)
@@ -12,7 +12,7 @@ if (($auth->verify(P_USERMOD)) && (isset($_GET['mod']))) {
        redir("403");
 }
 
-if (isset($_POST['name'])) {
+if (isset($_POST['submit'])) {
        $formok = true;
        /* Check passwords */
        if (strlen($_POST['password']) != 0) {
@@ -24,7 +24,8 @@ if (isset($_POST['name'])) {
        }
 
 
-       if (!$user->setName($_POST['name'])) { $formok = false; $formmsg['name'] = $user->lastErrorMessage; }
+       if (!$user->setForename($_POST['forename'])) { $formok = false; $formmsg['forename'] = $nu->lastErrorMessage; }
+       if (!$user->setSurname($_POST['surname'])) { $formok = false; $formmsg['surname'] = $nu->lastErrorMessage; }
        if (!$user->setRoom($_POST['room'])) { $formok = false; $formmsg['room'] = $user->lastErrorMessage; }
        if (!$user->setEmail($_POST['email'])) { $formok = false; $formmsg['email'] = $user->lastErrorMessage; }
        if (!$user->setPhone($_POST['phone'])) { $formok = false; $formmsg['phone'] = $user->lastErrorMessage; }
index 6b564372c85e4bfdfe6adbcf6b0831bf81a4f1be..383403a882162a0d2f3cf18424ea145331425feb 100644 (file)
@@ -2,7 +2,8 @@ CREATE TABLE `users` (
        id int AUTO_INCREMENT,
        login varchar(50),
        password varchar(100),
-       name varchar(100),
+       forename varchar(100),
+       surname varchar(100),
        room varchar(5),
        email varchar(50),
        phone varchar(25),
index 629a70b0c0628c81fbb5c28a439e0a41202880e7..3fc7151cff8694cb6727f8033329cf3098ec58fb 100644 (file)
@@ -11,7 +11,8 @@ případ, že by bylo potřeba Vás okamžitě informovat o závažné věci (od
        field("Heslo", "password", "password", "validatePassword");
        field("Zopakovat heslo", "password", "password2", "validatePassword");
        heading("Osobní údaje");
-       field("Jméno", "text", "name", "validateSomething");
+       field("Jméno", "text", "forename", "validateSomething");
+       field("Příjmení", "text", "surname", "validateSomething");
        field("Pokoj", "text", "room", "validateRoom");
        field("Email", "text", "email", "validateEmail");
        field("Telefon", "text", "phone", "validateSomething");
index ae84f696e5ceda808da53b0566d995468c024fa5..5d5c30c967dabe6c2f9d0f0aa851b5bbea737567 100644 (file)
@@ -7,7 +7,8 @@
 <?php
        heading("Osobní údaje");
        field("Login", "plain", "login");
-       field("Jméno", "text", "name", "validateSomething");
+       field("Jméno", "text", "forename", "validateSomething");
+       field("Příjmení", "text", "surname", "validateSomething");
        field("Pokoj", "text", "room", "validateRoom");
        field("Email", "text", "email", "validateEmail");
        field("Telefon", "text", "phone", "validateSomething");
@@ -21,7 +22,7 @@
                $user->privileges);
        }
 ?>
-<tr><th colspan="2"><div class="center"><input type="submit" value="<?=tr("Uložit")?>" /></div></th><td>&nbsp;</td></tr>
+<tr><th colspan="2"><div class="center"><input type="submit" name="submit" value="<?=tr("Uložit")?>" /></div></th><td>&nbsp;</td></tr>
 </table>
 
 </form>