JSlip  1.0
AccountModel.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/Model.php');
9 
10 class AccountModel extends Model
11 {
12 
13  public function getList($cnd) {
14 
15  $this->connect();
16 
17  $where = $this->_getListWhere($cnd);
18  $cnt = $this->_getListCnt($where);
19  $list = $this->_getListDat($where, $cnt, $cnd['pager']);
20 
21  $this->close();
22 
23  return $list;
24  }
25 
26  private function _getListWhere($cnd) {
27 
28  $where = " WHERE (TRUE)";
29 
30  if ($cnd['cnd_login_id'] != '') {
31  $where .= " AND `a`.`login_id` LIKE '%" . $this->esc($cnd['cnd_login_id']) . "%'";
32  }
33 
34  if ($cnd['cnd_name'] != '') {
35  $where .= " AND `m`.`name` LIKE '%" . $this->esc($cnd['cnd_name']) . "%'";
36  }
37 
38  return $where;
39  }
40 
41  private function _getListCnt($where) {
42 
43  $sql = "SELECT COUNT(*) AS `cnt` FROM `t_auth` `a` INNER JOIN `t_member` `m` ON `a`.`aid` = `m`.`aid`" . $where;
44  $rec = $this->getRecord($sql);
45 
46  return $rec[0]['cnt'];
47  }
48 
49  private function _getListDat($where, $cnt, $pager) {
50 
51  $pg = $this->getPaging($cnt, $pager['page'], $pager['rpp']);
52 
53  if ($cnt < 0) {
54  $rec = [];
55  } else {
56  $sql = "SELECT"
57  . " `a`.`login_id`, `m`.*"
58  . " FROM `t_auth` `a` INNER JOIN `t_member` `m` ON `a`.`aid` = `m`.`aid`"
59  . $where
60  . " ORDER BY `m`.`name`, `a`.`login_id`"
61  . " LIMIT " . $pg['ofst'] . ", " . $pg['rpp']
62  ;
63  $rec = $this->getRecord($sql);
64  }
65 
66  return [
67  'cnt' => $pg['cnt'],
68  'rpp' => $pg['rpp'],
69  'last' => $pg['last'],
70  'page' => $pg['page'],
71  'rec' => $rec,
72  ];
73  }
74 
75  public function getData($mid) {
76 
77  $this->connect();
78  $sql = "SELECT `a`.`login_id`, `m`.*"
79  . " FROM `t_auth` `a` INNER JOIN `t_member` `m` ON `a`.`aid` = `m`.`aid`"
80  . " WHERE `m`.`mid` = '" . $this->esc($mid) . "'"
81  ;
82  $rec = $this->getRecord($sql);
83  $this->close();
84 
85  return (empty($rec[0])) ? [] : $rec[0];
86  }
87 
88  public function regist($param) {
89 
90  $err = '';
91 
92  $this->connect();
93  $this->begin();
94 
95  try {
96 
97  if (empty($param['passwd1'])) {
98  $sql = "UPDATE `t_auth` SET"
99  . " `login_id`" . " = '" . $this->esc($param['login_id']) . "'"
100  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
101  . " WHERE `aid` = '" . $this->esc($param['aid']) . "'"
102  ;
103  } else {
104  $sql = "UPDATE `t_auth` SET"
105  . " `login_id`" . " = '" . $this->esc($param['login_id']) . "'"
106  . ", `password`" . " = '" . password_hash($param['passwd1'], PASSWORD_DEFAULT) . "'"
107  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
108  . " WHERE `aid` = '" . $this->esc($param['aid']) . "'"
109  ;
110  }
111 
112  $ans = $this->query($sql);
113 
114  $sql = "UPDATE `t_member` SET"
115  . " `name`" . " = '" . $this->esc($param['name']) . "'"
116  . ", `role`" . " = '" . $this->esc($param['role']) . "'"
117  . ", `email`" . " = '" . $this->esc($param['email']) . "'"
118  . ", `tel`" . " = '" . $this->esc($param['tel']) . "'"
119  . ", `update_person`" . " = " . $_SESSION['minfo']['mid']
120  . " WHERE `mid` = '" . $this->esc($param['mid']) . "'"
121  ;
122  $ans = $this->query($sql);
123 
124  } catch(Exception $e) {
125  $err = $e->getMessage();
126  }
127 
128  if (empty($err)) {
129  $this->commit();
130  } else {
131  $this->rollback();
132  }
133 
134  $this->close();
135 
136  return $err;
137  }
138 
139  public function insert($param) {
140 
141  $err = '';
142 
143  $this->connect();
144  $this->begin();
145 
146  try {
147 
148  $sql = "INSERT INTO `t_auth`"
149  . " (`login_id`, `password`, `update_person`)"
150  . " VALUES"
151  . " ('" . $this->esc($param['login_id']) . "'"
152  . ", '" . password_hash($param['passwd1'], PASSWORD_DEFAULT) . "'"
153  . ", '" . $_SESSION['minfo']['mid']. "'"
154  . ")"
155  ;
156  $ans = $this->query($sql);
157  $aid = $this->insert_id();
158 
159  $sql = "INSERT INTO `t_member`"
160  . " (`aid`, `name`, `role`, `email`, `tel`, `update_person`)"
161  . " VALUES"
162  . " ('" . $aid . "'"
163  . ", '" . $this->esc($param['name']) . "'"
164  . ", '" . $this->esc($param['role']) . "'"
165  . ", '" . $this->esc($param['email']) . "'"
166  . ", '" . $this->esc($param['tel']) . "'"
167  . ", '" . $_SESSION['minfo']['mid']. "'"
168  . ")"
169  ;
170  $ans = $this->query($sql);
171 
172  } catch(Exception $e) {
173  $err = $e->getMessage();
174  }
175 
176  if (empty($err)) {
177  $this->commit();
178  } else {
179  $this->rollback();
180  }
181 
182  $this->close();
183 
184  return $err;
185  }
186 
187  public function delete($param) {
188 
189  $err = '';
190  $aid = $param['aid'];
191  $mid = $param['mid'];
192 
193  $this->connect();
194  $this->begin();
195 
196  try {
197 
198  $sql = "DELETE FROM `t_member` WHERE `mid` = '" . $this->esc($mid) . "'";
199  $ans = $this->query($sql);
200 
201  $sql = "DELETE FROM `t_auth` WHERE `aid` = '" . $this->esc($aid) . "'";
202  $ans = $this->query($sql);
203 
204  } catch(Exception $e) {
205  $err = $e->getMessage();
206  }
207 
208  if (empty($err)) {
209  $this->commit();
210  } else {
211  $this->rollback();
212  }
213 
214  $this->close();
215 
216  return $err;
217  }
218 
219  public function chkDup($login_id) {
220 
221  $this->connect();
222  $sql = "SELECT COUNT(*) AS `cnt` FROM `t_auth` WHERE `login_id` = '" . $this->esc($login_id) . "'";
223  $rec = $this->getRecord($sql);
224  $this->close();
225 
226  return $rec[0]['cnt'];
227  }
228 }
AccountModel\regist
regist($param)
Definition: AccountModel.php:88
AccountModel\_getListDat
_getListDat($where, $cnt, $pager)
Definition: AccountModel.php:49
Model\connect
connect()
Definition: Model.php:12
Model\begin
begin()
Definition: Model.php:31
Model\query
query($sql)
Definition: Model.php:47
Model\getRecord
getRecord($sql)
Definition: Model.php:55
AccountModel\_getListWhere
_getListWhere($cnd)
Definition: AccountModel.php:26
AccountModel\getList
getList($cnd)
Definition: AccountModel.php:13
AccountModel\insert
insert($param)
Definition: AccountModel.php:139
Model\insert_id
insert_id()
Definition: Model.php:51
AccountModel\chkDup
chkDup($login_id)
Definition: AccountModel.php:219
AccountModel\_getListCnt
_getListCnt($where)
Definition: AccountModel.php:41
Model
Definition: Model.php:8
Model\commit
commit()
Definition: Model.php:35
Model\close
close()
Definition: Model.php:27
Model\esc
esc($str)
Definition: Model.php:43
Model\getPaging
getPaging($cnt, $page, $rpp)
Definition: Model.php:69
$cnt
$cnt
Definition: tex_tmplt_bs.php:319
Model\rollback
rollback()
Definition: Model.php:39
AccountModel\getData
getData($mid)
Definition: AccountModel.php:75
AccountModel
Definition: AccountModel.php:10