]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/profilesettings.php
7779379b12018de7dba784ff63355fc8d2911a38
[quix0rs-gnu-social.git] / actions / profilesettings.php
1 <?php
2 /* 
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  * 
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
15  * 
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/settingsaction.php');
23
24 class ProfilesettingsAction extends SettingsAction {
25         
26         function show_form($msg=NULL, $success=false) {
27                 common_show_header(_t('Profile settings'));
28                 $this->settings_menu();
29                 $this->message($msg, $success);
30                 common_element_start('form', array('method' => 'POST',
31                                                                                    'id' => 'profilesettings',
32                                                                                    'action' => 
33                                                                                    common_local_url('profilesettings')));
34                 common_input('nickname', _t('Nickname'));
35                 common_input('fullname', _t('Full name'));
36                 common_input('email', _t('Email address'));             
37                 common_input('homepage', _t('Homepage'));                               
38                 common_input('bio', _t('Bio'));
39                 common_input('location', _t('Location'));
40                 common_element('input', array('name' => 'submit',
41                                                                           'type' => 'submit',
42                                                                           'id' => 'submit'),
43                                            _t('Login'));
44                 common_element('input', array('name' => 'cancel',
45                                                                           'type' => 'button',
46                                                                           'id' => 'cancel'),
47                                            _t('Cancel'));
48                 common_element_end('form');
49                 common_show_footer();
50         }
51         
52         function handle_post() {
53                 $nickname = $this->arg('nickname');
54                 $fullname = $this->arg('fullname');
55                 $email = $this->arg('email');
56                 $homepage = $this->arg('homepage');
57                 $bio = $this->arg('bio');
58                 $location = $this->arg('location');
59
60                 $user = common_current_user();
61                 assert(!is_null($user)); # should already be checked
62                 
63                 # FIXME: scrub input
64                 # FIXME: transaction!
65                 
66                 $user->nickname = $this->arg('nickname');
67                 $user->email = $this->arg('email');
68                 
69                 if (!$user->update()) {
70                         common_server_error(_t('Couldnt update user.'));
71                         return;
72                 }
73
74                 $profile = $user->getProfile();
75
76                 $profile->nickname = $user->nickname;
77                 $profile->fullname = $this->arg('fullname');
78                 $profile->homepage = $this->arg('homepage');
79                 $profile->bio = $this->arg('bio');
80                 $profile->location = $this->arg('location');
81
82                 if (!$profile->update()) {
83                         common_server_error(_t('Couldnt save profile.'));
84                         return;
85                 }
86                 
87                 $this->show_form(_t('Settings saved.'), TRUE);
88         }
89 }