2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Marcus Campbell
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************/
21 require_once 'header.inc.php';
22 $sf = new ServiceFactory();
23 $templateservice =& $sf->getServiceInstance('TemplateService');
24 $userservice =& $sf->getServiceInstance('UserService');
28 @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
31 if ($userservice->isLoggedOn()) {
33 $currentUser = $userservice->getCurrentUser();
34 $currentUserID = $userservice->getCurrentUserId();
35 $currentUsername = $currentUser[$userservice->getFieldName('username')];
40 $userid = intval($user);
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);
48 $userid =& $userinfo['uId'];
52 $tplVars['error'] = T_('Username was not specified');
53 $templateservice->loadTemplate('error.404.tpl', $tplVars);
57 if ($user == $currentUsername) {
58 $title = T_('My Profile');
60 $title = T_('Profile') .': '. $user;
62 $tplVars['pagetitle'] = $title;
63 $tplVars['subtitle'] = $title;
65 $tplVars['user'] = $user;
66 $tplVars['userid'] = $userid;
68 if (isset($_POST['submitted'])) {
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) {
78 $tplVars['error'] = T_('Password and confirmation do not match.');
80 if ($detPass != "" && strlen($detPass) < 6) {
82 $tplVars['error'] = T_('Password must be at least 6 characters long.');
84 if (!$userservice->isValidEmail($detMail)) {
86 $tplVars['error'] = T_('E-mail address is not valid.');
89 if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc)) {
90 $tplvars['error'] = T_('An error occurred while saving your changes.');
92 $tplVars['msg'] = T_('Changes saved.');
95 $userinfo = $userservice->getUserByUsername($user);
98 if ($currentUserID != $userid) {
99 $templatename = 'profile.tpl.php';
101 $templatename = 'editprofile.tpl.php';
102 $tplVars['formaction'] = createURL('profile', $user);
105 $tplVars['row'] = $userinfo;
106 $templateservice->loadTemplate($templatename, $tplVars);