XOOPS  2.6.0
edituser.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 
23 include __DIR__ . DIRECTORY_SEPARATOR . 'mainfile.php';
24 
26 $xoops->preload()->triggerEvent('core.edituser.start');
27 $xoops->loadLanguage('user');
28 
29 // If not a user, redirect
30 if (!$xoops->isUser()) {
31  $xoops->redirect('index.php', 3, XoopsLocale::E_NO_ACTION_PERMISSION);
32  exit();
33 }
34 
35 // initialize $op variable
36 $op = Request::getCmd('op', 'editprofile');
37 
39 if ($op == 'saveuser') {
40  if (!$xoops->security()->check()) {
41  $xoops->redirect(
42  'index.php',
43  3,
44  XoopsLocale::E_NO_ACTION_PERMISSION . "<br />" . implode('<br />', $xoops->security()->getErrors())
45  );
46  exit();
47  }
48  $uid = Request::getInt('uid', 0);
49  if (empty($uid) || $xoops->user->getVar('uid') != $uid) {
50  $xoops->redirect('index.php', 3, XoopsLocale::E_NO_ACTION_PERMISSION);
51  exit();
52  }
53  $errors = array();
54  $email='';
55  if ($xoops->getConfig('allow_chgmail') == 1) {
56  $email = Request::getString('email', '');
57  $email = $myts->stripSlashesGPC(trim($email));
58  if ($email == '' || ! $xoops->checkEmail($email)) {
59  $errors[] = XoopsLocale::E_INVALID_EMAIL;
60  }
61  }
62  $password = Request::getString('password', '');
63  $password = $myts->stripSlashesGPC(trim($password));
64  if ($password != '') {
65  if (mb_strlen($password) < $xoops->getConfig('minpass')) {
66  $errors[] = sprintf(XoopsLocale::EF_PASSWORD_MUST_BE_GREATER_THAN, $xoops->getConfig('minpass'));
67  }
68  $vpass = Request::getString('vpass', '');
69  $vpass = $myts->stripSlashesGPC(trim($vpass));
70  if ($password != $vpass) {
72  }
73  }
74  if (count($errors) > 0) {
75  $xoops->header();
76  echo '<div>';
77  foreach ($errors as $er) {
78  echo '<span class="red bold">' . $er . '</span><br />';
79  }
80  echo '</div><br />';
81  $op = 'editprofile';
82  } else {
83  $member_handler = $xoops->getHandlerMember();
84  $edituser = $member_handler->getUser($uid);
85  $edituser->setVar('name', Request::getString('name', ''));
86  if ($xoops->getConfig('allow_chgmail') == 1) {
87  $edituser->setVar('email', $email, true);
88  }
89  if ($password != '') {
90  $edituser->setVar('pass', password_hash($password, PASSWORD_DEFAULT), true);
91  }
92  $edituser->setVar('url', $xoops->formatURL(Request::getUrl('url', '')));
93  $edituser->setVar('user_icq', Request::getString('user_icq', ''));
94  $edituser->setVar('user_from', Request::getString('user_from', ''));
95  $edituser->setVar('user_sig', XoopsLocale::substr(Request::getString('user_sig', ''), 0, 255));
96  $edituser->setVar('user_viewemail', Request::getBool('user_viewemail', 0));
97  $edituser->setVar('user_aim', Request::getString('user_aim', ''));
98  $edituser->setVar('user_yim', Request::getString('user_yim', ''));
99  $edituser->setVar('user_msnm', Request::getString('user_msnm', ''));
100  $edituser->setVar('attachsig', Request::getBool('attachsig', 0));
101  $edituser->setVar('timezone_offset', Request::getFloat('timezone_offset', 0));
102  $edituser->setVar('uorder', Request::getInt('uorder', 0));
103  $edituser->setVar('umode', Request::getString('umode', 'flat'));
104  $edituser->setVar('notify_method', Request::getInt('notify_method', 1));
105  $edituser->setVar('notify_mode', Request::getInt('notify_mode', 1));
106  $edituser->setVar('bio', XoopsLocale::substr(Request::getString('bio', ''), 0, 255));
107  $edituser->setVar('user_occ', Request::getString('user_occ', ''));
108  $edituser->setVar('user_intrest', Request::getString('user_intrest', ''));
109  $edituser->setVar('user_mailok', Request::getBool('user_mailok', 0));
110  if (! $member_handler->insertUser($edituser)) {
111  $xoops->header();
112  echo $edituser->getHtmlErrors();
113  $xoops->footer();
114  } else {
115  $xoops->redirect('userinfo.php?uid=' . $uid, 1, XoopsLocale::S_YOUR_PROFILE_UPDATED);
116  }
117  exit();
118  }
119 }
120 
121 if ($op == 'editprofile') {
122  $xoops->header('module:system/system_edituser.tpl');
123  $xoops->tpl()->assign('uid', $xoops->user->getVar("uid"));
124  $xoops->tpl()->assign('editprofile', true);
125  $form = new Xoops\Form\ThemeForm(XoopsLocale::EDIT_PROFILE, 'userinfo', 'edituser.php', 'post', true);
126  $uname_label = new Xoops\Form\Label(XoopsLocale::USERNAME, $xoops->user->getVar('uname'));
127  $form->addElement($uname_label);
128  $name_text = new Xoops\Form\Text(XoopsLocale::REAL_NAME, 'name', 30, 60, $xoops->user->getVar('name', 'E'));
129  $form->addElement($name_text);
131  if ($xoops->getConfig('allow_chgmail') == 1) {
132  $email_text = new Xoops\Form\Text('', 'email', 30, 60, $xoops->user->getVar('email'));
133  } else {
134  $email_text = new Xoops\Form\Label('', $xoops->user->getVar('email'));
135  }
136  $email_tray->addElement($email_text);
137  $email_cbox_value = $xoops->user->user_viewemail() ? 1 : 0;
138  $email_cbox = new Xoops\Form\Checkbox('', 'user_viewemail', $email_cbox_value);
139  $email_cbox->addOption(1, XoopsLocale::ALLOW_OTHER_USERS_TO_VIEW_EMAIL);
140  $email_tray->addElement($email_cbox);
141  $form->addElement($email_tray);
142  $url_text = new Xoops\Form\Text(XoopsLocale::WEBSITE, 'url', 30, 100, $xoops->user->getVar('url', 'E'));
143  $form->addElement($url_text);
144 
145  $timezone_select = new Xoops\Form\SelectTimeZone(
147  'timezone_offset',
148  $xoops->user->getVar('timezone_offset')
149  );
150  $icq_text = new Xoops\Form\Text(XoopsLocale::ICQ, 'user_icq', 15, 15, $xoops->user->getVar('user_icq', 'E'));
151  $aim_text = new Xoops\Form\Text(XoopsLocale::AIM, 'user_aim', 18, 18, $xoops->user->getVar('user_aim', 'E'));
152  $yim_text = new Xoops\Form\Text(XoopsLocale::YIM, 'user_yim', 25, 25, $xoops->user->getVar('user_yim', 'E'));
153  $msnm_text = new Xoops\Form\Text(XoopsLocale::MSNM, 'user_msnm', 30, 100, $xoops->user->getVar('user_msnm', 'E'));
154  $location_text = new Xoops\Form\Text(
156  'user_from',
157  30,
158  100,
159  $xoops->user->getVar('user_from', 'E')
160  );
161  $occupation_text = new Xoops\Form\Text(
163  'user_occ',
164  30,
165  100,
166  $xoops->user->getVar('user_occ', 'E')
167  );
168  $interest_text = new Xoops\Form\Text(
170  'user_intrest',
171  30,
172  150,
173  $xoops->user->getVar('user_intrest', 'E')
174  );
175  $sig_tray = new Xoops\Form\ElementTray(XoopsLocale::SIGNATURE, '<br />');
176  $sig_tarea = new Xoops\Form\DhtmlTextArea('', 'user_sig', $xoops->user->getVar('user_sig', 'E'));
177  $sig_tray->addElement($sig_tarea);
178  $sig_cbox_value = $xoops->user->getVar('attachsig') ? 1 : 0;
179  $sig_cbox = new Xoops\Form\Checkbox('', 'attachsig', $sig_cbox_value);
180  $sig_cbox->addOption(1, XoopsLocale::ALWAYS_ATTACH_MY_SIGNATURE);
181  $sig_tray->addElement($sig_cbox);
182  $bio_tarea = new Xoops\Form\TextArea(XoopsLocale::EXTRA_INFO, 'bio', $xoops->user->getVar('bio', 'E'));
183  $pwd_text = new Xoops\Form\Password('', 'password', 10, 32);
184  $pwd_text2 = new Xoops\Form\Password('', 'vpass', 10, 32);
185  $pwd_tray = new Xoops\Form\ElementTray(
187  );
188  $pwd_tray->addElement($pwd_text);
189  $pwd_tray->addElement($pwd_text2);
190  $mailok_radio = new Xoops\Form\RadioYesNo(
192  'user_mailok',
193  $xoops->user->getVar('user_mailok')
194  );
195  $uid_hidden = new Xoops\Form\Hidden('uid', $xoops->user->getVar('uid'));
196  $op_hidden = new Xoops\Form\Hidden('op', 'saveuser');
197  $submit_button = new Xoops\Form\Button('', 'submit', XoopsLocale::SAVE_CHANGES, 'submit');
198 
199  $form->addElement($timezone_select);
200  $form->addElement($icq_text);
201  $form->addElement($aim_text);
202  $form->addElement($yim_text);
203  $form->addElement($msnm_text);
204  $form->addElement($location_text);
205  $form->addElement($occupation_text);
206  $form->addElement($interest_text);
207  $form->addElement($sig_tray);
208  $form->addElement($bio_tarea);
209  $form->addElement($pwd_tray);
210  $form->addElement($mailok_radio);
211  $form->addElement($uid_hidden);
212  $form->addElement($op_hidden);
213  //$form->addElement($token_hidden);
214  $form->addElement($submit_button);
215  if ($xoops->getConfig('allow_chgmail') == 1) {
216  $form->setRequired($email_text);
217  }
218  $form->display();
219  $xoops->footer();
220 }
if(!$xoops->isUser()) $op
Definition: edituser.php:36
const E_INVALID_EMAIL
Definition: en_US.php:334
const E_NO_ACTION_PERMISSION
Definition: en_US.php:352
if($uname== ''||$pass== '') $member_handler
Definition: checklogin.php:44
const EF_PASSWORD_MUST_BE_GREATER_THAN
Definition: en_US.php:266
static getInstance()
Definition: Xoops.php:160
$email_text
const SAVE_CHANGES
Definition: en_US.php:962
$form
Definition: xoops_code.php:21
exit
Definition: browse.php:104
const TIME_ZONE
Definition: en_US.php:1052
const INTEREST
Definition: en_US.php:484
$vpass
Definition: register.php:74
defined('DS') or define('DS' DIRECTORY_SEPARATOR
Definition: common.php:41
const OCCUPATION
Definition: en_US.php:872
const EDIT_PROFILE
Definition: en_US.php:228
const REAL_NAME
Definition: en_US.php:942
const S_YOUR_PROFILE_UPDATED
Definition: en_US.php:1037
const PASSWORD
Definition: en_US.php:895
if(!$xoops->isUser()) $uid
Definition: index.php:31
const E_PASSWORDS_MUST_MATCH
Definition: en_US.php:359
const SIGNATURE
Definition: en_US.php:1005
const EXTRA_INFO
Definition: en_US.php:309
const USERNAME
Definition: en_US.php:1079
const TYPE_NEW_PASSWORD_TWICE_TO_CHANGE_IT
Definition: en_US.php:1067
$myts
Definition: edituser.php:38
const ALWAYS_ATTACH_MY_SIGNATURE
Definition: en_US.php:67
$xoops
Definition: edituser.php:25
const Q_RECEIVE_OCCASIONAL_EMAIL_NOTICES_FROM_ADMINISTRATORS
Definition: en_US.php:934
const ALLOW_OTHER_USERS_TO_VIEW_EMAIL
Definition: en_US.php:60
const LOCATION
Definition: en_US.php:515
$email_tray
static substr($str, $start, $length, $trimmarker= '...')
Definition: Abstract.php:194
$email
Definition: lostpass.php:32