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 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
23 $userservice =& ServiceFactory::getServiceInstance('UserService');
27 @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
30 if ($userservice->isLoggedOn()) {
32 $currentUser = $userservice->getCurrentUser();
33 $currentUserID = $userservice->getCurrentUserId();
34 $currentUsername = $currentUser[$userservice->getFieldName('username')];
39 $userid = intval($user);
41 $user = urldecode($user);
42 if (!($userinfo = $userservice->getUserByUsername($user))) {
43 $tplVars['error'] = sprintf(T_('User with username %s was not found'), $user);
44 $templateservice->loadTemplate('error.404.tpl', $tplVars);
47 $userid =& $userinfo['uId'];
51 $tplVars['error'] = T_('Username was not specified');
52 $templateservice->loadTemplate('error.404.tpl', $tplVars);
56 if ($user == $currentUsername) {
57 $title = T_('My Profile');
59 $title = T_('Profile') .': '. $user;
61 $tplVars['pagetitle'] = $title;
62 $tplVars['subtitle'] = $title;
64 $tplVars['user'] = $user;
65 $tplVars['userid'] = $userid;
67 if (isset($_POST['submitted'])) {
69 $detPass = trim($_POST['pPass']);
70 $detPassConf = trim($_POST['pPassConf']);
71 $detName = trim($_POST['pName']);
72 $detMail = trim($_POST['pMail']);
73 $detPage = trim($_POST['pPage']);
74 $detDesc = filter($_POST['pDesc']);
75 if ($detPass != $detPassConf) {
77 $tplVars['error'] = T_('Password and confirmation do not match.');
79 if ($detPass != "" && strlen($detPass) < 6) {
81 $tplVars['error'] = T_('Password must be at least 6 characters long.');
83 if (!$userservice->isValidEmail($detMail)) {
85 $tplVars['error'] = T_('E-mail address is not valid.');
88 if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc)) {
89 $tplvars['error'] = T_('An error occurred while saving your changes.');
91 $tplVars['msg'] = T_('Changes saved.');
94 $userinfo = $userservice->getUserByUsername($user);
97 if ($currentUserID != $userid) {
98 $templatename = 'profile.tpl.php';
100 $templatename = 'editprofile.tpl.php';
101 $tplVars['formaction'] = createURL('profile', $user);
104 $tplVars['row'] = $userinfo;
105 $templateservice->loadTemplate($templatename, $tplVars);