JSlip  1.0
AccountController.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/View.php');
9 require_once(dirname(__FILE__) . '/../../lib/Controller.php');
10 require_once(dirname(__FILE__) . '/AccountModel.php');
11 
12 define('PAGER_RPP', 10);
13 
15 {
16  public $param;
17  public $rest;
18  public $viewName;
19  public $dat;
20  public $pager;
21  public $model;
22  public $view;
23 
24  public function main($param) {
25 
26  if ($_SESSION['minfo']['role'] != 'root') {
27  $this->viewName = 'account_err';
28  return;
29  }
30 
31  $this->rest = '';
32  $this->param = $param;
33  $this->model = new AccountModel();
34  $this->view = new View();
35 
36  $this->param['base'] = dirname(__FILE__);
37 
38  if (empty($this->param['act'])) {
39  $this->_list();
40  } else {
41  switch ($this->param['act']) {
42  case 'create': $this->_create(); break;
43  case 'drop': $this->_drop(); break;
44  case 'edit': $this->_edit(); break;
45  case 'remember': $this->_remember(); break;
46  case 'search': $this->_search(); break;
47  case 'check': $this->_check(); break;
48  case 'regist': $this->_regist(); break;
49  default: $this->_list(); break;
50  }
51  }
52  }
53 
54  private function _list() {
55 
56  $this->viewName = 'account_list';
57 
58  $this->dat['cnd'] = [
59  'cnd_login_id' => '',
60  'cnd_name' => '',
61  'pager' => ['page' => 1, 'rpp' => PAGER_RPP],
62  ];
63 
64  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
65 
66  $_SESSION['account_list_cnd'] = $this->dat['cnd'];
67  }
68 
69  private function _search() {
70 
71  $this->viewName = 'account_list';
72 
73  $this->dat['cnd'] = [
74  'cnd_name' => $this->param['cnd_name'],
75  'cnd_login_id' => $this->param['cnd_login_id'],
76  'pager' => ['page' => $this->param['page_curr'], 'rpp' => PAGER_RPP],
77  ];
78 
79  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
80 
81  $_SESSION['account_list_cnd'] = $this->dat['cnd'];
82  }
83 
84  private function _remember() {
85 
86  $this->viewName = 'account_list';
87  $this->dat['cnd'] = $_SESSION['account_list_cnd'];
88  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
89  }
90 
91  private function _edit() {
92 
93  $this->viewName = 'account_edit';
94  $this->dat = $this->model->getData($this->param['mid']);
95  }
96 
97  private function _check() {
98 
99  $err = [];
100 
101  $insert = (empty($this->param['insert'])) ? false : true;
102  $name = $this->param['name'];
103  $role = $this->param['role'];
104  $email = $this->param['email'];
105  $tel = $this->param['tel'];
106  $login_id = $this->param['login_id'];
107  $passwd0 = $this->param['passwd0'];
108  $passwd1 = $this->param['passwd1'];
109 
110  if (empty($name)) {
111  $err[] = 'メンバー名は必須です。';
112  }
113 
114  if (empty($login_id)) {
115  $err[] = 'アカウントは必須です。';
116  } else {
117  if ($insert) {
118  if ($this->model->chkDup($login_id)) {
119  $err[] = '既に存在するアカウントです。';
120  }
121  }
122  }
123 
124  if ($insert) {
125  if (empty($passwd0)) {
126  $err[] = 'パスワードは必須です。';
127  }
128  }
129 
130  if (!empty($passwd1)) {
131  if ($passwd0 != $passwd1) {
132  $err[] = 'パスワードが不正です。';
133  }
134  }
135 
136  if (empty($err)) {
137  $this->rest = json_encode(['sts' => 'OK']);
138  } else {
139  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
140  }
141  }
142 
143  private function _regist() {
144 
145  $insert = (empty($this->param['insert'])) ? false : true;
146 
147  if ($insert) {
148  $err = $this->model->insert($this->param);
149  } else {
150  $err = $this->model->regist($this->param);
151  }
152 
153  if (!empty($err)) {
154  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
155  return;
156  }
157 
158  $this->rest = json_encode(['sts' => 'OK']);
159  }
160 
161  private function _create() {
162 
163  $this->viewName = 'account_create';
164  }
165 
166  private function _drop() {
167 
168  $err = $this->model->delete($this->param);
169 
170  if (!empty($err)) {
171  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
172  return;
173  }
174 
175  $this->rest = json_encode(['sts' => 'OK']);
176  }
177 }
AccountController\_regist
_regist()
Definition: AccountController.php:143
AccountController\_edit
_edit()
Definition: AccountController.php:91
AccountController\$view
$view
Definition: AccountController.php:22
AccountController\_create
_create()
Definition: AccountController.php:161
AccountController\main
main($param)
Definition: AccountController.php:24
View
Definition: View.php:8
AccountController\$param
$param
Definition: AccountController.php:16
AccountController\$pager
$pager
Definition: AccountController.php:20
AccountController\$model
$model
Definition: AccountController.php:21
Controller
Definition: Controller.php:15
AccountController
Definition: AccountController.php:14
AccountController\_check
_check()
Definition: AccountController.php:97
AccountController\$dat
$dat
Definition: AccountController.php:19
AccountController\_search
_search()
Definition: AccountController.php:69
AccountController\_drop
_drop()
Definition: AccountController.php:166
AccountController\_remember
_remember()
Definition: AccountController.php:84
AccountController\$rest
$rest
Definition: AccountController.php:17
PAGER_RPP
const PAGER_RPP
Definition: AccountController.php:12
AccountController\$viewName
$viewName
Definition: AccountController.php:18
AccountController\_list
_list()
Definition: AccountController.php:54
AccountModel
Definition: AccountModel.php:10