2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Scuttle project
4 http://sourceforge.net/projects/scuttle/
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.
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.
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 ***************************************************************************/
22 require_once('header.inc.php');
23 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
24 $userservice =& ServiceFactory::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);