summaryrefslogtreecommitdiff
path: root/src/views/pages/users/include.php
blob: 6e8c90b56440e7370e502af937a0dbd96cac6769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php global $mm;

require_once('User.class.php');

/**
 * This will take care of possibly updating and displaying a value in the
 * 'users' table.
 */
function inputText($user, $name, $label, $hint='') {
	if ($user->canEdit()) {
		if (isset($_POST["user_$name"])) {
			$user->setConf($name, $_POST["user_$name"]);
		}
	}
	
	$current_setting = $user->getConf($name);
	
	global $mm;
	$t = $mm->template();
	$t->inputText("user_$name", $label, $hint, $current_setting,
	              !$user->canEdit());
}

function inputArray($user, $name, $arr) {
	global $mm;
	$t = $mm->template();
	
	if (isset($_POST[$name]) && is_array($_POST[$name])) {
		$user->setConfArray($name, $_POST[$name]);
	}
	$defaults = $user->getConfArray($name);
	
	foreach ($arr as $value => $label) {
		$t->inputBool($name, $value, $label,
		              in_array($value, $defaults), !$user->canEdit());
	}
}

function inputNewPassword($user, $name, $label) {
	@$password1 = $_POST[$name          ];
	@$password2 = $_POST[$name.'_verify'];
	
	// Check the verify box, not main box, so that we don't get tripped by
	// browsers annoyingly autocompleting the password.
	$is_set = ($password2 != '');
	
	global $mm;
	$t = $mm->template();

	if ($is_set) {
		$matches = ( $password1 == $password2 );
		if ($matches) {
			$user->setPassword($password1);
			$t->inputP('Password successfully updated.');
		} else {
			$t->inputP("Passwords don't match.", true);
		}
	}
	$t->inputNewPassword($name, $label);
}