Added original date and updated date to bookmark output if different.
[scuttle] / profile.php
1 <?php
2 /***************************************************************************
3 Copyright (C) 2004 - 2006 Marcus Campbell
4 http://scuttle.org/
5
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.
10
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.
15
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 ***************************************************************************/
20
21 require_once 'header.inc.php';
22 $templateservice =& ServiceFactory::getServiceInstance('TemplateService');
23 $userservice =& ServiceFactory::getServiceInstance('UserService');
24
25 $tplVars = array();
26
27 @list($url, $user) = isset($_SERVER['PATH_INFO']) ? explode('/', $_SERVER['PATH_INFO']) : NULL;
28
29 $loggedon = false;
30 if ($userservice->isLoggedOn()) {
31     $loggedon = true;
32     $currentUser = $userservice->getCurrentUser();
33     $currentUserID = $userservice->getCurrentUserId();
34     $currentUsername = $currentUser[$userservice->getFieldName('username')];
35 }
36
37 if ($user) {
38     if (is_int($user)) {
39         $userid = intval($user);
40     } else {
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);
45             exit();
46         } else {
47             $userid =& $userinfo['uId'];
48         }
49     }
50 } else {
51     $tplVars['error'] = T_('Username was not specified');
52     $templateservice->loadTemplate('error.404.tpl', $tplVars);
53     exit();
54 }
55
56 if ($user == $currentUsername) {
57     $title = T_('My Profile');
58 } else {
59     $title = T_('Profile') .': '. $user;
60 }
61 $tplVars['pagetitle'] = $title;
62 $tplVars['subtitle'] = $title;
63
64 $tplVars['user'] = $user;
65 $tplVars['userid'] = $userid;
66
67 if (isset($_POST['submitted'])) {
68     $error = false;
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) {
76         $error = true;
77         $tplVars['error'] = T_('Password and confirmation do not match.');
78     }
79     if ($detPass != "" && strlen($detPass) < 6) {
80         $error = true;
81         $tplVars['error'] = T_('Password must be at least 6 characters long.');
82     }
83     if (!$userservice->isValidEmail($detMail)) {
84         $error = true;
85         $tplVars['error'] = T_('E-mail address is not valid.');
86     }
87     if (!$error) {
88         if (!$userservice->updateUser($userid, $detPass, $detName, $detMail, $detPage, $detDesc)) {
89             $tplvars['error'] = T_('An error occurred while saving your changes.');
90         } else {
91             $tplVars['msg'] = T_('Changes saved.');
92         }
93     }
94     $userinfo = $userservice->getUserByUsername($user);
95 }
96
97 if ($currentUserID != $userid) {
98     $templatename = 'profile.tpl.php';
99 } else {
100     $templatename = 'editprofile.tpl.php';
101     $tplVars['formaction']  = createURL('profile', $user);
102 }
103
104 $tplVars['row'] = $userinfo;
105 $templateservice->loadTemplate($templatename, $tplVars);
106 ?>

Benjamin Mako Hill || Want to submit a patch?