1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<?php
htmlHeader();
?>
<?php
//TODO: Switch to a http request instead of curl
// class mixpanelTracker {
// public $token = '24743c6567f831ddfcbbbd3f397e11e4';
// public $host = 'http://api.mixpanel.com/';
// public function __construct() {
// }
// function set($distinct_id, $properties=array()) {
// $params = array(
// '$token' => $this->token,
// '$distinct_id' => $distinct_id,
// '$set' => $properties
// );
// $url = $this->host . 'engage/?verbose=1&data=' . base64_encode(json_encode($params));
// exec("curl '" . $url . "' >/dev/null 2>&1 &");
// }
// }
topbar($headerLinks);
if (!$accepted) {
echo "Sign in first";
htmlFooter();
exit;
}
include('./includes/maps.php');
include_once('./includes/sqlEmbedded.php');
function validatename($name) {
if (strlen($name) < 1) return "Name to short";
if (strlen($name) > 25) return "Name is too long (".strlen($name)."/25)";
if (!preg_match("~[a-zA-Z0-9]\b~", $name)) return "Must contain atleast 1 Alpha-Numerical character";
return true;
}
/**
* Returns true if the given user has opted out of emails, false otherwise
*/
function isOptedOutOfEmails($userID) {
$userID = mysql_escape_string($userID);
$sql = "SELECT `isOptedOutOfEmails` FROM `users`
WHERE `ID` = '$userID' AND `isOptedOutOfEmails` = 1
LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
return (mysql_num_rows($result) >= 1);
}
function setOptedOutOfEmails($userID, $setting) {
$userID = mysql_escape_string($userID);
if ($setting) $setting == '1'; else $setting == '0';
$sql = "UPDATE `users`
SET `isOptedOutOfEmails` = '$setting'
WHERE `ID` = '$userID'
LIMIT 1";
$result = mysql_query($sql) or die(mysql_error());
}
if (isset($_POST['updateSettings']) AND $_POST['updateSettings'] == 'true') {
$userID = $_SESSION['userID'];
if (isset($_POST['displayName'])) {
//$inputname = stripSlashes($_POST['displayName']);
$inputname = $_POST['displayName'];
//Validate before replacements. To perevent < becoming > (longer)
$nameError = validatename($inputname);
//$inputname = htmlentities($inputname);
$inputname = htmlspecialchars($inputname, ENT_COMPAT | ENT_HTML5);
$inputname = chatFilter($inputname);
$inputname = str_replace(" ", " ", $inputname);
if ($nameError === true) {
$inputname = sql_clean($inputname);
$sql = "UPDATE `users`
SET `displayName` = '$inputname'
WHERE `ID` = '$userID'
";
mysql_query($sql);
$_SESSION['displayName'] = $inputname;
$r .= "<br />Name change success!";
} else {
$r .= "<br />Error: ".$nameError;
}
}
if ($_POST['emailOptOut'] == 'true') {
setOptedOutOfEmails($userID, true);
$r .= "<br />You are opted out of emails";
$r .= '<script>mixpanel.people.set("$unsubscribed", true);</script>';
} else {
setOptedOutOfEmails($userID, false);
$r .= "<br />You are accepting emails";
$r .= '<script>mixpanel.people.set("$unsubscribed", false);</script>';
//$metrics = new mixpanelTracker($mpToken);
//$metrics->set(10, array('$unsubscribed'=>false));
}
DoRedirect($r);
exit;
}
$checked = '';
if (isOptedOutOfEmails($userID)) {
$checked = 'checked="yes"';
}
$displayName = $_SESSION['displayName'];
//$displayName = htmlspecialchars($_SESSION['displayName'], ENT_COMPAT | ENT_HTML5);
?>
<div class="wrapper">
<h2>Control Panel</h2>
<form action="cp" method="post" name="changename">
<input type="hidden" name="updateSettings" value="true">
<fieldset style='width:400px'>
<legend>Settings:</legend>
Display Name: <input type="text" size="20" maxlength="14" value="<?php echo $displayName ?>" name="displayName" class="forminput" />
<br /><br />We'll only send you important feature updates!
<br /><input type="checkbox" name="emailOptOut" value="true" <?php echo $checked ?>>
Opt out of emails?
<br /><br />
<input type="submit" value="Update settings" class="forminput" />
</fieldset>
</div>
</form>
<?php
htmlFooter();
?>
|