GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#1930)
by
unknown
13:51
created

procMemberAdminUpdateGroup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 3
nop 0
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  memberAdminController
5
 * @author NAVER ([email protected])
6
 * member module of the admin controller class
7
 */
8
class memberAdminController extends member
9
{
10
	/**
11
	 * Initialization
12
	 * @return void
13
	 */
14
	function init()
15
	{
16
	}
17
18
	/**
19
	 * Add a user (Administrator)
20
	 * @return void|Object (void : success, Object : fail)
21
	 */
22
	function procMemberAdminInsert()
23
	{
24
		// if(Context::getRequestMethod() == "GET") return new Object(-1, "msg_invalid_request");
25
		// Extract the necessary information in advance
26
		$logged_info = Context::get('logged_info');
27
		if($logged_info->is_admin != 'Y' || !checkCSRF())
28
		{
29
			return new Object(-1, 'msg_invalid_request');
30
		}
31
32
		$args = Context::gets('member_srl','email_address','find_account_answer', 'allow_mailing','allow_message','denied','is_admin','description','group_srl_list','limit_date');
33
		$oMemberModel = &getModel ('member');
34
		$config = $oMemberModel->getMemberConfig ();
35
		$getVars = array();
36 View Code Duplication
		if($config->signupForm)
37
		{
38
			foreach($config->signupForm as $formInfo)
39
			{
40
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
41
				{
42
					$getVars[] = $formInfo->name;
43
				}
44
			}
45
		}
46
		foreach($getVars as $val)
47
		{
48
			$args->{$val} = Context::get($val);
49
		}
50
		$args->member_srl = Context::get('member_srl');
51
		if(Context::get('reset_password'))
52
			$args->password = Context::get('reset_password');
53
		else unset($args->password);
54
55
		// Remove some unnecessary variables from all the vars
56
		$all_args = Context::getRequestVars();
57
		unset($all_args->module);
58
		unset($all_args->act);
59
		unset($all_args->mid);
60
		unset($all_args->error_return_url);
61
		unset($all_args->success_return_url);
62
		unset($all_args->ruleset);
63
		if(!isset($args->limit_date)) $args->limit_date = "";
64
		unset($all_args->password);
65
		unset($all_args->password2);
66
		unset($all_args->reset_password);
67
		// Add extra vars after excluding necessary information from all the requested arguments
68
		$extra_vars = delObjectVars($all_args, $args);
69
		$args->extra_vars = serialize($extra_vars);
70
		// Check if an original member exists having the member_srl
71
		if($args->member_srl)
72
		{
73
			// Create a member model object
74
			$oMemberModel = getModel('member');
75
			// Get memebr profile
76
			$columnList = array('member_srl');
77
			$member_info = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl, 0, $columnList);
78
			// If no original member exists, make a new one
79
			if($member_info->member_srl != $args->member_srl) unset($args->member_srl);
80
		}
81
82
		// remove whitespace
83
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
84 View Code Duplication
		foreach($checkInfos as $val)
85
		{
86
			if(isset($args->{$val}))
87
			{
88
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
89
			}
90
		}
91
92
		$oMemberController = getController('member');
93
		// Execute insert or update depending on the value of member_srl
94
		if(!$args->member_srl)
95
		{
96
			$args->password = Context::get('password');
97
			$output = $oMemberController->insertMember($args);
98
			$msg_code = 'success_registed';
99
		}
100
		else
101
		{
102
			$output = $oMemberController->updateMember($args);
103
			$msg_code = 'success_updated';
104
		}
105
106
		if(!$output->toBool()) return $output;
107
		// Save Signature
108
		$signature = Context::get('signature');
109
		$oMemberController->putSignature($args->member_srl, $signature);
110
		// Return result
111
		$this->add('member_srl', $args->member_srl);
112
		$this->setMessage($msg_code);
113
114
		$profile_image = $_FILES['profile_image'];
115
		if(is_uploaded_file($profile_image['tmp_name']))
116
		{
117
			$oMemberController->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
118
		}
119
120
		$image_mark = $_FILES['image_mark'];
121
		if(is_uploaded_file($image_mark['tmp_name']))
122
		{
123
			$oMemberController->insertImageMark($args->member_srl, $image_mark['tmp_name']);
124
		}
125
126
		$image_name = $_FILES['image_name'];
127
		if (is_uploaded_file($image_name['tmp_name']))
128
		{
129
			$oMemberController->insertImageName($args->member_srl, $image_name['tmp_name']);
130
		}
131
132
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminList');
133
		$this->setRedirectUrl($returnUrl);
134
	}
135
136
	/**
137
	 * Delete a user (Administrator)
138
	 * @return void|Object (void : success, Object : fail)
139
	 */
140
	function procMemberAdminDelete()
141
	{
142
		// Separate all the values into DB entries and others
143
		$member_srl = Context::get('member_srl');
144
145
		$oMemberController = getController('member');
146
		$output = $oMemberController->deleteMember($member_srl);
147
		if(!$output->toBool()) return $output;
148
149
		$this->add('page',Context::get('page'));
150
		$this->setMessage("success_deleted");
151
	}
152
153
154
	public function procMemberAdminInsertDefaultConfig()
155
	{
156
		$args = Context::gets(
157
			'enable_join',
158
			'enable_confirm',
159
			'webmaster_name',
160
			'webmaster_email',
161
			'password_strength',
162
			'password_hashing_algorithm',
163
			'password_hashing_work_factor',
164
			'password_hashing_auto_upgrade'
165
		);
166
		
167
		$oPassword = new Password();
168
		if(!array_key_exists($args->password_hashing_algorithm, $oPassword->getSupportedAlgorithms()))
169
		{
170
			$args->password_hashing_algorithm = 'md5';
171
		}
172
		
173
		$args->password_hashing_work_factor = intval($args->password_hashing_work_factor, 10);
174
		if($args->password_hashing_work_factor < 4)
175
		{
176
			$args->password_hashing_work_factor = 4;
177
		}
178
		if($args->password_hashing_work_factor > 16)
179
		{
180
			$args->password_hashing_work_factor = 16;
181
		}
182
		if($args->password_hashing_auto_upgrade != 'Y')
183
		{
184
			$args->password_hashing_auto_upgrade = 'N';
185
		}
186
187
		if((!$args->webmaster_name || !$args->webmaster_email) && $args->enable_confirm == 'Y')
188
		{
189
			return new Object(-1, 'msg_mail_authorization');
190
		}
191
192
		$oModuleController = getController('module');
193
		$output = $oModuleController->updateModuleConfig('member', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
194
195
		// default setting end
196
		$this->setMessage('success_updated');
197
198
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminDefaultConfig');
199
		$this->setRedirectUrl($returnUrl);
200
	}
201
202
	public function procMemberAdminInsertSignupConfig()
203
	{
204
		$oMemberModel = getModel('member');
205
		$oModuleController = getController('module');
206
207
		$args = Context::gets(
208
			'limit_day',
209
			'limit_day_description',
210
			'agreement',
211
			'redirect_url',
212
			'profile_image', 'profile_image_max_width', 'profile_image_max_height',
213
			'image_name', 'image_name_max_width', 'image_name_max_height',
214
			'image_mark', 'image_mark_max_width', 'image_mark_max_height',
215
			'signature_editor_skin', 'sel_editor_colorset'
216
		);
217
218
		$list_order = Context::get('list_order');
219
		$usable_list = Context::get('usable_list');
220
		$all_args = Context::getRequestVars();
221
222
		$args->limit_day = (int)$args->limit_day;
223
		if(!trim(strip_tags($args->agreement)))
224
		{
225
			$agreement_file = _XE_PATH_.'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt';
226
			FileHandler::removeFile($agreement_file);
227
			$args->agreement = NULL;
228
		}
229
230
		if($args->redirect_url)
231
		{
232
			$oModuleModel = getModel('module');
233
			$redirectModuleInfo = $oModuleModel->getModuleInfoByModuleSrl($args->redirect_url, array('mid'));
234
235
			if(!$redirectModuleInfo)
236
			{
237
				return new Object('-1', 'msg_exist_selected_module');
238
			}
239
240
			$args->redirect_url = Context::getDefaultUrl().$redirectModuleInfo->mid;
241
		}
242
243
		$args->profile_image = $args->profile_image ? 'Y' : 'N';
244
		$args->image_name = $args->image_name ? 'Y' : 'N';
245
		$args->image_mark = $args->image_mark ? 'Y' : 'N';
246
		$args->signature  = $args->signature != 'Y' ? 'N' : 'Y';
247
		$args->identifier = $all_args->identifier;
248
249
		// set default
250
		$all_args->is_nick_name_public = 'Y';
251
		$all_args->is_find_account_question_public = 'N';
252
253
		// signupForm
254
		global $lang;
255
		$signupForm = array();
256
		$items = array('user_id', 'password', 'user_name', 'nick_name', 'email_address', 'find_account_question', 'homepage', 'blog', 'birthday', 'signature', 'profile_image', 'image_name', 'image_mark', 'profile_image_max_width', 'profile_image_max_height', 'image_name_max_width', 'image_name_max_height', 'image_mark_max_width', 'image_mark_max_height');
257
		$mustRequireds = array('email_address', 'nick_name', 'password', 'find_account_question');
258
		$extendItems = $oMemberModel->getJoinFormList();
259
		foreach($list_order as $key)
0 ignored issues
show
Bug introduced by
The expression $list_order of type string is not traversable.
Loading history...
260
		{
261
			$signupItem = new stdClass();
262
			$signupItem->isIdentifier = ($key == $all_args->identifier);
263
			$signupItem->isDefaultForm = in_array($key, $items);
264
265
			$signupItem->name = $key;
266
			if(!in_array($key, $items)) $signupItem->title = $key;
267
			else $signupItem->title = $lang->{$key};
268
			$signupItem->mustRequired = in_array($key, $mustRequireds);
269
			$signupItem->imageType = (strpos($key, 'image') !== false);
270
			$signupItem->required = ($all_args->{$key} == 'required') || $signupItem->mustRequired || $signupItem->isIdentifier;
271
			$signupItem->isUse = in_array($key, $usable_list) || $signupItem->required;
272
			$signupItem->isPublic = ($all_args->{'is_'.$key.'_public'} == 'Y' && $signupItem->isUse) ? 'Y' : 'N';
273 View Code Duplication
			if($signupItem->imageType)
274
			{
275
				$signupItem->max_width = $all_args->{$key.'_max_width'};
276
				$signupItem->max_height = $all_args->{$key.'_max_height'};
277
			}
278
279
			// set extends form
280
			if(!$signupItem->isDefaultForm)
281
			{
282
				$extendItem = $extendItems[$all_args->{$key.'_member_join_form_srl'}];
283
				$signupItem->type = $extendItem->column_type;
284
				$signupItem->member_join_form_srl = $extendItem->member_join_form_srl;
285
				$signupItem->title = $extendItem->column_title;
286
				$signupItem->description = $extendItem->description;
287
288
				// check usable value change, required/option
289
				if($signupItem->isUse != ($extendItem->is_active == 'Y') || $signupItem->required != ($extendItem->required == 'Y'))
290
				{
291
					unset($update_args);
292
					$update_args = new stdClass;
293
					$update_args->member_join_form_srl = $extendItem->member_join_form_srl;
294
					$update_args->is_active = $signupItem->isUse?'Y':'N';
295
					$update_args->required = $signupItem->required?'Y':'N';
296
297
					$update_output = executeQuery('member.updateJoinForm', $update_args);
0 ignored issues
show
Unused Code introduced by
$update_output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
298
				}
299
300
				unset($extendItem);
301
			}
302
			$signupForm[] = $signupItem;
303
		}
304
		$args->signupForm = $signupForm;
305
306
		// create Ruleset
307
		$this->_createSignupRuleset($signupForm, $args->agreement);
0 ignored issues
show
Documentation introduced by
$signupForm is of type array, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
308
		$this->_createLoginRuleset($args->identifier);
309
		$this->_createFindAccountByQuestion($args->identifier);
310
311
		// check agreement value exist
312
		if($args->agreement)
313
		{
314
			$agreement_file = _XE_PATH_.'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt';
315
			$output = FileHandler::writeFile($agreement_file, $args->agreement);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $output is correct as \FileHandler::writeFile(...file, $args->agreement) (which targets FileHandler::writeFile()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
316
317
			unset($args->agreement);
318
		}
319
320
		$output = $oModuleController->updateModuleConfig('member', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
321
322
		// default setting end
323
		$this->setMessage('success_updated');
324
325
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminSignUpConfig');
326
		$this->setRedirectUrl($returnUrl);
327
	}
328
329
	public function procMemberAdminInsertLoginConfig()
330
	{
331
		$oModuleController = getController('module');
332
333
		$args = Context::gets(
334
			'change_password_date',
335
			'enable_login_fail_report',
336
			'max_error_count',
337
			'max_error_count_time',
338
			'after_login_url',
339
			'after_logout_url'
340
		);
341
342
		if(!$args->change_password_date)
343
		{
344
			$args->change_password_date = 0;
345
		}
346
347
		if(!trim(strip_tags($args->after_login_url)))
348
		{
349
			$args->after_login_url = NULL;
350
		}
351
		if(!trim(strip_tags($args->after_logout_url)))
352
		{
353
			$args->after_logout_url = NULL;
354
		}
355
356
		$output = $oModuleController->updateModuleConfig('member', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
357
358
		// default setting end
359
		$this->setMessage('success_updated');
360
361
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminLoginConfig');
362
		$this->setRedirectUrl($returnUrl);
363
	}
364
365
	public function procMemberAdminInsertDesignConfig()
366
	{
367
		$oModuleController = getController('module');
368
369
		$args = Context::gets(
370
			'layout_srl',
371
			'skin',
372
			'colorset',
373
			'mlayout_srl',
374
			'mskin'
375
		);
376
377
		$args->layout_srl = $args->layout_srl ? $args->layout_srl : NULL;
378
		if(!$args->skin)
379
		{
380
			$args->skin = 'default';
381
		}
382
		if(!$args->colorset)
383
		{
384
			$args->colorset = 'white';
385
		}
386
387
		$args->mlayout_srl = $args->mlayout_srl ? $args->mlayout_srl : NULL;
388
		if(!$args->mskin)
389
		{
390
			$args->mskin = 'default';
391
		}
392
393
		$output = $oModuleController->updateModuleConfig('member', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
394
395
		// default setting end
396
		$this->setMessage('success_updated');
397
398
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminDesignConfig');
399
		$this->setRedirectUrl($returnUrl);
400
	}
401
402
	function createSignupForm($identifier)
403
	{
404
		global $lang;
405
		$oMemberModel = getModel('member');
406
407
		// Get join form list which is additionally set
408
		$extendItems = $oMemberModel->getJoinFormList();
409
410
		$items = array('user_id', 'password', 'user_name', 'nick_name', 'email_address', 'find_account_question', 'homepage', 'blog', 'birthday', 'signature', 'profile_image', 'image_name', 'image_mark');
411
		$mustRequireds = array('email_address', 'nick_name','password', 'find_account_question');
412
		$orgRequireds = array('email_address', 'password', 'find_account_question', 'user_id', 'nick_name', 'user_name');
413
		$orgUse = array('email_address', 'password', 'find_account_question', 'user_id', 'nick_name', 'user_name', 'homepage', 'blog', 'birthday');
414
		$list_order = array();
415
416
		foreach($items as $key)
417
		{
418
			unset($signupItem);
419
			$signupItem = new stdClass;
420
			$signupItem->isDefaultForm = true;
421
			$signupItem->name = $key;
422
			$signupItem->title = $key;
423
			$signupItem->mustRequired = in_array($key, $mustRequireds);
424
			$signupItem->imageType = (strpos($key, 'image') !== false);
425
			$signupItem->required = in_array($key, $orgRequireds);
426
			$signupItem->isUse = ($config->{$key} == 'Y') || in_array($key, $orgUse);
0 ignored issues
show
Bug introduced by
The variable $config does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
427
			$signupItem->isPublic = ($signupItem->isUse) ? 'Y' : 'N';
428
			if($key == 'find_account_question' || $key == 'password')
429
			{
430
				$signupItem->isPublic = 'N';
431
			}
432
			$signupItem->isIdentifier = ($key == $identifier);
433 View Code Duplication
			if ($signupItem->imageType){
434
				$signupItem->max_width = $config->{$key.'_max_width'};
435
				$signupItem->max_height = $config->{$key.'_max_height'};
436
			}
437
			if($signupItem->isIdentifier)
438
				array_unshift($list_order, $signupItem);
439
			else
440
				$list_order[] = $signupItem;
441
		}
442
		if(is_array($extendItems))
443
		{
444
			foreach($extendItems as $form_srl=>$item_info)
445
			{
446
				unset($signupItem);
447
				$signupItem = new stdClass;
448
				$signupItem->name = $item_info->column_name;
449
				$signupItem->title = $item_info->column_title;
450
				$signupItem->type = $item_info->column_type;
451
				$signupItem->member_join_form_srl = $form_srl;
452
				$signupItem->mustRequired = in_array($key, $mustRequireds);
0 ignored issues
show
Bug introduced by
The variable $key seems to be defined by a foreach iteration on line 416. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
453
				$signupItem->required = ($item_info->required == 'Y');
454
				$signupItem->isUse = ($item_info->is_active == 'Y');
455
				$signupItem->isPublic = ($signupItem->isUse) ? 'Y' : 'N';
456
				$signupItem->description = $item_info->description;
457 View Code Duplication
				if($signupItem->imageType)
458
				{
459
					$signupItem->max_width = $config->{$key.'_max_width'};
460
					$signupItem->max_height = $config->{$key.'_max_height'};
461
				}
462
				$list_order[] = $signupItem;
463
			}
464
		}
465
466
		return $list_order;
467
	}
468
469
	/**
470
	 * Create ruleset file of signup
471
	 * @param object $signupForm (user define signup form)
472
	 * @param string $agreement
473
	 * @return void
474
	 */
475
	function _createSignupRuleset($signupForm, $agreement = null){
476
		$xml_file = './files/ruleset/insertMember.xml';
477
		$buff = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL.
478
			'<ruleset version="1.5.0">' . PHP_EOL.
479
			'<customrules>' . PHP_EOL.
480
			'</customrules>' . PHP_EOL.
481
			'<fields>' . PHP_EOL . '%s' . PHP_EOL . '</fields>' . PHP_EOL.
482
			'</ruleset>';
483
484
		$fields = array();
485
486
		if ($agreement)
0 ignored issues
show
Bug Best Practice introduced by
The expression $agreement of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
487
		{
488
			$fields[] = '<field name="accept_agreement"><if test="$act == \'procMemberInsert\'" attr="required" value="true" /></field>';
489
		}
490
		foreach($signupForm as $formInfo)
491
		{
492
			if($formInfo->required || $formInfo->mustRequired)
493
			{
494
				if($formInfo->type == 'tel' || $formInfo->type == 'kr_zip')
495
				{
496
					$fields[] = sprintf('<field name="%s[]" required="true" />', $formInfo->name);
497
				}
498
				else if($formInfo->name == 'password')
499
				{
500
					$fields[] = '<field name="password"><if test="$act == \'procMemberInsert\'" attr="required" value="true" /><if test="$act == \'procMemberInsert\'" attr="length" value="4:20" /></field>';
501
					$fields[] = '<field name="password2"><if test="$act == \'procMemberInsert\'" attr="required" value="true" /><if test="$act == \'procMemberInsert\'" attr="equalto" value="password" /></field>';
502
				}
503
				else if($formInfo->name == 'find_account_question')
504
				{
505
					$fields[] = '<field name="find_account_question" required="true" />';
506
					$fields[] = '<field name="find_account_answer" required="true" length=":250" />';
507
				}
508
				else if($formInfo->name == 'email_address')
509
				{
510
					$fields[] = sprintf('<field name="%s" required="true" rule="email"/>', $formInfo->name);
511
				}
512
				else if($formInfo->name == 'user_id')
513
				{
514
					$fields[] = sprintf('<field name="%s" required="true" rule="userid" length="3:20" />', $formInfo->name);
515
				}
516
				else if($formInfo->name == 'nick_name')
517
				{
518
					$fields[] = sprintf('<field name="%s" required="true" length="2:20" />', $formInfo->name);
519
				}
520
				else if(strpos($formInfo->name, 'image') !== false)
521
				{
522
					$fields[] = sprintf('<field name="%s"><if test="$act != \'procMemberAdminInsert\' &amp;&amp; $__%s_exist != \'true\'" attr="required" value="true" /></field>', $formInfo->name, $formInfo->name);
523
				}
524
				else if($formInfo->name == 'signature')
525
				{
526
					$fields[] = '<field name="signature"><if test="$member_srl" attr="required" value="true" /></field>';
527
				}
528
				else
529
				{
530
					$fields[] = sprintf('<field name="%s" required="true" />', $formInfo->name);
531
				}
532
			}
533
		}
534
535
		$xml_buff = sprintf($buff, implode(PHP_EOL, $fields));
536
		FileHandler::writeFile($xml_file, $xml_buff);
537
		unset($xml_buff);
538
539
		$validator   = new Validator($xml_file);
540
		$validator->setCacheDir('files/cache');
541
		$validator->getJsPath();
542
	}
543
544
	/**
545
	 * Create ruleset file of login
546
	 * @param string $identifier (login identifier)
547
	 * @return void
548
	 */
549
	function _createLoginRuleset($identifier)
550
	{
551
		$xml_file = './files/ruleset/login.xml';
552
		$buff = '<?xml version="1.0" encoding="utf-8"?>'.
553
			'<ruleset version="1.5.0">'.
554
			'<customrules>'.
555
			'</customrules>'.
556
			'<fields>%s</fields>'.
557
			'</ruleset>';
558
559
		$fields = array();
560
		$trans = array('email_address'=>'email', 'user_id'=> 'userid');
561
		$fields[] = sprintf('<field name="user_id" required="true" rule="%s"/>', $trans[$identifier]);
562
		$fields[] = '<field name="password" required="true" />';
563
564
		$xml_buff = sprintf($buff, implode('', $fields));
565
		Filehandler::writeFile($xml_file, $xml_buff);
566
567
		$validator   = new Validator($xml_file);
568
		$validator->setCacheDir('files/cache');
569
		$validator->getJsPath();
570
	}
571
572
	/**
573
	 * Create ruleset file of find account
574
	 * @param string $identifier (login identifier)
575
	 * @return void
576
	 */
577
	function _createFindAccountByQuestion($identifier)
578
	{
579
		$xml_file = './files/ruleset/find_member_account_by_question.xml';
580
		$buff = '<?xml version="1.0" encoding="utf-8"?>'.
581
			'<ruleset version="1.5.0">'.
582
			'<customrules>'.
583
			'</customrules>'.
584
			'<fields>%s</fields>'.
585
			'</ruleset>';
586
587
		$fields = array();
588
		if($identifier == 'user_id')
589
			$fields[] = '<field name="user_id" required="true" rule="userid" />';
590
591
		$fields[] = '<field name="email_address" required="true" rule="email" />';
592
		$fields[] = '<field name="find_account_question" required="true" />';
593
		$fields[] = '<field name="find_account_answer" required="true" length=":250"/>';
594
595
		$xml_buff = sprintf($buff, implode('', $fields));
596
		Filehandler::writeFile($xml_file, $xml_buff);
597
598
		$validator   = new Validator($xml_file);
599
		$validator->setCacheDir('files/cache');
600
		$validator->getJsPath();
601
	}
602
603
	/**
604
	 * Add a user group
605
	 * @return void|Object (void : success, Object : fail)
606
	 */
607
	function procMemberAdminInsertGroup()
608
	{
609
		$args = Context::gets('title','description','is_default','image_mark');
610
		$output = $this->insertGroup($args);
0 ignored issues
show
Bug introduced by
It seems like $args defined by \Context::gets('title', ...default', 'image_mark') on line 609 can be null; however, memberAdminController::insertGroup() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
611
		if(!$output->toBool()) return $output;
612
613
		$this->add('group_srl','');
614
		$this->add('page',Context::get('page'));
615
		$this->setMessage('success_registed');
616
617
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminGroupList');
618
		$this->setRedirectUrl($returnUrl);
619
	}
620
621
	/**
622
	 * Update user group information
623
	 * @return void|Object (void : success, Object : fail)
624
	 */
625
	function procMemberAdminUpdateGroup()
626
	{
627
		$group_srl = Context::get('group_srl');
0 ignored issues
show
Unused Code introduced by
$group_srl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
628
629
		$args = Context::gets('group_srl','title','description','is_default','image_mark');
630
		$args->site_srl = 0;
631
		$output = $this->updateGroup($args);
632
		if(!$output->toBool()) return $output;
633
634
		$this->add('group_srl','');
635
		$this->add('page',Context::get('page'));
636
		$this->setMessage('success_updated');
637
638
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminGroupList');
639
		$this->setRedirectUrl($returnUrl);
640
	}
641
642
	/**
643
	 * Update user group information
644
	 * @return void|Object (void : success, Object : fail)
645
	 */
646 View Code Duplication
	function procMemberAdminDeleteGroup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
647
	{
648
		$group_srl = Context::get('group_srl');
649
650
		$output = $this->deleteGroup($group_srl);
651
		if(!$output->toBool()) return $output;
652
653
		$this->add('group_srl','');
654
		$this->add('page',Context::get('page'));
655
		$this->setMessage('success_deleted');
656
657
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminGroupList');
658
		$this->setRedirectUrl($returnUrl);
659
	}
660
661
	/**
662
	 * Add a join form
663
	 * @return void|Object (void : success, Object : fail)
664
	 */
665
	function procMemberAdminInsertJoinForm()
666
	{
667
		$args = new stdClass();
668
		$args->member_join_form_srl = Context::get('member_join_form_srl');
669
670
		$args->column_type = Context::get('column_type');
671
		$args->column_name = strtolower(Context::get('column_id'));
672
		$args->column_title = Context::get('column_title');
673
		$args->default_value = explode("\n", str_replace("\r", '', Context::get('default_value')));
674
		$args->required = Context::get('required');
675
		$args->is_active = (isset($args->required));
676
		if(!in_array(strtoupper($args->required), array('Y','N')))$args->required = 'N';
677
		$args->description = Context::get('description') ? Context::get('description') : '';
678
		// Default values
679
		if(in_array($args->column_type, array('checkbox','select','radio')) && count($args->default_value))
680
		{
681
			$args->default_value = serialize($args->default_value);
682
		}
683
		else
684
		{
685
			$args->default_value = '';
686
		}
687
688
		// Check ID duplicated
689
		$oMemberModel = getModel('member');
690
		$config = $oMemberModel->getMemberConfig();
691
		foreach($config->signupForm as $item)
692
		{
693
			if($item->name == $args->column_name)
694
			{
695
				if($args->member_join_form_srl && $args->member_join_form_srl == $item->member_join_form_srl) continue;
696
				return new Object(-1,'msg_exists_user_id');
697
			}
698
		}
699
		// Fix if member_join_form_srl exists. Add if not exists.
700
		$isInsert;
0 ignored issues
show
Bug introduced by
The variable $isInsert seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
701
		if(!$args->member_join_form_srl)
702
		{
703
			$isInsert = true;
704
			$args->list_order = $args->member_join_form_srl = getNextSequence();
705
			$output = executeQuery('member.insertJoinForm', $args);
706
		}
707
		else
708
		{
709
			$output = executeQuery('member.updateJoinForm', $args);
710
		}
711
712
		if(!$output->toBool()) return $output;
713
714
		// memberConfig update
715
		$signupItem = new stdClass();
716
		$signupItem->name = $args->column_name;
717
		$signupItem->title = $args->column_title;
718
		$signupItem->type = $args->column_type;
719
		$signupItem->member_join_form_srl = $args->member_join_form_srl;
720
		$signupItem->required = ($args->required == 'Y');
721
		$signupItem->isUse = ($args->is_active == 'Y');
722
		$signupItem->description = $args->description;
723
		$signupItem->isPublic = 'Y';
724
725
		$oMemberModel = getModel('member');
726
		$config = $oMemberModel->getMemberConfig();
727
		unset($config->agreement);
728
729
		if($isInsert)
0 ignored issues
show
Bug introduced by
The variable $isInsert does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
730
		{
731
			$config->signupForm[] = $signupItem;
732
		}
733
		else
734
		{
735 View Code Duplication
			foreach($config->signupForm as $key=>$val)
736
			{
737
				if($val->member_join_form_srl == $signupItem->member_join_form_srl)
738
				{
739
					$config->signupForm[$key] = $signupItem;
740
				}
741
			}
742
		}
743
		$oModuleController = getController('module');
744
		$output = $oModuleController->updateModuleConfig('member', $config);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
745
746
		$this->setMessage('success_registed');
747
748
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminJoinFormList');
749
		$this->setRedirectUrl($returnUrl);
750
	}
751
752
	/**
753
	 * Delete a join form
754
	 * @return void
755
	 */
756
	function procMemberAdminDeleteJoinForm()
757
	{
758
		$member_join_form_srl = Context::get('member_join_form_srl');
759
		$this->deleteJoinForm($member_join_form_srl);
760
761
		$oMemberModel = getModel('member');
762
		$config = $oMemberModel->getMemberConfig();
763
		unset($config->agreement);
764
765 View Code Duplication
		foreach($config->signupForm as $key=>$val)
766
		{
767
			if($val->member_join_form_srl == $member_join_form_srl)
768
			{
769
				unset($config->signupForm[$key]);
770
				break;
771
			}
772
		}
773
		$oModuleController = getController('module');
774
		$output = $oModuleController->updateModuleConfig('member', $config);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
775
	}
776
777
	/**
778
	 * Move up/down the member join form and modify it
779
	 * @deprecated
780
	 * @return void
781
	 */
782
	function procMemberAdminUpdateJoinForm()
783
	{
784
		$member_join_form_srl = Context::get('member_join_form_srl');
785
		$mode = Context::get('mode');
786
787
		switch($mode)
788
		{
789
			case 'up' :
790
				$output = $this->moveJoinFormUp($member_join_form_srl);
0 ignored issues
show
Deprecated Code introduced by
The method memberAdminController::moveJoinFormUp() has been deprecated.

This method has been deprecated.

Loading history...
791
				$msg_code = 'success_moved';
792
				break;
793
			case 'down' :
794
				$output = $this->moveJoinFormDown($member_join_form_srl);
0 ignored issues
show
Deprecated Code introduced by
The method memberAdminController::moveJoinFormDown() has been deprecated.

This method has been deprecated.

Loading history...
795
				$msg_code = 'success_moved';
796
				break;
797
			case 'delete' :
798
				$output = $this->deleteJoinForm($member_join_form_srl);
799
				$msg_code = 'success_deleted';
800
				break;
801
			case 'update' :
802
				break;
803
		}
804
		if(!$output->toBool()) return $output;
0 ignored issues
show
Bug introduced by
The variable $output does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
805
806
		$this->setMessage($msg_code);
0 ignored issues
show
Bug introduced by
The variable $msg_code does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
807
	}
808
809
	/**
810
	 * selected member manager layer in dispAdminList
811
	 * @return void|Object (void : success, Object : fail)
812
	 */
813
	function procMemberAdminSelectedMemberManage()
814
	{
815
		$var = Context::getRequestVars();
816
		$groups = $var->groups;
817
		$members = $var->member_srls;
818
819
		$oDB = &DB::getInstance();
820
		$oDB->begin();
821
822
		$oMemberController = getController('member');
823
		foreach($members as $key=>$member_srl)
824
		{
825
			$args = new stdClass();
826
			$args->member_srl = $member_srl;
827
			switch($var->type)
828
			{
829
				case 'modify':
830
					{
831
						if(count($groups) > 0)
832
						{
833
							$args->site_srl = 0;
834
							// One of its members to delete all the group
835
							$output = executeQuery('member.deleteMemberGroupMember', $args);
836
							if(!$output->toBool())
837
							{
838
								$oDB->rollback();
839
								return $output;
840
							}
841
							// Enter one of the loop a
842
							foreach($groups as $group_srl)
843
							{
844
								$output = $oMemberController->addMemberToGroup($args->member_srl,$group_srl);
845
								if(!$output->toBool())
846
								{
847
									$oDB->rollback();
848
									return $output;
849
								}
850
							}
851
						}
852
						if($var->denied)
853
						{
854
							$args->denied = $var->denied;
855
							$output = executeQuery('member.updateMemberDeniedInfo', $args);
856
							if(!$output->toBool())
857
							{
858
								$oDB->rollback();
859
								return $output;
860
							}
861
						}
862
						$this->setMessage('success_updated');
863
						break;
864
					}
865
				case 'delete':
866
					{
867
						$oMemberController->memberInfo = null;
0 ignored issues
show
Bug introduced by
The property memberInfo does not seem to exist in ModuleObject.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
868
						$output = $oMemberController->deleteMember($member_srl);
869
						if(!$output->toBool())
870
						{
871
							$oDB->rollback();
872
							return $output;
873
						}
874
						$this->setMessage('success_deleted');
875
					}
876
			}
877
			$oMemberController->_clearMemberCache($args->member_srl);
878
		}
879
880
		$message = $var->message;
881
		// Send a message
882
		if($message)
883
		{
884
			$oCommunicationController = getController('communication');
885
886
			$logged_info = Context::get('logged_info');
887
			$title = cut_str($message,10,'...');
888
			$sender_member_srl = $logged_info->member_srl;
889
890
			foreach($members as $member_srl)
891
			{
892
				$oCommunicationController->sendMessage($sender_member_srl, $member_srl, $title, $message, false);
893
			}
894
		}
895
896
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminList');
897
		$this->setRedirectUrl($returnUrl);
898
	}
899
900
	/**
901
	 * Delete the selected members
902
	 * @return void|Object (void : success, Object : fail)
903
	 */
904 View Code Duplication
	function procMemberAdminDeleteMembers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
905
	{
906
		$target_member_srls = Context::get('target_member_srls');
907
		if(!$target_member_srls) return new Object(-1, 'msg_invalid_request');
908
		$member_srls = explode(',', $target_member_srls);
909
		$oMemberController = getController('member');
910
911
		foreach($member_srls as $member)
912
		{
913
			$output = $oMemberController->deleteMember($member);
914
			if(!$output->toBool())
915
			{
916
				$this->setMessage('failed_deleted');
917
				return $output;
918
			}
919
		}
920
921
		$this->setMessage('success_deleted');
922
	}
923
924
	/**
925
	 * Update a group of selected memebrs
926
	 * @return void|Object (void : success, Object : fail)
927
	 */
928
	function procMemberAdminUpdateMembersGroup()
929
	{
930
		$member_srl = Context::get('member_srl');
931
		if(!$member_srl) return new Object(-1,'msg_invalid_request');
932
		$member_srls = explode(',',$member_srl);
933
934
		$group_srl = Context::get('group_srls');
935
		if(!is_array($group_srl)) $group_srls = explode('|@|', $group_srl);
936
		else $group_srls = $group_srl;
937
938
		$oDB = &DB::getInstance();
939
		$oDB->begin();
940
		// Delete a group of selected members
941
		$args = new stdClass;
942
		$args->member_srl = $member_srl;
943
		$output = executeQuery('member.deleteMembersGroup', $args);
944
		if(!$output->toBool())
945
		{
946
			$oDB->rollback();
947
			return $output;
948
		}
949
		// Add to a selected group
950
		$group_count = count($group_srls);
951
		$member_count = count($member_srls);
952
		for($j=0;$j<$group_count;$j++)
953
		{
954
			$group_srl = (int)trim($group_srls[$j]);
955
			if(!$group_srl) continue;
956
			for($i=0;$i<$member_count;$i++)
957
			{
958
				$member_srl = (int)trim($member_srls[$i]);
959
				if(!$member_srl) continue;
960
961
				$args = new stdClass;
962
				$args->member_srl = $member_srl;
963
				$args->group_srl = $group_srl;
964
965
				$output = executeQuery('member.addMemberToGroup', $args);
966
				if(!$output->toBool())
967
				{
968
					$oDB->rollback();
969
					return $output;
970
				}
971
			}
972
		}
973
		$oDB->commit();
974
975
		$this->_deleteMemberGroupCache();
976
977
		$this->setMessage('success_updated');
978
979
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
980
		{
981
			global $lang;
982
			htmlHeader();
983
			alertScript($lang->success_updated);
984
			reload(true);
985
			closePopupScript();
986
			htmlFooter();
987
			Context::close();
988
			exit;
989
		}
990
	}
991
992
	/**
993
	 * Add a denied ID
994
	 * @return void
995
	 */
996
	function procMemberAdminInsertDeniedID()
997
	{
998
		$user_ids = Context::get('user_id');
999
1000
		$user_ids = explode(',',$user_ids);
1001
		$success_ids = array();
1002
1003
		foreach($user_ids as $val)
1004
		{
1005
			$val = trim($val);
1006
			if(!$val) continue;
1007
1008
			$output = $this->insertDeniedID($val, '');
1009
			if($output->toBool()) $success_ids[] = $val;
1010
		}
1011
1012
		$this->add('user_ids', implode(',',$success_ids));
1013
1014
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminDeniedIDList');
1015
		$this->setRedirectUrl($returnUrl);
1016
	}
1017
1018
	/**
1019
	 * Add a denied nick name
1020
	 * @return void
1021
	 */
1022
	function procMemberAdminUpdateDeniedNickName()
1023
	{
1024
		$nick_name = Context::get('nick_name');
1025
1026
		$mode = Context::get('mode');
1027
		$mode = $mode ? $mode : 'insert';
1028
1029
		if($mode == 'delete')
1030
		{
1031
			$output = $this->deleteDeniedNickName($nick_name);
1032
			if(!$output->toBool())
1033
			{
1034
				return $output;
1035
			}
1036
			$msg_code = 'success_deleted';
1037
			$this->setMessage($msg_code);
1038
		}
1039
		else
1040
		{
1041
			$nick_names = explode(',',$nick_name);
1042
			$success_nick_names = array();
1043
1044
			foreach($nick_names as $val)
1045
			{
1046
				$val = trim($val);
1047
				if(!$val) continue;
1048
1049
				$output = $this->insertDeniedNickName($val, '');
1050
				if($output->toBool()) $success_nick_names[] = $val;
1051
			}
1052
1053
			$this->add('nick_names', implode(',',$success_nick_names));
1054
		}
1055
	}
1056
1057
	/**
1058
	 * Update denied ID
1059
	 * @return void|Object (void : success, Object : fail)
1060
	 */
1061
	function procMemberAdminUpdateDeniedID()
1062
	{
1063
		$user_id = Context::get('user_id');
1064
		$mode = Context::get('mode');
1065
1066
		switch($mode)
1067
		{
1068
			case 'delete' :
1069
				$output = $this->deleteDeniedID($user_id);
1070
				if(!$output->toBool()) return $output;
1071
				$msg_code = 'success_deleted';
1072
				break;
1073
		}
1074
1075
		$this->add('page',Context::get('page'));
1076
		$this->setMessage($msg_code);
0 ignored issues
show
Bug introduced by
The variable $msg_code does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1077
	}
1078
1079
	/**
1080
	 * Add an administrator
1081
	 * @param object $args
1082
	 * @return object (info of added member)
1083
	 */
1084
	function insertAdmin($args)
1085
	{
1086
		// Assign an administrator
1087
		$args->is_admin = 'Y';
1088
		// Get admin group and set
1089
		$oMemberModel = getModel('member');
1090
		$admin_group = $oMemberModel->getAdminGroup();
1091
		$args->group_srl_list = $admin_group->group_srl;
1092
1093
		$oMemberController = getController('member');
1094
		return $oMemberController->insertMember($args);
1095
	}
1096
1097
	/**
1098
	 * Change the group values of member
1099
	 * @param int $source_group_srl
1100
	 * @param int $target_group_srl
1101
	 * @return Object
1102
	 */
1103
	function changeGroup($source_group_srl, $target_group_srl)
1104
	{
1105
		$args = new stdClass;
1106
		$args->source_group_srl = $source_group_srl;
1107
		$args->target_group_srl = $target_group_srl;
1108
1109
		$output = executeQuery('member.changeGroup', $args);
1110
		$this->_deleteMemberGroupCache($site_srl);
0 ignored issues
show
Bug introduced by
The variable $site_srl does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1111
1112
		return $output;
1113
	}
1114
1115
	/**
1116
	 * Insert a group
1117
	 * @param object $args
1118
	 * @return Object
1119
	 */
1120
	function insertGroup($args)
1121
	{
1122
		if(!$args->site_srl) $args->site_srl = 0;
1123
		// Check the value of is_default.
1124 View Code Duplication
		if($args->is_default != 'Y')
1125
		{
1126
			$args->is_default = 'N';
1127
		}
1128
		else
1129
		{
1130
			$output = executeQuery('member.updateGroupDefaultClear', $args);
1131
			if(!$output->toBool()) return $output;
1132
		}
1133
1134
		if(!isset($args->list_order) || $args->list_order=='')
1135
		{
1136
			$args->list_order = $args->group_srl;
1137
		}
1138
1139
		if(!$args->group_srl) $args->group_srl = getNextSequence();
1140
		$args->list_order = $args->group_srl;
1141
		$output = executeQuery('member.insertGroup', $args);
1142
		$this->_deleteMemberGroupCache($args->site_srl);
1143
1144
		return $output;
1145
	}
1146
1147
	/**
1148
	 * Modify Group Information
1149
	 * @param object $args
1150
	 * @return Object
1151
	 */
1152
	function updateGroup($args)
1153
	{
1154
		if(!$args->site_srl) $args->site_srl = 0;
1155
		// Check the value of is_default.
1156
		if(!$args->group_srl) return new Object(-1, 'lang->msg_not_founded');
1157 View Code Duplication
		if($args->is_default!='Y')
1158
		{
1159
			$args->is_default = 'N';
1160
		}
1161
		else
1162
		{
1163
			$output = executeQuery('member.updateGroupDefaultClear', $args);
1164
			if(!$output->toBool()) return $output;
1165
		}
1166
1167
		$output = executeQuery('member.updateGroup', $args);
1168
		$this->_deleteMemberGroupCache($args->site_srl);
1169
		return $output;
1170
	}
1171
1172
	/**
1173
	 * Delete a Group
1174
	 * @param int $group_srl
1175
	 * @param int $site_srl
1176
	 * @return Object
1177
	 */
1178
	function deleteGroup($group_srl, $site_srl = 0)
1179
	{
1180
		// Create a member model object
1181
		$oMemberModel = getModel('member');
1182
1183
		// Check the group_srl (If is_default == 'Y', it cannot be deleted)
1184
		$columnList = array('group_srl', 'is_default');
1185
		$group_info = $oMemberModel->getGroup($group_srl, $columnList);
1186
1187
		if(!$group_info) return new Object(-1, 'lang->msg_not_founded');
1188
		if($group_info->is_default == 'Y') return new Object(-1, 'msg_not_delete_default');
1189
1190
		// Get groups where is_default == 'Y'
1191
		$columnList = array('site_srl', 'group_srl');
1192
		$default_group = $oMemberModel->getDefaultGroup($site_srl, $columnList);
1193
		$default_group_srl = $default_group->group_srl;
1194
1195
		// Change to default_group_srl
1196
		$this->changeGroup($group_srl, $default_group_srl);
1197
1198
		$args = new stdClass;
1199
		$args->group_srl = $group_srl;
1200
		$output = executeQuery('member.deleteGroup', $args);
1201
		$this->_deleteMemberGroupCache($site_srl);
1202
		return $output;
1203
	}
1204
1205
	/**
1206
	 * Set group config
1207
	 * @return void
1208
	 */
1209
	public function procMemberAdminGroupConfig()
1210
	{
1211
		$vars = Context::getRequestVars();
1212
1213
		$oMemberModel = getModel('member');
1214
		$oModuleController = getController('module');
1215
1216
		// group image mark option
1217
		$config = $oMemberModel->getMemberConfig();
1218
		$config->group_image_mark = $vars->group_image_mark;
1219
		unset($config->agreement);
1220
		$output = $oModuleController->updateModuleConfig('member', $config);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1221
1222
		$defaultGroup = $oMemberModel->getDefaultGroup(0);
1223
		$defaultGroupSrl = $defaultGroup->group_srl;
1224
		$group_srls = $vars->group_srls;
1225
		foreach($group_srls as $order=>$group_srl)
1226
		{
1227
			$isInsert = false;
0 ignored issues
show
Unused Code introduced by
$isInsert is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1228
			$update_args = new stdClass();
1229
			$update_args->title = $vars->group_titles[$order];
1230
			$update_args->description = $vars->descriptions[$order];
1231
			$update_args->image_mark = $vars->image_marks[$order];
1232
			$update_args->list_order = $order + 1;
1233
1234
			if(!$update_args->title) continue;
1235
1236
			if(is_numeric($group_srl)) {
1237
				$update_args->group_srl = $group_srl;
1238
				$output = $this->updateGroup($update_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1239
			}
1240
			else {
1241
				$update_args->group_srl = getNextSequence();
1242
				$output = $this->insertGroup($update_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1243
			}
1244
1245
			if($vars->defaultGroup == $group_srl) {
1246
				$defaultGroupSrl = $update_args->group_srl;
1247
			}
1248
		}
1249
1250
		//set default group
1251
		$default_args = $oMemberModel->getGroup($defaultGroupSrl);
1252
		$default_args->is_default = 'Y';
1253
		$default_args->group_srl = $defaultGroupSrl;
1254
		$output = $this->updateGroup($default_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1255
1256
		$this->setMessage(Context::getLang('success_updated').' ('.Context::getLang('msg_insert_group_name_detail').')');
1257
1258
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminGroupList');
1259
		$this->setRedirectUrl($returnUrl);
1260
	}
1261
1262
1263
	/**
1264
	 * Set group order
1265
	 * @return void
1266
	 */
1267
	function procMemberAdminUpdateGroupOrder()
1268
	{
1269
		$vars = Context::getRequestVars();
1270
1271
		foreach($vars->group_srls as $key => $val)
1272
		{
1273
			$args = new stdClass;
1274
			$args->group_srl = $val;
1275
			$args->list_order = $key + 1;
1276
			executeQuery('member.updateMemberGroupListOrder', $args);
1277
		}
1278
1279
		$this->_deleteMemberGroupCache($vars->site_srl);
1280
1281
		$this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispMemberAdminGroupList'));
1282
	}
1283
1284
	/**
1285
	 * Delete cached group data
1286
	 * @return void
1287
	*/
1288
	function _deleteMemberGroupCache($site_srl = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $site_srl is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1289
	{
1290
		//remove from cache
1291
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1292
		if($oCacheHandler->isSupport())
1293
		{
1294
			$oCacheHandler->invalidateGroupKey('member');
1295
		}
1296
	}
1297
1298
	/**
1299
	 * Register denied ID
1300
	 * @param string $user_id
1301
	 * @param string $description
1302
	 * @return Object
1303
	 */
1304
	function insertDeniedID($user_id, $description = '')
1305
	{
1306
		$args = new stdClass();
1307
		$args->user_id = $user_id;
1308
		$args->description = $description;
1309
		$args->list_order = -1*getNextSequence();
1310
1311
		return executeQuery('member.insertDeniedID', $args);
1312
	}
1313
1314
	function insertDeniedNickName($nick_name, $description = '')
1315
	{
1316
		$args = new stdClass();
1317
		$args->nick_name = $nick_name;
1318
		$args->description = $description;
1319
1320
		return executeQuery('member.insertDeniedNickName', $args);
1321
	}
1322
1323
	/**
1324
	 * delete a denied id
1325
	 * @param string $user_id
1326
	 * @return object
1327
	 */
1328
	function deleteDeniedID($user_id)
1329
	{
1330
		if(!$user_id) unset($user_id);
1331
1332
		$args = new stdClass;
1333
		$args->user_id = $user_id;
1334
		return executeQuery('member.deleteDeniedID', $args);
1335
	}
1336
1337
	/**
1338
	 * delete a denied nick name
1339
	 * @param string $nick_name
1340
	 * @return object
1341
	 */
1342
	function deleteDeniedNickName($nick_name)
1343
	{
1344
		if(!$nick_name) unset($nick_name);
1345
1346
		$args = new stdClass;
1347
		$args->nick_name = $nick_name;
1348
		return executeQuery('member.deleteDeniedNickName', $args);
1349
	}
1350
1351
	/**
1352
	 * Delete a join form
1353
	 * @param int $member_join_form_srl
1354
	 * @return Object
1355
	 */
1356
	function deleteJoinForm($member_join_form_srl)
1357
	{
1358
		$args = new stdClass();
1359
		$args->member_join_form_srl = $member_join_form_srl;
1360
		$output = executeQuery('member.deleteJoinForm', $args);
1361
		return $output;
1362
	}
1363
1364
	/**
1365
	 * Move up a join form
1366
	 * @deprecated
1367
	 * @param int $member_join_form_srl
1368
	 * @return Object
1369
	 */
1370
	function moveJoinFormUp($member_join_form_srl)
1371
	{
1372
		$oMemberModel = getModel('member');
1373
		// Get information of the join form
1374
		$args = new stdClass;
1375
		$args->member_join_form_srl = $member_join_form_srl;
1376
		$output = executeQuery('member.getJoinForm', $args);
1377
1378
		$join_form = $output->data;
1379
		$list_order = $join_form->list_order;
1380
		// Get a list of all join forms
1381
		$join_form_list = $oMemberModel->getJoinFormList();
1382
		$join_form_srl_list = array_keys($join_form_list);
1383
		if(count($join_form_srl_list)<2) return new Object();
1384
1385
		$prev_member_join_form = NULL;
1386
		foreach($join_form_list as $key => $val)
1387
		{
1388
			if($val->member_join_form_srl == $member_join_form_srl) break;
1389
			$prev_member_join_form = $val;
1390
		}
1391
		// Return if no previous join form exists
1392
		if(!$prev_member_join_form) return new Object();
1393
		// Information of the join form
1394
		$cur_args = new stdClass;
1395
		$cur_args->member_join_form_srl = $member_join_form_srl;
1396
		$cur_args->list_order = $prev_member_join_form->list_order;
1397
		// Information of the target join form
1398
		$prev_args = new stdClass;
1399
		$prev_args->member_join_form_srl = $prev_member_join_form->member_join_form_srl;
1400
		$prev_args->list_order = $list_order;
1401
		// Execute Query
1402
		$output = executeQuery('member.updateMemberJoinFormListorder', $cur_args);
1403
		if(!$output->toBool()) return $output;
1404
1405
		executeQuery('member.updateMemberJoinFormListorder', $prev_args);
1406
		if(!$output->toBool()) return $output;
1407
1408
		return new Object();
1409
	}
1410
1411
	/**
1412
	 * Move down a join form
1413
	 * @deprecated
1414
	 * @param int $member_join_form_srl
1415
	 * @return Object
1416
	 */
1417
	function moveJoinFormDown($member_join_form_srl)
1418
	{
1419
		$oMemberModel = getModel('member');
1420
		// Get information of the join form
1421
		$args = new stdClass;
1422
		$args->member_join_form_srl = $member_join_form_srl;
1423
		$output = executeQuery('member.getJoinForm', $args);
1424
1425
		$join_form = $output->data;
1426
		$list_order = $join_form->list_order;
1427
		// Get information of all join forms
1428
		$join_form_list = $oMemberModel->getJoinFormList();
1429
		$join_form_srl_list = array_keys($join_form_list);
1430
		if(count($join_form_srl_list)<2) return new Object();
1431
1432
		for($i=0;$i<count($join_form_srl_list);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
1433
		{
1434
			if($join_form_srl_list[$i]==$member_join_form_srl) break;
1435
		}
1436
1437
		$next_member_join_form_srl = $join_form_srl_list[$i+1];
1438
		// Return if no previous join form exists
1439
		if(!$next_member_join_form_srl) return new Object();
1440
		$next_member_join_form = $join_form_list[$next_member_join_form_srl];
1441
		// Information of the join form
1442
		$cur_args = new stdClass;
1443
		$cur_args->member_join_form_srl = $member_join_form_srl;
1444
		$cur_args->list_order = $next_member_join_form->list_order;
1445
		// Information of the target join form
1446
		$next_args = new stdClass;
1447
		$next_args->member_join_form_srl = $next_member_join_form->member_join_form_srl;
1448
		$next_args->list_order = $list_order;
1449
		// Execute Query
1450
		$output = executeQuery('member.updateMemberJoinFormListorder', $cur_args);
1451
		if(!$output->toBool()) return $output;
1452
1453
		$output = executeQuery('member.updateMemberJoinFormListorder', $next_args);
1454
		if(!$output->toBool()) return $output;
1455
1456
		return new Object();
1457
	}
1458
}
1459
/* End of file member.admin.controller.php */
1460
/* Location: ./modules/member/member.admin.controller.php */
1461