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