* Updated isValidEmail regex to match plussed addresses
[scuttle] / profile.php
1 <?php
2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
5 http://scuttle.org/
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 ***************************************************************************/
21
22 require_once('header.inc.php');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
24 $userservice =& ServiceFactory::getServiceInstance('UserService');
25
26 $tplVars = array();
27
28 @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
29
30 $loggedon = false;
31 if ($userservice->isLoggedOn()) {
32     $loggedon = true;
33     $currentUser = $userservice->getCurrentUser();
34     $currentUserID = $userservice->getCurrentUserId();
35     $currentUsername = $currentUser[$userservice->getFieldName('username')];
36 }
37
38 if ($user) {
39     if (is_int($user)) {
40         $userid = intval($user);
41     } else {
42         $user = urldecode($user);
43         if (!($userinfo = $userservice->getUserByUsername($user))) {
44             $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
45             $templateservice->loadTemplate('error.404.tpl', $tplVars);
46             exit();
47         } else {
48             $userid =& $userinfo['uId'];
49         }
50     }
51 } else {
52     $tplVars['error'] = T_('Username was not specified');
53     $templateservice->loadTemplate('error.404.tpl', $tplVars);
54     exit();
55 }
56
57 if ($user == $currentUsername) {
58     $title = T_('My Profile');
59 } else {
60     $title = T_('Profile') .': '. $user;
61 }
62 $tplVars['pagetitle'] = $title;
63 $tplVars['subtitle'] = $title;
64
65 $tplVars['user'] = $user;
66 $tplVars['userid'] = $userid;
67
68 if (isset($_POST['submitted'])) {
69     $error = false;
70     $detPass = trim($_POST['pPass']);
71     $detPassConf = trim($_POST['pPassConf']);
72     $detName = trim($_POST['pName']);
73     $detMail = trim($_POST['pMail']);
74     $detPage = trim($_POST['pPage']);
75     $detDesc = filter($_POST['pDesc']);
76     if ($detPass != $detPassConf) {
77         $error = true;
78         $tplVars['error'] = T_('Password and confirmation do not match.');
79     }
80     if ($detPass != "" && strlen($detPass) < 6) {
81         $error = true;
82         $tplVars['error'] = T_('Password must be at least 6 characters long.');
83     }
84     if (!$userservice->isValidEmail($detMail)) {
85         $error = true;
86         $tplVars['error'] = T_('E-mail address is not valid.');
87     }
88     if (!$error) {
89         if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc)) {
90             $tplvars['error'] = T_('An error occurred while saving your changes.');
91         } else {
92             $tplVars['msg'] = T_('Changes saved.');
93         }
94     }
95     $userinfo = $userservice->getUserByUsername($user);
96 }
97
98 if ($currentUserID != $userid) {
99     $templatename = 'profile.tpl.php';
100 } else {
101     $templatename = 'editprofile.tpl.php';
102     $tplVars['formaction']  = createURL('profile', $user);
103 }
104
105 $tplVars['row'] = $userinfo;
106 $templateservice->loadTemplate($templatename, $tplVars);
107 ?>

Benjamin Mako Hill || Want to submit a patch?