Completed
Push — master ( a4e9d3...8e8e92 )
by Nazar
04:38
created

users::users_general()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * @package    CleverStyle CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\admin\Controller;
11
use
12
	cs\Config,
13
	cs\Group,
14
	cs\Index,
15
	cs\Language,
16
	cs\Page,
17
	cs\Route,
18
	cs\User,
19
	h;
20
21
trait users {
22
	static function users_general () {
23
		$Index       = Index::instance();
24
		$Index->form = false;
25
		$Index->content(
26
			h::cs_system_admin_users_general()
27
		);
28
	}
29
	static function users_groups () {
30
		$a       = Index::instance();
31
		$a->form = false;
32
		$a->content(
33
			h::cs_system_admin_groups_list()
34
		);
35
	}
36
	static function users_mail () {
37
		$Config              = Config::instance();
38
		$Index               = Index::instance();
39
		$L                   = Language::instance();
40
		$Index->apply_button = true;
41
		$Index->content(
42
			static::vertical_table(
43
				[
44
					[
45
						h::info('smtp'),
46
						h::radio(
47
							[
48
								'name'    => 'core[smtp]',
49
								'checked' => $Config->core['smtp'],
50
								'value'   => [0, 1],
51
								'in'      => [$L->off, $L->on],
52
								'OnClick' => ["$('#smtp_form').parent().parent().children().hide();", "$('#smtp_form').parent().parent().children().show();"]
53
							]
54
						)
55
					],
56
					[
57
						[
58
							'',
59
							h::{'table#smtp_form tr'}(
60
								h::td(
61
									static::core_input('smtp_host')
62
								),
63
								h::td(
64
									static::core_input('smtp_port')
65
								),
66
								h::td(
67
									[
68
										h::info('smtp_secure'),
69
										h::radio(
70
											[
71
												'name'    => 'core[smtp_secure]',
72
												'checked' => $Config->core['smtp_secure'],
73
												'value'   => ['', 'ssl', 'tls'],
74
												'in'      => [$L->off, 'SSL', 'TLS']
75
											]
76
										)
77
									]
78
								),
79
								h::td(
80
									[
81
										$L->smtp_auth,
82
										h::radio(
83
											[
84
												'name'    => 'core[smtp_auth]',
85
												'checked' => $Config->core['smtp_auth'],
86
												'value'   => [0, 1],
87
												'in'      => [$L->off, $L->on],
88
												'OnClick' => ["$('#smtp_user, #smtp_password').hide();", "$('#smtp_user, #smtp_password').show();"]
89
											]
90
										)
91
									]
92
								),
93
								[
94
									h::td(
95
										static::core_input('smtp_user')
96
									),
97
									[
98
										'style' => (!$Config->core['smtp_auth'] ? 'display: none;' : '').' padding-left: 20px;',
99
										'id'    => 'smtp_user'
100
									]
101
								],
102
								[
103
									h::td(
104
										static::core_input('smtp_password')
105
									),
106
									[
107
										'style' => !$Config->core['smtp_auth'] ? 'display: none;' : '',
108
										'id'    => 'smtp_password'
109
									]
110
								]
111
							)
112
						],
113
						[
114
							'style' => !$Config->core['smtp'] ? 'display: none; ' : ''
115
						]
116
					],
117
					static::core_input('mail_from'),
118
					static::core_input('mail_from_name'),
119
					static::core_textarea('mail_signature', 'cs-editor-simple'),
120
					[
121
						'',
122
						h::{'td button[is=cs-button][onclick=cs.test_email_sending()]'}($L->test_email_sending)
123
					]
124
				]
125
			)
126
		);
127
	}
128
	static function users_permissions () {
129
		$a       = Index::instance();
130
		$a->form = false;
131
		$a->content(
132
			h::cs_system_admin_permissions_list()
133
		);
134
	}
135
	static function users_security () {
136
		$Config = Config::instance();
137
		$Index  = Index::instance();
138
		$L      = Language::instance();
139
		/**
140
		 * @var \cs\_SERVER $_SERVER
141
		 */
142
		$Index->apply_button = true;
143
		$Index->content(
144
			static::vertical_table(
145
				[
146
					[
147
						h::info('key_expire'),
148
						h::{'input[is=cs-input-text][type=number]'}(
149
							[
150
								'name'  => 'core[key_expire]',
151
								'value' => $Config->core['key_expire'],
152
								'min'   => 1
153
							]
154
						).
155
						$L->seconds
156
					],
157
					[
158
						h::info('ip_black_list'),
159
						h::{'textarea[is=cs-textarea][autosize]'}(
160
							$Config->core['ip_black_list'],
161
							[
162
								'name' => 'core[ip_black_list]'
163
							]
164
						)
165
					],
166
					[
167
						h::info('ip_admin_list_only'),
168
						h::radio(
169
							[
170
								'name'    => 'core[ip_admin_list_only]',
171
								'checked' => $Config->core['ip_admin_list_only'],
172
								'value'   => [0, 1],
173
								'in'      => [$L->off, $L->on]
174
							]
175
						)
176
					],
177
					[
178
						h::info('ip_admin_list'),
179
						h::{'textarea[is=cs-textarea][autosize]'}(
180
							$Config->core['ip_admin_list'],
181
							[
182
								'name' => 'core[ip_admin_list]'
183
							]
184
						).
185
						h::br().
186
						$L->current_ip.': '.h::b($_SERVER->ip)
187
					]
188
				]
189
			)
190
		);
191
	}
192
	static function users_users () {
193
		$L    = Language::instance();
194
		$Page = Page::instance();
195
		$User = User::instance();
196
		$a    = Index::instance();
197
		$rc   = Route::instance()->route;
198
		if (isset($rc[2], $rc[3])) {
199
			$is_bot = in_array(3, (array)$User->get_groups($rc[3]));
200
			switch ($rc[2]) {
201
				case 'groups':
202
					if ($is_bot || !isset($rc[3]) || $rc[3] == User::ROOT_ID) {
203
						break;
204
					}
205
					$a->cancel_button_back = true;
206
					$Group                 = Group::instance();
207
					$user_groups           = array_reverse($User->get_groups($rc[3]));
208
					$all_groups            = $Group->get_all();
209
					$groups_selected       = h::{'li.cs-block-primary.cs-text.primary'}(
210
						$L->selected_groups
211
					);
212
					$groups_list           = h::{'li.cs-block-primary.cs-text.primary'}(
213
						$L->other_groups
214
					);
215
					if (is_array($user_groups) && !empty($user_groups)) {
216
						foreach ($user_groups as $group) {
217
							$group = $Group->get($group);
218
							$groups_selected .= h::{'li.cs-block-success.cs-text-success'}(
219
								$group['title'],
220
								[
221
									'data-id' => $group['id'],
222
									'tooltip' => $group['description']
223
								]
224
							);
225
						}
226
					}
227
					if (is_array($all_groups) && !empty($all_groups)) {
228
						foreach ($all_groups as $group) {
229
							if ($group['id'] == User::BOT_GROUP_ID || in_array($group['id'], $user_groups)) {
230
								continue;
231
							}
232
							$groups_list .= h::{'li.cs-block-warning.cs-text-warning'}(
233
								$group['title'],
234
								[
235
									'data-id' => $group['id'],
236
									'tooltip' => $group['description']
237
								]
238
							);
239
						}
240
					}
241
					$Page->title(
242
						$L->user_groups($User->username($rc[3]))
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
243
					);
244
					$a->content(
245
						h::{'h2.cs-text-center'}(
246
							$L->user_groups(
0 ignored issues
show
Documentation Bug introduced by
The method user_groups does not exist on object<cs\Language>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
247
								$User->username($rc[3])
248
							),
249
							[
250
								'tooltip' => $L->user_groups_info
251
							]
252
						).
253
						h::{'div'}(
254
							h::{'ul#cs-users-groups-list-selected'}($groups_selected).
255
							h::{'ul#cs-users-groups-list'}($groups_list)
256
						).
257
						h::{'input[type=hidden]'}(
258
							[
259
								'name'  => 'user[id]',
260
								'value' => $rc[3]
261
							]
262
						).
263
						h::{'input#cs-user-groups[type=hidden]'}(
264
							[
265
								'name' => 'user[groups]'
266
							]
267
						)
268
					);
269
					break;
270
			}
271
			$a->content(
272
				h::{'input[type=hidden]'}(
273
					[
274
						'name'  => 'mode',
275
						'value' => $rc[2]
276
					]
277
				)
278
			);
279
		} else {
280
			$a->form = false;
281
			$a->content(
282
				h::{'cs-system-admin-users-list'}()
283
			);
284
		}
285
	}
286
}
287