| 1 | <?php |
|---|
| 2 | // $Id: edituser.php,v 1.5 2006/05/01 02:37:26 onokazu Exp $ |
|---|
| 3 | // ------------------------------------------------------------------------ // |
|---|
| 4 | // XOOPS - PHP Content Management System // |
|---|
| 5 | // Copyright (c) 2000 XOOPS.org // |
|---|
| 6 | // <http://www.xoops.org/> // |
|---|
| 7 | // ------------------------------------------------------------------------ // |
|---|
| 8 | // This program is free software; you can redistribute it and/or modify // |
|---|
| 9 | // it under the terms of the GNU General Public License as published by // |
|---|
| 10 | // the Free Software Foundation; either version 2 of the License, or // |
|---|
| 11 | // (at your option) any later version. // |
|---|
| 12 | // // |
|---|
| 13 | // You may not change or alter any portion of this comment or credits // |
|---|
| 14 | // of supporting developers from this source code or any supporting // |
|---|
| 15 | // source code which is considered copyrighted (c) material of the // |
|---|
| 16 | // original comment or credit authors. // |
|---|
| 17 | // // |
|---|
| 18 | // This program 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 | // You should have received a copy of the GNU General Public License // |
|---|
| 24 | // along with this program; if not, write to the Free Software // |
|---|
| 25 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|---|
| 26 | // ------------------------------------------------------------------------ // |
|---|
| 27 | $xoopsOption['pagetype'] = 'user'; |
|---|
| 28 | include 'mainfile.php'; |
|---|
| 29 | include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|---|
| 30 | |
|---|
| 31 | // If not a user, redirect |
|---|
| 32 | if (!is_object($xoopsUser)) { |
|---|
| 33 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 34 | exit(); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | // initialize $op variable |
|---|
| 38 | $op = 'editprofile'; |
|---|
| 39 | if (!empty($_POST['op'])) { |
|---|
| 40 | $op = $_POST['op']; |
|---|
| 41 | } |
|---|
| 42 | if (!empty($_GET['op'])) { |
|---|
| 43 | $op = $_GET['op']; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | $config_handler =& xoops_gethandler('config'); |
|---|
| 47 | $xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER); |
|---|
| 48 | |
|---|
| 49 | if ($op == 'saveuser') { |
|---|
| 50 | if (!XoopsSingleTokenHandler::quickValidate('edituser')) { |
|---|
| 51 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 52 | exit; |
|---|
| 53 | } |
|---|
| 54 | $uid = 0; |
|---|
| 55 | if (!empty($_POST['uid'])) { |
|---|
| 56 | $uid = intval($_POST['uid']); |
|---|
| 57 | } |
|---|
| 58 | if (empty($uid) || $xoopsUser->getVar('uid') != $uid) { |
|---|
| 59 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 60 | exit(); |
|---|
| 61 | } |
|---|
| 62 | $errors = array(); |
|---|
| 63 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 64 | if ($xoopsConfigUser['allow_chgmail'] == 1) { |
|---|
| 65 | $email = ''; |
|---|
| 66 | if (!empty($_POST['email'])) { |
|---|
| 67 | $email = $myts->stripSlashesGPC(trim($_POST['email'])); |
|---|
| 68 | } |
|---|
| 69 | if ($email == '' || !checkEmail($email)) { |
|---|
| 70 | $errors[] = _US_INVALIDMAIL; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | $password = ''; |
|---|
| 74 | if (!empty($_POST['password'])) { |
|---|
| 75 | $password = $myts->stripSlashesGPC(trim($_POST['password'])); |
|---|
| 76 | } |
|---|
| 77 | if ($password != '') { |
|---|
| 78 | if (strlen($password) < $xoopsConfigUser['minpass']) { |
|---|
| 79 | $errors[] = sprintf(_US_PWDTOOSHORT,$xoopsConfigUser['minpass']); |
|---|
| 80 | } |
|---|
| 81 | $vpass = ''; |
|---|
| 82 | if (!empty($_POST['vpass'])) { |
|---|
| 83 | $vpass = $myts->stripSlashesGPC(trim($_POST['vpass'])); |
|---|
| 84 | } |
|---|
| 85 | if ($password != $vpass) { |
|---|
| 86 | $errors[] = _US_PASSNOTSAME; |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | if (count($errors) > 0) { |
|---|
| 90 | include XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 91 | echo '<div>'; |
|---|
| 92 | foreach ($errors as $er) { |
|---|
| 93 | echo '<span style="color: #ff0000; font-weight: bold;">'.$er.'</span><br />'; |
|---|
| 94 | } |
|---|
| 95 | echo '</div><br />'; |
|---|
| 96 | $op = 'editprofile'; |
|---|
| 97 | } else { |
|---|
| 98 | $member_handler =& xoops_gethandler('member'); |
|---|
| 99 | $edituser =& $member_handler->getUser($uid); |
|---|
| 100 | $edituser->setVar('name', $_POST['name']); |
|---|
| 101 | if ($xoopsConfigUser['allow_chgmail'] == 1) { |
|---|
| 102 | $edituser->setVar('email', $email, true); |
|---|
| 103 | } |
|---|
| 104 | $edituser->setVar('url', formatURL($_POST['url'])); |
|---|
| 105 | //$edituser->setVar('user_icq', $_POST['user_icq']); |
|---|
| 106 | $edituser->setVar('user_from', $_POST['user_from']); |
|---|
| 107 | $edituser->setVar('user_sig', xoops_substr($_POST['user_sig'], 0, 255)); |
|---|
| 108 | $user_viewemail = (!empty($_POST['user_viewemail'])) ? 1 : 0; |
|---|
| 109 | $edituser->setVar('user_viewemail', $user_viewemail); |
|---|
| 110 | //$edituser->setVar('user_aim', $_POST['user_aim']); |
|---|
| 111 | //$edituser->setVar('user_yim', $_POST['user_yim']); |
|---|
| 112 | //$edituser->setVar('user_msnm', $_POST['user_msnm']); |
|---|
| 113 | if ($password != '') { |
|---|
| 114 | $edituser->setVar('pass', md5($password), true); |
|---|
| 115 | } |
|---|
| 116 | $attachsig = !empty($_POST['attachsig']) ? 1 : 0; |
|---|
| 117 | $edituser->setVar('attachsig', $attachsig); |
|---|
| 118 | //$edituser->setVar('timezone_offset', $_POST['timezone_offset']); |
|---|
| 119 | $edituser->setVar('uorder', $_POST['uorder']); |
|---|
| 120 | $edituser->setVar('umode', $_POST['umode']); |
|---|
| 121 | $edituser->setVar('notify_method', $_POST['notify_method']); |
|---|
| 122 | $edituser->setVar('notify_mode', $_POST['notify_mode']); |
|---|
| 123 | $edituser->setVar('bio', xoops_substr($_POST['bio'], 0, 255)); |
|---|
| 124 | $edituser->setVar('user_occ', $_POST['user_occ']); |
|---|
| 125 | $edituser->setVar('user_intrest', $_POST['user_intrest']); |
|---|
| 126 | $edituser->setVar('user_mailok', $_POST['user_mailok']); |
|---|
| 127 | if (!empty($_POST['usecookie'])) { |
|---|
| 128 | setcookie($xoopsConfig['usercookie'], $xoopsUser->getVar('uname'), time()+ 31536000); |
|---|
| 129 | } else { |
|---|
| 130 | setcookie($xoopsConfig['usercookie']); |
|---|
| 131 | } |
|---|
| 132 | if (!$member_handler->insertUser($edituser)) { |
|---|
| 133 | include XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 134 | echo $edituser->getHtmlErrors(); |
|---|
| 135 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 136 | } else { |
|---|
| 137 | redirect_header('userinfo.php?uid='.$uid, 1, _US_PROFUPDATED); |
|---|
| 138 | } |
|---|
| 139 | exit(); |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | if ($op == 'editprofile') { |
|---|
| 145 | include_once XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 146 | include_once XOOPS_ROOT_PATH.'/include/comment_constants.php'; |
|---|
| 147 | echo '<a href="userinfo.php?uid='.$xoopsUser->getVar('uid').'">'. _US_PROFILE .'</a> <span style="font-weight:bold;">»»</span> '. _US_EDITPROFILE .'<br /><br />'; |
|---|
| 148 | $form = new XoopsThemeForm(_US_EDITPROFILE, 'userinfo', 'edituser.php'); |
|---|
| 149 | $uname_label = new XoopsFormLabel(_US_NICKNAME, $xoopsUser->getVar('uname')); |
|---|
| 150 | $form->addElement($uname_label); |
|---|
| 151 | $name_text = new XoopsFormText(_US_REALNAME, 'name', 30, 60, $xoopsUser->getVar('name', 'E')); |
|---|
| 152 | $form->addElement($name_text); |
|---|
| 153 | $email_tray = new XoopsFormElementTray(_US_EMAIL, '<br />'); |
|---|
| 154 | if ($xoopsConfigUser['allow_chgmail'] == 1) { |
|---|
| 155 | $email_text = new XoopsFormText('', 'email', 30, 60, $xoopsUser->getVar('email')); |
|---|
| 156 | } else { |
|---|
| 157 | $email_text = new XoopsFormLabel('', $xoopsUser->getVar('email')); |
|---|
| 158 | } |
|---|
| 159 | $email_tray->addElement($email_text); |
|---|
| 160 | $email_cbox_value = $xoopsUser->user_viewemail() ? 1 : 0; |
|---|
| 161 | $email_cbox = new XoopsFormCheckBox('', 'user_viewemail', $email_cbox_value); |
|---|
| 162 | $email_cbox->addOption(1, _US_ALLOWVIEWEMAIL); |
|---|
| 163 | $email_tray->addElement($email_cbox); |
|---|
| 164 | $form->addElement($email_tray); |
|---|
| 165 | $url_text = new XoopsFormText(_US_WEBSITE, 'url', 30, 100, $xoopsUser->getVar('url', 'E')); |
|---|
| 166 | $form->addElement($url_text); |
|---|
| 167 | |
|---|
| 168 | //$timezone_select = new XoopsFormSelectTimezone(_US_TIMEZONE, 'timezone_offset', $xoopsUser->getVar('timezone_offset')); |
|---|
| 169 | //$icq_text = new XoopsFormText(_US_ICQ, 'user_icq', 15, 15, $xoopsUser->getVar('user_icq', 'E')); |
|---|
| 170 | //$aim_text = new XoopsFormText(_US_AIM, 'user_aim', 18, 18, $xoopsUser->getVar('user_aim', 'E')); |
|---|
| 171 | //$yim_text = new XoopsFormText(_US_YIM, 'user_yim', 25, 25, $xoopsUser->getVar('user_yim', 'E')); |
|---|
| 172 | //$msnm_text = new XoopsFormText(_US_MSNM, 'user_msnm', 30, 100, $xoopsUser->getVar('user_msnm', 'E')); |
|---|
| 173 | $location_text = new XoopsFormText(_US_LOCATION, 'user_from', 30, 100, $xoopsUser->getVar('user_from', 'E')); |
|---|
| 174 | $occupation_text = new XoopsFormText(_US_OCCUPATION, 'user_occ', 30, 100, $xoopsUser->getVar('user_occ', 'E')); |
|---|
| 175 | $interest_text = new XoopsFormText(_US_INTEREST, 'user_intrest', 30, 150, $xoopsUser->getVar('user_intrest', 'E')); |
|---|
| 176 | $sig_tray = new XoopsFormElementTray(_US_SIGNATURE, '<br />'); |
|---|
| 177 | include_once 'include/xoopscodes.php'; |
|---|
| 178 | $sig_tarea = new XoopsFormDhtmlTextArea('', 'user_sig', $xoopsUser->getVar('user_sig', 'E')); |
|---|
| 179 | $sig_tray->addElement($sig_tarea); |
|---|
| 180 | $sig_cbox_value = $xoopsUser->getVar('attachsig') ? 1 : 0; |
|---|
| 181 | $sig_cbox = new XoopsFormCheckBox('', 'attachsig', $sig_cbox_value); |
|---|
| 182 | $sig_cbox->addOption(1, _US_SHOWSIG); |
|---|
| 183 | $sig_tray->addElement($sig_cbox); |
|---|
| 184 | $umode_select = new XoopsFormSelect(_US_CDISPLAYMODE, 'umode', $xoopsUser->getVar('umode')); |
|---|
| 185 | $umode_select->addOptionArray(array('nest'=>_NESTED, 'flat'=>_FLAT, 'thread'=>_THREADED)); |
|---|
| 186 | $uorder_select = new XoopsFormSelect(_US_CSORTORDER, 'uorder', $xoopsUser->getVar('uorder')); |
|---|
| 187 | $uorder_select->addOptionArray(array(XOOPS_COMMENT_OLD1ST => _OLDESTFIRST, XOOPS_COMMENT_NEW1ST => _NEWESTFIRST)); |
|---|
| 188 | // RMV-NOTIFY |
|---|
| 189 | // TODO: add this to admin user-edit functions... |
|---|
| 190 | include_once XOOPS_ROOT_PATH . "/language/" . $xoopsConfig['language'] . '/notification.php'; |
|---|
| 191 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
|---|
| 192 | $notify_method_select = new XoopsFormSelect(_NOT_NOTIFYMETHOD, 'notify_method', $xoopsUser->getVar('notify_method')); |
|---|
| 193 | $notify_method_select->addOptionArray(array(XOOPS_NOTIFICATION_METHOD_DISABLE=>_NOT_METHOD_DISABLE, XOOPS_NOTIFICATION_METHOD_PM=>_NOT_METHOD_PM, XOOPS_NOTIFICATION_METHOD_EMAIL=>_NOT_METHOD_EMAIL)); |
|---|
| 194 | $notify_mode_select = new XoopsFormSelect(_NOT_NOTIFYMODE, 'notify_mode', $xoopsUser->getVar('notify_mode')); |
|---|
| 195 | $notify_mode_select->addOptionArray(array(XOOPS_NOTIFICATION_MODE_SENDALWAYS=>_NOT_MODE_SENDALWAYS, XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE=>_NOT_MODE_SENDONCE, XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT=>_NOT_MODE_SENDONCEPERLOGIN)); |
|---|
| 196 | $bio_tarea = new XoopsFormTextArea(_US_EXTRAINFO, 'bio', $xoopsUser->getVar('bio', 'E')); |
|---|
| 197 | $cookie_radio_value = empty($_COOKIE[$xoopsConfig['usercookie']]) ? 0 : 1; |
|---|
| 198 | $cookie_radio = new XoopsFormRadioYN(_US_USECOOKIE, 'usecookie', $cookie_radio_value, _YES, _NO); |
|---|
| 199 | $pwd_text = new XoopsFormPassword('', 'password', 10, 32); |
|---|
| 200 | $pwd_text2 = new XoopsFormPassword('', 'vpass', 10, 32); |
|---|
| 201 | $pwd_tray = new XoopsFormElementTray(_US_PASSWORD.'<br />'._US_TYPEPASSTWICE); |
|---|
| 202 | $pwd_tray->addElement($pwd_text); |
|---|
| 203 | $pwd_tray->addElement($pwd_text2); |
|---|
| 204 | $mailok_radio = new XoopsFormRadioYN(_US_MAILOK, 'user_mailok', $xoopsUser->getVar('user_mailok')); |
|---|
| 205 | $uid_hidden = new XoopsFormHidden('uid', $xoopsUser->getVar('uid')); |
|---|
| 206 | $op_hidden = new XoopsFormHidden('op', 'saveuser'); |
|---|
| 207 | $token_hidden = new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('edituser')); |
|---|
| 208 | $submit_button = new XoopsFormButton('', 'submit', _US_SAVECHANGES, 'submit'); |
|---|
| 209 | |
|---|
| 210 | $form->addElement($timezone_select); |
|---|
| 211 | //$form->addElement($icq_text); |
|---|
| 212 | //$form->addElement($aim_text); |
|---|
| 213 | //$form->addElement($yim_text); |
|---|
| 214 | //$form->addElement($msnm_text); |
|---|
| 215 | $form->addElement($location_text); |
|---|
| 216 | $form->addElement($occupation_text); |
|---|
| 217 | $form->addElement($interest_text); |
|---|
| 218 | $form->addElement($sig_tray); |
|---|
| 219 | $form->addElement($umode_select); |
|---|
| 220 | $form->addElement($uorder_select); |
|---|
| 221 | $form->addElement($notify_method_select); |
|---|
| 222 | $form->addElement($notify_mode_select); |
|---|
| 223 | $form->addElement($bio_tarea); |
|---|
| 224 | $form->addElement($pwd_tray); |
|---|
| 225 | $form->addElement($cookie_radio); |
|---|
| 226 | $form->addElement($mailok_radio); |
|---|
| 227 | $form->addElement($uid_hidden); |
|---|
| 228 | $form->addElement($op_hidden); |
|---|
| 229 | $form->addElement($token_hidden); |
|---|
| 230 | $form->addElement($submit_button); |
|---|
| 231 | if ($xoopsConfigUser['allow_chgmail'] == 1) { |
|---|
| 232 | $form->setRequired($email_text); |
|---|
| 233 | } |
|---|
| 234 | $form->display(); |
|---|
| 235 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | if ($op == 'avatarform') { |
|---|
| 240 | include XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 241 | echo '<a href="userinfo.php?uid='.$xoopsUser->getVar('uid').'">'. _US_PROFILE .'</a> <span style="font-weight:bold;">»»</span> '. _US_UPLOADMYAVATAR .'<br /><br />'; |
|---|
| 242 | $oldavatar = $xoopsUser->getVar('user_avatar'); |
|---|
| 243 | if (!empty($oldavatar) && $oldavatar != 'blank.gif') { |
|---|
| 244 | echo '<div style="text-align:center;"><h4 style="color:#ff0000; font-weight:bold;">'._US_OLDDELETED.'</h4>'; |
|---|
| 245 | echo '<img src="'.XOOPS_UPLOAD_URL.'/'.$oldavatar.'" alt="" /></div>'; |
|---|
| 246 | } |
|---|
| 247 | if ($xoopsConfigUser['avatar_allow_upload'] == 1 && $xoopsUser->getVar('posts') >= $xoopsConfigUser['avatar_minposts']) { |
|---|
| 248 | include_once 'class/xoopsformloader.php'; |
|---|
| 249 | $form = new XoopsThemeForm(_US_UPLOADMYAVATAR, 'uploadavatar', 'edituser.php'); |
|---|
| 250 | $form->setExtra('enctype="multipart/form-data"'); |
|---|
| 251 | $form->addElement(new XoopsFormLabel(_US_MAXPIXEL, $xoopsConfigUser['avatar_width'].' x '.$xoopsConfigUser['avatar_height'])); |
|---|
| 252 | $form->addElement(new XoopsFormLabel(_US_MAXIMGSZ, $xoopsConfigUser['avatar_maxsize'])); |
|---|
| 253 | $form->addElement(new XoopsFormFile(_US_SELFILE, 'avatarfile', $xoopsConfigUser['avatar_maxsize']), true); |
|---|
| 254 | $form->addElement(new XoopsFormHidden('op', 'avatarupload')); |
|---|
| 255 | $form->addElement(new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('avatarupload'))); |
|---|
| 256 | $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid'))); |
|---|
| 257 | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|---|
| 258 | $form->display(); |
|---|
| 259 | } |
|---|
| 260 | $avatar_handler =& xoops_gethandler('avatar'); |
|---|
| 261 | $form2 = new XoopsThemeForm(_US_CHOOSEAVT, 'uploadavatar', 'edituser.php'); |
|---|
| 262 | $avatar_select = new XoopsFormSelect('', 'user_avatar', $xoopsUser->getVar('user_avatar')); |
|---|
| 263 | $avatar_select->addOptionArray($avatar_handler->getList('S')); |
|---|
| 264 | $avatar_select->setExtra("onchange='showImgSelected(\"avatar\", \"user_avatar\", \"uploads\", \"\", \"".XOOPS_URL."\")'"); |
|---|
| 265 | $avatar_tray = new XoopsFormElementTray(_US_AVATAR, ' '); |
|---|
| 266 | $avatar_tray->addElement($avatar_select); |
|---|
| 267 | $avatar_tray->addElement(new XoopsFormLabel('', "<img src='".XOOPS_UPLOAD_URL."/".$xoopsUser->getVar("user_avatar", "E")."' name='avatar' id='avatar' alt='' /> <a href=\"javascript:openWithSelfMain('".XOOPS_URL."/misc.php?action=showpopups&type=avatars','avatars',600,400);\">"._LIST."</a>")); |
|---|
| 268 | $form2->addElement($avatar_tray); |
|---|
| 269 | $form2->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid'))); |
|---|
| 270 | $form2->addElement(new XoopsFormHidden('op', 'avatarchoose')); |
|---|
| 271 | $form2->addElement(new XoopsFormToken(XoopsSingleTokenHandler::quickCreate('avatarchoose'))); |
|---|
| 272 | $form2->addElement(new XoopsFormButton('', 'submit2', _SUBMIT, 'submit')); |
|---|
| 273 | $form2->display(); |
|---|
| 274 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 275 | } |
|---|
| 276 | |
|---|
| 277 | if ($op == 'avatarupload') { |
|---|
| 278 | if (!XoopsSingleTokenHandler::quickValidate('avatarupload')) { |
|---|
| 279 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 280 | exit; |
|---|
| 281 | } |
|---|
| 282 | $xoops_upload_file = array(); |
|---|
| 283 | $uid = 0; |
|---|
| 284 | if (!empty($_POST['xoops_upload_file']) && is_array($_POST['xoops_upload_file'])){ |
|---|
| 285 | $xoops_upload_file = $_POST['xoops_upload_file']; |
|---|
| 286 | } |
|---|
| 287 | if (!empty($_POST['uid'])) { |
|---|
| 288 | $uid = intval($_POST['uid']); |
|---|
| 289 | } |
|---|
| 290 | if (empty($uid) || $xoopsUser->getVar('uid') != $uid ) { |
|---|
| 291 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 292 | exit(); |
|---|
| 293 | } |
|---|
| 294 | if ($xoopsConfigUser['avatar_allow_upload'] == 1 && $xoopsUser->getVar('posts') >= $xoopsConfigUser['avatar_minposts']) { |
|---|
| 295 | include_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|---|
| 296 | $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'), $xoopsConfigUser['avatar_maxsize'], $xoopsConfigUser['avatar_width'], $xoopsConfigUser['avatar_height']); |
|---|
| 297 | $uploader->setAllowedExtensions(array('gif', 'jpeg', 'jpg', 'png')); |
|---|
| 298 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
|---|
| 299 | $uploader->setPrefix('cavt'); |
|---|
| 300 | if ($uploader->upload()) { |
|---|
| 301 | $avt_handler =& xoops_gethandler('avatar'); |
|---|
| 302 | $avatar =& $avt_handler->create(); |
|---|
| 303 | $avatar->setVar('avatar_file', $uploader->getSavedFileName()); |
|---|
| 304 | $avatar->setVar('avatar_name', $xoopsUser->getVar('uname')); |
|---|
| 305 | $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); |
|---|
| 306 | $avatar->setVar('avatar_display', 1); |
|---|
| 307 | $avatar->setVar('avatar_type', 'C'); |
|---|
| 308 | if (!$avt_handler->insert($avatar)) { |
|---|
| 309 | @unlink($uploader->getSavedDestination()); |
|---|
| 310 | } else { |
|---|
| 311 | $oldavatar = $xoopsUser->getVar('user_avatar'); |
|---|
| 312 | if (!empty($oldavatar) && $oldavatar != 'blank.gif' && !preg_match("/^savt/", strtolower($oldavatar))) { |
|---|
| 313 | $avatars =& $avt_handler->getObjects(new Criteria('avatar_file', $oldavatar)); |
|---|
| 314 | $avt_handler->delete($avatars[0]); |
|---|
| 315 | $oldavatar_path = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.$oldavatar)); |
|---|
| 316 | if (0 === strpos($oldavatar_path, XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) { |
|---|
| 317 | unlink($oldavatar_path); |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | $sql = sprintf("UPDATE %s SET user_avatar = %s WHERE uid = %u", $xoopsDB->prefix('users'), $xoopsDB->quoteString($uploader->getSavedFileName()), $xoopsUser->getVar('uid')); |
|---|
| 321 | $xoopsDB->query($sql); |
|---|
| 322 | $avt_handler->addUser($avatar->getVar('avatar_id'), $xoopsUser->getVar('uid')); |
|---|
| 323 | redirect_header('userinfo.php?t='.time().'&uid='.$xoopsUser->getVar('uid'),0, _US_PROFUPDATED); |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | include XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 328 | echo $uploader->getErrors(); |
|---|
| 329 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | if ($op == 'avatarchoose') { |
|---|
| 334 | if (!XoopsSingleTokenHandler::quickValidate('avatarchoose')) { |
|---|
| 335 | redirect_header('index.php',3,_US_NOEDITRIGHT); |
|---|
| 336 | exit; |
|---|
| 337 | } |
|---|
| 338 | $uid = 0; |
|---|
| 339 | if (!empty($_POST['uid'])) { |
|---|
| 340 | $uid = intval($_POST['uid']); |
|---|
| 341 | } |
|---|
| 342 | if (empty($uid) || $xoopsUser->getVar('uid') != $uid ) { |
|---|
| 343 | redirect_header('index.php', 3, _US_NOEDITRIGHT); |
|---|
| 344 | exit(); |
|---|
| 345 | } |
|---|
| 346 | $avt_handler =& xoops_gethandler('avatar'); |
|---|
| 347 | $user_avatar = 'blank.gif'; |
|---|
| 348 | $user_avatar_object = false; |
|---|
| 349 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 350 | if ($user_avatar_req = trim($myts->stripSlashesGPC($_POST['user_avatar']))) { |
|---|
| 351 | // allow system avatar selection only |
|---|
| 352 | if (preg_match("/^savt/", $user_avatar_req)) { |
|---|
| 353 | $criteria =& new CriteriaCompo(new Criteria('avatar_file', addslashes($user_avatar_req))); |
|---|
| 354 | $criteria->add(new Criteria('avatar_type', 'S')); |
|---|
| 355 | if ($avatars = $avt_handler->getObjects($criteria)) { |
|---|
| 356 | if (is_object($avatars[0])) { |
|---|
| 357 | $user_avatar = $avatars[0]->getVar('avatar_file'); |
|---|
| 358 | $user_avatar_object =& $avatars[0]; |
|---|
| 359 | } |
|---|
| 360 | } |
|---|
| 361 | } |
|---|
| 362 | } |
|---|
| 363 | $user_avatarpath = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.$user_avatar)); |
|---|
| 364 | if (0 === strpos($user_avatarpath, XOOPS_UPLOAD_PATH) && is_file($user_avatarpath)) { |
|---|
| 365 | $oldavatar = $xoopsUser->getVar('user_avatar'); |
|---|
| 366 | $xoopsUser->setVar('user_avatar', $user_avatar); |
|---|
| 367 | $member_handler =& xoops_gethandler('member'); |
|---|
| 368 | if (!$member_handler->insertUser($xoopsUser)) { |
|---|
| 369 | include XOOPS_ROOT_PATH.'/header.php'; |
|---|
| 370 | echo $xoopsUser->getHtmlErrors(); |
|---|
| 371 | include XOOPS_ROOT_PATH.'/footer.php'; |
|---|
| 372 | exit(); |
|---|
| 373 | } |
|---|
| 374 | if ($oldavatar && $oldavatar != 'blank.gif' && preg_match("/^cavt/", strtolower($oldavatar))) { |
|---|
| 375 | $criteria =& new CriteriaCompo(new Criteria('avatar_file', addslashes($oldavatar))); |
|---|
| 376 | $criteria->add(new Criteria('avatar_type', 'C')); |
|---|
| 377 | $avatars =& $avt_handler->getObjects($criteria); |
|---|
| 378 | if (is_object($avatars[0])) { |
|---|
| 379 | $avt_handler->delete($avatars[0]); |
|---|
| 380 | } |
|---|
| 381 | $oldavatar_path = str_replace("\\", "/", realpath(XOOPS_UPLOAD_PATH.'/'.$oldavatar)); |
|---|
| 382 | if (0 === strpos($oldavatar_path, XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) { |
|---|
| 383 | unlink($oldavatar_path); |
|---|
| 384 | } |
|---|
| 385 | } |
|---|
| 386 | if (is_object($user_avatar_object)) { |
|---|
| 387 | $avt_handler->addUser($user_avatar_object->getVar('avatar_id'), $xoopsUser->getVar('uid')); |
|---|
| 388 | } |
|---|
| 389 | } |
|---|
| 390 | redirect_header('userinfo.php?uid='.$uid, 0, _US_PROFUPDATED); |
|---|
| 391 | } |
|---|
| 392 | ?> |
|---|