forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAction.class.php
More file actions
512 lines (467 loc) · 13.3 KB
/
Action.class.php
File metadata and controls
512 lines (467 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* 会員テーブル登録用クラス
*
* @package NetCommons Components
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
class Users_Action
{
/**
* @var DBオブジェクトを保持
*
* @access private
*/
var $_db = null;
/**
* @var DIコンテナを保持
*
* @access private
*/
var $_container = null;
/**
* コンストラクター
*
* @access public
*/
function Users_Action() {
$this->_container =& DIContainerFactory::getContainer();
$this->_db =& $this->_container->getComponent("DbObject");
}
/**
* 会員テーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updUsers($params=array(), $where_params=array(), $footer_flag=true) {
return $this->_db->updateExecute("users", $params, $where_params, $footer_flag);
}
/**
* 会員テーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insUser($params=array()) {
$sitesView =& $this->_container->getComponent("sitesView");
$sites = $sitesView->getSelfSite();
while(1) {
$id = $this->_db->nextSeq("users");
$user_id = sha1(uniqid($sites['site_id'].$id, true));
// Hash値で同じものがないか念のためチェック
$result = $this->_db->selectExecute("users", array("user_id" => $user_id));
if ($result === false) {
return false;
}
if(!isset($result[0]['user_id'])) {
break;
}
}
$params = array_merge(array("user_id" => $user_id), $params);
$result = $this->_db->insertExecute("users", $params, true);
if ($result === false) {
return false;
}
return $user_id;
}
/**
* 項目テーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insItem($params=array()) {
$item_id = $this->_db->insertExecute("items", $params, true, "item_id");
if ($item_id === false) {
return false;
}
return $item_id;
}
/**
* 項目説明文テーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insItemDesc($item_id, $params=array()) {
$db_params = array("item_id"=>0);
$db_params = array_merge($db_params, $params);
$db_params["item_id"] = $item_id;
return $this->_db->insertExecute("items_desc", $db_params);
}
/**
* 項目選択式テーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insItemOptions($item_id, $params=array()) {
$db_params = array("item_id"=>0);
$db_params = array_merge($db_params, $params);
$db_params["item_id"] = $item_id;
return $this->_db->insertExecute("items_options", $db_params);
}
/**
* 項目権限リンクテーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insItemsAuthLink($params = array()) {
return $this->_db->insertExecute("items_authorities_link", $params, true);
}
/**
* 項目権限リンクテーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updItemsAuthLink($params=array(), $where_params=array(), $footer_flag=true) {
return $this->_db->updateExecute("items_authorities_link", $params, $where_params, $footer_flag);
}
/**
* 会員項目リンクテーブルInsert
*
* @param array $params パラメータ引数
* @return boolean true or false
* @access public
*/
function insUserItemLink($params = array()) {
return $this->_db->insertExecute("users_items_link", $params, false);
}
/**
* 項目テーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updItem($params=array(), $where_params=array(), $footer_flag=true) {
return $this->_db->updateExecute("items", $params, $where_params, $footer_flag);
}
/**
* 項目説明文テーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updItemDesc($params=array(), $where_params=array()) {
return $this->_db->updateExecute("items_desc", $params, $where_params, false);
}
/**
* 項目選択式テーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updItemOptions($params=array(), $where_params=array()) {
return $this->_db->updateExecute("items_options", $params, $where_params, false);
}
/**
* 会員項目リンクテーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function updUsersItemsLink($params=array(), $where_params=array()) {
return $this->_db->updateExecute("users_items_link", $params, $where_params, false);
}
/**
* 会員項目リンクテーブルUpdate
*
* @param array $params パラメータ引数
* @param array $where_params Whereパラメータ引数
* @return boolean true or false
* @access public
*/
function _updUsersItemsLink(&$result, &$params) {
$container =& DIContainerFactory::getContainer();
$db =& $container->getComponent("DbObject");
$func = array("Users_Action","_updateExecute");
while ($obj = $result->fetchRow()) {
$db_params = array("content"=>$params[$obj["tag_name"]]);
$where_params = array("user_id"=>$params["user_id"],"item_id"=>$obj["item_id"]);
$sql = $db->getUpdateSQL("users_items_link", $db_params, $where_params, false);
$res = $db->execute($sql, $db_params);
if (!$res) {
$db->addError();
return false;
}
}
return true;
}
/**
* 会員テーブルDelete(user_id)
*
* @param int $user_id ユーザーID
* @return boolean true or false
* @access public
*/
function delUserById($user_id) {
$params = array( "user_id" => $user_id );
$result = $this->_db->deleteExecute("users", $params);
if (!$result) {
return false;
}
$result = $this->_db->deleteExecute("users_items_link", $params);
if (!$result) {
return false;
}
return true;
}
/**
* 項目テーブルDelete(item_id)
*
* @param int $item_id 項目ID
* @return boolean true or false
* @access public
*/
function delItemById($item_id) {
$params = array( "item_id" => $item_id );
$result = $this->_db->deleteExecute("items", $params);
if (!$result) {
return false;
}
$result = $this->_db->deleteExecute("items_desc", $params);
if (!$result) {
return false;
}
$result = $this->_db->deleteExecute("items_options", $params);
if (!$result) {
return false;
}
$result = $this->_db->deleteExecute("users_items_link", $params);
if (!$result) {
return false;
}
$result = $this->_db->deleteExecute("items_authorities_link", $params);
if (!$result) {
return false;
}
return true;
}
/**
* users_items_linkテーブルDelete
*
* @param int item_id 項目ID
* @return boolean true or false
* @access public
*/
function delUsersItemsLinkById($item_id, $user_id = null)
{
if($user_id == null) {
$params = array(
"item_id" => $item_id
);
} else {
$params = array(
"item_id" => $item_id,
"user_id" => $user_id
);
}
$result = $this->_db->deleteExecute("users_items_link", $params);
if ($result === false) {
$this->_db->addError();
return $result;
}
return true;
}
/**
* ItemDescテーブルDelete
*
* @param int item_id 項目ID
* @return boolean true or false
* @access public
*/
function delItemDescById($item_id)
{
$params = array(
"item_id" => $item_id
);
$result = $this->_db->deleteExecute("items_desc", $params);
if ($result === false) {
$this->_db->addError();
return $result;
}
return true;
}
/**
* items_optionsテーブルDelete
*
* @param int item_id 項目ID
* @return boolean true or false
* @access public
*/
function delItemOptionsById($item_id)
{
$params = array(
"item_id" => $item_id
);
$result = $this->_db->deleteExecute("items_options", $params);
if ($result === false) {
$this->_db->addError();
return $result;
}
return true;
}
/**
* 会員データを削除する
*
* @param mix $roomId 削除対象ルームID
* @return boolean true or false
* @access public
*/
function deleteUser($userId)
{
if (empty($userId)) {
return true;
}
$userIds = $userId;
if (!is_array($userId)) {
$userIds = array($userId);
}
$inValue = "'" . implode("','", $userIds) . "'";
$sql = "SELECT P.room_id, "
. "U.role_authority_id "
. "FROM {pages} P "
. "INNER JOIN {users} U "
. "ON P.insert_user_id = U.user_id "
. "WHERE P.thread_num = ? "
. "AND P.private_flag = ? "
. "AND P.space_type = ? "
. "AND P.insert_user_id IN (" . $inValue . ")";
$bindValues = array(
0,
_ON,
_SPACE_TYPE_GROUP
);
$privateRoomsPerRole = $this->_db->execute($sql, $bindValues, null, null, true, array($this, '_fetchPrivateRoomPerRole'));
$roles = array_keys($privateRoomsPerRole);
$sql = "SELECT M.action_name, "
. "M.delete_action, "
. "AM.role_authority_id "
. "FROM {modules} M "
. "INNER JOIN {authorities_modules_link} AM "
. "ON M.module_id = AM.module_id "
. "WHERE M.system_flag = ? "
. "AND AM.role_authority_id IN ('" . implode("','", $roles) . "')";
$bindValues = array(
_OFF
);
$modulesPerRole =& $this->_db->execute($sql, $bindValues, null, null, true, array($this, '_fetchModulePerRole'));
if ($modulesPerRole === false) {
return false;
}
$pagesAction =& $this->_container->getComponent('pagesAction');
foreach ($privateRoomsPerRole as $roleId => $privateRooms) {
if (!$pagesAction->deleteEachModule($privateRooms, $modulesPerRole[$roleId])) {
return false;
}
foreach ($privateRooms as $roomId) {
if (!$pagesAction->deleteRoom($roomId)) {
return false;
}
}
}
if (!$this->deleteByInOperator('users', $inValue)) {
return false;
}
if (!$this->deleteByInOperator('users_items_link', $inValue)) {
return false;
}
if (!$this->deleteByInOperator('pages_users_link', $inValue)) {
return false;
}
$sql = "UPDATE {uploads} "
. "SET "
. "garbage_flag = ? "
. "WHERE action_name = ? "
. "AND unique_id IN (" . $inValue . ") "
. "AND garbage_flag = ?";
$bindValues = array(
_ON,
'common_download_user',
_OFF
);
if (!$this->_db->execute($sql, $bindValues)) {
$this->_db->addError();
return false;
}
return true;
}
/**
* ロール毎のプライベートスペースデータ配列を作成する。
*
* @param object $recordSet プライベートスペースデータADORecordSet
* @return array モジュールデータ配列
* @access public
*/
function _fetchPrivateRoomPerRole($recordSet)
{
$privateRoomsPerRole = array();
while ($privateRoom = $recordSet->fetchRow()) {
$roleId = $privateRoom['role_authority_id'];
$privateRoomsPerRole[$roleId][] = $privateRoom['room_id'];
}
return $privateRoomsPerRole;
}
/**
* ロール毎にモジュールデータ配列を作成する
*
* @param array $recordSet タスクADORecordSet
* @return array モジュールデータ配列
* @access private
*/
function _fetchModulePerRole($recordSet) {
$modulesPerRole = array();
while ($module = $recordSet->fetchRow()) {
$roleId = $module['role_authority_id'];
$modulesPerRole[$roleId][] = $module;
}
return $modulesPerRole;
}
/**
* IN演算子でデータを削除する。
*
* @param string $tableName 対象テーブル名称
* @param string $inValue IN演算子の値(カンマ区切り文字列)
* @return boolean true or false
* @access public
*/
function deleteByInOperator($tableName, $inValue)
{
if (empty($inValue)) {
return true;
}
$sql = "DELETE FROM {" . $tableName . "} "
. "WHERE user_id IN (" . $inValue . ")";
if (!$this->_db->execute($sql)) {
$this->_db->addError();
return false;
}
return true;
}
}
?>