/** * Save user data * * @param bool Indicates when is a edit */ function save_data($edit = false) { global $xoopsSecurity, $xoopsDB; $q = ''; // Query String foreach ($_POST as $k => $v) { ${$k} = $v; if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'sbt' || $k == 'action' || $k == 'password' || $k == 'passwordc') { continue; } $q .= $q == '' ? "{$k}=" . urlencode($v) : "&{$k}=" . urlencode($v); } if (!$xoopsSecurity->check()) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Sorry, you don\'t have permission to add users.', 'rmcommon'), 1); die; } if ($edit) { if ($uid <= 0) { redirectMsg('users.php', __('The specified user is not valid!', 'rmcommon'), 1); die; } $user = new RMUser($uid); if ($user->isNew()) { redirectMsg('users.php', __('The specified user does not exists!', 'rmcommon'), 1); die; } } else { $user = new RMUser(); } // Check uname, password and passwordc if ($uname == '' || $email == '' || !$edit && ($password == '' || $passwordc == '')) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Please fill all required fields and try again!', 'rmcommon'), 1); die; } // Check passwords if ($password != $passwordc) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Passwords doesn\'t match. Please chek them.', 'rmcommon'), 1); die; } // Check if user exists $sql = "SELECT COUNT(*) FROM " . $xoopsDB->prefix("users") . " WHERE (uname = '{$uname}' OR email = '{$email}')" . ($edit ? " AND uid != " . $user->uid : ''); list($exists) = $xoopsDB->fetchRow($xoopsDB->query($sql)); if ($exists > 0) { RMUris::redirect_with_message(__('Another user with same username or email already exists!', 'rmcommon'), 'users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, RMMSG_ERROR); } // Save user data $user->setVar('name', $name); $user->setVar('uname', $uname); $user->setVar('display_name', $display_name); $user->setVar('email', $email); if (!$edit) { $user->assignVar('user_regdate', time()); } if ($password != '') { $user->assignVar('pass', md5($password)); } $user->setVar('level', 1); $user->setVar('timezone_offset', $timezone); $user->setVar('url', $url); /** * If "All" has been selected then we need to get all * groups ID's */ if (in_array(0, $groups)) { $groups = array(); $result = $xoopsDB->query("SELECT groupid FROm " . $xoopsDB->prefix("groups")); while ($row = $xoopsDB->fetchArray($result)) { $groups[] = $row['groupid']; } unset($result); } /** * If no group has been selected, then we add user to * Anonymous group */ if (empty($groups)) { $groups = array(XOOPS_GROUP_ANONYMOUS); } $user->setGroups($groups); // Plugins and modules can save metadata. // Metadata are generated by other dynamical fields $user = RMEvents::get()->run_event('rmcommon.add.usermeta.4save', $user); if ($user->save()) { $user = RMEvents::get()->run_event($edit ? 'rmcommon.user.edited' : 'rmcommon.user.created', $user); redirectMsg('users.php', __('Database updated successfully!', 'rmcommon'), 0); } else { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('The users could not be saved. Please try again!', 'rmcommon') . '<br />' . $user->errors(), 1); } }
/** * Save user data * * @param bool Indicates when is a edit */ function save_data($edit = false) { global $xoopsSecurity; $q = ''; // Query String foreach ($_POST as $k => $v) { ${$k} = $v; if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'sbt' || $k == 'action' || $k == 'password' || $k == 'passwordc') { continue; } $q .= $q == '' ? "{$k}=" . urlencode($v) : "&{$k}=" . urlencode($v); } if (!$xoopsSecurity->check()) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Sorry, you don\'t have permission to add users.', 'rmcommon'), 1); die; } if ($edit) { if ($uid <= 0) { redirectMsg('users.php', __('The specified user is not valid!', 'rmcommon'), 1); die; } $user = new RMUser($uid); if ($user->isNew()) { redirectMsg('users.php', __('The specified user does not exists!', 'rmcommon'), 1); die; } } else { $user = new RMUser(); } // Check uname, password and passwordc if ($uname == '' || $email == '' || !$edit && ($password == '' || $passwordc == '')) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Please fill all required fields and try again!', 'rmcommon'), 1); die; } // Check passwords if ($password != $passwordc) { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Passwords doesn\'t match. Please chek them.', 'rmcommon'), 1); die; } // Save user data $user->setVar('name', $name); $user->setVar('uname', $uname); $user->setVar('display_name', $display_name); $user->setVar('email', $email); if (!$edit) { $user->assignVar('user_regdate', time()); } if ($password != '') { $user->assignVar('pass', md5($password)); } $user->setVar('level', 1); $user->setVar('timezone_offset', $timezone); $user->setVar('url', $url); $user->setGroups($groups); // Plugins and modules can save metadata. // Metadata are generated by other dynamical fields $user = RMEvents::get()->run_event('rmcommon.add.usermeta.4save', $user); if ($user->save()) { $user = RMEvents::get()->run_event($edit ? 'rmcommon.user.edited' : 'rmcommon.user.created', $user); redirectMsg('users.php', __('Database updated successfully!', 'rmcommon'), 0); } else { redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('The users could not be saved. Please try again!', 'rmcommon') . '<br />' . $user->errors(), 1); } }