diff options
Diffstat (limited to 'inc/poche/Database.class.php')
-rw-r--r-- | inc/poche/Database.class.php | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 8da7a994..cd5a9a31 100644 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -37,19 +37,34 @@ class Database { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | public function isInstalled() { | 39 | public function isInstalled() { |
40 | $sql = "SELECT username FROM users WHERE id=?"; | 40 | $sql = "SELECT username FROM users"; |
41 | $query = $this->executeQuery($sql, array('1')); | 41 | $query = $this->executeQuery($sql, array()); |
42 | $hasAdmin = $query->fetchAll(); | 42 | $hasAdmin = count($query->fetchAll()); |
43 | 43 | ||
44 | if (count($hasAdmin) == 0) | 44 | if ($hasAdmin == 0) |
45 | return FALSE; | 45 | return FALSE; |
46 | 46 | ||
47 | return TRUE; | 47 | return TRUE; |
48 | } | 48 | } |
49 | 49 | ||
50 | public function install($login, $password) { | 50 | public function install($login, $password) { |
51 | $sql = 'INSERT INTO users ( username, password ) VALUES (?, ?)'; | 51 | $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)'; |
52 | $params = array($login, $password); | 52 | $params = array($login, $password, $login, ' '); |
53 | $query = $this->executeQuery($sql, $params); | ||
54 | |||
55 | $sequence = ''; | ||
56 | if (STORAGE == 'postgres') { | ||
57 | $sequence = 'users_id_seq'; | ||
58 | } | ||
59 | |||
60 | $id_user = intval($this->getLastId($sequence)); | ||
61 | |||
62 | $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; | ||
63 | $params = array($id_user, 'pager', '10'); | ||
64 | $query = $this->executeQuery($sql, $params); | ||
65 | |||
66 | $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; | ||
67 | $params = array($id_user, 'language', 'en_EN.UTF8'); | ||
53 | $query = $this->executeQuery($sql, $params); | 68 | $query = $this->executeQuery($sql, $params); |
54 | 69 | ||
55 | return TRUE; | 70 | return TRUE; |
@@ -195,7 +210,7 @@ class Database { | |||
195 | $query = $this->executeQuery($sql_action, $params_action); | 210 | $query = $this->executeQuery($sql_action, $params_action); |
196 | } | 211 | } |
197 | 212 | ||
198 | public function getLastId() { | 213 | public function getLastId($column = '') { |
199 | return $this->getHandle()->lastInsertId(); | 214 | return $this->getHandle()->lastInsertId($column); |
200 | } | 215 | } |
201 | } | 216 | } |