| [ Index ] |
PHP Cross Reference of Xoops v2.4.5 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Extended User Profile 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 13 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 14 * @package profile 15 * @since 2.3.0 16 * @author Taiwen Jiang <phppp@users.sourceforge.net> 17 * @author Jan Pedersen 18 * @author trabis <lusopoemas@gmail.com> 19 * @version $Id: register.php 3988 2009-12-05 15:46:47Z trabis $ 20 */ 21 22 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'header.php'; 23 24 if ($GLOBALS['xoopsUser']) { 25 header('location: userinfo.php?uid= ' . $GLOBALS['xoopsUser']->getVar('uid')); 26 exit(); 27 } 28 29 if (!empty($_GET['op']) && in_array($_GET['op'], array('actv', 'activate'))) { 30 header("location: ./activate.php" . (empty($_SERVER['QUERY_STRING']) ? "" : "?" . $_SERVER['QUERY_STRING'])); 31 exit(); 32 } 33 34 xoops_load('XoopsUserUtility'); 35 $myts =& MyTextSanitizer::getInstance(); 36 37 $config_handler =& xoops_gethandler('config'); 38 $GLOBALS['xoopsConfigUser'] = $config_handler->getConfigsByCat(XOOPS_CONF_USER); 39 if (empty($GLOBALS['xoopsConfigUser']['allow_register'])) { 40 redirect_header('index.php', 6, _US_NOREGISTER); 41 exit(); 42 } 43 44 $op = !isset($_POST['op']) ? 'register' : $_POST['op']; 45 $uid = isset($_POST['uid']) ? intval( $_POST['uid'] ) : 0; 46 $current_step = isset($_POST['step']) ? intval( $_POST['step'] ) : 0; 47 48 // First step is already secured by with the captcha Token so lets check the others 49 if ($current_step > 0 && !$GLOBALS['xoopsSecurity']->check()) { 50 redirect_header('user.php', 5, _PROFILE_MA_EXPIRED); 51 exit(); 52 } 53 54 $criteria = new CriteriaCompo(); 55 $criteria->setSort("step_order"); 56 $regstep_handler = xoops_getmodulehandler('regstep'); 57 58 if (!$steps = $regstep_handler->getAll($criteria, null, false, false)) { 59 redirect_header(XOOPS_URL . '/', 6, _PROFILE_MA_NOSTEPSAVAILABLE); 60 exit(); 61 } 62 63 foreach (array_keys($steps) as $key) { 64 $steps[$key]['step_no'] = $key + 1; 65 } 66 67 $xoopsOption['template_main'] = 'profile_register.html'; 68 include $GLOBALS['xoops']->path('header.php'); 69 70 $GLOBALS['xoopsTpl']->assign('steps', $steps); 71 $GLOBALS['xoopsTpl']->assign('lang_register_steps', _PROFILE_MA_REGISTER_STEPS); 72 73 $xoBreadcrumbs[] = array('link' => XOOPS_URL . "/modules/" . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/register.php', 'title' => _PROFILE_MA_REGISTER); 74 if (isset($steps[$current_step])) { 75 $xoBreadcrumbs[] = array('title' => $steps[$current_step]['step_name']); 76 } 77 78 $member_handler =& xoops_gethandler('member'); 79 $profile_handler = xoops_getmodulehandler('profile'); 80 81 $fields = $profile_handler->loadFields(); 82 $userfields = $profile_handler->getUserVars(); 83 84 if ($uid == 0) { 85 // No user yet? Create one and set default values. 86 $newuser = $member_handler->createUser(); 87 $profile = $profile_handler->create(); 88 if (count($fields) > 0) { 89 foreach (array_keys($fields) as $i) { 90 $fieldname = $fields[$i]->getVar('field_name'); 91 if (in_array($fieldname, $userfields)) { 92 $default = $fields[$i]->getVar('field_default'); 93 if ($default === '' || $default === null) { 94 continue; 95 } 96 $newuser->setVar($fieldname, $default); 97 } 98 } 99 } 100 } else { 101 // We already have a user? Just load it! Security is handled by token so there is no fake uid here. 102 $newuser = $member_handler->getUser($uid); 103 $profile = $profile_handler->get($uid); 104 } 105 106 // Lets merge current $_POST with $_SESSION['profile_post'] so we can have access to info submited in previous steps 107 // Get all fields that we can expect from a $_POST inlcuding our private '_message_' 108 $fieldnames = array(); 109 foreach (array_keys($fields) as $i ) { 110 $fieldnames[] = $fields[$i]->getVar('field_name'); 111 } 112 $fieldnames = array_merge($fieldnames, $userfields); 113 $fieldnames[] = '_message_'; 114 115 // Get $_POST that matches above criteria, we do not need to store step, tokens, etc 116 $postfields = array(); 117 foreach ($fieldnames as $fieldname ) { 118 if (isset($_POST[$fieldname])) { 119 $postfields[$fieldname] = $_POST[$fieldname]; 120 } 121 } 122 123 if ($current_step == 0) { 124 // Reset any previous session for first step 125 $_SESSION['profile_post'] = array(); 126 } else { 127 // Merge current $_POST with $_SESSION['profile_post'] 128 $_SESSION['profile_post'] = array_merge($_SESSION['profile_post'], $postfields); 129 $_POST = array_merge($_SESSION['profile_post'], $_POST); 130 } 131 132 // Set vars from $_POST/$_SESSION['profile_post'] 133 foreach (array_keys($fields) as $field) { 134 if (!isset($_POST[$field])) { 135 continue; 136 } 137 138 $value = $fields[$field]->getValueForSave($_POST[$field]); 139 if (in_array($field, $userfields)) { 140 $newuser->setVar($field, $value); 141 } else { 142 $profile->setVar($field, $value); 143 } 144 } 145 146 $stop = ''; 147 148 // Check user data at first step 149 if ($current_step == 1) { 150 $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC(trim($_POST['uname']) ) : ''; 151 $email = isset($_POST['email']) ? $myts->stripSlashesGPC(trim($_POST['email']) ) : ''; 152 $url = isset($_POST['url']) ? $myts->stripSlashesGPC(trim($_POST['url']) ) : ''; 153 $pass = isset($_POST['pass']) ? $myts->stripSlashesGPC(trim($_POST['pass']) ) : ''; 154 $vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC(trim($_POST['vpass']) ) : ''; 155 $agree_disc = (isset($_POST['agree_disc']) && intval($_POST['agree_disc']) ) ? 1 : 0; 156 157 if ($GLOBALS['xoopsConfigUser']['reg_dispdsclmr'] != 0 && $GLOBALS['xoopsConfigUser']['reg_disclaimer'] != '') { 158 if (empty($agree_disc)) { 159 $stop .= _US_UNEEDAGREE . '<br />'; 160 } 161 } 162 163 $newuser->setVar('uname', $uname); 164 $newuser->setVar('email', $email); 165 $newuser->setVar('pass', $pass ? md5($pass) : ''); 166 $stop .= XoopsUserUtility::validate($newuser, $pass, $vpass); 167 168 xoops_load('XoopsCaptcha'); 169 $xoopsCaptcha = XoopsCaptcha::getInstance(); 170 if (!$xoopsCaptcha->verify()) { 171 $stop .= $xoopsCaptcha->getMessage(); 172 } 173 } 174 175 // If the last step required SAVE or if we're on the last step then we will insert/update user on database 176 if ($current_step > 0 && empty($stop) && (!empty($steps[$current_step - 1]['step_save']) || !isset($steps[$current_step]))) { 177 178 $isNew = $newuser->isNew(); 179 180 //Did created an user already? If not then let us set some extra info 181 if ($isNew) { 182 $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC(trim($_POST['uname'])) : ''; 183 $email = isset($_POST['email']) ? $myts->stripSlashesGPC(trim($_POST['email'])) : ''; 184 $url = isset($_POST['url']) ? $myts->stripSlashesGPC(trim($_POST['url'])) : ''; 185 $pass = isset($_POST['pass']) ? $myts->stripSlashesGPC(trim($_POST['pass'])) : ''; 186 $newuser->setVar('uname', $uname); 187 $newuser->setVar('email', $email); 188 $newuser->setVar('pass', $pass ? md5($pass) : ''); 189 $actkey = substr(md5(uniqid(mt_rand(), 1) ), 0, 8); 190 $newuser->setVar('actkey', $actkey, true); 191 $newuser->setVar('user_regdate', time(), true); 192 if ($GLOBALS['xoopsConfigUser']['activation_type'] == 1) { 193 $newuser->setVar('level', 1, true); 194 } else { 195 $newuser->setVar('level', 0, true); 196 } 197 } 198 199 // Insert/update user and check if we have succeded 200 if (!$member_handler->insertUser($newuser)) { 201 $stop .= _US_REGISTERNG . "<br />"; 202 $stop .= implode('<br />', $newuser->getErrors() ); 203 } else { 204 // User inserted! Now insert custom profile fields 205 $profile->setVar('profile_id', $newuser->getVar('uid') ); 206 $profile_handler->insert($profile); 207 208 // We are good! If this is 'was' a new user then we handle notification 209 if ($isNew) { 210 if ($GLOBALS['xoopsConfigUser']['new_user_notify'] == 1 && !empty($GLOBALS['xoopsConfigUser']['new_user_notify_group'])) { 211 $xoopsMailer =& xoops_getMailer(); 212 $xoopsMailer->reset(); 213 $xoopsMailer->useMail(); 214 $xoopsMailer->setToGroups($member_handler->getGroup($GLOBALS['xoopsConfigUser']['new_user_notify_group'])); 215 $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); 216 $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); 217 $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT,$GLOBALS['xoopsConfig']['sitename'])); 218 $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $newuser->getVar('uname'))); 219 $xoopsMailer->send(true); 220 } 221 222 $message = ""; 223 if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newuser->getVar('uid'))) { 224 $message = _PROFILE_MA_REGISTER_NOTGROUP . "<br />"; 225 } else if ($GLOBALS['xoopsConfigUser']['activation_type'] == 1) { 226 XoopsUserUtility::sendWelcome($newuser); 227 } else if ($GLOBALS['xoopsConfigUser']['activation_type'] == 0) { 228 $xoopsMailer =& xoops_getMailer(); 229 $xoopsMailer->reset(); 230 $xoopsMailer->useMail(); 231 $xoopsMailer->setTemplate('register.tpl'); 232 $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); 233 $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); 234 $xoopsMailer->assign('SITEURL', XOOPS_URL."/"); 235 $xoopsMailer->assign('X_UPASS', $_POST['vpass']); 236 $xoopsMailer->setToUsers($newuser); 237 $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); 238 $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); 239 $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname'))); 240 if (!$xoopsMailer->send(true)) { 241 $_SESSION['profile_post']['_message_'] = 0; 242 } else { 243 $_SESSION['profile_post']['_message_'] = 1; 244 } 245 } else if ($GLOBALS['xoopsConfigUser']['activation_type'] == 2) { 246 $xoopsMailer =& xoops_getMailer(); 247 $xoopsMailer->reset(); 248 $xoopsMailer->useMail(); 249 $xoopsMailer->setTemplate('adminactivate.tpl'); 250 $xoopsMailer->assign('USERNAME', $newuser->getVar('uname')); 251 $xoopsMailer->assign('USEREMAIL', $newuser->getVar('email')); 252 $xoopsMailer->assign('USERACTLINK', XOOPS_URL . "/modules/" . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/activate.php?id=' . $newuser->getVar('uid') . '&actkey=' . $newuser->getVar('actkey', 'n')); 253 $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); 254 $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); 255 $xoopsMailer->assign('SITEURL', XOOPS_URL . "/"); 256 $xoopsMailer->setToGroups($member_handler->getGroup($GLOBALS['xoopsConfigUser']['activation_group'])); 257 $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); 258 $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); 259 $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname'))); 260 if (!$xoopsMailer->send()) { 261 $_SESSION['profile_post']['_message_'] = 2; 262 } else { 263 $_SESSION['profile_post']['_message_'] = 3; 264 } 265 } 266 if ($message) { 267 $GLOBALS['xoopsTpl']->append('confirm', $message); 268 } 269 } 270 } 271 } 272 273 if (!empty($stop) || isset($steps[$current_step])) { 274 include_once dirname(__FILE__) . '/include/forms.php'; 275 $current_step = empty($stop) ? $current_step : $current_step - 1; 276 $reg_form = profile_getRegisterForm($newuser, $profile, $steps[$current_step]); 277 $reg_form->assign($GLOBALS['xoopsTpl']); 278 $GLOBALS['xoopsTpl']->assign('current_step', $current_step); 279 $GLOBALS['xoopsTpl']->assign('stop', $stop); 280 } else { 281 // No errors and no more steps, finish 282 $GLOBALS['xoopsTpl']->assign('finish', _PROFILE_MA_REGISTER_FINISH); 283 $GLOBALS['xoopsTpl']->assign('current_step', -1); 284 if ( $GLOBALS['xoopsConfigUser']['activation_type'] == 1 && !empty($_SESSION['profile_post']['pass'])) { 285 $GLOBALS['xoopsTpl']->assign('finish_login', _PROFILE_MA_FINISH_LOGIN); 286 $GLOBALS['xoopsTpl']->assign('finish_uname', $newuser->getVar('uname')); 287 $GLOBALS['xoopsTpl']->assign('finish_pass', htmlspecialchars($_SESSION['profile_post']['pass'])); 288 } 289 if (isset($_SESSION['profile_post']['_message_'])) { 290 //todo, if user is activated by admin, then we should inform it along with error messages. _US_YOURREGMAILNG is not enough 291 $messages = array(_US_YOURREGMAILNG, _US_YOURREGISTERED, _US_YOURREGMAILNG, _US_YOURREGISTERED2); 292 $GLOBALS['xoopsTpl']->assign('finish_message', $messages[$_SESSION['profile_post']['_message_']]); 293 } 294 $_SESSION['profile_post'] = null; 295 } 296 297 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'footer.php'; 298 299 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 01:39:09 2010 |