4 function settings_init(&$a) {
7 notice("Permission denied." . EOL);
11 require_once("mod/profile.php");
12 profile_load($a,$a->user['nickname']);
16 function settings_post(&$a) {
20 notice( t('Permission denied.') . EOL);
23 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != $_SESSION['uid']) {
24 notice( t('Permission denied.') . EOL);
27 if((x($_POST,'password')) || (x($_POST,'confirm'))) {
29 $newpass = trim($_POST['password']);
30 $confirm = trim($_POST['confirm']);
33 if($newpass != $confirm ) {
34 notice( t('Passwords do not match. Password unchanged.') . EOL);
38 if((! x($newpass)) || (! x($confirm))) {
39 notice( t('Empty passwords are not allowed. Password unchanged.') . EOL);
44 $password = hash('whirlpool',$newpass);
45 $r = q("UPDATE `user` SET `password` = '%s' WHERE `uid` = %d LIMIT 1",
47 intval($_SESSION['uid']));
49 notice( t('Password changed.') . EOL);
51 notice( t('Password update failed. Please try again.') . EOL);
55 $username = notags(trim($_POST['username']));
56 $email = notags(trim($_POST['email']));
57 $timezone = notags(trim($_POST['timezone']));
62 $notify += intval($_POST['notify1']);
64 $notify += intval($_POST['notify2']);
66 $notify += intval($_POST['notify3']);
68 $notify += intval($_POST['notify4']);
70 $notify += intval($_POST['notify5']);
72 $username_changed = false;
73 $email_changed = false;
74 $zone_changed = false;
77 if($username != $a->user['username']) {
78 $username_changed = true;
79 if(strlen($username) > 40)
80 $err .= t(' Please use a shorter name.');
81 if(strlen($username) < 3)
82 $err .= t(' Name too short.');
84 if($email != $a->user['email']) {
85 $email_changed = true;
86 if(!eregi('[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,6}',$email))
87 $err .= t(' Not valid email.');
88 $r = q("SELECT `uid` FROM `user`
89 WHERE `email` = '%s' LIMIT 1",
92 if($r !== NULL && count($r))
93 $err .= t(' This email address is already registered.');
100 if($timezone != $a->user['timezone']) {
101 $zone_changed = true;
102 if(strlen($timezone))
103 date_default_timezone_set($timezone);
106 $str_group_allow = '';
107 $group_allow = $_POST['group_allow'];
108 if(is_array($group_allow)) {
109 array_walk($group_allow,'sanitise_acl');
110 $str_group_allow = implode('',$group_allow);
113 $str_contact_allow = '';
114 $contact_allow = $_POST['contact_allow'];
115 if(is_array($contact_allow)) {
116 array_walk($contact_allow,'sanitise_acl');
117 $str_contact_allow = implode('',$contact_allow);
120 $str_group_deny = '';
121 $group_deny = $_POST['group_deny'];
122 if(is_array($group_deny)) {
123 array_walk($group_deny,'sanitise_acl');
124 $str_group_deny = implode('',$group_deny);
127 $str_contact_deny = '';
128 $contact_deny = $_POST['contact_deny'];
129 if(is_array($contact_deny)) {
130 array_walk($contact_deny,'sanitise_acl');
131 $str_contact_deny = implode('',$contact_deny);
136 $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d WHERE `uid` = %d LIMIT 1",
140 dbesc($str_contact_allow),
141 dbesc($str_group_allow),
142 dbesc($str_contact_deny),
143 dbesc($str_group_deny),
145 intval($_SESSION['uid'])
148 notice( t('Settings updated.') . EOL);
150 if($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
152 // FIXME - set to un-verified, blocked and redirect to logout
157 // Refresh the content display with new data
159 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
160 intval($_SESSION['uid']));
166 if(! function_exists('settings_content')) {
167 function settings_content(&$a) {
170 notice( t('Permission denied.') . EOL );
174 require_once('view/acl_selectors.php');
176 $username = $a->user['username'];
177 $email = $a->user['email'];
178 $nickname = $a->user['nickname'];
179 $timezone = $a->user['timezone'];
180 $notify = $a->user['notify-flags'];
183 $nickname_block = file_get_contents("view/settings_nick_set.tpl");
186 $nickname_subdir = '';
187 if(strlen($a->get_path())) {
188 $subdir_tpl = file_get_contents('view/settings_nick_subdir.tpl');
189 $nickname_subdir = replace_macros($subdir_tpl, array(
190 '$baseurl' => $a->get_baseurl(),
191 '$nickname' => $nickname,
192 '$hostname' => $a->get_hostname()
197 $nickname_block = replace_macros($nickname_block,array(
198 '$nickname' => $nickname,
199 '$uid' => $_SESSION['uid'],
200 '$subdir' => $nickname_subdir,
201 '$basepath' => $a->get_hostname(),
202 '$baseurl' => $a->get_baseurl()));
204 $o = file_get_contents('view/settings.tpl');
206 $o = replace_macros($o,array(
207 '$baseurl' => $a->get_baseurl(),
208 '$uid' => $_SESSION['uid'],
209 '$username' => $username,
211 '$nickname_block' => $nickname_block,
212 '$timezone' => $timezone,
213 '$zoneselect' => select_timezone($timezone),
214 '$permissions' => t('Default Post Permissions'),
215 '$aclselect' => populate_acl($a->user),
216 '$sel_notify1' => (($notify & NOTIFY_INTRO) ? ' checked="checked" ' : ''),
217 '$sel_notify2' => (($notify & NOTIFY_CONFIRM) ? ' checked="checked" ' : ''),
218 '$sel_notify3' => (($notify & NOTIFY_WALL) ? ' checked="checked" ' : ''),
219 '$sel_notify4' => (($notify & NOTIFY_COMMENT) ? ' checked="checked" ' : ''),
220 '$sel_notify5' => (($notify & NOTIFY_MAIL) ? ' checked="checked" ' : '')