dialog.grants.users.php ➔ arrayMergeCorrect()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 2
dl 0
loc 17
rs 9.0777
c 0
b 0
f 0
ccs 0
cts 16
cp 0
crap 42
1
<?php
2
	include_once("dialog.grants.logic.php");
3
4
	include_once($this->store->get_config("code")."modules/mod_yui.php");
5
	include_once($this->store->get_config("code")."modules/mod_grant.php");
6
	include_once($this->store->get_config("code")."ar.php");
7
8
9
	$userConfig = $this->loadUserConfig();
10
	$authconfig = $userConfig['authentication'];
11
12
	define('ARGRANTBYTYPE', 8);
13
14
	$selectedpath = $this->getdata("selectedpath");
15
	$selecteduser = $this->getdata("selecteduser");
16
	$moregrants = $this->getdata("moregrants");
17
	$textmode = $this->getdata("textmode");
18
	$stored_vars = $this->getdata("arStoreVars");
19
	$data = $this->getdata('data');
20
21
	$textswitch = ar::getvar("textmode", "post");
0 ignored issues
show
Unused Code introduced by
The call to ar::getvar() has too many arguments starting with 'post'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
22
23
	if (!$selectedpath) {
24
		$selectedpath = $this->path;
25
	}
26
27
	$defaultGroupDir    = "/system/groups/";
28
	if (is_array($authconfig['groupdirs'])) {
29
		$defaultGroupDir = end($authconfig['groupdirs']);
30
	}
31
32
33
	$default_grants = array(
34
		"read" => "Read",
35
		"add" => "Add",
36
		"edit" => "Edit",
37
		"layout" => "Layout",
38
		"config" => "Config",
39
		"delete" => "Delete",
40
		"none" => "None"
41
	);
42
43
	$available_grants = $default_grants;
44
45
	$users = array();
46
	$selectedob = current($this->get($selectedpath, "system.get.phtml"));
47
	while (($selectedob->parent != '..')) {
48
		if($selectedob && $selectedob->data->config->grants) {
49
			foreach ($selectedob->data->config->grants as $type => $grant) {
50
				foreach ($grant as $id => $grants) {
51
					if ($type == 'pgroup') {
52 View Code Duplication
						foreach ($authconfig['groupdirs'] as $groupdir) {
53
							$path  = current($this->find($groupdir, 'login.value=\''.$id.'\'', 'system.get.path.phtml'));
54
							$name  = current($this->find($groupdir, 'login.value=\''.$id.'\'', 'system.get.name.phtml'));
55
							if ($path) {
56
								break;
57
							}
58
						}
59
					} else {
60
						// type is puser;
61 View Code Duplication
						foreach ($authconfig['userdirs'] as $userdir) {
62
							$path  = current($this->find($userdir, 'login.value=\''.$id.'\'', 'system.get.path.phtml'));
63
							$name  = current($this->find($userdir, 'login.value=\''.$id.'\'', 'system.get.name.phtml'));
64
							if ($path) {
65
								break;
66
							}
67
						}
68
					}
69
70
					$grantsstring = grantsArrayToString($grants);
71
					$grants_by_type = array();
72 View Code Duplication
					foreach ($grants as $grantname => $grantvalue) {
73
						if (!isset($available_grants[$grantname])) {
74
							$available_grants[$grantname] = yui::labelspan($grantname, 8);
75
						}
76
						if (is_array($grantvalue)) {
77
							$grants_by_type[$grantname] = $grantvalue;
78
							$grants[$grantname] = ARGRANTBYTYPE;
79
						}
80
					}
81
					if (!is_array($users[$path])) {
82
						$users[$path] = array(
83
							"name" => $name,
84
							"type" => $type,
85
							"grants" => array(
86
								'array' => $grants,
87
								'bytype' => $grants_by_type,
88
								"grantsstring" => $grantsstring
89
							)
90
						);
91
						if ($selectedob->path != $selectedpath) {
92
							$users[$path]["grants_inherited"] = 1;
93
						}
94
					}
95
				}
96
			}
97
		}
98
		$selectedob = current($this->get($selectedob->parent, "system.get.phtml"));
99
		$maxloop--;
100
	}
101
102
	$extrausers = $this->getdata("extrausers");
103
	if (!is_array($extrausers)) {
104
		$extrausers = array();
105
	}
106
	if ($users[$selecteduser]['grants_inherited']) {
107
		$extrausers[] = $selecteduser;
108
	}
109
110
	foreach ($extrausers as $key => $extrauser) {
111
		if ($users[$extrauser]) {
112
			if ($users[$extrauser]['grants_inherited']) {
113
				unset($users[$extrauser]);
114
			} else {
115
				continue;
116
			}
117
		}
118
		if (!$this->exists($extrauser)) {
119
			unset($extrausers[$key]);
120
			continue;
121
		} else {
122
			$extra_ob = current($this->get($extrauser, 'system.get.phtml'));
123
			if (strpos($extra_ob->type, "pshortcut") === 0) {
124
				$extra_ob = current($this->get($extra_ob->data->path, 'system.get.phtml'));
125
			}
126
127
			if (
128
				$extra_ob->AR_implements("puser") ||
129
				$extra_ob->AR_implements("pgroup")
130
131
			) {
132
				$users[$extra_ob->path] = array(
133
					"name" => $extra_ob->nlsdata->name,
134
					"type" => $extra_ob->type,
135
					"grants" => array(
136
						'array' => array(),
137
						'bytype' => '',
138
						'grantsstring' => ''
139
					)
140
				);
141
			} else {
142
				$error = "Object $extrauser is not a user or group";
143
				unset($extrausers[$key]);
144
			}
145
		}
146
	}
147
148
	$useradd = $this->getvar("useradd");
149
	if ($useradd) {
150
		if ($this->exists($extrauser)) {
151
			if (!$error) {
152
				$selecteduser = $extrauser; // Select the new user.
153
			}
154
		} else {
155
			$error = "User $extrauser not found.";
156
		}
157
	} else {
158
		$error = '';
159
	}
160
161
	$add_bytype = $this->getvar("add_bytype");
162
	if ($add_bytype) {
163
		$typename = $this->getvar("typename");
164
		$data[$selectedpath][$selecteduser]['grants']['bytype'][$moregrants][$typename] = ARGRANTGLOBAL;
165
	}
166
167
	function arrayMergeCorrect($left, $right) {
168
		if (is_null($right)) {
169
			return $left;
170
		}
171
		if (is_array($right)) {
172
			foreach ($right as $key => $value) {
173
				if (!is_numeric($key)) {
174
					$left[$key] = isset($left[$key]) ? arrayMergeCorrect($left[$key], $value) : $value;
175
				} else {
176
					$left[] = arrayMergeCorrect($left[$key], $value);
177
				}
178
			}
179
			return $left;
180
		} else {
181
			return $right;
182
		}
183
	}
184
185
186
	$typetree = $this->call('typetree.ini');
187
	$typenames = $this->getvar("arTypeNames");
188
	asort($typenames);
189
190
/*	// FIXME: Types met grants uit de grantsstring vissen.
191
	$types = array(
192
		"particle" => "Article",
193
		"pbookmark" => "Bookmark",
194
		"ppage" => "Page",
195
		"psite" => "Site"
196
	);
197
*/
198
199
	$modifiers = array(
200
		"Default" => ARGRANTGLOBAL,
201
		"Current only" => ARGRANTLOCAL,
202
		"Children only" => ARGRANTCHILDREN,
203
		"By type" => ARGRANTBYTYPE,
204
		"Unset grant" => 0
205
	);
206
207
	$modifiers = array(
208
		"*" => ARGRANTGLOBAL,
209
		"=" => ARGRANTLOCAL,
210
		">" => ARGRANTCHILDREN,
211
		"T" => ARGRANTBYTYPE,
212
		"X" => 0
213
	);
214
215
	$ob_id = str_replace("/", ":", $selectedpath);
216
?>
217
<div class="items">
218
	<h2><?php echo $ARnls['ariadne:grants:users_with_grants']; echo yui::labelspan($selectedpath, 20); ?></h2>
219
	<input type="hidden" name="selecteduser" value="<?php echo htmlspecialchars($selecteduser); ?>">
220
	<?php if ($error) { ?>
221
		<div class="error"><?php echo $error; ?></div>
222
	<?php } ?>
223
	<?php	foreach ($users as $path => $info) {
224
			$user_id = str_replace("/", ":", $path);
225
			$formdata = $data[$selectedpath][$path];
226
			$stored_formdata = $stored_vars['data'][$selectedpath][$path];
227
228
			// Merge info fromdata form with $info
229
			$info['grants'] = arrayMergeCorrect($info['grants'], $stored_formdata['grants']);
230
			$info['grants'] = arrayMergeCorrect($info['grants'], $formdata['grants']);
231
//			$info['grants'] = array_merge($info['grants'], $stored_formdata['grants'], $formdata['grants']);
232
//			echo "<pre>";
233
//			print_r($info['grants']);
234
			if (isset($textswitch) && $textswitch == 1) {
235
				$grants = (array)$formdata['grants']['array'];
236
				foreach ($grants as $key => $val) {
237
					if ($val == 8) {
238
						$grants[ $key ] = $formdata['grants']['bytype'][ $key ];
239
					}
240
				}
241
				$info['grants']['grantsstring'] = grantsArrayToString($grants);
242
			} else if (isset($textswitch) && $textswitch == 0) {
243
				$g_comp = new mod_grant;
244
				$newgrants = array();
245
//				print_r($info['grants']);
246
247
				$g_comp->compile($formdata['grants']['grantsstring'], $newgrants);
248
249
				$grants_by_type = array();
250 View Code Duplication
				foreach ($newgrants as $grantname => $grantvalue) {
251
					if (!isset($available_grants[$grantname])) {
252
						$available_grants[$grantname] = yui::labelspan($grantname, 8);
253
					}
254
					if (is_array($grantvalue)) {
255
						$grants_by_type[$grantname] = $grantvalue;
256
						$newgrants[$grantname] = ARGRANTBYTYPE;
257
					}
258
				}
259
				$formdata['grants']['array'] = $newgrant;
260
				$formdata['grants']['bytype'] = $grants_by_type;
261
262
			}
263
//			echo "</pre>";
264
	?>
265
		<div class="item<?php if($path == $selecteduser) { echo " selected";} if ($info['grants_inherited']) { echo " inherited";} ?>">
266
			<div class="info">
267
				<label class="block" for="selectuser_<?php echo $user_id; ?>">
268
					<img src="<?php echo $this->call('system.get.icon.php', array('type' => $info['type'], 'size' => 'medium'));?>" alt="<?php echo $info['type']; ?>">
269
					<span class="name"><?php echo $info['name']; ?></span><br>
270
					<span class="grants_string"><?php echo htmlspecialchars($info['grants']['grantsstring']); ?></span>
271
				</label>
272
				<input type="submit" name="selecteduser" class="hidden" value="<?php echo $path; ?>" id="selectuser_<?php echo $user_id; ?>">
273
			</div>
274
			<?php 	if (!$info['grants_inherited']) { ?>
275
				<?php	if($textmode) {	?>
276
					<label class="textmode block" for="textmode"></label>
277
					<input class="hidden" type="submit" name="textmode" value="0" id="textmode">
278
					<div class="grants_textmode">
279
						<h2>Advanced grants</h2>
280
						<textarea class="grantstext" name="data[<?php echo $selectedpath;?>][<?php echo $path; ?>][grants][grantsstring]" rows=4 cols=30><?php echo htmlspecialchars( $info['grants']['grantsstring'] ); ?></textarea>
281
					</div>
282
				<?php	} else {	?>
283
					<label class="textmode block" for="textmode"></label>
284
					<input class="hidden" type="submit" name="textmode" value="1" id="textmode">
285
					<div class="grants">
286
						<?php	foreach ($available_grants as $grant => $grant_name) {
287
								if ($info['grants']['array'][$grant]) {
288
									$checked = "checked = 'checked' ";
289
									$value = $info['grants']['array'][$grant];
290
								} else {
291
									$checked = '';
292
									$value = ARGRANTGLOBAL;
293
								}
294
								if ($grant == $moregrants) {
295
									$checked .= "disabled";
296
								}
297
								if ($info['grants']['array'][$grant] == 0 || $info['grants']['array'][$grant] == 6) {
298
									// normal grants;
299
									$labelclass="normal";
300
								} else {
301
									$labelclass="specific";
302
								}
303
304
305
								if (is_array($info['grants']['bytype'])) {
306
									foreach ($info['grants']['bytype'] as $bytype_grant => $bytype_types) {
307
										foreach ($bytype_types as $bytype_type => $bytype_value) {
308
											$dataname = "data[$selectedpath][$path][grants][bytype][$bytype_grant][$bytype_type]";
309
											?>
310
											<input type="hidden" name="<?php echo $dataname; ?>" value="<?php echo $bytype_value; ?>">
311
											<?php
312
										}
313
									}
314
								}
315
						?>
316
							<div class="field checkbox <?php echo $class; ?>">
317
								<input name="data[<?php echo $selectedpath; ?>][<?php echo $path; ?>][grants][array][<?php echo $grant; ?>]" type='hidden' value='0'>
318
								<input class="<?php echo $extraclass; ?>" name="data[<?php echo $selectedpath; ?>][<?php echo $path; ?>][grants][array][<?php echo $grant; ?>]" <?php echo $checked; ?> type='checkbox' id='<?php echo $grant; ?>' value='<?php echo $value;?>'>
319
								<label class="<?php echo $labelclass; ?>" for='<?php echo $grant; ?>'><?php echo $grant_name; ?></label>
320
								<label for="moregrants_<?php echo $grant; ?>" class="block more" title="More grants"></label>
321
								<?php if ($grant == $moregrants) { ?>
322
									<input type="submit" class="hidden" value="" name="moregrants" id="moregrants_<?php echo $grant; ?>">
323
								<?php } else { ?>
324
									<input type="submit" class="hidden" value="<?php echo $grant; ?>" name="moregrants" id="moregrants_<?php echo $grant; ?>">
325
								<?php } ?>
326
							</div>
327
						<?php	}	?>
328
						<div class="clear"></div>
329
						<?php 	if ($moregrants) {	?>
330
							<div class="moregrants">
331
								<h2>More grants: <?php echo $moregrants; ?></h2>
332
								<div class="modifier">
333
									Grant modifier
334
									<?php
335
										$name="data[$selectedpath][$path][grants][array][$moregrants]";
336
									?>
337
										<input type="hidden" value="<?php echo $info['grants']['array'][$moregrants]; ?>" name="<?php echo $name;?>">
338
									<?php
339
										foreach ($modifiers as $modname => $modvalue) {
340
											$selected = '';
341
											//echo "[" . $info['grants']['array'][$moregrants] . " == " . $modvalue . "]";
342
											if ($info['grants']['array'][$moregrants] == $modvalue) {
343
												$selected = 'selected';
344
											}
345
											?>
346
											<label class="modifier <?php echo $selected;?>" for="mg_<?php echo $user_id . ":" . $modvalue; ?>"><?php echo $modname; ?></label>
347
											<input type='submit' class='hidden' value="<?php echo $modvalue;?>" id="mg_<?php echo $user_id . ":" . $modvalue; ?>" name="<?php echo $name;?>">
348
									<?php 	} ?>
349
								</div>
350
351
								<?php if ($info['grants']['array'][$moregrants] == ARGRANTBYTYPE) {	?>
352
									<h2>Type-specific grants</h2>
353
									<div class="addtype">
354
										<input type="hidden" value="0" name="add_bytype">
355
										<select name="typename">
356
										<?php	foreach ($typenames as $type => $name) {
357
												if (!isset($info['grants']['bytype'][$moregrants][$type])) {
358
										?>
359
											<option value="<?php echo $type; ?>"><?php echo $name; ?></option>
360
										<?php		}
361
											}
362
										?>
363
										</select>&nbsp;<input class="button" type="submit" value="Add" name="add_bytype">
364
									</div>
365
									<div class="types">
366
										<?php
367
											if (is_array($info['grants']['bytype']) && is_array($info['grants']['bytype'][$moregrants])) {
368
												foreach ($info['grants']['bytype'][$moregrants] as $type => $value) {
369
													$name = $typenames[$type];
370
										?>
371
											<div class="type">
372
												<div class="field checkbox">
373
													<!--input name="data[<?php echo $selectedpath; ?>][<?php echo $path; ?>][grants][bytype][<?php echo $moregrants; ?>][<?php echo $type; ?>]" value=<?php echo ARGRANTGLOBAL?> <?php echo $checked; ?>type='checkbox' id='<?php echo $moregrants . "_" . $type; ?>'-->
374
												</div>
375
												<img src="<?php echo $this->call('system.get.icon.php', array('type' => $info['type']));?>" alt="<?php echo $type; ?>">
376
												<span class="name"><?php echo $name; ?></span>
377
378
												<?php
379
													$dataname="data[$selectedpath][$path][grants][bytype][$moregrants][$type]";
380
												?>
381
													<input type="hidden" value="<?php echo $info['grants']['bytype'][$moregrants][$type]; ?>" name="<?php echo $dataname;?>">
382
												<?php foreach ($modifiers as $modname => $modvalue) {
383
													if ($modvalue == ARGRANTBYTYPE) {
384
														continue;
385
													}
386
													$selected = '';
387
													//echo "[" . $info['grants']['bytpe'][$moregrants][$type] . " == " . $modvalue . "]";
388
													if ($info['grants']['bytype'][$moregrants][$type] == $modvalue) {
389
														$selected = 'selected';
390
													}
391
													?>
392
													<label class="modifier <?php echo $selected;?>" for="mg_<?php echo $user_id . ":" . $moregrants . ":" . $type . ":" . $modvalue; ?>"><?php echo $modname; ?></label>
393
													<input type='submit' class='hidden' value="<?php echo $modvalue;?>" id="mg_<?php echo $user_id . ":" . $moregrants . ":" . $type . ":" . $modvalue; ?>" name="<?php echo $dataname;?>">
394
												<?php } ?>
395
396
											</div>
397
										<?php
398
												}
399
											}
400
										?>
401
									</div>
402
								<?php	} ?>
403
							</div>
404
						<?php	}?>
405
406
					</div>
407
				<?php	}	?>
408
			<?php	}	?>
409
		</div>
410
	<?php	}	?>
411
</div>
412
<div class="browse">
413
	<?php
414
		if (is_array($extrausers)) {
415
			foreach ($extrausers as $extrauser) {
416
	?>
417
			<input type='hidden' name="extrausers[]" value="<?php echo $extrauser; ?>">
418
	<?php
419
			}
420
		}
421
422
		$wgBrowseRoot = $defaultGroupDir;
423
		$arConfig = $this->loadUserConfig();
424
		foreach (array('groupdirs', 'userdirs') as $groupType) {
425
			$authDirs = array_reverse( (array) $arConfig['authentication'][$groupType] );
426
			foreach ($authDirs as $authDir) {
427
				if ($authDir != $wgBrowseRoot) {
428
					$extraroots .= "extraroots[]=$authDir&";
429
				}
430
			}
431
		}
432
		if ($extraroots) {
433
			$extraroots = substr($extraroots, 0, -1);
434
		}
435
436
	?>
437
	<input type="text" id="extrauser" name="extrausers[]" value="<?php echo $defaultGroupDir; ?>">
438
	<input class="button" type="button" value="..." title="<?php echo $ARnls['browse']; ?>" onclick='callbacktarget="extrauser"; window.open("<?php echo $this->make_ariadne_url('/'); ?>" + document.getElementById("extrauser").value + "dialog.browse.php<?php echo $extraroots ? "?" . $extraroots : ""; ?>", "browse", "height=480,width=750"); return false;'>
439
	<input type="hidden" id="hidden_useradd" name="useradd" value=''>
440
	<input type="submit" class="button" name="useradd" value="<?php echo $ARnls['add']; ?>">
441
</div>
442